hegel icon indicating copy to clipboard operation
hegel copied to clipboard

editing of union object in function is unsound

Open thecotne opened this issue 5 years ago • 1 comments

function process(a: { value: true } | { value: false }) {
  a.value = false;
}

const CONSTANT: { value: true } = { value: true };

process(CONSTANT);

try

type Data = { a: string } | { a: number }

function notOk(data: Data) {
  data.a = 'sdsds' // should error
}

function ok(data: Data) {
  if (typeof data.a === 'string') {
    data.a = 'sds' // ok
  }
  if (typeof data.a === 'number') {
    data.a = 111 // ok
  }
}

try

thecotne avatar May 14 '20 22:05 thecotne

Oops. Will try to fix it.

JSMonk avatar May 14 '20 22:05 JSMonk