-
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
Ensure static index signatures have an errorNode available #44129
Ensure static index signatures have an errorNode available #44129
Conversation
src/compiler/checker.ts
Outdated
@@ -36898,6 +36898,11 @@ namespace ts { | |||
const someBaseTypeHasBothIndexers = forEach(getBaseTypes(<InterfaceType>type), base => getIndexTypeOfType(base, IndexKind.String) && getIndexTypeOfType(base, IndexKind.Number)); | |||
errorNode = someBaseTypeHasBothIndexers || !type.symbol.declarations ? undefined : type.symbol.declarations[0]; | |||
} | |||
if (!errorNode) { |
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.
Seems like this isn't the right fix - you'll still end up with the wrong error span, just as in the following example:
class Foo {
[p: string]: any;
static [p: string]: number;
}
error: Property 'prototype' of type 'Foo' is not assignable to string index type 'number'.
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.
I've opened up #44134 to track that.
… stop checking prototype props
ebfdfd4
to
a8327a0
Compare
@DanielRosenwasser This now fixes both reporting issues and, per our discussion to mitigate the impact of that and preserve the usefulness of the feature, also disables checking if index signatures are consistent with prototype properties on class static sides. |
@DanielRosenwasser you want a cherry pick for this, I assume? @typescript-bot cherry-pick this into release-4.3 |
Heya @weswigham, I've started to run the task to cherry-pick this into |
Hey @weswigham, I've opened #44240 for you. |
Component commits: 7a9854c Ensure static index signatures have an errorNode available 626b431 Merge branch 'master' into error-node-static-index-signatures a8327a0 Lookup static index signature declarations in the right symbol table, stop checking prototype props Co-authored-by: Wesley Wigham <t-weswig@microsoft.com>
So they can actually report the compatibility error they were trying to issue when the string and number index signatures mismatched.
Fixes #44082
Fixes #44134