Skip to content

Commit ab72d39

Browse files
committed
allow generic arrays to be indexed with concrete string numerics
1 parent 012fa84 commit ab72d39

4 files changed

+19
-1
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17744,7 +17744,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1774417744
const propertyTypes = map(getPropertiesOfType(type), prop => getLiteralTypeFromProperty(prop, include));
1774517745
const indexKeyTypes = map(getIndexInfosOfType(type), info =>
1774617746
info !== enumNumberIndexInfo && isKeyTypeIncluded(info.keyType, include) ?
17747-
info.keyType === stringType && include & TypeFlags.Number ? stringOrNumberType : info.keyType : neverType);
17747+
info.keyType === stringType && include & TypeFlags.Number ? stringOrNumberType : info.keyType === numberType ? getUnionType([numberType, numericStringType]) : info.keyType : neverType);
1774817748
return getUnionType(concatenate(propertyTypes, indexKeyTypes), UnionReduction.Literal, /*aliasSymbol*/ undefined, /*aliasTypeArguments*/ undefined, origin);
1774917749
}
1775017750

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts] ////
2+
3+
=== typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts ===
4+
type Test1<A extends any[]> = A["0"];
5+
>Test1 : Symbol(Test1, Decl(typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts, 0, 0))
6+
>A : Symbol(A, Decl(typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts, 0, 11))
7+
>A : Symbol(A, Decl(typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts, 0, 11))
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//// [tests/cases/compiler/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts] ////
2+
3+
=== typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts ===
4+
type Test1<A extends any[]> = A["0"];
5+
>Test1 : Test1<A>
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
type Test1<A extends any[]> = A["0"];

0 commit comments

Comments
 (0)