Open
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 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
.