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
Expected behavior: foo and quux both pass type checking with strict null checks.
Actual behavior: foo is fine, but tsc complains about something.bar.baz in quux. It is almost like it interprets it as (true || something.bar) && something.bar.baz which would indeed be unsafe.
Uh oh!
There was an error while loading. Please reload this page.
OR-ing an expression which passes type checking with
true
causes that expression to fail type checking.TypeScript Version: 3.6.0-dev.20190611
Search Terms: boolean logic strict null check confused or with true
Code
Expected behavior:
foo
andquux
both pass type checking with strict null checks.Actual behavior:
foo
is fine, but tsc complains aboutsomething.bar.baz
inquux
. It is almost like it interprets it as(true || something.bar) && something.bar.baz
which would indeed be unsafe.Playground Link: https://www.typescriptlang.org/play/#src=type%20Foo%20%3D%20%7B%20bar%3F%3A%20%7B%20baz%3F%3A%20string%20%7D%20%7D%3B%0D%0Aconst%20foo%20%3D%20(something%3A%20Foo)%20%3D%3E%20(something.bar%20%26%26%20something.bar.baz)%3B%0D%0Aconst%20quux%20%3D%20(something%3A%20Foo)%20%3D%3E%20true%20%7C%7C%20(something.bar%20%26%26%20something.bar.baz)%3B%0D%0A
— N.B. it only fails with strict null checks turned on
Related Issues: I did not find any.
The text was updated successfully, but these errors were encountered: