We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The below code:
class M { __m: any; } class C { __c: any; } type D = typeof M | typeof C; interface R { [i: string]: D; } function f1(p: D) { } interface P { p1: string; p2: string; } function f2<K extends keyof P>(p: K) { let r: R = {}; if (p in r) { f1(r[p]); // Error `R[K]` is not assignable to `D` } }
Gives me the error R[K] is not assignable to D.
R[K]
D
Though isn't R[K] equal to D?
The text was updated successfully, but these errors were encountered:
you do not really need the generic type parameter here. this should be written as:
function f2(p: keyof P) { let r: R = {}; if (p in r) { f1(r[p]); } }
Sorry, something went wrong.
It seems to work without a generic type parameter. Though, in my actual code I'm using the following signature:
public set<K extends keyof P>(prop: K, value: P[K] | null | undefined): void;
This no longer reproduces in the nightly build. I believe it was fixed in #12770.
ahejlsberg
No branches or pull requests
The below code:
Gives me the error
R[K]
is not assignable toD
.Though isn't
R[K]
equal toD
?The text was updated successfully, but these errors were encountered: