-
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
Mapped generic types lose index signature #23080
Comments
@weswigham this should be fixed by #23090, correct? |
I think so? But @ahejlsberg was unenthused with that fix and was looking for a more holistic approach to the problems and inconsistencies we have in the |
Spoke to @ahejlsberg, he has a different proposal for adding a new |
Another example: enum MyEnum {
ValA = 0,
ValB = 1,
}
type IEnumTpProp<R> = {[key in keyof typeof MyEnum]: R };
var X: IEnumTpProp<string> = {
ValA: "text1",
ValB: "text2",
0: "error" // expected: error; current: error; //OK
};
X[MyEnum[MyEnum.ValA]] = "no error"; // current: no error; expected: no error // **OK**
X[MyEnum.ValA] = "no error??"; // current: no error; expected: error // **KO** |
Sample described in OP should be fixed by #23592. @dardino the behavior in your example is expected, since enums have a numeric index signature. enum MyEnum {
ValA = 0,
ValB = 1,
}
type IEnumTpProp<R> = { [key in MyEnum]: R };
var X: IEnumTpProp<string> = {
[MyEnum.ValA]: "text1",
[MyEnum.ValB]: "text2",
0 :"" //Error, duplicate entry
}; |
TypeScript Version: 2.9.0-dev.20180402
Search Terms: partial mapped types index signature enum
Code
Expected behavior:
No compile errors. This was the behavior in 2.7.2.
Actual behavior:
With noImplicitAny=true, the Partial and Pick versions of the type triggers error TS7017: Element implicitly has an 'any' type because type 'Partial<IFruitMetadata>' has no index signature.
Playground Link
#22892 looks like it might be related.
The text was updated successfully, but these errors were encountered: