diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0ea0a7398f55d..f7bac1eb8d79c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -17744,7 +17744,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const propertyTypes = map(getPropertiesOfType(type), prop => getLiteralTypeFromProperty(prop, include)); const indexKeyTypes = map(getIndexInfosOfType(type), info => info !== enumNumberIndexInfo && isKeyTypeIncluded(info.keyType, include) ? - info.keyType === stringType && include & TypeFlags.Number ? stringOrNumberType : info.keyType : neverType); + info.keyType === stringType && include & TypeFlags.Number ? stringOrNumberType : info.keyType === numberType ? getUnionType([numberType, numericStringType]) : info.keyType : neverType); return getUnionType(concatenate(propertyTypes, indexKeyTypes), UnionReduction.Literal, /*aliasSymbol*/ undefined, /*aliasTypeArguments*/ undefined, origin); } diff --git a/tests/baselines/reference/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.symbols b/tests/baselines/reference/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.symbols new file mode 100644 index 0000000000000..06cd8260c6735 --- /dev/null +++ b/tests/baselines/reference/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.symbols @@ -0,0 +1,8 @@ +//// [tests/cases/compiler/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts] //// + +=== typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts === +type Test1 = A["0"]; +>Test1 : Symbol(Test1, Decl(typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts, 0, 0)) +>A : Symbol(A, Decl(typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts, 0, 11)) +>A : Symbol(A, Decl(typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts, 0, 11)) + diff --git a/tests/baselines/reference/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.types b/tests/baselines/reference/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.types new file mode 100644 index 0000000000000..fd0301ea382e3 --- /dev/null +++ b/tests/baselines/reference/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.types @@ -0,0 +1,6 @@ +//// [tests/cases/compiler/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts] //// + +=== typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts === +type Test1 = A["0"]; +>Test1 : Test1 + diff --git a/tests/cases/compiler/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts b/tests/cases/compiler/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts new file mode 100644 index 0000000000000..02671cdad0894 --- /dev/null +++ b/tests/cases/compiler/typeParameterConstrainedToArrayIndexableByConcreteStringNumeric.ts @@ -0,0 +1,4 @@ +// @strict: true +// @noEmit: true + +type Test1 = A["0"];