-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
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
After updating to 3.x.x getting TS2536 #28647
Comments
This might be affected by this: #27490 (and thus working as intended).
I'd wait on a final say from someone on the team though, |
What I find odd is the intellisense/editor picking up the correct value. Is there a way to have the same behavior without the error? |
Is your editor using an older version of tsserver? |
I'm using VSCode and even the typescript playground it works (even with the error it resolves the correct type). |
I think @jack-williams is right; but I'm unsure if we wanted this specific kind of pattern to break |
This is working as intended. A simplified example: function f1<T, U extends Record<string, keyof T>, K extends keyof U>(obj: T, map: U, key: K) {
return obj[map[key]]; // Error
} Here, Changing the constraint of function f2<T, U extends Record<keyof U, keyof T>, K extends keyof U>(obj: T, map: U, key: K) {
return obj[map[key]]; // Ok
} |
Yep, so it seems like I was completely wrong on this one. The mistake I made was that the PR I linked to only concerned the case when relating to an indexed access type; this example is about relating from an indexed access type. Subtle, but wrong. Sorry! |
cc @DanielRosenwasser to double-check that we're documenting this break in the 3.2 (? I think that's the first) release. |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Sorry to comment on a closed issue, is this suppose to happen: interface MyGetter {
vstring : string,
vnumber: number,
vhidden: boolean;
}
declare interface TestGeneric<Getters> {
<Map extends Record<string, keyof Getters>>(map: Map) : { [K in keyof Map]: Getters[Map[K]]};
}
declare interface TestSpecific {
<Map extends Record<string, keyof MyGetter>>(map: Map): { [K in keyof Map]: MyGetter[Map[K]]}
}
declare const genericInterface: TestGeneric<MyGetter>;
declare const speficInterface: TestSpecific;
const generic = genericInterface({
testString: 'vstring',
testNumber: 'vnumber'
});
const specific = speficInterface({
testString: 'vstring',
testNumber: 'vnumber'
});
generic.testNumber; //number
specific.testNumber; // number
generic.testString; // string
specific.testString; //string
|
TypeScript Version: [email protected]
Search Terms:
TS2536 Record Map vuex
Code
Expected behavior:
No compile issue, is working using [email protected], checked the breaking changes and found nothing in regards to this.
Intellisense still works as expected giving error if you change
expectedStr
to an invalid value.Actual behavior:
Not giving error: index.ts:9:33 - error TS2536: Type 'Map[K]' cannot be used to index type 'T'.
Playground Link:
playground
The text was updated successfully, but these errors were encountered: