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.
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.
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
anyand 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 }