-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Relax requirements on index signatures to 'any' when a type also contains a string index signature to 'any' #43065
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
Relax requirements on index signatures to 'any' when a type also contains a string index signature to 'any' #43065
Conversation
@typescript-bot pack this |
Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at bb8f30c. You can monitor the build here. |
Hey @DanielRosenwasser, something went wrong when looking for the build artifact. (You can check the log here). |
@typescript-bot pack this |
Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at bb8f30c. You can monitor the build here. |
Hey @DanielRosenwasser, I've packed this into an installable tgz. You can install it for testing by referencing it in your
and then running |
One thing I just thought of - when #26797 goes in, I think it would be best not to relax the requirements to other index signatures since this is just meant to unbreak code. |
bothToAny = someObj; | ||
~~~~~~~~~ | ||
!!! error TS2322: Type 'Obj' is not assignable to type 'StringTo<any> & NumberTo<any>'. | ||
!!! error TS2322: Type 'Obj' is not assignable to type 'NumberTo<any>'. | ||
!!! error TS2322: Index signature is missing in type 'Obj'. |
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.
This might be questionable. This used to work in 4.2, but this PR doesn't un-break this code.
|
||
bothToAny = sToAny; | ||
bothToAny = nToAny; | ||
bothToAny = someObj; |
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.
This is the example that's been un-broken.
Fixes #43064
When checking compatibility between two types, TypeScript should not require a corresponding source index signature if the target side index signature maps to
any
and the target side has a string index signature that maps toany
.So an index signature like in
is still required of a source type, but neither index signature in
should be required; however, the number index signature in
should always be required because the number index signature doesn't map to
any
.TL;DR:
Given
type SomeObject = { hello: string, world: number }
:SomeObject -> { [x: string]: any }
SomeObject -> { [x: string]: any, [x: number]: any }
SomeObject -> { [x: number]: any }
SomeObject -> { [x: string]: any, [x: number]: string }