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
TypeScript Version: 4.1.0-dev.20200823 also tested with 4.0.2
Search Terms:
TS2532
Object is possibly 'undefined' Code
interfaceFoo{foo: string;bar: string;}exportdefaultfunctiongetBar(obj: Foo|undefined): string{constfoo=obj?.foo;if(!foo){thrownewError("Invalid args");}returnobj.bar;// <--- obj is possible undefined here according to tsc even though it can never really be}
Expected behavior:
No typescript error should be shown here, because 'obj' can never be undefined since 'foo' would then also be undefined so the code would never reach the final return.
Actual behavior:
with --strictNullChecks TS2532: Object is possibly 'undefined' at the final return line for 'obj'
TypeScript Version: 4.1.0-dev.20200823 also tested with 4.0.2
Search Terms:
TS2532
Object is possibly 'undefined'
Code
Expected behavior:
No typescript error should be shown here, because 'obj' can never be undefined since 'foo' would then also be undefined so the code would never reach the final return.
Actual behavior:
with --strictNullChecks
TS2532: Object is possibly 'undefined'
at the final return line for 'obj'Playground Link:
Playground Link
Related Issues:
The text was updated successfully, but these errors were encountered: