-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Excess property check numeric indexers #8822
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
Conversation
Previously, having a numeric indexer on a target type meant that excess object property checking would allow any property. Now only numeric properties are allowed.
A lot of tests used non-numeric property names for object literals that are contextually typed only by a numeric indexer.
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(78,5): error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. | ||
Property '2.0' is incompatible with index signature. | ||
Type 'number' is not assignable to type 'string'. | ||
tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(79,5): error TS2322: Type '{ 1.0: string; 2.0: number; a: string; b: number; c: () => void; "d": string; "e": number; "3.0": string; "4.0": number; f: any; X: string; foo(): string; }' is not assignable to type '{ [x: number]: string; }'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the previous error was definitely more helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually this looks just wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really? I think it's correct to point out that 'a' is not expected in a number-indexed type. And the error locality is better than the assignability error.
I guess the ideal would be to issue both errors?
👍 |
Fixes #8768.
A lot of tests used non-numeric property names for object literals that are contextually typed only by a numeric indexer. I changed the tests to use numeric names after reading them. I don't think any of them depended on the non-numeric names.