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".
Bug Report
π Search Terms
optional chain, generic, this, method
π Version & Regression Information
Bug started in TypeScript 3.7.
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Generic
Tis not resolved.keyof Tresults innever.π Expected behavior
Generic
Tshould resolve toYso thatkeyof Tresolves to"a" | "b" | "foo".