Skip to content

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

Merged
merged 5 commits into from
May 26, 2016

Conversation

sandersn
Copy link
Member

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.

sandersn added 4 commits May 25, 2016 10:12
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; }'.
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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?

@mhegazy
Copy link
Contributor

mhegazy commented May 26, 2016

👍

@sandersn sandersn merged commit 0a623f8 into master May 26, 2016
@sandersn sandersn deleted the excess-property-check-numeric-indexers branch May 26, 2016 20:40
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants