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
TypeScript Version: 3.1.0-dev.20180810
Code
const f = <T extends { [K0 in K]: string; } & { cool: string; }, K extends keyof T>(t: T, k: K) => { const s: string = t[k]; };
Expected behavior: Successful compilation
Actual behavior: I get the following error:
error TS2322: Type 'T[K]' is not assignable to type 'string'. const s: string = t[k]; ~
Playground Link: Link
Additional Notes: This compiles successfully (link):
const f = <T extends { [K0 in K]: string; } & { cool: string; }, K extends keyof T>(t: T, k: K) => { const s: string = t['cool']; };
as does this (link):
const f = <T extends { [K0 in K]: string; }, K extends keyof T>(t: T, k: K) => { const s: string = t[k]; };
The text was updated successfully, but these errors were encountered:
The issue here is that we're not examining all constraints of indexed access types in type relations, rather we jump straight to base constraints.
In exploring the issue I also discovered that this errors where it shouldn't:
const f = <T extends { [P in K | "cool"]: string; }, K extends keyof T>(t: T, k: K) => { const s: string = t[k]; t.cool; // Error, but shouldn't be };
I'll put up a PR with a fix shortly.
Sorry, something went wrong.
ahejlsberg
No branches or pull requests
TypeScript Version: 3.1.0-dev.20180810
Code
Expected behavior: Successful compilation
Actual behavior: I get the following error:
Playground Link: Link
Additional Notes: This compiles successfully (link):
as does this (link):
The text was updated successfully, but these errors were encountered: