-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Improve support for numeric string types #48837
Conversation
@typescript-bot test this |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 2a7fc1e. You can monitor the build here. |
Heya @ahejlsberg, I've started to run the extended test suite on this PR at 2a7fc1e. You can monitor the build here. |
Heya @ahejlsberg, I've started to run the abridged perf test suite on this PR at 2a7fc1e. You can monitor the build here. Update: The results are in! |
Heya @ahejlsberg, I've started to run the diff-based community code test suite on this PR at 2a7fc1e. You can monitor the build here. Update: The results are in! |
@ahejlsberg Here they are:Comparison Report - main..48837
System
Hosts
Scenarios
Developer Information: |
@ahejlsberg |
I believe that this will close #48739 |
Tests and perf all look to be unaffected. |
Could someone revisit #41893 and explain what's going on here and how it either meshes with or supersedes it? The argument there that is that const arr: string[] = [];
const x: `${number}` = "-0.0e123";
arr[x] = "oopsie"; // <-- is this supposed to be okay or an error? Personally I'd love it if such a requirement existed and that But but now if you're doing this, it means that you agree that arrays and tuples have keys of type |
TypeScript represents numeric strings using the type
`${number}`
. This PR improves support for numeric string types to more accurately reflect that elements of arrays and tuples have numeric string property names. Specifically:${number}
. For example`Foo[][`${number}`]
resolves toFoo
instead of being an error. This is consistent with our existing rule that index signatures apply when the index type is a numeric string literal. For exampleFoo[]['0']
already resolves toFoo
.{ [K in keyof T]: XXX }
, whereT
is constrained to an array or tuple type,K
has an implied constraint ofnumber | `${number}`
.string
and a template literal type reduce to just the template literal type. For example,string & `${number}`
now reduces to just`${number}`
.Some examples:
For further context, see discussion in #48599.