hegel
hegel copied to clipboard
editing of union object in function is unsound
function process(a: { value: true } | { value: false }) {
a.value = false;
}
const CONSTANT: { value: true } = { value: true };
process(CONSTANT);
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
}
}
Oops. Will try to fix it.