Closed
Description
Bug Report
A type-asserted variable from unknown
, would become unknown
again at once its value changed
🔎 Search Terms
🕗 Version & Regression Information
- This problem could be reproduced between versions 4.3.5 (earlier versions not tested) and latest nightly
⏯ Playground Link
Playground link with relevant code
💻 Code
function isNumber(s: unknown): s is number { // it's the same even changed to string or other types
return typeof s === 'number';
}
let c: unknown = 123;
if (!isNumber(c)) {
throw new TypeError('what?');
}
c = c + 1;
/**
* Why would an asserted number become unknown again?
*/
if (c + 1 === 0) {
console.log(c);
}
🙁 Actual behavior
the assert number-typed variable c
became unknown
again.
🙂 Expected behavior
It should keep being number
type