#Why does TS Narrow variables with a type annotation?
8 messages · Page 1 of 1 (latest)
8 messages · Page 1 of 1 (latest)
Can someone explain this behavior? I explicitly annotated a variable to boolean and it's not a constant. But TS typeof operator narrows the type and uses the current value.
let a: boolean = true;
// ^? let a: boolean
type A = typeof a;
// ^? type A = true
It knows at this point of execution a must be true.
If you add a line of a = false then it changes to a different type.