-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
Bug Report
π Search Terms
optional chain, generic, this, method
π Version & Regression Information
Bug started in TypeScript 3.7.
- I was unable to test this on prior versions because optional chaining did not exist before 3.7
β― Playground Link
Playground link with relevant code
π» Code
interface X {
foo<T>(this: T, arg: keyof T): void;
}
interface Y extends X {
a: number;
b: string;
}
declare const value: Y | undefined;
// this works
if (value) {
value?.foo("a");
}
// this doesn't
value?.foo("a"); // Argument of type 'string' is not assignable to parameter of type 'never'.
π Actual behavior
Generic T
is not resolved. keyof T
results in never
.
π Expected behavior
Generic T
should resolve to Y
so that keyof T
resolves to "a" | "b" | "foo"
.
noahwillcrow
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue