You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// @ts-check// NOTE: Problem only happens when strictNullChecks is on. // repro: https://www.typescriptlang.org/play?strictNullChecks=true&ts=3.9.3&useJavaScript=true#/** * * @typedef Thing * @property {number} id *//** * @param {Thing|null} variable * @return {variable is Thing} */constisNotNull=variable=>variable!==null;/** * @param {Thing|null} thing */constfn=thing=>{thing;// as expected, type is Thing | nullif(isNotNull(thing)){thing;// as expected, type is Thingthing.id;// no error}constisAvailable=isNotNull(thing);if(isAvailable){thing;// unexpected: type is Thing | nullthing.id;// error: Object is possibly null}};
Expected behavior:
In the body of the second if, thing will be typed as Thing.
Actual behavior:
In the body of the second if, thing is typed as Thing | null
TypeScript Version: seen in 3.8.3, 3.9.2, 3.9.3, nightly
Search Terms: "jsdoc" "typescript" "strictnullcheck" "type guard"
Code
Expected behavior:
In the body of the second
if
,thing
will be typed asThing
.Actual behavior:
In the body of the second
if
,thing
is typed asThing | null
Playground Link: https://www.typescriptlang.org/play?strictNullChecks=true&ts=3.9.2&useJavaScript=true
Related Issues: no
The text was updated successfully, but these errors were encountered: