Closed
Description
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
)
let mappedObject: {[K in "foo"]: null | {x: string}} = {foo: {x: "hello"}};
declare function foo<T>(x: T): null | T;
function bar<K extends "foo">(key: K) {
const element = foo(mappedObject[key]);
if (element == null)
return;
const x = 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.