-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue