π Search Terms
parameter constraint array index indexable number template literal
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
https://www.typescriptlang.org/play?ts=5.4.0-dev.20231218#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwxAGcMBGAHgEF4QAPQ1YI+NAa1RwHdUBtAXQB8AClgwAXPEoBKCZR6pkAWwBGIGHwDcAKFCRYCFOmx4CxDACYqNeiEbM2Hbv2GjZMyTwAGAEgDeClTUAX09NIA
π» 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 to Foo 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 example Foo[]['0'] already resolves to Foo.
π Search Terms
parameter constraint array index indexable number template literal
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.4.0-dev.20231218#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwxAGcMBGAHgEF4QAPQ1YI+NAa1RwHdUBtAXQB8AClgwAXPEoBKCZR6pkAWwBGIGHwDcAKFCRYCFOmx4CxDACYqNeiEbM2Hbv2GjZMyTwAGAEgDeClTUAX09NIA
π» Code
π Actual behavior
test2is 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: