Open hstahl opened 4 years ago
@hstahl do you agree this is an equivalent case?
type FilterKeysOf<T, Condition> = { [K in keyof T]: T[K] extends Condition ? K : never }[keyof T];
type ArrayKeysOf<T> = FilterKeysOf<T, readonly unknown[]>;
interface I {
foo: string;
bar: string[];
baz: number;
}
class A<T extends I> {
protected treasure: T
constructor(treasure: T) {
this.treasure = treasure;
}
getArrayTreasure<K extends ArrayKeysOf<T>>(fieldName: K): T[K] {
return this.treasure[fieldName];
}
getQuxArrayTreasure() {
this.getArrayTreasure('bar');
}
}
@RyanCavanaugh Yes, your case seems to behave in the same way.
TypeScript Version: 3.8.3 & 4.0.0-dev.20200506
Search Terms: TS2345 generic constructor super superclass method type parameter inheritance conditional type constraint
Code
Expected behavior: Compiles without errors.
Actual behavior: TS v3.8.3:
TS v4.0.0-dev.20200506:
Playground Link: Link Related Issues: