I ran across this while migrating my project to strictNullChecks and it's positively bizarre.
TypeScript Version: master (50f442f)
Search Terms: mapped type narrow narrowing null strictNullChecks never
Code (with strictNullChecks)
letmappedObject: {[Kin"foo"]: null|{x: string}}={foo: {x: "hello"}};declarefunctionfoo<T>(x: T): null|T;functionbar<Kextends"foo">(key: K){constelement=foo(mappedObject[key]);if(element==null)return;constx=element.x;}Expected behavior: Compile without error.
Actual behavior: Error: Property 'x' does not exist on type 'never'.
Playground Link:link (remember to enable strictNullChecks)
Related Issues: Didn't find any.
I ran across this while migrating my project to
strictNullChecksand it's positively bizarre.TypeScript Version: master (50f442f)
Search Terms: mapped type narrow narrowing null strictNullChecks never
Code (with
strictNullChecks)Expected behavior: Compile without error.
Actual behavior: Error: Property 'x' does not exist on type 'never'.
Playground Link:link (remember to enable strictNullChecks)
Related Issues: Didn't find any.