-
Couldn't load subscription status.
- Fork 13.1k
Open
Labels
Domain: Indexed Access TypesThe issue relates to accessing subtypes via index accessThe issue relates to accessing subtypes via index accessPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone
Description
π Search Terms
parameter constraint array index indexable number template literal
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
declare function test1<A extends unknown[]>(arr: A): A[number];
declare function test2<A extends unknown[]>(arr: A): A[`${number}`];π Actual behavior
test2 is an error
π Expected behavior
I expect both to be roughly identical - both should not error here.
Additional information about the issue
I think that this should be OK since #48837:
- Numeric index signatures apply when the index type is
${number}. For example`Foo[][`${number}`]resolves toFooinstead 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.
ssalbdivad and whzx5bybssalbdivad
Metadata
Metadata
Assignees
Labels
Domain: Indexed Access TypesThe issue relates to accessing subtypes via index accessThe issue relates to accessing subtypes via index accessPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some casesThe current behavior isn't wrong, but it's possible to see that it might be better in some cases