diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 51e9adcefd1bb..453532b1c5649 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -30,6 +30,13 @@ namespace ts { (preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly); } + function getIndexSignatureParameterErrorChain() { + return chainDiagnosticMessages( + /*details*/ undefined, + Diagnostics.An_index_signature_parameter_type_must_be_assignable_to_string_number_symbol + ); + } + export function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker { const getPackagesSet: () => Map = memoize(() => { const set = createMap(); @@ -9444,6 +9451,10 @@ namespace ts { if (isGenericMappedType(objectType)) { return type.simplified = substituteIndexedMappedType(objectType, type); } + const indexedType = getResultingTypeOfIndexOnType(objectType, indexType); + if (indexedType) { + return type.simplified = getSimplifiedType(indexedType); + } if (objectType.flags & TypeFlags.TypeParameter) { const constraint = getConstraintOfTypeParameter(objectType as TypeParameter); if (constraint && isGenericMappedType(constraint)) { @@ -11081,7 +11092,7 @@ namespace ts { if (s & TypeFlags.Null && (!strictNullChecks || t & TypeFlags.Null)) return true; if (s & TypeFlags.Object && t & TypeFlags.NonPrimitive) return true; if (s & TypeFlags.UniqueESSymbol || t & TypeFlags.UniqueESSymbol) return false; - if (relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation || relation === indexAssignableRelation || relation === indexAccessAssignableRelation) { + if (relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation) { if (s & TypeFlags.Any) return true; // Type number or any numeric literal type is assignable to any numeric enum type or any // numeric enum literal type. This rule exists for backwards compatibility reasons because @@ -11090,10 +11101,12 @@ namespace ts { t & TypeFlags.Enum || t & TypeFlags.NumberLiteral && t & TypeFlags.EnumLiteral)) return true; } if (relation === indexAccessAssignableRelation) { + if (s & TypeFlags.Any) return true; if (s & TypeFlags.NumberLike && t & TypeFlags.String) return true; if (s & TypeFlags.NumberLiteral && t & TypeFlags.StringLiteral) return (source as LiteralType).value === +(target as LiteralType).value; } if (relation === indexAssignableRelation) { + if (s & TypeFlags.Any) return true; if (s & TypeFlags.String && t & TypeFlags.Number) return true; if (s & TypeFlags.StringLiteral && t & TypeFlags.NumberLiteral) return +(source as LiteralType).value === (target as LiteralType).value; } @@ -18938,7 +18951,7 @@ namespace ts { function getArrayifiedType(type: Type) { if (forEachType(type, t => !(t.flags & (TypeFlags.Any | TypeFlags.Instantiable) || isArrayType(t) || isTupleType(t)))) { - return createArrayType(getIndexTypeOfType(type, IndexKind.Number) || errorType); + return createArrayType(getResultingTypeOfIndexOnType(type, numberType) || errorType); } return type; } @@ -29011,23 +29024,8 @@ namespace ts { if (!parameter.type) { return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_must_have_a_type_annotation); } - if (parameter.type.kind !== SyntaxKind.StringKeyword && parameter.type.kind !== SyntaxKind.NumberKeyword) { - const type = getTypeFromTypeNode(parameter.type); - - if (type.flags & TypeFlags.String || type.flags & TypeFlags.Number) { - return grammarErrorOnNode(parameter.name, - Diagnostics.An_index_signature_parameter_type_cannot_be_a_type_alias_Consider_writing_0_Colon_1_Colon_2_instead, - getTextOfNode(parameter.name), - typeToString(type), - typeToString(getTypeFromTypeNode(node.type!))); - } - - if (type.flags & TypeFlags.Union && allTypesAssignableToKind(type, TypeFlags.StringLiteral, /*strict*/ true)) { - return grammarErrorOnNode(parameter.name, - Diagnostics.An_index_signature_parameter_type_cannot_be_a_union_type_Consider_using_a_mapped_object_type_instead); - } - - return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_must_be_string_or_number); + else { + checkTypeAssignableTo(getTypeFromTypeNode(parameter.type), stringNumberSymbolType, parameter.name, /*headMessage*/ undefined, getIndexSignatureParameterErrorChain); } if (!node.type) { return grammarErrorOnNode(node, Diagnostics.An_index_signature_must_have_a_type_annotation); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 30c7230f22229..79f3172ba2d7c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -71,7 +71,7 @@ "category": "Error", "code": 1022 }, - "An index signature parameter type must be 'string' or 'number'.": { + "An index signature parameter type must be assignable to 'string | number | symbol'.": { "category": "Error", "code": 1023 }, @@ -955,14 +955,6 @@ "category": "Error", "code": 1335 }, - "An index signature parameter type cannot be a type alias. Consider writing '[{0}: {1}]: {2}' instead.": { - "category": "Error", - "code": 1336 - }, - "An index signature parameter type cannot be a union type. Consider using a mapped object type instead.": { - "category": "Error", - "code": 1337 - }, "'infer' declarations are only permitted in the 'extends' clause of a conditional type.": { "category": "Error", "code": 1338 diff --git a/src/services/codefixes/convertToMappedObjectType.ts b/src/services/codefixes/convertToMappedObjectType.ts deleted file mode 100644 index 0d79d6363c0ae..0000000000000 --- a/src/services/codefixes/convertToMappedObjectType.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* @internal */ -namespace ts.codefix { - const fixIdAddMissingTypeof = "fixConvertToMappedObjectType"; - const fixId = fixIdAddMissingTypeof; - const errorCodes = [Diagnostics.An_index_signature_parameter_type_cannot_be_a_union_type_Consider_using_a_mapped_object_type_instead.code]; - - type FixableDeclaration = InterfaceDeclaration | TypeAliasDeclaration; - - registerCodeFix({ - errorCodes, - getCodeActions: context => { - const { sourceFile, span } = context; - const info = getInfo(sourceFile, span.start); - if (!info) return undefined; - const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, info)); - const name = idText(info.container.name); - return [createCodeFixAction(fixId, changes, [Diagnostics.Convert_0_to_mapped_object_type, name], fixId, [Diagnostics.Convert_0_to_mapped_object_type, name])]; - }, - fixIds: [fixId], - getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => { - const info = getInfo(diag.file, diag.start); - if (info) doChange(changes, diag.file, info); - }) - }); - - interface Info { readonly indexSignature: IndexSignatureDeclaration; readonly container: FixableDeclaration; } - function getInfo(sourceFile: SourceFile, pos: number): Info | undefined { - const token = getTokenAtPosition(sourceFile, pos); - const indexSignature = cast(token.parent.parent, isIndexSignatureDeclaration); - if (isClassDeclaration(indexSignature.parent)) return undefined; - const container = isInterfaceDeclaration(indexSignature.parent) ? indexSignature.parent : cast(indexSignature.parent.parent, isTypeAliasDeclaration); - return { indexSignature, container }; - } - - function createTypeAliasFromInterface(declaration: FixableDeclaration, type: TypeNode): TypeAliasDeclaration { - return createTypeAliasDeclaration(declaration.decorators, declaration.modifiers, declaration.name, declaration.typeParameters, type); - } - - function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, { indexSignature, container }: Info): void { - const members = isInterfaceDeclaration(container) ? container.members : (container.type).members; - const otherMembers = members.filter(member => !isIndexSignatureDeclaration(member)); - const parameter = first(indexSignature.parameters); - const mappedTypeParameter = createTypeParameterDeclaration(cast(parameter.name, isIdentifier), parameter.type); - const mappedIntersectionType = createMappedTypeNode( - hasReadonlyModifier(indexSignature) ? createModifier(SyntaxKind.ReadonlyKeyword) : undefined, - mappedTypeParameter, - indexSignature.questionToken, - indexSignature.type); - const intersectionType = createIntersectionTypeNode([ - ...getAllSuperTypeNodes(container), - mappedIntersectionType, - ...(otherMembers.length ? [createTypeLiteralNode(otherMembers)] : emptyArray), - ]); - changes.replaceNode(sourceFile, container, createTypeAliasFromInterface(container, intersectionType)); - } -} diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index fee6da0f8a317..1e0544c99f914 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -72,7 +72,6 @@ "codefixes/requireInTs.ts", "codefixes/useDefaultImport.ts", "codefixes/fixAddModuleReferTypeMissingTypeof.ts", - "codefixes/convertToMappedObjectType.ts", "refactors/convertExport.ts", "refactors/convertImport.ts", "refactors/extractSymbol.ts", diff --git a/tests/baselines/reference/arraySigChecking.errors.txt b/tests/baselines/reference/arraySigChecking.errors.txt index 1968957363caa..b574bd7f01231 100644 --- a/tests/baselines/reference/arraySigChecking.errors.txt +++ b/tests/baselines/reference/arraySigChecking.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/arraySigChecking.ts(11,17): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/compiler/arraySigChecking.ts(11,16): error TS1021: An index signature must have a type annotation. tests/cases/compiler/arraySigChecking.ts(18,5): error TS2322: Type 'void[]' is not assignable to type 'string[]'. Type 'void' is not assignable to type 'string'. tests/cases/compiler/arraySigChecking.ts(22,1): error TS2322: Type 'number[][]' is not assignable to type 'number[][][]'. @@ -18,8 +18,8 @@ tests/cases/compiler/arraySigChecking.ts(22,1): error TS2322: Type 'number[][]' } var foo: { [index: any]; }; // expect an error here - ~~~~~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. + ~~~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. } interface myInt { diff --git a/tests/baselines/reference/declarationEmitIndexTypeNotFound.errors.txt b/tests/baselines/reference/declarationEmitIndexTypeNotFound.errors.txt index 435ddd7c069e7..1bf9f175b5189 100644 --- a/tests/baselines/reference/declarationEmitIndexTypeNotFound.errors.txt +++ b/tests/baselines/reference/declarationEmitIndexTypeNotFound.errors.txt @@ -1,13 +1,10 @@ -tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'. tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(2,13): error TS2304: Cannot find name 'TypeNotFound'. tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(2,13): error TS4092: Parameter 'index' of index signature from exported interface has or is using private name 'TypeNotFound'. -==== tests/cases/compiler/declarationEmitIndexTypeNotFound.ts (3 errors) ==== +==== tests/cases/compiler/declarationEmitIndexTypeNotFound.ts (2 errors) ==== export interface Test { [index: TypeNotFound]: any; - ~~~~~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. ~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'TypeNotFound'. ~~~~~~~~~~~~ diff --git a/tests/baselines/reference/genericIndexTypeHasSensibleErrorMessage.errors.txt b/tests/baselines/reference/genericIndexTypeHasSensibleErrorMessage.errors.txt deleted file mode 100644 index ebcfc8d148273..0000000000000 --- a/tests/baselines/reference/genericIndexTypeHasSensibleErrorMessage.errors.txt +++ /dev/null @@ -1,7 +0,0 @@ -tests/cases/compiler/genericIndexTypeHasSensibleErrorMessage.ts(1,33): error TS1023: An index signature parameter type must be 'string' or 'number'. - - -==== tests/cases/compiler/genericIndexTypeHasSensibleErrorMessage.ts (1 errors) ==== - type Wat = { [x: T]: string }; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.errors.txt b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.errors.txt index 2f6db48bf2fa4..c99016013121b 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.errors.txt +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.errors.txt @@ -2,7 +2,6 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(10,21): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(11,22): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(11,26): error TS2314: Generic type 'C' requires 1 type argument(s). -tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(12,19): error TS1023: An index signature parameter type must be 'string' or 'number'. tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(12,22): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(12,26): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(14,23): error TS2314: Generic type 'C' requires 1 type argument(s). @@ -14,7 +13,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(26,30): error TS2314: Generic type 'E' requires 1 type argument(s). -==== tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts (14 errors) ==== +==== tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts (13 errors) ==== // it is an error to use a generic type without type arguments // all of these are errors @@ -35,8 +34,6 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc ~ !!! error TS2314: Generic type 'C' requires 1 type argument(s). declare var d: { [x: C]: C }; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. ~ !!! error TS2314: Generic type 'C' requires 1 type argument(s). ~ diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.errors.txt b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.errors.txt index d57f3c2fc0d03..579a1fc6a870c 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.errors.txt +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.errors.txt @@ -2,7 +2,6 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(10,13): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(11,14): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(11,18): error TS2314: Generic type 'C' requires 1 type argument(s). -tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(12,11): error TS1023: An index signature parameter type must be 'string' or 'number'. tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(12,14): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(12,18): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(14,13): error TS2314: Generic type 'C' requires 1 type argument(s). @@ -24,7 +23,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(37,10): error TS2314: Generic type 'E' requires 1 type argument(s). -==== tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts (24 errors) ==== +==== tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts (23 errors) ==== // it is an error to use a generic type without type arguments // all of these are errors @@ -45,8 +44,6 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc ~ !!! error TS2314: Generic type 'C' requires 1 type argument(s). var d: { [x: C]: C }; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. ~ !!! error TS2314: Generic type 'C' requires 1 type argument(s). ~ diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt index 276654562a1ec..0bf17b5fcf140 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt @@ -2,7 +2,6 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(10,13): error TS2314: Generic type 'I' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(11,14): error TS2314: Generic type 'I' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(11,18): error TS2314: Generic type 'I' requires 1 type argument(s). -tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(12,11): error TS1023: An index signature parameter type must be 'string' or 'number'. tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(12,14): error TS2314: Generic type 'I' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(12,18): error TS2314: Generic type 'I' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(14,13): error TS2314: Generic type 'I' requires 1 type argument(s). @@ -24,7 +23,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(37,10): error TS2314: Generic type 'E' requires 1 type argument(s). -==== tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts (24 errors) ==== +==== tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts (23 errors) ==== // it is an error to use a generic type without type arguments // all of these are errors @@ -45,8 +44,6 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc ~ !!! error TS2314: Generic type 'I' requires 1 type argument(s). var d: { [x: I]: I }; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. ~ !!! error TS2314: Generic type 'I' requires 1 type argument(s). ~ diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.errors.txt b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.errors.txt index 95857c925be91..d550342fd8553 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.errors.txt +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.errors.txt @@ -2,7 +2,6 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(10,21): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(11,22): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(11,26): error TS2314: Generic type 'C' requires 1 type argument(s). -tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(12,19): error TS1023: An index signature parameter type must be 'string' or 'number'. tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(12,22): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(12,26): error TS2314: Generic type 'C' requires 1 type argument(s). tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(14,23): error TS2314: Generic type 'C' requires 1 type argument(s). @@ -14,7 +13,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(26,30): error TS2314: Generic type 'E' requires 1 type argument(s). -==== tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts (14 errors) ==== +==== tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts (13 errors) ==== // it is an error to use a generic type without type arguments // all of these are errors @@ -35,8 +34,6 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc ~ !!! error TS2314: Generic type 'C' requires 1 type argument(s). declare var d: { [x: C]: C }; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. ~ !!! error TS2314: Generic type 'C' requires 1 type argument(s). ~ diff --git a/tests/baselines/reference/indexTypeCheck.errors.txt b/tests/baselines/reference/indexTypeCheck.errors.txt index 6b82a1a2570a0..913e64f7db3b2 100644 --- a/tests/baselines/reference/indexTypeCheck.errors.txt +++ b/tests/baselines/reference/indexTypeCheck.errors.txt @@ -9,11 +9,14 @@ tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: 'number' index type tests/cases/compiler/indexTypeCheck.ts(27,2): error TS2413: 'number' index type 'number' is not assignable to 'string' index type 'string'. Type 'number' is not assignable to type 'string'. tests/cases/compiler/indexTypeCheck.ts(32,3): error TS1096: An index signature must have exactly one parameter. -tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/compiler/indexTypeCheck.ts(36,2): error TS1021: An index signature must have a type annotation. +tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be assignable to 'string | number | symbol'. + Type 'Purple' is not assignable to type 'string | number | symbol'. + Type 'Purple' is not assignable to type 'symbol'. tests/cases/compiler/indexTypeCheck.ts(51,8): error TS2538: Type 'Blue' cannot be used as an index type. -==== tests/cases/compiler/indexTypeCheck.ts (8 errors) ==== +==== tests/cases/compiler/indexTypeCheck.ts (9 errors) ==== interface Red { [n:number]; // ok ~~~~~~~~~~~ @@ -67,8 +70,12 @@ tests/cases/compiler/indexTypeCheck.ts(51,8): error TS2538: Type 'Blue' cannot b interface Magenta { [p:Purple]; // error + ~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be assignable to 'string | number | symbol'. +!!! error TS1023: Type 'Purple' is not assignable to type 'string | number | symbol'. +!!! error TS1023: Type 'Purple' is not assignable to type 'symbol'. } var yellow: Yellow; diff --git a/tests/baselines/reference/indexerConstraints2.errors.txt b/tests/baselines/reference/indexerConstraints2.errors.txt index da7bca6f437d2..ca5c3448fd3c6 100644 --- a/tests/baselines/reference/indexerConstraints2.errors.txt +++ b/tests/baselines/reference/indexerConstraints2.errors.txt @@ -5,17 +5,14 @@ tests/cases/compiler/indexerConstraints2.ts(17,5): error TS2413: 'number' index Type 'A' is not assignable to type 'B'. tests/cases/compiler/indexerConstraints2.ts(26,5): error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'. Type 'A' is not assignable to type 'B'. -tests/cases/compiler/indexerConstraints2.ts(34,6): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[n: number]: A' instead. -tests/cases/compiler/indexerConstraints2.ts(40,6): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[s: string]: A' instead. -tests/cases/compiler/indexerConstraints2.ts(46,6): error TS1023: An index signature parameter type must be 'string' or 'number'. -tests/cases/compiler/indexerConstraints2.ts(52,6): error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead. -tests/cases/compiler/indexerConstraints2.ts(58,6): error TS1023: An index signature parameter type must be 'string' or 'number'. -tests/cases/compiler/indexerConstraints2.ts(64,6): error TS1023: An index signature parameter type must be 'string' or 'number'. -tests/cases/compiler/indexerConstraints2.ts(70,6): error TS1023: An index signature parameter type must be 'string' or 'number'. -tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead. +tests/cases/compiler/indexerConstraints2.ts(46,6): error TS1023: An index signature parameter type must be assignable to 'string | number | symbol'. + Type 'boolean' is not assignable to type 'string | number | symbol'. +tests/cases/compiler/indexerConstraints2.ts(58,6): error TS1023: An index signature parameter type must be assignable to 'string | number | symbol'. + Type 'NonIndexableUnion' is not assignable to type 'string | number | symbol'. + Type 'false' is not assignable to type 'string | number | symbol'. -==== tests/cases/compiler/indexerConstraints2.ts (11 errors) ==== +==== tests/cases/compiler/indexerConstraints2.ts (5 errors) ==== class A { a: number; } class B extends A { b: number; } @@ -60,16 +57,12 @@ tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signat interface L { [n: AliasedNumber]: A; - ~ -!!! error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[n: number]: A' instead. } type AliasedString = string; interface M { [s: AliasedString]: A; - ~ -!!! error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[s: string]: A' instead. } type AliasedBoolean = boolean; @@ -77,15 +70,14 @@ tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signat interface N { [b: AliasedBoolean]: A; ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be assignable to 'string | number | symbol'. +!!! error TS1023: Type 'boolean' is not assignable to type 'string | number | symbol'. } type IndexableUnion = "foo" | "bar"; interface O { [u: IndexableUnion]: A; - ~ -!!! error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead. } type NonIndexableUnion = boolean | {}; @@ -93,27 +85,23 @@ tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signat interface P { [u: NonIndexableUnion]: A; ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be assignable to 'string | number | symbol'. +!!! error TS1023: Type 'NonIndexableUnion' is not assignable to type 'string | number | symbol'. +!!! error TS1023: Type 'false' is not assignable to type 'string | number | symbol'. } type NonIndexableUnion2 = string | number; interface Q { [u: NonIndexableUnion2]: A; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. } type NonIndexableUnion3 = "foo" | 42; interface R { [u: NonIndexableUnion3]: A; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. } interface S { [u: "foo" | "bar"]: A; - ~ -!!! error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead. } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.errors.txt b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.errors.txt new file mode 100644 index 0000000000000..15be82de9e3e5 --- /dev/null +++ b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.errors.txt @@ -0,0 +1,55 @@ +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(24,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(25,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(26,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(27,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(28,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(29,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(30,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. + + +==== tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts (7 errors) ==== + export interface UserInterfaceColors { + [index: UserInterfaceElement]: ColorInfo; + } + export interface ColorInfo { + r: number; + g: number; + b: number; + a: number; + } + export enum UserInterfaceElement { + ActiveTitleBar = 0, + InactiveTitleBar = 1, + } + + const x: UserInterfaceColors = null as any; + + declare function expectColInfo(x: ColorInfo): void; + + // correct uses + expectColInfo(x[UserInterfaceElement.ActiveTitleBar]); + expectColInfo(x[UserInterfaceElement.InactiveTitleBar]); + + // errors + expectColInfo(x[0]); + ~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. + expectColInfo(x[1]); + ~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. + expectColInfo(x["0"]); + ~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. + expectColInfo(x["1"]); + ~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. + expectColInfo(x[0 as number]); + ~~~~~~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. + expectColInfo(x["0" as string]); + ~~~~~~~~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. + expectColInfo(x[12]); + ~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. + \ No newline at end of file diff --git a/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.js b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.js new file mode 100644 index 0000000000000..f3da598d3ce9d --- /dev/null +++ b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.js @@ -0,0 +1,53 @@ +//// [interfaceWithEnumKeyedIndexSignature.ts] +export interface UserInterfaceColors { + [index: UserInterfaceElement]: ColorInfo; +} +export interface ColorInfo { + r: number; + g: number; + b: number; + a: number; +} +export enum UserInterfaceElement { + ActiveTitleBar = 0, + InactiveTitleBar = 1, +} + +const x: UserInterfaceColors = null as any; + +declare function expectColInfo(x: ColorInfo): void; + +// correct uses +expectColInfo(x[UserInterfaceElement.ActiveTitleBar]); +expectColInfo(x[UserInterfaceElement.InactiveTitleBar]); + +// errors +expectColInfo(x[0]); +expectColInfo(x[1]); +expectColInfo(x["0"]); +expectColInfo(x["1"]); +expectColInfo(x[0 as number]); +expectColInfo(x["0" as string]); +expectColInfo(x[12]); + + +//// [interfaceWithEnumKeyedIndexSignature.js] +"use strict"; +exports.__esModule = true; +var UserInterfaceElement; +(function (UserInterfaceElement) { + UserInterfaceElement[UserInterfaceElement["ActiveTitleBar"] = 0] = "ActiveTitleBar"; + UserInterfaceElement[UserInterfaceElement["InactiveTitleBar"] = 1] = "InactiveTitleBar"; +})(UserInterfaceElement = exports.UserInterfaceElement || (exports.UserInterfaceElement = {})); +var x = null; +// correct uses +expectColInfo(x[UserInterfaceElement.ActiveTitleBar]); +expectColInfo(x[UserInterfaceElement.InactiveTitleBar]); +// errors +expectColInfo(x[0]); +expectColInfo(x[1]); +expectColInfo(x["0"]); +expectColInfo(x["1"]); +expectColInfo(x[0]); +expectColInfo(x["0"]); +expectColInfo(x[12]); diff --git a/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.symbols b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.symbols new file mode 100644 index 0000000000000..04cc6edf589df --- /dev/null +++ b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.symbols @@ -0,0 +1,87 @@ +=== tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts === +export interface UserInterfaceColors { +>UserInterfaceColors : Symbol(UserInterfaceColors, Decl(interfaceWithEnumKeyedIndexSignature.ts, 0, 0)) + + [index: UserInterfaceElement]: ColorInfo; +>index : Symbol(index, Decl(interfaceWithEnumKeyedIndexSignature.ts, 1, 5)) +>UserInterfaceElement : Symbol(UserInterfaceElement, Decl(interfaceWithEnumKeyedIndexSignature.ts, 8, 1)) +>ColorInfo : Symbol(ColorInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 2, 1)) +} +export interface ColorInfo { +>ColorInfo : Symbol(ColorInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 2, 1)) + + r: number; +>r : Symbol(ColorInfo.r, Decl(interfaceWithEnumKeyedIndexSignature.ts, 3, 28)) + + g: number; +>g : Symbol(ColorInfo.g, Decl(interfaceWithEnumKeyedIndexSignature.ts, 4, 14)) + + b: number; +>b : Symbol(ColorInfo.b, Decl(interfaceWithEnumKeyedIndexSignature.ts, 5, 14)) + + a: number; +>a : Symbol(ColorInfo.a, Decl(interfaceWithEnumKeyedIndexSignature.ts, 6, 14)) +} +export enum UserInterfaceElement { +>UserInterfaceElement : Symbol(UserInterfaceElement, Decl(interfaceWithEnumKeyedIndexSignature.ts, 8, 1)) + + ActiveTitleBar = 0, +>ActiveTitleBar : Symbol(UserInterfaceElement.ActiveTitleBar, Decl(interfaceWithEnumKeyedIndexSignature.ts, 9, 34)) + + InactiveTitleBar = 1, +>InactiveTitleBar : Symbol(UserInterfaceElement.InactiveTitleBar, Decl(interfaceWithEnumKeyedIndexSignature.ts, 10, 23)) +} + +const x: UserInterfaceColors = null as any; +>x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) +>UserInterfaceColors : Symbol(UserInterfaceColors, Decl(interfaceWithEnumKeyedIndexSignature.ts, 0, 0)) + +declare function expectColInfo(x: ColorInfo): void; +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 16, 31)) +>ColorInfo : Symbol(ColorInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 2, 1)) + +// correct uses +expectColInfo(x[UserInterfaceElement.ActiveTitleBar]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) +>UserInterfaceElement.ActiveTitleBar : Symbol(UserInterfaceElement.ActiveTitleBar, Decl(interfaceWithEnumKeyedIndexSignature.ts, 9, 34)) +>UserInterfaceElement : Symbol(UserInterfaceElement, Decl(interfaceWithEnumKeyedIndexSignature.ts, 8, 1)) +>ActiveTitleBar : Symbol(UserInterfaceElement.ActiveTitleBar, Decl(interfaceWithEnumKeyedIndexSignature.ts, 9, 34)) + +expectColInfo(x[UserInterfaceElement.InactiveTitleBar]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) +>UserInterfaceElement.InactiveTitleBar : Symbol(UserInterfaceElement.InactiveTitleBar, Decl(interfaceWithEnumKeyedIndexSignature.ts, 10, 23)) +>UserInterfaceElement : Symbol(UserInterfaceElement, Decl(interfaceWithEnumKeyedIndexSignature.ts, 8, 1)) +>InactiveTitleBar : Symbol(UserInterfaceElement.InactiveTitleBar, Decl(interfaceWithEnumKeyedIndexSignature.ts, 10, 23)) + +// errors +expectColInfo(x[0]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) + +expectColInfo(x[1]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) + +expectColInfo(x["0"]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) + +expectColInfo(x["1"]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) + +expectColInfo(x[0 as number]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) + +expectColInfo(x["0" as string]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) + +expectColInfo(x[12]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) + diff --git a/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.types b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.types new file mode 100644 index 0000000000000..2cc0c980cb328 --- /dev/null +++ b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.types @@ -0,0 +1,110 @@ +=== tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts === +export interface UserInterfaceColors { + [index: UserInterfaceElement]: ColorInfo; +>index : UserInterfaceElement +} +export interface ColorInfo { + r: number; +>r : number + + g: number; +>g : number + + b: number; +>b : number + + a: number; +>a : number +} +export enum UserInterfaceElement { +>UserInterfaceElement : UserInterfaceElement + + ActiveTitleBar = 0, +>ActiveTitleBar : UserInterfaceElement.ActiveTitleBar +>0 : 0 + + InactiveTitleBar = 1, +>InactiveTitleBar : UserInterfaceElement.InactiveTitleBar +>1 : 1 +} + +const x: UserInterfaceColors = null as any; +>x : UserInterfaceColors +>null as any : any +>null : null + +declare function expectColInfo(x: ColorInfo): void; +>expectColInfo : (x: ColorInfo) => void +>x : ColorInfo + +// correct uses +expectColInfo(x[UserInterfaceElement.ActiveTitleBar]); +>expectColInfo(x[UserInterfaceElement.ActiveTitleBar]) : void +>expectColInfo : (x: ColorInfo) => void +>x[UserInterfaceElement.ActiveTitleBar] : ColorInfo +>x : UserInterfaceColors +>UserInterfaceElement.ActiveTitleBar : UserInterfaceElement.ActiveTitleBar +>UserInterfaceElement : typeof UserInterfaceElement +>ActiveTitleBar : UserInterfaceElement.ActiveTitleBar + +expectColInfo(x[UserInterfaceElement.InactiveTitleBar]); +>expectColInfo(x[UserInterfaceElement.InactiveTitleBar]) : void +>expectColInfo : (x: ColorInfo) => void +>x[UserInterfaceElement.InactiveTitleBar] : ColorInfo +>x : UserInterfaceColors +>UserInterfaceElement.InactiveTitleBar : UserInterfaceElement.InactiveTitleBar +>UserInterfaceElement : typeof UserInterfaceElement +>InactiveTitleBar : UserInterfaceElement.InactiveTitleBar + +// errors +expectColInfo(x[0]); +>expectColInfo(x[0]) : void +>expectColInfo : (x: ColorInfo) => void +>x[0] : any +>x : UserInterfaceColors +>0 : 0 + +expectColInfo(x[1]); +>expectColInfo(x[1]) : void +>expectColInfo : (x: ColorInfo) => void +>x[1] : any +>x : UserInterfaceColors +>1 : 1 + +expectColInfo(x["0"]); +>expectColInfo(x["0"]) : void +>expectColInfo : (x: ColorInfo) => void +>x["0"] : any +>x : UserInterfaceColors +>"0" : "0" + +expectColInfo(x["1"]); +>expectColInfo(x["1"]) : void +>expectColInfo : (x: ColorInfo) => void +>x["1"] : any +>x : UserInterfaceColors +>"1" : "1" + +expectColInfo(x[0 as number]); +>expectColInfo(x[0 as number]) : void +>expectColInfo : (x: ColorInfo) => void +>x[0 as number] : any +>x : UserInterfaceColors +>0 as number : number +>0 : 0 + +expectColInfo(x["0" as string]); +>expectColInfo(x["0" as string]) : void +>expectColInfo : (x: ColorInfo) => void +>x["0" as string] : any +>x : UserInterfaceColors +>"0" as string : string +>"0" : "0" + +expectColInfo(x[12]); +>expectColInfo(x[12]) : void +>expectColInfo : (x: ColorInfo) => void +>x[12] : any +>x : UserInterfaceColors +>12 : 12 + diff --git a/tests/baselines/reference/parserES5SymbolIndexer1.errors.txt b/tests/baselines/reference/parserES5SymbolIndexer1.errors.txt deleted file mode 100644 index adfac8f700f2f..0000000000000 --- a/tests/baselines/reference/parserES5SymbolIndexer1.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer1.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'. - - -==== tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer1.ts (1 errors) ==== - interface I { - [s: symbol]: string; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5SymbolIndexer2.errors.txt b/tests/baselines/reference/parserES5SymbolIndexer2.errors.txt deleted file mode 100644 index 12eef8ec04967..0000000000000 --- a/tests/baselines/reference/parserES5SymbolIndexer2.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer2.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'. - - -==== tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer2.ts (1 errors) ==== - class C { - [s: symbol]: string; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserES5SymbolIndexer3.errors.txt b/tests/baselines/reference/parserES5SymbolIndexer3.errors.txt deleted file mode 100644 index c9cd9db4fab8b..0000000000000 --- a/tests/baselines/reference/parserES5SymbolIndexer3.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer3.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'. - - -==== tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer3.ts (1 errors) ==== - var x: { - [s: symbol]: string; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexSignature6.errors.txt b/tests/baselines/reference/parserIndexSignature6.errors.txt index db53f219832ed..4ac1b3d43b4a2 100644 --- a/tests/baselines/reference/parserIndexSignature6.errors.txt +++ b/tests/baselines/reference/parserIndexSignature6.errors.txt @@ -1,9 +1,14 @@ -tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature6.ts(2,4): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature6.ts(2,3): error TS1021: An index signature must have a type annotation. +tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature6.ts(2,4): error TS1023: An index signature parameter type must be assignable to 'string | number | symbol'. + Type 'boolean' is not assignable to type 'string | number | symbol'. -==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature6.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature6.ts (2 errors) ==== interface I { [a:boolean] + ~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be assignable to 'string | number | symbol'. +!!! error TS1023: Type 'boolean' is not assignable to type 'string | number | symbol'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserIndexSignature8.errors.txt b/tests/baselines/reference/parserIndexSignature8.errors.txt index 87369df1b76c7..ebe6c508a8d96 100644 --- a/tests/baselines/reference/parserIndexSignature8.errors.txt +++ b/tests/baselines/reference/parserIndexSignature8.errors.txt @@ -1,12 +1,19 @@ -tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts(1,13): error TS1023: An index signature parameter type must be 'string' or 'number'. -tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts(2,14): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts(1,12): error TS1021: An index signature must have a type annotation. +tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts(2,13): error TS1021: An index signature must have a type annotation. +tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts(2,14): error TS1023: An index signature parameter type must be assignable to 'string | number | symbol'. + Type 'RegExp' is not assignable to type 'string | number | symbol'. + Type 'RegExp' is not assignable to type 'symbol'. -==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts (3 errors) ==== var foo: { [index: any]; }; // expect an error here - ~~~~~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. + ~~~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. var foo2: { [index: RegExp]; }; // expect an error here + ~~~~~~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. ~~~~~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be assignable to 'string | number | symbol'. +!!! error TS1023: Type 'RegExp' is not assignable to type 'string | number | symbol'. +!!! error TS1023: Type 'RegExp' is not assignable to type 'symbol'. \ No newline at end of file diff --git a/tests/baselines/reference/parserSymbolIndexer1.errors.txt b/tests/baselines/reference/parserSymbolIndexer1.errors.txt deleted file mode 100644 index 5c6c38d52b122..0000000000000 --- a/tests/baselines/reference/parserSymbolIndexer1.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer1.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'. - - -==== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer1.ts (1 errors) ==== - interface I { - [s: symbol]: string; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserSymbolIndexer2.errors.txt b/tests/baselines/reference/parserSymbolIndexer2.errors.txt deleted file mode 100644 index 3961f4942de4b..0000000000000 --- a/tests/baselines/reference/parserSymbolIndexer2.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer2.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'. - - -==== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer2.ts (1 errors) ==== - class C { - [s: symbol]: string; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserSymbolIndexer4.errors.txt b/tests/baselines/reference/parserSymbolIndexer4.errors.txt deleted file mode 100644 index 1cf184a48472b..0000000000000 --- a/tests/baselines/reference/parserSymbolIndexer4.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer4.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'. - - -==== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer4.ts (1 errors) ==== - var x: { - [s: symbol]: string; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. - } \ No newline at end of file diff --git a/tests/baselines/reference/symbolIndexerCompatabilityExamples.js b/tests/baselines/reference/symbolIndexerCompatabilityExamples.js new file mode 100644 index 0000000000000..33948bb316319 --- /dev/null +++ b/tests/baselines/reference/symbolIndexerCompatabilityExamples.js @@ -0,0 +1,179 @@ +//// [symbolIndexerCompatabilityExamples.ts] +interface Dict { + [index: string]: T; + [index: symbol]: T; + [index: number]: T; +} + +const keyMap: Dict = {}; + +function set(index: keyof T) { + keyMap[index] = 1; +} + +interface Dict2 { + [index: string | number | symbol]: T; +} + +const keyMap2: Dict2 = {}; + +function set2(index: keyof T) { + keyMap2[index] = 1; +} + +interface Dict3 { + [index: string | symbol]: T; +} + +const keyMap3: Dict3 = {}; + +function set3(index: keyof T) { + keyMap3[index] = 1; +} + +interface Dict4 { + [index: string]: T; + [index: symbol]: T; +} + +const keyMap4: Dict4 = {}; + +function set4(index: keyof T) { + keyMap4[index] = 1; +} + +/** + * Key can only be number, string or symbol + * */ +class SimpleMapMap { + private o: { [k: K]: V } = {}; + + public has(k: K): boolean { + return k in this.o; + } + + public get(k: K): V { + return this.o[k]; + } + + public set(k: K, v: V) { + this.o[k] = v; + } + + public getMap(k: K): V { + if (k in this.o) { + return this.o[k]; + } + const res = new SimpleMapMap(); + this.o[k] = res as any as V; + return res as any as V; + } + + public clear() { + this.o = {}; + } +} + +class SimpleMapMap2 { + private o: { [k: PropertyKey]: V } = {}; + + public has(k: K): boolean { + return k in this.o; + } + + public get(k: K): V { + return this.o[k]; + } + + public set(k: K, v: V) { + this.o[k] = v; + } + + public getMap(k: K): V { + if (k in this.o) { + return this.o[k]; + } + const res = new SimpleMapMap2(); + this.o[k] = res as any as V; + return res as any as V; + } + + public clear() { + this.o = {}; + } +} + + +//// [symbolIndexerCompatabilityExamples.js] +"use strict"; +var keyMap = {}; +function set(index) { + keyMap[index] = 1; +} +var keyMap2 = {}; +function set2(index) { + keyMap2[index] = 1; +} +var keyMap3 = {}; +function set3(index) { + keyMap3[index] = 1; +} +var keyMap4 = {}; +function set4(index) { + keyMap4[index] = 1; +} +/** + * Key can only be number, string or symbol + * */ +var SimpleMapMap = /** @class */ (function () { + function SimpleMapMap() { + this.o = {}; + } + SimpleMapMap.prototype.has = function (k) { + return k in this.o; + }; + SimpleMapMap.prototype.get = function (k) { + return this.o[k]; + }; + SimpleMapMap.prototype.set = function (k, v) { + this.o[k] = v; + }; + SimpleMapMap.prototype.getMap = function (k) { + if (k in this.o) { + return this.o[k]; + } + var res = new SimpleMapMap(); + this.o[k] = res; + return res; + }; + SimpleMapMap.prototype.clear = function () { + this.o = {}; + }; + return SimpleMapMap; +}()); +var SimpleMapMap2 = /** @class */ (function () { + function SimpleMapMap2() { + this.o = {}; + } + SimpleMapMap2.prototype.has = function (k) { + return k in this.o; + }; + SimpleMapMap2.prototype.get = function (k) { + return this.o[k]; + }; + SimpleMapMap2.prototype.set = function (k, v) { + this.o[k] = v; + }; + SimpleMapMap2.prototype.getMap = function (k) { + if (k in this.o) { + return this.o[k]; + } + var res = new SimpleMapMap2(); + this.o[k] = res; + return res; + }; + SimpleMapMap2.prototype.clear = function () { + this.o = {}; + }; + return SimpleMapMap2; +}()); diff --git a/tests/baselines/reference/symbolIndexerCompatabilityExamples.symbols b/tests/baselines/reference/symbolIndexerCompatabilityExamples.symbols new file mode 100644 index 0000000000000..b4e884fb92be4 --- /dev/null +++ b/tests/baselines/reference/symbolIndexerCompatabilityExamples.symbols @@ -0,0 +1,310 @@ +=== tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts === +interface Dict { +>Dict : Symbol(Dict, Decl(symbolIndexerCompatabilityExamples.ts, 0, 0)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 0, 15)) + + [index: string]: T; +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 1, 5)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 0, 15)) + + [index: symbol]: T; +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 2, 5)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 0, 15)) + + [index: number]: T; +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 3, 5)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 0, 15)) +} + +const keyMap: Dict = {}; +>keyMap : Symbol(keyMap, Decl(symbolIndexerCompatabilityExamples.ts, 6, 5)) +>Dict : Symbol(Dict, Decl(symbolIndexerCompatabilityExamples.ts, 0, 0)) + +function set(index: keyof T) { +>set : Symbol(set, Decl(symbolIndexerCompatabilityExamples.ts, 6, 32)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 8, 13)) +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 8, 31)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 8, 13)) + + keyMap[index] = 1; +>keyMap : Symbol(keyMap, Decl(symbolIndexerCompatabilityExamples.ts, 6, 5)) +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 8, 31)) +} + +interface Dict2 { +>Dict2 : Symbol(Dict2, Decl(symbolIndexerCompatabilityExamples.ts, 10, 1)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 12, 16)) + + [index: string | number | symbol]: T; +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 13, 5)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 12, 16)) +} + +const keyMap2: Dict2 = {}; +>keyMap2 : Symbol(keyMap2, Decl(symbolIndexerCompatabilityExamples.ts, 16, 5)) +>Dict2 : Symbol(Dict2, Decl(symbolIndexerCompatabilityExamples.ts, 10, 1)) + +function set2(index: keyof T) { +>set2 : Symbol(set2, Decl(symbolIndexerCompatabilityExamples.ts, 16, 34)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 18, 14)) +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 18, 32)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 18, 14)) + + keyMap2[index] = 1; +>keyMap2 : Symbol(keyMap2, Decl(symbolIndexerCompatabilityExamples.ts, 16, 5)) +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 18, 32)) +} + +interface Dict3 { +>Dict3 : Symbol(Dict3, Decl(symbolIndexerCompatabilityExamples.ts, 20, 1)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 22, 16)) + + [index: string | symbol]: T; +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 23, 5)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 22, 16)) +} + +const keyMap3: Dict3 = {}; +>keyMap3 : Symbol(keyMap3, Decl(symbolIndexerCompatabilityExamples.ts, 26, 5)) +>Dict3 : Symbol(Dict3, Decl(symbolIndexerCompatabilityExamples.ts, 20, 1)) + +function set3(index: keyof T) { +>set3 : Symbol(set3, Decl(symbolIndexerCompatabilityExamples.ts, 26, 34)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 28, 14)) +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 28, 32)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 28, 14)) + + keyMap3[index] = 1; +>keyMap3 : Symbol(keyMap3, Decl(symbolIndexerCompatabilityExamples.ts, 26, 5)) +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 28, 32)) +} + +interface Dict4 { +>Dict4 : Symbol(Dict4, Decl(symbolIndexerCompatabilityExamples.ts, 30, 1)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 32, 16)) + + [index: string]: T; +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 33, 5)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 32, 16)) + + [index: symbol]: T; +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 34, 5)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 32, 16)) +} + +const keyMap4: Dict4 = {}; +>keyMap4 : Symbol(keyMap4, Decl(symbolIndexerCompatabilityExamples.ts, 37, 5)) +>Dict4 : Symbol(Dict4, Decl(symbolIndexerCompatabilityExamples.ts, 30, 1)) + +function set4(index: keyof T) { +>set4 : Symbol(set4, Decl(symbolIndexerCompatabilityExamples.ts, 37, 34)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 39, 14)) +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 39, 32)) +>T : Symbol(T, Decl(symbolIndexerCompatabilityExamples.ts, 39, 14)) + + keyMap4[index] = 1; +>keyMap4 : Symbol(keyMap4, Decl(symbolIndexerCompatabilityExamples.ts, 37, 5)) +>index : Symbol(index, Decl(symbolIndexerCompatabilityExamples.ts, 39, 32)) +} + +/** + * Key can only be number, string or symbol + * */ +class SimpleMapMap { +>SimpleMapMap : Symbol(SimpleMapMap, Decl(symbolIndexerCompatabilityExamples.ts, 41, 1)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 46, 19)) +>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 46, 41)) + + private o: { [k: K]: V } = {}; +>o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 47, 18)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 46, 19)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 46, 41)) + + public has(k: K): boolean { +>has : Symbol(SimpleMapMap.has, Decl(symbolIndexerCompatabilityExamples.ts, 47, 34)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 49, 15)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 46, 19)) + + return k in this.o; +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 49, 15)) +>this.o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) +>this : Symbol(SimpleMapMap, Decl(symbolIndexerCompatabilityExamples.ts, 41, 1)) +>o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) + } + + public get(k: K): V { +>get : Symbol(SimpleMapMap.get, Decl(symbolIndexerCompatabilityExamples.ts, 51, 5)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 53, 15)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 46, 19)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 46, 41)) + + return this.o[k]; +>this.o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) +>this : Symbol(SimpleMapMap, Decl(symbolIndexerCompatabilityExamples.ts, 41, 1)) +>o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 53, 15)) + } + + public set(k: K, v: V) { +>set : Symbol(SimpleMapMap.set, Decl(symbolIndexerCompatabilityExamples.ts, 55, 5)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 57, 15)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 46, 19)) +>v : Symbol(v, Decl(symbolIndexerCompatabilityExamples.ts, 57, 20)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 46, 41)) + + this.o[k] = v; +>this.o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) +>this : Symbol(SimpleMapMap, Decl(symbolIndexerCompatabilityExamples.ts, 41, 1)) +>o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 57, 15)) +>v : Symbol(v, Decl(symbolIndexerCompatabilityExamples.ts, 57, 20)) + } + + public getMap(k: K): V { +>getMap : Symbol(SimpleMapMap.getMap, Decl(symbolIndexerCompatabilityExamples.ts, 59, 5)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 61, 18)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 46, 19)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 46, 41)) + + if (k in this.o) { +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 61, 18)) +>this.o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) +>this : Symbol(SimpleMapMap, Decl(symbolIndexerCompatabilityExamples.ts, 41, 1)) +>o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) + + return this.o[k]; +>this.o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) +>this : Symbol(SimpleMapMap, Decl(symbolIndexerCompatabilityExamples.ts, 41, 1)) +>o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 61, 18)) + } + const res = new SimpleMapMap(); +>res : Symbol(res, Decl(symbolIndexerCompatabilityExamples.ts, 65, 13)) +>SimpleMapMap : Symbol(SimpleMapMap, Decl(symbolIndexerCompatabilityExamples.ts, 41, 1)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 46, 19)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 46, 41)) + + this.o[k] = res as any as V; +>this.o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) +>this : Symbol(SimpleMapMap, Decl(symbolIndexerCompatabilityExamples.ts, 41, 1)) +>o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 61, 18)) +>res : Symbol(res, Decl(symbolIndexerCompatabilityExamples.ts, 65, 13)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 46, 41)) + + return res as any as V; +>res : Symbol(res, Decl(symbolIndexerCompatabilityExamples.ts, 65, 13)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 46, 41)) + } + + public clear() { +>clear : Symbol(SimpleMapMap.clear, Decl(symbolIndexerCompatabilityExamples.ts, 68, 5)) + + this.o = {}; +>this.o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) +>this : Symbol(SimpleMapMap, Decl(symbolIndexerCompatabilityExamples.ts, 41, 1)) +>o : Symbol(SimpleMapMap.o, Decl(symbolIndexerCompatabilityExamples.ts, 46, 46)) + } +} + +class SimpleMapMap2 { +>SimpleMapMap2 : Symbol(SimpleMapMap2, Decl(symbolIndexerCompatabilityExamples.ts, 73, 1)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 75, 20)) +>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 75, 42)) + + private o: { [k: PropertyKey]: V } = {}; +>o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 76, 18)) +>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 75, 42)) + + public has(k: K): boolean { +>has : Symbol(SimpleMapMap2.has, Decl(symbolIndexerCompatabilityExamples.ts, 76, 44)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 78, 15)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 75, 20)) + + return k in this.o; +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 78, 15)) +>this.o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) +>this : Symbol(SimpleMapMap2, Decl(symbolIndexerCompatabilityExamples.ts, 73, 1)) +>o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) + } + + public get(k: K): V { +>get : Symbol(SimpleMapMap2.get, Decl(symbolIndexerCompatabilityExamples.ts, 80, 5)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 82, 15)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 75, 20)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 75, 42)) + + return this.o[k]; +>this.o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) +>this : Symbol(SimpleMapMap2, Decl(symbolIndexerCompatabilityExamples.ts, 73, 1)) +>o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 82, 15)) + } + + public set(k: K, v: V) { +>set : Symbol(SimpleMapMap2.set, Decl(symbolIndexerCompatabilityExamples.ts, 84, 5)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 86, 15)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 75, 20)) +>v : Symbol(v, Decl(symbolIndexerCompatabilityExamples.ts, 86, 20)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 75, 42)) + + this.o[k] = v; +>this.o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) +>this : Symbol(SimpleMapMap2, Decl(symbolIndexerCompatabilityExamples.ts, 73, 1)) +>o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 86, 15)) +>v : Symbol(v, Decl(symbolIndexerCompatabilityExamples.ts, 86, 20)) + } + + public getMap(k: K): V { +>getMap : Symbol(SimpleMapMap2.getMap, Decl(symbolIndexerCompatabilityExamples.ts, 88, 5)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 90, 18)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 75, 20)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 75, 42)) + + if (k in this.o) { +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 90, 18)) +>this.o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) +>this : Symbol(SimpleMapMap2, Decl(symbolIndexerCompatabilityExamples.ts, 73, 1)) +>o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) + + return this.o[k]; +>this.o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) +>this : Symbol(SimpleMapMap2, Decl(symbolIndexerCompatabilityExamples.ts, 73, 1)) +>o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 90, 18)) + } + const res = new SimpleMapMap2(); +>res : Symbol(res, Decl(symbolIndexerCompatabilityExamples.ts, 94, 13)) +>SimpleMapMap2 : Symbol(SimpleMapMap2, Decl(symbolIndexerCompatabilityExamples.ts, 73, 1)) +>K : Symbol(K, Decl(symbolIndexerCompatabilityExamples.ts, 75, 20)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 75, 42)) + + this.o[k] = res as any as V; +>this.o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) +>this : Symbol(SimpleMapMap2, Decl(symbolIndexerCompatabilityExamples.ts, 73, 1)) +>o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) +>k : Symbol(k, Decl(symbolIndexerCompatabilityExamples.ts, 90, 18)) +>res : Symbol(res, Decl(symbolIndexerCompatabilityExamples.ts, 94, 13)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 75, 42)) + + return res as any as V; +>res : Symbol(res, Decl(symbolIndexerCompatabilityExamples.ts, 94, 13)) +>V : Symbol(V, Decl(symbolIndexerCompatabilityExamples.ts, 75, 42)) + } + + public clear() { +>clear : Symbol(SimpleMapMap2.clear, Decl(symbolIndexerCompatabilityExamples.ts, 97, 5)) + + this.o = {}; +>this.o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) +>this : Symbol(SimpleMapMap2, Decl(symbolIndexerCompatabilityExamples.ts, 73, 1)) +>o : Symbol(SimpleMapMap2.o, Decl(symbolIndexerCompatabilityExamples.ts, 75, 47)) + } +} + diff --git a/tests/baselines/reference/symbolIndexerCompatabilityExamples.types b/tests/baselines/reference/symbolIndexerCompatabilityExamples.types new file mode 100644 index 0000000000000..bc9a81af1964c --- /dev/null +++ b/tests/baselines/reference/symbolIndexerCompatabilityExamples.types @@ -0,0 +1,295 @@ +=== tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts === +interface Dict { + [index: string]: T; +>index : string + + [index: symbol]: T; +>index : symbol + + [index: number]: T; +>index : number +} + +const keyMap: Dict = {}; +>keyMap : Dict +>{} : {} + +function set(index: keyof T) { +>set : (index: keyof T) => void +>index : keyof T + + keyMap[index] = 1; +>keyMap[index] = 1 : 1 +>keyMap[index] : Dict[keyof T] +>keyMap : Dict +>index : keyof T +>1 : 1 +} + +interface Dict2 { + [index: string | number | symbol]: T; +>index : string | number | symbol +} + +const keyMap2: Dict2 = {}; +>keyMap2 : Dict2 +>{} : {} + +function set2(index: keyof T) { +>set2 : (index: keyof T) => void +>index : keyof T + + keyMap2[index] = 1; +>keyMap2[index] = 1 : 1 +>keyMap2[index] : Dict2[keyof T] +>keyMap2 : Dict2 +>index : keyof T +>1 : 1 +} + +interface Dict3 { + [index: string | symbol]: T; +>index : string | symbol +} + +const keyMap3: Dict3 = {}; +>keyMap3 : Dict3 +>{} : {} + +function set3(index: keyof T) { +>set3 : (index: keyof T) => void +>index : keyof T + + keyMap3[index] = 1; +>keyMap3[index] = 1 : 1 +>keyMap3[index] : Dict3[keyof T] +>keyMap3 : Dict3 +>index : keyof T +>1 : 1 +} + +interface Dict4 { + [index: string]: T; +>index : string + + [index: symbol]: T; +>index : symbol +} + +const keyMap4: Dict4 = {}; +>keyMap4 : Dict4 +>{} : {} + +function set4(index: keyof T) { +>set4 : (index: keyof T) => void +>index : keyof T + + keyMap4[index] = 1; +>keyMap4[index] = 1 : 1 +>keyMap4[index] : Dict4[keyof T] +>keyMap4 : Dict4 +>index : keyof T +>1 : 1 +} + +/** + * Key can only be number, string or symbol + * */ +class SimpleMapMap { +>SimpleMapMap : SimpleMapMap + + private o: { [k: K]: V } = {}; +>o : { [k: K]: V; } +>k : K +>{} : {} + + public has(k: K): boolean { +>has : (k: K) => boolean +>k : K + + return k in this.o; +>k in this.o : boolean +>k : K +>this.o : { [k: K]: V; } +>this : this +>o : { [k: K]: V; } + } + + public get(k: K): V { +>get : (k: K) => V +>k : K + + return this.o[k]; +>this.o[k] : { [k: K]: V; }[K] +>this.o : { [k: K]: V; } +>this : this +>o : { [k: K]: V; } +>k : K + } + + public set(k: K, v: V) { +>set : (k: K, v: V) => void +>k : K +>v : V + + this.o[k] = v; +>this.o[k] = v : V +>this.o[k] : { [k: K]: V; }[K] +>this.o : { [k: K]: V; } +>this : this +>o : { [k: K]: V; } +>k : K +>v : V + } + + public getMap(k: K): V { +>getMap : (k: K) => V +>k : K + + if (k in this.o) { +>k in this.o : boolean +>k : K +>this.o : { [k: K]: V; } +>this : this +>o : { [k: K]: V; } + + return this.o[k]; +>this.o[k] : { [k: K]: V; }[K] +>this.o : { [k: K]: V; } +>this : this +>o : { [k: K]: V; } +>k : K + } + const res = new SimpleMapMap(); +>res : SimpleMapMap +>new SimpleMapMap() : SimpleMapMap +>SimpleMapMap : typeof SimpleMapMap + + this.o[k] = res as any as V; +>this.o[k] = res as any as V : V +>this.o[k] : { [k: K]: V; }[K] +>this.o : { [k: K]: V; } +>this : this +>o : { [k: K]: V; } +>k : K +>res as any as V : V +>res as any : any +>res : SimpleMapMap + + return res as any as V; +>res as any as V : V +>res as any : any +>res : SimpleMapMap + } + + public clear() { +>clear : () => void + + this.o = {}; +>this.o = {} : {} +>this.o : { [k: K]: V; } +>this : this +>o : { [k: K]: V; } +>{} : {} + } +} + +class SimpleMapMap2 { +>SimpleMapMap2 : SimpleMapMap2 + + private o: { [k: PropertyKey]: V } = {}; +>o : { [k: string | number | symbol]: V; } +>k : string | number | symbol +>{} : {} + + public has(k: K): boolean { +>has : (k: K) => boolean +>k : K + + return k in this.o; +>k in this.o : boolean +>k : K +>this.o : { [k: string | number | symbol]: V; } +>this : this +>o : { [k: string | number | symbol]: V; } + } + + public get(k: K): V { +>get : (k: K) => V +>k : K + + return this.o[k]; +>this.o[k] : { [k: string | number | symbol]: V; }[K] +>this.o : { [k: string | number | symbol]: V; } +>this : this +>o : { [k: string | number | symbol]: V; } +>k : K + } + + public set(k: K, v: V) { +>set : (k: K, v: V) => void +>k : K +>v : V + + this.o[k] = v; +>this.o[k] = v : V +>this.o[k] : { [k: string | number | symbol]: V; }[K] +>this.o : { [k: string | number | symbol]: V; } +>this : this +>o : { [k: string | number | symbol]: V; } +>k : K +>v : V + } + + public getMap(k: K): V { +>getMap : (k: K) => V +>k : K + + if (k in this.o) { +>k in this.o : boolean +>k : K +>this.o : { [k: string | number | symbol]: V; } +>this : this +>o : { [k: string | number | symbol]: V; } + + return this.o[k]; +>this.o[k] : { [k: string | number | symbol]: V; }[K] +>this.o : { [k: string | number | symbol]: V; } +>this : this +>o : { [k: string | number | symbol]: V; } +>k : K + } + const res = new SimpleMapMap2(); +>res : SimpleMapMap2 +>new SimpleMapMap2() : SimpleMapMap2 +>SimpleMapMap2 : typeof SimpleMapMap2 + + this.o[k] = res as any as V; +>this.o[k] = res as any as V : V +>this.o[k] : { [k: string | number | symbol]: V; }[K] +>this.o : { [k: string | number | symbol]: V; } +>this : this +>o : { [k: string | number | symbol]: V; } +>k : K +>res as any as V : V +>res as any : any +>res : SimpleMapMap2 + + return res as any as V; +>res as any as V : V +>res as any : any +>res : SimpleMapMap2 + } + + public clear() { +>clear : () => void + + this.o = {}; +>this.o = {} : {} +>this.o : { [k: string | number | symbol]: V; } +>this : this +>o : { [k: string | number | symbol]: V; } +>{} : {} + } +} + diff --git a/tests/baselines/reference/symbolProperty17.errors.txt b/tests/baselines/reference/symbolProperty17.errors.txt deleted file mode 100644 index 51f77646f0db7..0000000000000 --- a/tests/baselines/reference/symbolProperty17.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/conformance/es6/Symbols/symbolProperty17.ts(3,6): error TS1023: An index signature parameter type must be 'string' or 'number'. - - -==== tests/cases/conformance/es6/Symbols/symbolProperty17.ts (1 errors) ==== - interface I { - [Symbol.iterator]: number; - [s: symbol]: string; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. - "__@iterator": string; - } - - var i: I; - var it = i[Symbol.iterator]; \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty29.errors.txt b/tests/baselines/reference/symbolProperty29.errors.txt deleted file mode 100644 index 1efaeb2b3bfb8..0000000000000 --- a/tests/baselines/reference/symbolProperty29.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/conformance/es6/Symbols/symbolProperty29.ts(5,6): error TS1023: An index signature parameter type must be 'string' or 'number'. - - -==== tests/cases/conformance/es6/Symbols/symbolProperty29.ts (1 errors) ==== - class C1 { - [Symbol.toStringTag]() { - return { x: "" }; - } - [s: symbol]: () => { x: string }; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. - } \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty30.errors.txt b/tests/baselines/reference/symbolProperty30.errors.txt deleted file mode 100644 index b839d11d1b803..0000000000000 --- a/tests/baselines/reference/symbolProperty30.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/conformance/es6/Symbols/symbolProperty30.ts(5,6): error TS1023: An index signature parameter type must be 'string' or 'number'. - - -==== tests/cases/conformance/es6/Symbols/symbolProperty30.ts (1 errors) ==== - class C1 { - [Symbol.toStringTag]() { - return { x: "" }; - } - [s: symbol]: () => { x: number }; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. - } \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty31.errors.txt b/tests/baselines/reference/symbolProperty31.errors.txt deleted file mode 100644 index 39735c017b2ad..0000000000000 --- a/tests/baselines/reference/symbolProperty31.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/conformance/es6/Symbols/symbolProperty31.ts(7,6): error TS1023: An index signature parameter type must be 'string' or 'number'. - - -==== tests/cases/conformance/es6/Symbols/symbolProperty31.ts (1 errors) ==== - class C1 { - [Symbol.toStringTag]() { - return { x: "" }; - } - } - class C2 extends C1 { - [s: symbol]: () => { x: string }; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. - } \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty32.errors.txt b/tests/baselines/reference/symbolProperty32.errors.txt deleted file mode 100644 index 4051f8f91c84b..0000000000000 --- a/tests/baselines/reference/symbolProperty32.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/conformance/es6/Symbols/symbolProperty32.ts(7,6): error TS1023: An index signature parameter type must be 'string' or 'number'. - - -==== tests/cases/conformance/es6/Symbols/symbolProperty32.ts (1 errors) ==== - class C1 { - [Symbol.toStringTag]() { - return { x: "" }; - } - } - class C2 extends C1 { - [s: symbol]: () => { x: number }; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. - } \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty33.errors.txt b/tests/baselines/reference/symbolProperty33.errors.txt index 5c23a80f8ca7f..1f3432759fdb5 100644 --- a/tests/baselines/reference/symbolProperty33.errors.txt +++ b/tests/baselines/reference/symbolProperty33.errors.txt @@ -1,8 +1,7 @@ tests/cases/conformance/es6/Symbols/symbolProperty33.ts(1,18): error TS2449: Class 'C2' used before its declaration. -tests/cases/conformance/es6/Symbols/symbolProperty33.ts(7,6): error TS1023: An index signature parameter type must be 'string' or 'number'. -==== tests/cases/conformance/es6/Symbols/symbolProperty33.ts (2 errors) ==== +==== tests/cases/conformance/es6/Symbols/symbolProperty33.ts (1 errors) ==== class C1 extends C2 { ~~ !!! error TS2449: Class 'C2' used before its declaration. @@ -13,6 +12,4 @@ tests/cases/conformance/es6/Symbols/symbolProperty33.ts(7,6): error TS1023: An i } class C2 { [s: symbol]: () => { x: string }; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty34.errors.txt b/tests/baselines/reference/symbolProperty34.errors.txt index bd909ae3b68c5..6adbeb6fa7afb 100644 --- a/tests/baselines/reference/symbolProperty34.errors.txt +++ b/tests/baselines/reference/symbolProperty34.errors.txt @@ -1,8 +1,7 @@ tests/cases/conformance/es6/Symbols/symbolProperty34.ts(1,18): error TS2449: Class 'C2' used before its declaration. -tests/cases/conformance/es6/Symbols/symbolProperty34.ts(7,6): error TS1023: An index signature parameter type must be 'string' or 'number'. -==== tests/cases/conformance/es6/Symbols/symbolProperty34.ts (2 errors) ==== +==== tests/cases/conformance/es6/Symbols/symbolProperty34.ts (1 errors) ==== class C1 extends C2 { ~~ !!! error TS2449: Class 'C2' used before its declaration. @@ -13,6 +12,4 @@ tests/cases/conformance/es6/Symbols/symbolProperty34.ts(7,6): error TS1023: An i } class C2 { [s: symbol]: () => { x: number }; - ~ -!!! error TS1023: An index signature parameter type must be 'string' or 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt b/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt new file mode 100644 index 0000000000000..675b448adce8d --- /dev/null +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt @@ -0,0 +1,419 @@ +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(17,5): error TS2322: Type 'B' is not assignable to type 'A'. + Index signature is missing in type 'B'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(18,5): error TS2322: Type 'AB' is not assignable to type 'A'. + Index signature is missing in type 'AB'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(20,5): error TS2322: Type 'A' is not assignable to type 'B'. + Index signature is missing in type 'A'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(21,5): error TS2322: Type 'AB' is not assignable to type 'B'. + Index signature is missing in type 'AB'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(32,5): error TS2322: Type 'B' is not assignable to type 'SubA'. + Index signature is missing in type 'B'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(33,5): error TS2322: Type 'AB' is not assignable to type 'SubA'. + Index signature is missing in type 'AB'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(35,5): error TS2322: Type 'SubA' is not assignable to type 'A'. + Index signature is missing in type 'SubA'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(36,5): error TS2322: Type 'SubA' is not assignable to type 'B'. + Index signature is missing in type 'SubA'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(37,5): error TS2322: Type 'SubA' is not assignable to type 'AB'. + Index signature is missing in type 'SubA'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(44,5): error TS2536: Type 'K1' cannot be used to index type 'SubB'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(46,5): error TS2322: Type 'B' is not assignable to type 'SubB'. + Index signature is missing in type 'B'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(47,5): error TS2322: Type 'AB' is not assignable to type 'SubB'. + Index signature is missing in type 'AB'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(50,5): error TS2322: Type 'SubB' is not assignable to type 'A'. + Index signature is missing in type 'SubB'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(51,5): error TS2322: Type 'SubB' is not assignable to type 'B'. + Index signature is missing in type 'SubB'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(52,5): error TS2322: Type 'SubB' is not assignable to type 'AB'. + Index signature is missing in type 'SubB'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(53,5): error TS2322: Type 'SubB' is not assignable to type 'SubA'. + Index signature is missing in type 'SubB'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(74,5): error TS2322: Type 'C' is not assignable to type 'D'. + Index signature is missing in type 'C'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(77,5): error TS2322: Type 'C' is not assignable to type 'E'. + Index signature is missing in type 'C'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(108,5): error TS2322: Type 'G' is not assignable to type 'F'. + Index signature is missing in type 'G'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(113,5): error TS2322: Type 'F' is not assignable to type 'G'. + Index signature is missing in type 'F'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(118,5): error TS2322: Type 'F' is not assignable to type 'FG'. + Index signature is missing in type 'F'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(119,5): error TS2322: Type 'G' is not assignable to type 'FG'. + Index signature is missing in type 'G'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(123,5): error TS2322: Type 'F' is not assignable to type 'F & G'. + Type 'F' is not assignable to type 'G'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(124,5): error TS2322: Type 'G' is not assignable to type 'F & G'. + Type 'G' is not assignable to type 'F'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(128,5): error TS2322: Type 'F' is not assignable to type 'IFG'. + Index signature is missing in type 'F'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(129,5): error TS2322: Type 'G' is not assignable to type 'IFG'. + Index signature is missing in type 'G'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(146,5): error TS2413: 'S3' index type 'string' is not assignable to 'S3.A' index type '"a"'. + Type 'string' is not assignable to type '"a"'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(151,5): error TS2413: 'S3' index type 'string' is not assignable to 'S3.A' index type 'never'. + Type 'string' is not assignable to type 'never'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(161,5): error TS2322: Type 'I' is not assignable to type 'H'. + Property '[S3.A]' is missing in type 'I'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(162,5): error TS2322: Type 'J' is not assignable to type 'H'. + Property '[S3.A]' is missing in type 'J'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(164,5): error TS2322: Type 'L' is not assignable to type 'H'. + Types of property '[S3.A]' are incompatible. + Type 'string' is not assignable to type '"a"'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(166,5): error TS2322: Type 'H' is not assignable to type 'I'. + 'S3' and 'S3.A' index signatures are incompatible. + Type 'string' is not assignable to type '"a"'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(167,5): error TS2322: Type 'J' is not assignable to type 'I'. + 'S3' and 'S3.A' index signatures are incompatible. + Type 'string' is not assignable to type '"a"'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(171,5): error TS2322: Type 'H' is not assignable to type 'J'. + 'S3' and 'S3.A' index signatures are incompatible. + Type 'string' is not assignable to type 'never'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(172,5): error TS2322: Type 'I' is not assignable to type 'J'. + 'S3' and 'S3.A' index signatures are incompatible. + Type 'string' is not assignable to type 'never'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(176,5): error TS2322: Type 'H' is not assignable to type 'K'. + Type 'H' is not assignable to type '{ a: string; b: string; c: string; }'. + Property 'b' is missing in type 'H'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(177,5): error TS2322: Type 'I' is not assignable to type 'H'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(178,5): error TS2322: Type 'J' is not assignable to type 'K'. + Type 'J' is not assignable to type '{ a: string; b: string; c: string; }'. + Property 'a' is missing in type 'J'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(179,5): error TS2322: Type 'L' is not assignable to type 'K'. + Type 'L' is not assignable to type '{ [S3.A]: "a"; }'. + Types of property '[S3.A]' are incompatible. + Type 'string' is not assignable to type '"a"'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(181,5): error TS2322: Type 'H' is not assignable to type 'L'. + Type 'H' is not assignable to type '{ a: string; b: string; c: string; }'. + Property 'b' is missing in type 'H'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(182,5): error TS2322: Type 'I' is not assignable to type 'L'. + Type 'I' is not assignable to type '{ a: string; b: string; c: string; }'. + Property 'a' is missing in type 'I'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5): error TS2322: Type 'J' is not assignable to type 'L'. + Type 'J' is not assignable to type '{ a: string; b: string; c: string; }'. + Property 'a' is missing in type 'J'. + + +==== tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts (42 errors) ==== + interface A { + [x: "a" | "b" | "c"]: string; + } + + interface B { + [x: "b" | "c" | "d"]: string; + } + + interface AB { + [x: "b" | "c"]: string; + } + + function f1< + K1 extends "a" | "b" | "c", + K2 extends K1 + >(a: A, b: B, ab: AB, k1: K1, k2: K2) { + a = b; // error: B is missing `"a"` + ~ +!!! error TS2322: Type 'B' is not assignable to type 'A'. +!!! error TS2322: Index signature is missing in type 'B'. + a = ab; // error: AB is missing `"a"` + ~ +!!! error TS2322: Type 'AB' is not assignable to type 'A'. +!!! error TS2322: Index signature is missing in type 'AB'. + + b = a; // error: A is missing `"d"` + ~ +!!! error TS2322: Type 'A' is not assignable to type 'B'. +!!! error TS2322: Index signature is missing in type 'A'. + b = ab; // error: AB is missing `"d"` + ~ +!!! error TS2322: Type 'AB' is not assignable to type 'B'. +!!! error TS2322: Index signature is missing in type 'AB'. + + ab = a; + ab = b; + + interface SubA { + [x: K1]: string; + } + let s: SubA = {}; + s[k1]; // valid + s = a; + s = b; // error: doesn't provide `"b"` + ~ +!!! error TS2322: Type 'B' is not assignable to type 'SubA'. +!!! error TS2322: Index signature is missing in type 'B'. + s = ab; // error: doesn't provide `"b"` + ~ +!!! error TS2322: Type 'AB' is not assignable to type 'SubA'. +!!! error TS2322: Index signature is missing in type 'AB'. + + a = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ~ +!!! error TS2322: Type 'SubA' is not assignable to type 'A'. +!!! error TS2322: Index signature is missing in type 'SubA'. + b = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ~ +!!! error TS2322: Type 'SubA' is not assignable to type 'B'. +!!! error TS2322: Index signature is missing in type 'SubA'. + ab = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ~~ +!!! error TS2322: Type 'SubA' is not assignable to type 'AB'. +!!! error TS2322: Index signature is missing in type 'SubA'. + + interface SubB { + [x: K2]: string; + } + let s2: SubB = {}; + s2[k2]; // valid + s2[k1]; // invalid + ~~~~~~ +!!! error TS2536: Type 'K1' cannot be used to index type 'SubB'. + s2 = a; + s2 = b; // error: doesn't provide `"b"` + ~~ +!!! error TS2322: Type 'B' is not assignable to type 'SubB'. +!!! error TS2322: Index signature is missing in type 'B'. + s2 = ab; // error: doesn't provide `"b"` + ~~ +!!! error TS2322: Type 'AB' is not assignable to type 'SubB'. +!!! error TS2322: Index signature is missing in type 'AB'. + s2 = s; + + a = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ~ +!!! error TS2322: Type 'SubB' is not assignable to type 'A'. +!!! error TS2322: Index signature is missing in type 'SubB'. + b = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ~ +!!! error TS2322: Type 'SubB' is not assignable to type 'B'. +!!! error TS2322: Index signature is missing in type 'SubB'. + ab = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ~~ +!!! error TS2322: Type 'SubB' is not assignable to type 'AB'. +!!! error TS2322: Index signature is missing in type 'SubB'. + s = s2; // error: might not provide any of the keys of K1 + ~ +!!! error TS2322: Type 'SubB' is not assignable to type 'SubA'. +!!! error TS2322: Index signature is missing in type 'SubB'. + } + + interface C { + [x: "a" | "b" | "c"]: string; + [y: 1 | 2 | 3]: string; + } + + interface D { + [x: "a" | "b" | "c" | "d"]: string; + [y: 1 | 2 | 3 | 4]: string; + } + + interface E { + [x: "a" | "b" | "c" | "d" | 1 | 2 | 3 | 4]: string; + } + + function f2(c: C, d: D, e: E) { + c = d; + c = e; + + d = c; // error: C is missing an index for `"d"` and `4` + ~ +!!! error TS2322: Type 'C' is not assignable to type 'D'. +!!! error TS2322: Index signature is missing in type 'C'. + d = e; + + e = c; // error: C is missing an index for `"d"` and `4` + ~ +!!! error TS2322: Type 'C' is not assignable to type 'E'. +!!! error TS2322: Index signature is missing in type 'C'. + e = d; + } + + enum S1 { + A = "a", + B = "b", + C = "c" + } + + enum S2 { + A = "a", + B = "b", + C = "c" + } + + interface F { + [x: S1]: string; + } + + interface G { + [x: S2]: string; + } + + interface FG { + [x: S1 | S2]: string; + } + + interface IFG extends F, G {} + + function f3(f: F, g: G, fg: FG, fg2: F & G, fg3: IFG) { + f = g; // error: incompatible string enums + ~ +!!! error TS2322: Type 'G' is not assignable to type 'F'. +!!! error TS2322: Index signature is missing in type 'G'. + f = fg; // OK + f = fg2; // OK + f = fg3; // OK + + g = f; // error: incompatible string enums + ~ +!!! error TS2322: Type 'F' is not assignable to type 'G'. +!!! error TS2322: Index signature is missing in type 'F'. + g = fg; // OK + g = fg2; // OK + g = fg3; // OK + + fg = f; // error: doesn't provide S2 + ~~ +!!! error TS2322: Type 'F' is not assignable to type 'FG'. +!!! error TS2322: Index signature is missing in type 'F'. + fg = g; // error: doesn't provide S1 + ~~ +!!! error TS2322: Type 'G' is not assignable to type 'FG'. +!!! error TS2322: Index signature is missing in type 'G'. + fg = fg2; // OK + fg = fg3; // OK + + fg2 = f; // error: doesn't provide S2 + ~~~ +!!! error TS2322: Type 'F' is not assignable to type 'F & G'. +!!! error TS2322: Type 'F' is not assignable to type 'G'. + fg2 = g; // error: doesn't provide S1 + ~~~ +!!! error TS2322: Type 'G' is not assignable to type 'F & G'. +!!! error TS2322: Type 'G' is not assignable to type 'F'. + fg2 = fg; // OK + fg2 = fg3; // OK + + fg3 = f; // error: doesn't provide S2 + ~~~ +!!! error TS2322: Type 'F' is not assignable to type 'IFG'. +!!! error TS2322: Index signature is missing in type 'F'. + fg3 = g; // error: doesn't provide S1 + ~~~ +!!! error TS2322: Type 'G' is not assignable to type 'IFG'. +!!! error TS2322: Index signature is missing in type 'G'. + fg3 = fg; // OK + fg3 = fg2; // OK + } + + enum S3 { + A = "a", + B = "b", + C = "c" + } + + interface H { + [x: S3]: string; + [S3.A]: "a"; + } + + interface I { + [x: S3]: string; + ~~~~~~~~~~~~~~~~ +!!! error TS2413: 'S3' index type 'string' is not assignable to 'S3.A' index type '"a"'. +!!! error TS2413: Type 'string' is not assignable to type '"a"'. + [x: S3.A]: "a"; + } + + interface J { + [x: S3]: string; + ~~~~~~~~~~~~~~~~ +!!! error TS2413: 'S3' index type 'string' is not assignable to 'S3.A' index type 'never'. +!!! error TS2413: Type 'string' is not assignable to type 'never'. + [x: S3.A]: never; + } + + type K = {[K in S3]: string} & {[S3.A]: "a"}; + type L = {[K in S3]: string} & {[x: S3.A]: "a"}; + + // TODO: reconcile union signatures with properties? + // Properties don't technically retain their enuminess, this may even be expected for string enums, if _very_ subtle + function f4(h: H, i: I, j: J, k: K, l: L) { + h = i; + ~ +!!! error TS2322: Type 'I' is not assignable to type 'H'. +!!! error TS2322: Property '[S3.A]' is missing in type 'I'. + h = j; + ~ +!!! error TS2322: Type 'J' is not assignable to type 'H'. +!!! error TS2322: Property '[S3.A]' is missing in type 'J'. + h = k; + h = l; + ~ +!!! error TS2322: Type 'L' is not assignable to type 'H'. +!!! error TS2322: Types of property '[S3.A]' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"a"'. + + i = h; + ~ +!!! error TS2322: Type 'H' is not assignable to type 'I'. +!!! error TS2322: 'S3' and 'S3.A' index signatures are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"a"'. + i = j; + ~ +!!! error TS2322: Type 'J' is not assignable to type 'I'. +!!! error TS2322: 'S3' and 'S3.A' index signatures are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"a"'. + i = k; + i = l; + + j = h; + ~ +!!! error TS2322: Type 'H' is not assignable to type 'J'. +!!! error TS2322: 'S3' and 'S3.A' index signatures are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'never'. + j = i; + ~ +!!! error TS2322: Type 'I' is not assignable to type 'J'. +!!! error TS2322: 'S3' and 'S3.A' index signatures are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'never'. + j = k; + j = l; + + k = h; + ~ +!!! error TS2322: Type 'H' is not assignable to type 'K'. +!!! error TS2322: Type 'H' is not assignable to type '{ a: string; b: string; c: string; }'. +!!! error TS2322: Property 'b' is missing in type 'H'. + h = i; + ~ +!!! error TS2322: Type 'I' is not assignable to type 'H'. + k = j; + ~ +!!! error TS2322: Type 'J' is not assignable to type 'K'. +!!! error TS2322: Type 'J' is not assignable to type '{ a: string; b: string; c: string; }'. +!!! error TS2322: Property 'a' is missing in type 'J'. + k = l; + ~ +!!! error TS2322: Type 'L' is not assignable to type 'K'. +!!! error TS2322: Type 'L' is not assignable to type '{ [S3.A]: "a"; }'. +!!! error TS2322: Types of property '[S3.A]' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"a"'. + + l = h; + ~ +!!! error TS2322: Type 'H' is not assignable to type 'L'. +!!! error TS2322: Type 'H' is not assignable to type '{ a: string; b: string; c: string; }'. +!!! error TS2322: Property 'b' is missing in type 'H'. + l = i; + ~ +!!! error TS2322: Type 'I' is not assignable to type 'L'. +!!! error TS2322: Type 'I' is not assignable to type '{ a: string; b: string; c: string; }'. +!!! error TS2322: Property 'a' is missing in type 'I'. + l = j; + ~ +!!! error TS2322: Type 'J' is not assignable to type 'L'. +!!! error TS2322: Type 'J' is not assignable to type '{ a: string; b: string; c: string; }'. +!!! error TS2322: Property 'a' is missing in type 'J'. + l = k; + } + \ No newline at end of file diff --git a/tests/baselines/reference/unionIndexerGeneralAssignability.js b/tests/baselines/reference/unionIndexerGeneralAssignability.js new file mode 100644 index 0000000000000..6a5d01fd4ee76 --- /dev/null +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.js @@ -0,0 +1,288 @@ +//// [unionIndexerGeneralAssignability.ts] +interface A { + [x: "a" | "b" | "c"]: string; +} + +interface B { + [x: "b" | "c" | "d"]: string; +} + +interface AB { + [x: "b" | "c"]: string; +} + +function f1< + K1 extends "a" | "b" | "c", + K2 extends K1 +>(a: A, b: B, ab: AB, k1: K1, k2: K2) { + a = b; // error: B is missing `"a"` + a = ab; // error: AB is missing `"a"` + + b = a; // error: A is missing `"d"` + b = ab; // error: AB is missing `"d"` + + ab = a; + ab = b; + + interface SubA { + [x: K1]: string; + } + let s: SubA = {}; + s[k1]; // valid + s = a; + s = b; // error: doesn't provide `"b"` + s = ab; // error: doesn't provide `"b"` + + a = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + b = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ab = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + + interface SubB { + [x: K2]: string; + } + let s2: SubB = {}; + s2[k2]; // valid + s2[k1]; // invalid + s2 = a; + s2 = b; // error: doesn't provide `"b"` + s2 = ab; // error: doesn't provide `"b"` + s2 = s; + + a = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + b = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ab = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + s = s2; // error: might not provide any of the keys of K1 +} + +interface C { + [x: "a" | "b" | "c"]: string; + [y: 1 | 2 | 3]: string; +} + +interface D { + [x: "a" | "b" | "c" | "d"]: string; + [y: 1 | 2 | 3 | 4]: string; +} + +interface E { + [x: "a" | "b" | "c" | "d" | 1 | 2 | 3 | 4]: string; +} + +function f2(c: C, d: D, e: E) { + c = d; + c = e; + + d = c; // error: C is missing an index for `"d"` and `4` + d = e; + + e = c; // error: C is missing an index for `"d"` and `4` + e = d; +} + +enum S1 { + A = "a", + B = "b", + C = "c" +} + +enum S2 { + A = "a", + B = "b", + C = "c" +} + +interface F { + [x: S1]: string; +} + +interface G { + [x: S2]: string; +} + +interface FG { + [x: S1 | S2]: string; +} + +interface IFG extends F, G {} + +function f3(f: F, g: G, fg: FG, fg2: F & G, fg3: IFG) { + f = g; // error: incompatible string enums + f = fg; // OK + f = fg2; // OK + f = fg3; // OK + + g = f; // error: incompatible string enums + g = fg; // OK + g = fg2; // OK + g = fg3; // OK + + fg = f; // error: doesn't provide S2 + fg = g; // error: doesn't provide S1 + fg = fg2; // OK + fg = fg3; // OK + + fg2 = f; // error: doesn't provide S2 + fg2 = g; // error: doesn't provide S1 + fg2 = fg; // OK + fg2 = fg3; // OK + + fg3 = f; // error: doesn't provide S2 + fg3 = g; // error: doesn't provide S1 + fg3 = fg; // OK + fg3 = fg2; // OK +} + +enum S3 { + A = "a", + B = "b", + C = "c" +} + +interface H { + [x: S3]: string; + [S3.A]: "a"; +} + +interface I { + [x: S3]: string; + [x: S3.A]: "a"; +} + +interface J { + [x: S3]: string; + [x: S3.A]: never; +} + +type K = {[K in S3]: string} & {[S3.A]: "a"}; +type L = {[K in S3]: string} & {[x: S3.A]: "a"}; + +// TODO: reconcile union signatures with properties? +// Properties don't technically retain their enuminess, this may even be expected for string enums, if _very_ subtle +function f4(h: H, i: I, j: J, k: K, l: L) { + h = i; + h = j; + h = k; + h = l; + + i = h; + i = j; + i = k; + i = l; + + j = h; + j = i; + j = k; + j = l; + + k = h; + h = i; + k = j; + k = l; + + l = h; + l = i; + l = j; + l = k; +} + + +//// [unionIndexerGeneralAssignability.js] +function f1(a, b, ab, k1, k2) { + a = b; // error: B is missing `"a"` + a = ab; // error: AB is missing `"a"` + b = a; // error: A is missing `"d"` + b = ab; // error: AB is missing `"d"` + ab = a; + ab = b; + var s = {}; + s[k1]; // valid + s = a; + s = b; // error: doesn't provide `"b"` + s = ab; // error: doesn't provide `"b"` + a = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + b = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ab = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + var s2 = {}; + s2[k2]; // valid + s2[k1]; // invalid + s2 = a; + s2 = b; // error: doesn't provide `"b"` + s2 = ab; // error: doesn't provide `"b"` + s2 = s; + a = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + b = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ab = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + s = s2; // error: might not provide any of the keys of K1 +} +function f2(c, d, e) { + c = d; + c = e; + d = c; // error: C is missing an index for `"d"` and `4` + d = e; + e = c; // error: C is missing an index for `"d"` and `4` + e = d; +} +var S1; +(function (S1) { + S1["A"] = "a"; + S1["B"] = "b"; + S1["C"] = "c"; +})(S1 || (S1 = {})); +var S2; +(function (S2) { + S2["A"] = "a"; + S2["B"] = "b"; + S2["C"] = "c"; +})(S2 || (S2 = {})); +function f3(f, g, fg, fg2, fg3) { + f = g; // error: incompatible string enums + f = fg; // OK + f = fg2; // OK + f = fg3; // OK + g = f; // error: incompatible string enums + g = fg; // OK + g = fg2; // OK + g = fg3; // OK + fg = f; // error: doesn't provide S2 + fg = g; // error: doesn't provide S1 + fg = fg2; // OK + fg = fg3; // OK + fg2 = f; // error: doesn't provide S2 + fg2 = g; // error: doesn't provide S1 + fg2 = fg; // OK + fg2 = fg3; // OK + fg3 = f; // error: doesn't provide S2 + fg3 = g; // error: doesn't provide S1 + fg3 = fg; // OK + fg3 = fg2; // OK +} +var S3; +(function (S3) { + S3["A"] = "a"; + S3["B"] = "b"; + S3["C"] = "c"; +})(S3 || (S3 = {})); +// TODO: reconcile union signatures with properties? +// Properties don't technically retain their enuminess, this may even be expected for string enums, if _very_ subtle +function f4(h, i, j, k, l) { + h = i; + h = j; + h = k; + h = l; + i = h; + i = j; + i = k; + i = l; + j = h; + j = i; + j = k; + j = l; + k = h; + h = i; + k = j; + k = l; + l = h; + l = i; + l = j; + l = k; +} diff --git a/tests/baselines/reference/unionIndexerGeneralAssignability.symbols b/tests/baselines/reference/unionIndexerGeneralAssignability.symbols new file mode 100644 index 0000000000000..7062cec49f388 --- /dev/null +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.symbols @@ -0,0 +1,537 @@ +=== tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts === +interface A { +>A : Symbol(A, Decl(unionIndexerGeneralAssignability.ts, 0, 0)) + + [x: "a" | "b" | "c"]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 1, 5)) +} + +interface B { +>B : Symbol(B, Decl(unionIndexerGeneralAssignability.ts, 2, 1)) + + [x: "b" | "c" | "d"]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 5, 5)) +} + +interface AB { +>AB : Symbol(AB, Decl(unionIndexerGeneralAssignability.ts, 6, 1)) + + [x: "b" | "c"]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 9, 5)) +} + +function f1< +>f1 : Symbol(f1, Decl(unionIndexerGeneralAssignability.ts, 10, 1)) + + K1 extends "a" | "b" | "c", +>K1 : Symbol(K1, Decl(unionIndexerGeneralAssignability.ts, 12, 12)) + + K2 extends K1 +>K2 : Symbol(K2, Decl(unionIndexerGeneralAssignability.ts, 13, 31)) +>K1 : Symbol(K1, Decl(unionIndexerGeneralAssignability.ts, 12, 12)) + +>(a: A, b: B, ab: AB, k1: K1, k2: K2) { +>a : Symbol(a, Decl(unionIndexerGeneralAssignability.ts, 15, 2)) +>A : Symbol(A, Decl(unionIndexerGeneralAssignability.ts, 0, 0)) +>b : Symbol(b, Decl(unionIndexerGeneralAssignability.ts, 15, 7)) +>B : Symbol(B, Decl(unionIndexerGeneralAssignability.ts, 2, 1)) +>ab : Symbol(ab, Decl(unionIndexerGeneralAssignability.ts, 15, 13)) +>AB : Symbol(AB, Decl(unionIndexerGeneralAssignability.ts, 6, 1)) +>k1 : Symbol(k1, Decl(unionIndexerGeneralAssignability.ts, 15, 21)) +>K1 : Symbol(K1, Decl(unionIndexerGeneralAssignability.ts, 12, 12)) +>k2 : Symbol(k2, Decl(unionIndexerGeneralAssignability.ts, 15, 29)) +>K2 : Symbol(K2, Decl(unionIndexerGeneralAssignability.ts, 13, 31)) + + a = b; // error: B is missing `"a"` +>a : Symbol(a, Decl(unionIndexerGeneralAssignability.ts, 15, 2)) +>b : Symbol(b, Decl(unionIndexerGeneralAssignability.ts, 15, 7)) + + a = ab; // error: AB is missing `"a"` +>a : Symbol(a, Decl(unionIndexerGeneralAssignability.ts, 15, 2)) +>ab : Symbol(ab, Decl(unionIndexerGeneralAssignability.ts, 15, 13)) + + b = a; // error: A is missing `"d"` +>b : Symbol(b, Decl(unionIndexerGeneralAssignability.ts, 15, 7)) +>a : Symbol(a, Decl(unionIndexerGeneralAssignability.ts, 15, 2)) + + b = ab; // error: AB is missing `"d"` +>b : Symbol(b, Decl(unionIndexerGeneralAssignability.ts, 15, 7)) +>ab : Symbol(ab, Decl(unionIndexerGeneralAssignability.ts, 15, 13)) + + ab = a; +>ab : Symbol(ab, Decl(unionIndexerGeneralAssignability.ts, 15, 13)) +>a : Symbol(a, Decl(unionIndexerGeneralAssignability.ts, 15, 2)) + + ab = b; +>ab : Symbol(ab, Decl(unionIndexerGeneralAssignability.ts, 15, 13)) +>b : Symbol(b, Decl(unionIndexerGeneralAssignability.ts, 15, 7)) + + interface SubA { +>SubA : Symbol(SubA, Decl(unionIndexerGeneralAssignability.ts, 23, 11)) + + [x: K1]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 26, 9)) +>K1 : Symbol(K1, Decl(unionIndexerGeneralAssignability.ts, 12, 12)) + } + let s: SubA = {}; +>s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) +>SubA : Symbol(SubA, Decl(unionIndexerGeneralAssignability.ts, 23, 11)) + + s[k1]; // valid +>s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) +>k1 : Symbol(k1, Decl(unionIndexerGeneralAssignability.ts, 15, 21)) + + s = a; +>s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) +>a : Symbol(a, Decl(unionIndexerGeneralAssignability.ts, 15, 2)) + + s = b; // error: doesn't provide `"b"` +>s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) +>b : Symbol(b, Decl(unionIndexerGeneralAssignability.ts, 15, 7)) + + s = ab; // error: doesn't provide `"b"` +>s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) +>ab : Symbol(ab, Decl(unionIndexerGeneralAssignability.ts, 15, 13)) + + a = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` +>a : Symbol(a, Decl(unionIndexerGeneralAssignability.ts, 15, 2)) +>s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) + + b = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` +>b : Symbol(b, Decl(unionIndexerGeneralAssignability.ts, 15, 7)) +>s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) + + ab = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` +>ab : Symbol(ab, Decl(unionIndexerGeneralAssignability.ts, 15, 13)) +>s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) + + interface SubB { +>SubB : Symbol(SubB, Decl(unionIndexerGeneralAssignability.ts, 36, 11)) + + [x: K2]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 39, 9)) +>K2 : Symbol(K2, Decl(unionIndexerGeneralAssignability.ts, 13, 31)) + } + let s2: SubB = {}; +>s2 : Symbol(s2, Decl(unionIndexerGeneralAssignability.ts, 41, 7)) +>SubB : Symbol(SubB, Decl(unionIndexerGeneralAssignability.ts, 36, 11)) + + s2[k2]; // valid +>s2 : Symbol(s2, Decl(unionIndexerGeneralAssignability.ts, 41, 7)) +>k2 : Symbol(k2, Decl(unionIndexerGeneralAssignability.ts, 15, 29)) + + s2[k1]; // invalid +>s2 : Symbol(s2, Decl(unionIndexerGeneralAssignability.ts, 41, 7)) +>k1 : Symbol(k1, Decl(unionIndexerGeneralAssignability.ts, 15, 21)) + + s2 = a; +>s2 : Symbol(s2, Decl(unionIndexerGeneralAssignability.ts, 41, 7)) +>a : Symbol(a, Decl(unionIndexerGeneralAssignability.ts, 15, 2)) + + s2 = b; // error: doesn't provide `"b"` +>s2 : Symbol(s2, Decl(unionIndexerGeneralAssignability.ts, 41, 7)) +>b : Symbol(b, Decl(unionIndexerGeneralAssignability.ts, 15, 7)) + + s2 = ab; // error: doesn't provide `"b"` +>s2 : Symbol(s2, Decl(unionIndexerGeneralAssignability.ts, 41, 7)) +>ab : Symbol(ab, Decl(unionIndexerGeneralAssignability.ts, 15, 13)) + + s2 = s; +>s2 : Symbol(s2, Decl(unionIndexerGeneralAssignability.ts, 41, 7)) +>s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) + + a = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` +>a : Symbol(a, Decl(unionIndexerGeneralAssignability.ts, 15, 2)) +>s2 : Symbol(s2, Decl(unionIndexerGeneralAssignability.ts, 41, 7)) + + b = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` +>b : Symbol(b, Decl(unionIndexerGeneralAssignability.ts, 15, 7)) +>s2 : Symbol(s2, Decl(unionIndexerGeneralAssignability.ts, 41, 7)) + + ab = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` +>ab : Symbol(ab, Decl(unionIndexerGeneralAssignability.ts, 15, 13)) +>s2 : Symbol(s2, Decl(unionIndexerGeneralAssignability.ts, 41, 7)) + + s = s2; // error: might not provide any of the keys of K1 +>s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) +>s2 : Symbol(s2, Decl(unionIndexerGeneralAssignability.ts, 41, 7)) +} + +interface C { +>C : Symbol(C, Decl(unionIndexerGeneralAssignability.ts, 53, 1)) + + [x: "a" | "b" | "c"]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 56, 5)) + + [y: 1 | 2 | 3]: string; +>y : Symbol(y, Decl(unionIndexerGeneralAssignability.ts, 57, 5)) +} + +interface D { +>D : Symbol(D, Decl(unionIndexerGeneralAssignability.ts, 58, 1)) + + [x: "a" | "b" | "c" | "d"]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 61, 5)) + + [y: 1 | 2 | 3 | 4]: string; +>y : Symbol(y, Decl(unionIndexerGeneralAssignability.ts, 62, 5)) +} + +interface E { +>E : Symbol(E, Decl(unionIndexerGeneralAssignability.ts, 63, 1)) + + [x: "a" | "b" | "c" | "d" | 1 | 2 | 3 | 4]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 66, 5)) +} + +function f2(c: C, d: D, e: E) { +>f2 : Symbol(f2, Decl(unionIndexerGeneralAssignability.ts, 67, 1)) +>c : Symbol(c, Decl(unionIndexerGeneralAssignability.ts, 69, 12)) +>C : Symbol(C, Decl(unionIndexerGeneralAssignability.ts, 53, 1)) +>d : Symbol(d, Decl(unionIndexerGeneralAssignability.ts, 69, 17)) +>D : Symbol(D, Decl(unionIndexerGeneralAssignability.ts, 58, 1)) +>e : Symbol(e, Decl(unionIndexerGeneralAssignability.ts, 69, 23)) +>E : Symbol(E, Decl(unionIndexerGeneralAssignability.ts, 63, 1)) + + c = d; +>c : Symbol(c, Decl(unionIndexerGeneralAssignability.ts, 69, 12)) +>d : Symbol(d, Decl(unionIndexerGeneralAssignability.ts, 69, 17)) + + c = e; +>c : Symbol(c, Decl(unionIndexerGeneralAssignability.ts, 69, 12)) +>e : Symbol(e, Decl(unionIndexerGeneralAssignability.ts, 69, 23)) + + d = c; // error: C is missing an index for `"d"` and `4` +>d : Symbol(d, Decl(unionIndexerGeneralAssignability.ts, 69, 17)) +>c : Symbol(c, Decl(unionIndexerGeneralAssignability.ts, 69, 12)) + + d = e; +>d : Symbol(d, Decl(unionIndexerGeneralAssignability.ts, 69, 17)) +>e : Symbol(e, Decl(unionIndexerGeneralAssignability.ts, 69, 23)) + + e = c; // error: C is missing an index for `"d"` and `4` +>e : Symbol(e, Decl(unionIndexerGeneralAssignability.ts, 69, 23)) +>c : Symbol(c, Decl(unionIndexerGeneralAssignability.ts, 69, 12)) + + e = d; +>e : Symbol(e, Decl(unionIndexerGeneralAssignability.ts, 69, 23)) +>d : Symbol(d, Decl(unionIndexerGeneralAssignability.ts, 69, 17)) +} + +enum S1 { +>S1 : Symbol(S1, Decl(unionIndexerGeneralAssignability.ts, 78, 1)) + + A = "a", +>A : Symbol(S1.A, Decl(unionIndexerGeneralAssignability.ts, 80, 9)) + + B = "b", +>B : Symbol(S1.B, Decl(unionIndexerGeneralAssignability.ts, 81, 12)) + + C = "c" +>C : Symbol(S1.C, Decl(unionIndexerGeneralAssignability.ts, 82, 12)) +} + +enum S2 { +>S2 : Symbol(S2, Decl(unionIndexerGeneralAssignability.ts, 84, 1)) + + A = "a", +>A : Symbol(S2.A, Decl(unionIndexerGeneralAssignability.ts, 86, 9)) + + B = "b", +>B : Symbol(S2.B, Decl(unionIndexerGeneralAssignability.ts, 87, 12)) + + C = "c" +>C : Symbol(S2.C, Decl(unionIndexerGeneralAssignability.ts, 88, 12)) +} + +interface F { +>F : Symbol(F, Decl(unionIndexerGeneralAssignability.ts, 90, 1)) + + [x: S1]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 93, 5)) +>S1 : Symbol(S1, Decl(unionIndexerGeneralAssignability.ts, 78, 1)) +} + +interface G { +>G : Symbol(G, Decl(unionIndexerGeneralAssignability.ts, 94, 1)) + + [x: S2]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 97, 5)) +>S2 : Symbol(S2, Decl(unionIndexerGeneralAssignability.ts, 84, 1)) +} + +interface FG { +>FG : Symbol(FG, Decl(unionIndexerGeneralAssignability.ts, 98, 1)) + + [x: S1 | S2]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 101, 5)) +>S1 : Symbol(S1, Decl(unionIndexerGeneralAssignability.ts, 78, 1)) +>S2 : Symbol(S2, Decl(unionIndexerGeneralAssignability.ts, 84, 1)) +} + +interface IFG extends F, G {} +>IFG : Symbol(IFG, Decl(unionIndexerGeneralAssignability.ts, 102, 1)) +>F : Symbol(F, Decl(unionIndexerGeneralAssignability.ts, 90, 1)) +>G : Symbol(G, Decl(unionIndexerGeneralAssignability.ts, 94, 1)) + +function f3(f: F, g: G, fg: FG, fg2: F & G, fg3: IFG) { +>f3 : Symbol(f3, Decl(unionIndexerGeneralAssignability.ts, 104, 29)) +>f : Symbol(f, Decl(unionIndexerGeneralAssignability.ts, 106, 12)) +>F : Symbol(F, Decl(unionIndexerGeneralAssignability.ts, 90, 1)) +>g : Symbol(g, Decl(unionIndexerGeneralAssignability.ts, 106, 17)) +>G : Symbol(G, Decl(unionIndexerGeneralAssignability.ts, 94, 1)) +>fg : Symbol(fg, Decl(unionIndexerGeneralAssignability.ts, 106, 23)) +>FG : Symbol(FG, Decl(unionIndexerGeneralAssignability.ts, 98, 1)) +>fg2 : Symbol(fg2, Decl(unionIndexerGeneralAssignability.ts, 106, 31)) +>F : Symbol(F, Decl(unionIndexerGeneralAssignability.ts, 90, 1)) +>G : Symbol(G, Decl(unionIndexerGeneralAssignability.ts, 94, 1)) +>fg3 : Symbol(fg3, Decl(unionIndexerGeneralAssignability.ts, 106, 43)) +>IFG : Symbol(IFG, Decl(unionIndexerGeneralAssignability.ts, 102, 1)) + + f = g; // error: incompatible string enums +>f : Symbol(f, Decl(unionIndexerGeneralAssignability.ts, 106, 12)) +>g : Symbol(g, Decl(unionIndexerGeneralAssignability.ts, 106, 17)) + + f = fg; // OK +>f : Symbol(f, Decl(unionIndexerGeneralAssignability.ts, 106, 12)) +>fg : Symbol(fg, Decl(unionIndexerGeneralAssignability.ts, 106, 23)) + + f = fg2; // OK +>f : Symbol(f, Decl(unionIndexerGeneralAssignability.ts, 106, 12)) +>fg2 : Symbol(fg2, Decl(unionIndexerGeneralAssignability.ts, 106, 31)) + + f = fg3; // OK +>f : Symbol(f, Decl(unionIndexerGeneralAssignability.ts, 106, 12)) +>fg3 : Symbol(fg3, Decl(unionIndexerGeneralAssignability.ts, 106, 43)) + + g = f; // error: incompatible string enums +>g : Symbol(g, Decl(unionIndexerGeneralAssignability.ts, 106, 17)) +>f : Symbol(f, Decl(unionIndexerGeneralAssignability.ts, 106, 12)) + + g = fg; // OK +>g : Symbol(g, Decl(unionIndexerGeneralAssignability.ts, 106, 17)) +>fg : Symbol(fg, Decl(unionIndexerGeneralAssignability.ts, 106, 23)) + + g = fg2; // OK +>g : Symbol(g, Decl(unionIndexerGeneralAssignability.ts, 106, 17)) +>fg2 : Symbol(fg2, Decl(unionIndexerGeneralAssignability.ts, 106, 31)) + + g = fg3; // OK +>g : Symbol(g, Decl(unionIndexerGeneralAssignability.ts, 106, 17)) +>fg3 : Symbol(fg3, Decl(unionIndexerGeneralAssignability.ts, 106, 43)) + + fg = f; // error: doesn't provide S2 +>fg : Symbol(fg, Decl(unionIndexerGeneralAssignability.ts, 106, 23)) +>f : Symbol(f, Decl(unionIndexerGeneralAssignability.ts, 106, 12)) + + fg = g; // error: doesn't provide S1 +>fg : Symbol(fg, Decl(unionIndexerGeneralAssignability.ts, 106, 23)) +>g : Symbol(g, Decl(unionIndexerGeneralAssignability.ts, 106, 17)) + + fg = fg2; // OK +>fg : Symbol(fg, Decl(unionIndexerGeneralAssignability.ts, 106, 23)) +>fg2 : Symbol(fg2, Decl(unionIndexerGeneralAssignability.ts, 106, 31)) + + fg = fg3; // OK +>fg : Symbol(fg, Decl(unionIndexerGeneralAssignability.ts, 106, 23)) +>fg3 : Symbol(fg3, Decl(unionIndexerGeneralAssignability.ts, 106, 43)) + + fg2 = f; // error: doesn't provide S2 +>fg2 : Symbol(fg2, Decl(unionIndexerGeneralAssignability.ts, 106, 31)) +>f : Symbol(f, Decl(unionIndexerGeneralAssignability.ts, 106, 12)) + + fg2 = g; // error: doesn't provide S1 +>fg2 : Symbol(fg2, Decl(unionIndexerGeneralAssignability.ts, 106, 31)) +>g : Symbol(g, Decl(unionIndexerGeneralAssignability.ts, 106, 17)) + + fg2 = fg; // OK +>fg2 : Symbol(fg2, Decl(unionIndexerGeneralAssignability.ts, 106, 31)) +>fg : Symbol(fg, Decl(unionIndexerGeneralAssignability.ts, 106, 23)) + + fg2 = fg3; // OK +>fg2 : Symbol(fg2, Decl(unionIndexerGeneralAssignability.ts, 106, 31)) +>fg3 : Symbol(fg3, Decl(unionIndexerGeneralAssignability.ts, 106, 43)) + + fg3 = f; // error: doesn't provide S2 +>fg3 : Symbol(fg3, Decl(unionIndexerGeneralAssignability.ts, 106, 43)) +>f : Symbol(f, Decl(unionIndexerGeneralAssignability.ts, 106, 12)) + + fg3 = g; // error: doesn't provide S1 +>fg3 : Symbol(fg3, Decl(unionIndexerGeneralAssignability.ts, 106, 43)) +>g : Symbol(g, Decl(unionIndexerGeneralAssignability.ts, 106, 17)) + + fg3 = fg; // OK +>fg3 : Symbol(fg3, Decl(unionIndexerGeneralAssignability.ts, 106, 43)) +>fg : Symbol(fg, Decl(unionIndexerGeneralAssignability.ts, 106, 23)) + + fg3 = fg2; // OK +>fg3 : Symbol(fg3, Decl(unionIndexerGeneralAssignability.ts, 106, 43)) +>fg2 : Symbol(fg2, Decl(unionIndexerGeneralAssignability.ts, 106, 31)) +} + +enum S3 { +>S3 : Symbol(S3, Decl(unionIndexerGeneralAssignability.ts, 131, 1)) + + A = "a", +>A : Symbol(S3.A, Decl(unionIndexerGeneralAssignability.ts, 133, 9)) + + B = "b", +>B : Symbol(S3.B, Decl(unionIndexerGeneralAssignability.ts, 134, 12)) + + C = "c" +>C : Symbol(S3.C, Decl(unionIndexerGeneralAssignability.ts, 135, 12)) +} + +interface H { +>H : Symbol(H, Decl(unionIndexerGeneralAssignability.ts, 137, 1)) + + [x: S3]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 140, 5)) +>S3 : Symbol(S3, Decl(unionIndexerGeneralAssignability.ts, 131, 1)) + + [S3.A]: "a"; +>[S3.A] : Symbol(H[S3.A], Decl(unionIndexerGeneralAssignability.ts, 140, 20)) +>S3.A : Symbol(S3.A, Decl(unionIndexerGeneralAssignability.ts, 133, 9)) +>S3 : Symbol(S3, Decl(unionIndexerGeneralAssignability.ts, 131, 1)) +>A : Symbol(S3.A, Decl(unionIndexerGeneralAssignability.ts, 133, 9)) +} + +interface I { +>I : Symbol(I, Decl(unionIndexerGeneralAssignability.ts, 142, 1)) + + [x: S3]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 145, 5)) +>S3 : Symbol(S3, Decl(unionIndexerGeneralAssignability.ts, 131, 1)) + + [x: S3.A]: "a"; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 146, 5)) +>S3 : Symbol(S3, Decl(unionIndexerGeneralAssignability.ts, 131, 1)) +>A : Symbol(S3.A, Decl(unionIndexerGeneralAssignability.ts, 133, 9)) +} + +interface J { +>J : Symbol(J, Decl(unionIndexerGeneralAssignability.ts, 147, 1)) + + [x: S3]: string; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 150, 5)) +>S3 : Symbol(S3, Decl(unionIndexerGeneralAssignability.ts, 131, 1)) + + [x: S3.A]: never; +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 151, 5)) +>S3 : Symbol(S3, Decl(unionIndexerGeneralAssignability.ts, 131, 1)) +>A : Symbol(S3.A, Decl(unionIndexerGeneralAssignability.ts, 133, 9)) +} + +type K = {[K in S3]: string} & {[S3.A]: "a"}; +>K : Symbol(K, Decl(unionIndexerGeneralAssignability.ts, 152, 1)) +>K : Symbol(K, Decl(unionIndexerGeneralAssignability.ts, 154, 11)) +>S3 : Symbol(S3, Decl(unionIndexerGeneralAssignability.ts, 131, 1)) +>[S3.A] : Symbol([S3.A], Decl(unionIndexerGeneralAssignability.ts, 154, 32)) +>S3.A : Symbol(S3.A, Decl(unionIndexerGeneralAssignability.ts, 133, 9)) +>S3 : Symbol(S3, Decl(unionIndexerGeneralAssignability.ts, 131, 1)) +>A : Symbol(S3.A, Decl(unionIndexerGeneralAssignability.ts, 133, 9)) + +type L = {[K in S3]: string} & {[x: S3.A]: "a"}; +>L : Symbol(L, Decl(unionIndexerGeneralAssignability.ts, 154, 45)) +>K : Symbol(K, Decl(unionIndexerGeneralAssignability.ts, 155, 11)) +>S3 : Symbol(S3, Decl(unionIndexerGeneralAssignability.ts, 131, 1)) +>x : Symbol(x, Decl(unionIndexerGeneralAssignability.ts, 155, 33)) +>S3 : Symbol(S3, Decl(unionIndexerGeneralAssignability.ts, 131, 1)) +>A : Symbol(S3.A, Decl(unionIndexerGeneralAssignability.ts, 133, 9)) + +// TODO: reconcile union signatures with properties? +// Properties don't technically retain their enuminess, this may even be expected for string enums, if _very_ subtle +function f4(h: H, i: I, j: J, k: K, l: L) { +>f4 : Symbol(f4, Decl(unionIndexerGeneralAssignability.ts, 155, 48)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) +>H : Symbol(H, Decl(unionIndexerGeneralAssignability.ts, 137, 1)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) +>I : Symbol(I, Decl(unionIndexerGeneralAssignability.ts, 142, 1)) +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) +>J : Symbol(J, Decl(unionIndexerGeneralAssignability.ts, 147, 1)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) +>K : Symbol(K, Decl(unionIndexerGeneralAssignability.ts, 152, 1)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) +>L : Symbol(L, Decl(unionIndexerGeneralAssignability.ts, 154, 45)) + + h = i; +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) + + h = j; +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) + + h = k; +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) + + h = l; +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) + + i = h; +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) + + i = j; +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) + + i = k; +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) + + i = l; +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) + + j = h; +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) + + j = i; +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) + + j = k; +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) + + j = l; +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) + + k = h; +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) + + h = i; +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) + + k = j; +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) + + k = l; +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) + + l = h; +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) + + l = i; +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) + + l = j; +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) + + l = k; +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) +} + diff --git a/tests/baselines/reference/unionIndexerGeneralAssignability.types b/tests/baselines/reference/unionIndexerGeneralAssignability.types new file mode 100644 index 0000000000000..f9c18af227d94 --- /dev/null +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.types @@ -0,0 +1,544 @@ +=== tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts === +interface A { + [x: "a" | "b" | "c"]: string; +>x : "a" | "b" | "c" +} + +interface B { + [x: "b" | "c" | "d"]: string; +>x : "b" | "c" | "d" +} + +interface AB { + [x: "b" | "c"]: string; +>x : "b" | "c" +} + +function f1< +>f1 : (a: A, b: B, ab: AB, k1: K1, k2: K2) => void + + K1 extends "a" | "b" | "c", + K2 extends K1 +>(a: A, b: B, ab: AB, k1: K1, k2: K2) { +>a : A +>b : B +>ab : AB +>k1 : K1 +>k2 : K2 + + a = b; // error: B is missing `"a"` +>a = b : B +>a : A +>b : B + + a = ab; // error: AB is missing `"a"` +>a = ab : AB +>a : A +>ab : AB + + b = a; // error: A is missing `"d"` +>b = a : A +>b : B +>a : A + + b = ab; // error: AB is missing `"d"` +>b = ab : AB +>b : B +>ab : AB + + ab = a; +>ab = a : A +>ab : AB +>a : A + + ab = b; +>ab = b : B +>ab : AB +>b : B + + interface SubA { + [x: K1]: string; +>x : K1 + } + let s: SubA = {}; +>s : SubA +>{} : {} + + s[k1]; // valid +>s[k1] : SubA[K1] +>s : SubA +>k1 : K1 + + s = a; +>s = a : A +>s : SubA +>a : A + + s = b; // error: doesn't provide `"b"` +>s = b : B +>s : SubA +>b : B + + s = ab; // error: doesn't provide `"b"` +>s = ab : AB +>s : SubA +>ab : AB + + a = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` +>a = s : SubA +>a : A +>s : SubA + + b = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` +>b = s : SubA +>b : B +>s : SubA + + ab = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` +>ab = s : SubA +>ab : AB +>s : SubA + + interface SubB { + [x: K2]: string; +>x : K2 + } + let s2: SubB = {}; +>s2 : SubB +>{} : {} + + s2[k2]; // valid +>s2[k2] : SubB[K2] +>s2 : SubB +>k2 : K2 + + s2[k1]; // invalid +>s2[k1] : SubB[K1] +>s2 : SubB +>k1 : K1 + + s2 = a; +>s2 = a : A +>s2 : SubB +>a : A + + s2 = b; // error: doesn't provide `"b"` +>s2 = b : B +>s2 : SubB +>b : B + + s2 = ab; // error: doesn't provide `"b"` +>s2 = ab : AB +>s2 : SubB +>ab : AB + + s2 = s; +>s2 = s : SubA +>s2 : SubB +>s : SubA + + a = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` +>a = s2 : SubB +>a : A +>s2 : SubB + + b = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` +>b = s2 : SubB +>b : B +>s2 : SubB + + ab = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` +>ab = s2 : SubB +>ab : AB +>s2 : SubB + + s = s2; // error: might not provide any of the keys of K1 +>s = s2 : SubB +>s : SubA +>s2 : SubB +} + +interface C { + [x: "a" | "b" | "c"]: string; +>x : "a" | "b" | "c" + + [y: 1 | 2 | 3]: string; +>y : 1 | 2 | 3 +} + +interface D { + [x: "a" | "b" | "c" | "d"]: string; +>x : "a" | "b" | "c" | "d" + + [y: 1 | 2 | 3 | 4]: string; +>y : 1 | 2 | 3 | 4 +} + +interface E { + [x: "a" | "b" | "c" | "d" | 1 | 2 | 3 | 4]: string; +>x : "a" | "b" | "c" | "d" | 1 | 2 | 3 | 4 +} + +function f2(c: C, d: D, e: E) { +>f2 : (c: C, d: D, e: E) => void +>c : C +>d : D +>e : E + + c = d; +>c = d : D +>c : C +>d : D + + c = e; +>c = e : E +>c : C +>e : E + + d = c; // error: C is missing an index for `"d"` and `4` +>d = c : C +>d : D +>c : C + + d = e; +>d = e : E +>d : D +>e : E + + e = c; // error: C is missing an index for `"d"` and `4` +>e = c : C +>e : E +>c : C + + e = d; +>e = d : D +>e : E +>d : D +} + +enum S1 { +>S1 : S1 + + A = "a", +>A : S1.A +>"a" : "a" + + B = "b", +>B : S1.B +>"b" : "b" + + C = "c" +>C : S1.C +>"c" : "c" +} + +enum S2 { +>S2 : S2 + + A = "a", +>A : S2.A +>"a" : "a" + + B = "b", +>B : S2.B +>"b" : "b" + + C = "c" +>C : S2.C +>"c" : "c" +} + +interface F { + [x: S1]: string; +>x : S1 +} + +interface G { + [x: S2]: string; +>x : S2 +} + +interface FG { + [x: S1 | S2]: string; +>x : S1 | S2 +} + +interface IFG extends F, G {} + +function f3(f: F, g: G, fg: FG, fg2: F & G, fg3: IFG) { +>f3 : (f: F, g: G, fg: FG, fg2: F & G, fg3: IFG) => void +>f : F +>g : G +>fg : FG +>fg2 : F & G +>fg3 : IFG + + f = g; // error: incompatible string enums +>f = g : G +>f : F +>g : G + + f = fg; // OK +>f = fg : FG +>f : F +>fg : FG + + f = fg2; // OK +>f = fg2 : F & G +>f : F +>fg2 : F & G + + f = fg3; // OK +>f = fg3 : IFG +>f : F +>fg3 : IFG + + g = f; // error: incompatible string enums +>g = f : F +>g : G +>f : F + + g = fg; // OK +>g = fg : FG +>g : G +>fg : FG + + g = fg2; // OK +>g = fg2 : F & G +>g : G +>fg2 : F & G + + g = fg3; // OK +>g = fg3 : IFG +>g : G +>fg3 : IFG + + fg = f; // error: doesn't provide S2 +>fg = f : F +>fg : FG +>f : F + + fg = g; // error: doesn't provide S1 +>fg = g : G +>fg : FG +>g : G + + fg = fg2; // OK +>fg = fg2 : F & G +>fg : FG +>fg2 : F & G + + fg = fg3; // OK +>fg = fg3 : IFG +>fg : FG +>fg3 : IFG + + fg2 = f; // error: doesn't provide S2 +>fg2 = f : F +>fg2 : F & G +>f : F + + fg2 = g; // error: doesn't provide S1 +>fg2 = g : G +>fg2 : F & G +>g : G + + fg2 = fg; // OK +>fg2 = fg : FG +>fg2 : F & G +>fg : FG + + fg2 = fg3; // OK +>fg2 = fg3 : IFG +>fg2 : F & G +>fg3 : IFG + + fg3 = f; // error: doesn't provide S2 +>fg3 = f : F +>fg3 : IFG +>f : F + + fg3 = g; // error: doesn't provide S1 +>fg3 = g : G +>fg3 : IFG +>g : G + + fg3 = fg; // OK +>fg3 = fg : FG +>fg3 : IFG +>fg : FG + + fg3 = fg2; // OK +>fg3 = fg2 : F & G +>fg3 : IFG +>fg2 : F & G +} + +enum S3 { +>S3 : S3 + + A = "a", +>A : S3.A +>"a" : "a" + + B = "b", +>B : S3.B +>"b" : "b" + + C = "c" +>C : S3.C +>"c" : "c" +} + +interface H { + [x: S3]: string; +>x : S3 + + [S3.A]: "a"; +>[S3.A] : "a" +>S3.A : S3.A +>S3 : typeof S3 +>A : S3.A +} + +interface I { + [x: S3]: string; +>x : S3 + + [x: S3.A]: "a"; +>x : S3.A +>S3 : any +} + +interface J { + [x: S3]: string; +>x : S3 + + [x: S3.A]: never; +>x : S3.A +>S3 : any +} + +type K = {[K in S3]: string} & {[S3.A]: "a"}; +>K : K +>[S3.A] : "a" +>S3.A : S3.A +>S3 : typeof S3 +>A : S3.A + +type L = {[K in S3]: string} & {[x: S3.A]: "a"}; +>L : L +>x : S3.A +>S3 : any + +// TODO: reconcile union signatures with properties? +// Properties don't technically retain their enuminess, this may even be expected for string enums, if _very_ subtle +function f4(h: H, i: I, j: J, k: K, l: L) { +>f4 : (h: H, i: I, j: J, k: K, l: L) => void +>h : H +>i : I +>j : J +>k : K +>l : L + + h = i; +>h = i : I +>h : H +>i : I + + h = j; +>h = j : J +>h : H +>j : J + + h = k; +>h = k : K +>h : H +>k : K + + h = l; +>h = l : L +>h : H +>l : L + + i = h; +>i = h : H +>i : I +>h : H + + i = j; +>i = j : J +>i : I +>j : J + + i = k; +>i = k : K +>i : I +>k : K + + i = l; +>i = l : L +>i : I +>l : L + + j = h; +>j = h : H +>j : J +>h : H + + j = i; +>j = i : I +>j : J +>i : I + + j = k; +>j = k : K +>j : J +>k : K + + j = l; +>j = l : L +>j : J +>l : L + + k = h; +>k = h : H +>k : K +>h : H + + h = i; +>h = i : I +>h : H +>i : I + + k = j; +>k = j : J +>k : K +>j : J + + k = l; +>k = l : L +>k : K +>l : L + + l = h; +>l = h : H +>l : L +>h : H + + l = i; +>l = i : I +>l : L +>i : I + + l = j; +>l = j : J +>l : L +>j : J + + l = k; +>l = k : K +>l : L +>k : K +} + diff --git a/tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts b/tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts new file mode 100644 index 0000000000000..70d69a45cb806 --- /dev/null +++ b/tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts @@ -0,0 +1,31 @@ +// @strict: true +export interface UserInterfaceColors { + [index: UserInterfaceElement]: ColorInfo; +} +export interface ColorInfo { + r: number; + g: number; + b: number; + a: number; +} +export enum UserInterfaceElement { + ActiveTitleBar = 0, + InactiveTitleBar = 1, +} + +const x: UserInterfaceColors = null as any; + +declare function expectColInfo(x: ColorInfo): void; + +// correct uses +expectColInfo(x[UserInterfaceElement.ActiveTitleBar]); +expectColInfo(x[UserInterfaceElement.InactiveTitleBar]); + +// errors +expectColInfo(x[0]); +expectColInfo(x[1]); +expectColInfo(x["0"]); +expectColInfo(x["1"]); +expectColInfo(x[0 as number]); +expectColInfo(x["0" as string]); +expectColInfo(x[12]); diff --git a/tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts b/tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts new file mode 100644 index 0000000000000..bf4d01751c1ca --- /dev/null +++ b/tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts @@ -0,0 +1,104 @@ +// @strict: true +interface Dict { + [index: string]: T; + [index: symbol]: T; + [index: number]: T; +} + +const keyMap: Dict = {}; + +function set(index: keyof T) { + keyMap[index] = 1; +} + +interface Dict2 { + [index: string | number | symbol]: T; +} + +const keyMap2: Dict2 = {}; + +function set2(index: keyof T) { + keyMap2[index] = 1; +} + +interface Dict3 { + [index: string | symbol]: T; +} + +const keyMap3: Dict3 = {}; + +function set3(index: keyof T) { + keyMap3[index] = 1; +} + +interface Dict4 { + [index: string]: T; + [index: symbol]: T; +} + +const keyMap4: Dict4 = {}; + +function set4(index: keyof T) { + keyMap4[index] = 1; +} + +/** + * Key can only be number, string or symbol + * */ +class SimpleMapMap { + private o: { [k: K]: V } = {}; + + public has(k: K): boolean { + return k in this.o; + } + + public get(k: K): V { + return this.o[k]; + } + + public set(k: K, v: V) { + this.o[k] = v; + } + + public getMap(k: K): V { + if (k in this.o) { + return this.o[k]; + } + const res = new SimpleMapMap(); + this.o[k] = res as any as V; + return res as any as V; + } + + public clear() { + this.o = {}; + } +} + +class SimpleMapMap2 { + private o: { [k: PropertyKey]: V } = {}; + + public has(k: K): boolean { + return k in this.o; + } + + public get(k: K): V { + return this.o[k]; + } + + public set(k: K, v: V) { + this.o[k] = v; + } + + public getMap(k: K): V { + if (k in this.o) { + return this.o[k]; + } + const res = new SimpleMapMap2(); + this.o[k] = res as any as V; + return res as any as V; + } + + public clear() { + this.o = {}; + } +} diff --git a/tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts b/tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts new file mode 100644 index 0000000000000..0274f215ee8c1 --- /dev/null +++ b/tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts @@ -0,0 +1,185 @@ +interface A { + [x: "a" | "b" | "c"]: string; +} + +interface B { + [x: "b" | "c" | "d"]: string; +} + +interface AB { + [x: "b" | "c"]: string; +} + +function f1< + K1 extends "a" | "b" | "c", + K2 extends K1 +>(a: A, b: B, ab: AB, k1: K1, k2: K2) { + a = b; // error: B is missing `"a"` + a = ab; // error: AB is missing `"a"` + + b = a; // error: A is missing `"d"` + b = ab; // error: AB is missing `"d"` + + ab = a; + ab = b; + + interface SubA { + [x: K1]: string; + } + let s: SubA = {}; + s[k1]; // valid + s = a; + s = b; // error: doesn't provide `"b"` + s = ab; // error: doesn't provide `"b"` + + a = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + b = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ab = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + + interface SubB { + [x: K2]: string; + } + let s2: SubB = {}; + s2[k2]; // valid + s2[k1]; // invalid + s2 = a; + s2 = b; // error: doesn't provide `"b"` + s2 = ab; // error: doesn't provide `"b"` + s2 = s; + + a = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + b = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ab = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + s = s2; // error: might not provide any of the keys of K1 +} + +interface C { + [x: "a" | "b" | "c"]: string; + [y: 1 | 2 | 3]: string; +} + +interface D { + [x: "a" | "b" | "c" | "d"]: string; + [y: 1 | 2 | 3 | 4]: string; +} + +interface E { + [x: "a" | "b" | "c" | "d" | 1 | 2 | 3 | 4]: string; +} + +function f2(c: C, d: D, e: E) { + c = d; + c = e; + + d = c; // error: C is missing an index for `"d"` and `4` + d = e; + + e = c; // error: C is missing an index for `"d"` and `4` + e = d; +} + +enum S1 { + A = "a", + B = "b", + C = "c" +} + +enum S2 { + A = "a", + B = "b", + C = "c" +} + +interface F { + [x: S1]: string; +} + +interface G { + [x: S2]: string; +} + +interface FG { + [x: S1 | S2]: string; +} + +interface IFG extends F, G {} + +function f3(f: F, g: G, fg: FG, fg2: F & G, fg3: IFG) { + f = g; // error: incompatible string enums + f = fg; // OK + f = fg2; // OK + f = fg3; // OK + + g = f; // error: incompatible string enums + g = fg; // OK + g = fg2; // OK + g = fg3; // OK + + fg = f; // error: doesn't provide S2 + fg = g; // error: doesn't provide S1 + fg = fg2; // OK + fg = fg3; // OK + + fg2 = f; // error: doesn't provide S2 + fg2 = g; // error: doesn't provide S1 + fg2 = fg; // OK + fg2 = fg3; // OK + + fg3 = f; // error: doesn't provide S2 + fg3 = g; // error: doesn't provide S1 + fg3 = fg; // OK + fg3 = fg2; // OK +} + +enum S3 { + A = "a", + B = "b", + C = "c" +} + +interface H { + [x: S3]: string; + [S3.A]: "a"; +} + +interface I { + [x: S3]: string; + [x: S3.A]: "a"; +} + +interface J { + [x: S3]: string; + [x: S3.A]: never; +} + +type K = {[K in S3]: string} & {[S3.A]: "a"}; +type L = {[K in S3]: string} & {[x: S3.A]: "a"}; + +// TODO: reconcile union signatures with properties? +// Properties don't technically retain their enuminess, this may even be expected for string enums, if _very_ subtle +function f4(h: H, i: I, j: J, k: K, l: L) { + h = i; + h = j; + h = k; + h = l; + + i = h; + i = j; + i = k; + i = l; + + j = h; + j = i; + j = k; + j = l; + + k = h; + h = i; + k = j; + k = l; + + l = h; + l = i; + l = j; + l = k; +} diff --git a/tests/cases/fourslash/codeFixConvertToMappedObjectType1.ts b/tests/cases/fourslash/codeFixConvertToMappedObjectType1.ts deleted file mode 100644 index f00702e7bdc04..0000000000000 --- a/tests/cases/fourslash/codeFixConvertToMappedObjectType1.ts +++ /dev/null @@ -1,17 +0,0 @@ -/// - -//// type K = "foo" | "bar"; -//// interface SomeType { -//// a: string; -//// [prop: K]: any; -//// } - -verify.codeFix({ - description: `Convert 'SomeType' to mapped object type`, - newFileContent: `type K = "foo" | "bar"; -type SomeType = { - [prop in K]: any; -} & { - a: string; -};` -}) diff --git a/tests/cases/fourslash/codeFixConvertToMappedObjectType10.ts b/tests/cases/fourslash/codeFixConvertToMappedObjectType10.ts deleted file mode 100644 index 073b20d91608f..0000000000000 --- a/tests/cases/fourslash/codeFixConvertToMappedObjectType10.ts +++ /dev/null @@ -1,23 +0,0 @@ -/// - -//// type K = "foo" | "bar"; -//// interface Foo { } -//// interface Bar { bar: T; } -//// interface SomeType extends Foo, Bar { -//// a: number; -//// b: T; -//// [prop: K]: any; -//// } - -verify.codeFix({ - description: `Convert 'SomeType' to mapped object type`, - newFileContent: `type K = "foo" | "bar"; -interface Foo { } -interface Bar { bar: T; } -type SomeType = Foo & Bar & { - [prop in K]: any; -} & { - a: number; - b: T; -};` -}) diff --git a/tests/cases/fourslash/codeFixConvertToMappedObjectType11.ts b/tests/cases/fourslash/codeFixConvertToMappedObjectType11.ts deleted file mode 100644 index b82ee1ac179e7..0000000000000 --- a/tests/cases/fourslash/codeFixConvertToMappedObjectType11.ts +++ /dev/null @@ -1,23 +0,0 @@ -/// - -//// type K = "foo" | "bar"; -//// interface Foo { } -//// interface Bar { bar: T; } -//// interface SomeType extends Foo, Bar { -//// a: number; -//// b: T; -//// readonly [prop: K]: any; -//// } - -verify.codeFix({ - description: `Convert 'SomeType' to mapped object type`, - newFileContent: `type K = "foo" | "bar"; -interface Foo { } -interface Bar { bar: T; } -type SomeType = Foo & Bar & { - readonly [prop in K]: any; -} & { - a: number; - b: T; -};` -}) diff --git a/tests/cases/fourslash/codeFixConvertToMappedObjectType12.ts b/tests/cases/fourslash/codeFixConvertToMappedObjectType12.ts deleted file mode 100644 index 6374dc43dacb4..0000000000000 --- a/tests/cases/fourslash/codeFixConvertToMappedObjectType12.ts +++ /dev/null @@ -1,12 +0,0 @@ -/// - -//// type K = "foo" | "bar"; -//// interface Foo { } -//// interface Bar { bar: T; } -//// interface SomeType extends Foo, Bar { -//// a: number; -//// b: T; -//// readonly [prop: K]?: any; -//// } - -verify.not.codeFixAvailable() diff --git a/tests/cases/fourslash/codeFixConvertToMappedObjectType2.ts b/tests/cases/fourslash/codeFixConvertToMappedObjectType2.ts deleted file mode 100644 index 27dfc7cab0d56..0000000000000 --- a/tests/cases/fourslash/codeFixConvertToMappedObjectType2.ts +++ /dev/null @@ -1,17 +0,0 @@ -/// - -//// type K = "foo" | "bar"; -//// type SomeType = { -//// a: string; -//// [prop: K]: any; -//// } - -verify.codeFix({ - description: `Convert 'SomeType' to mapped object type`, - newFileContent: `type K = "foo" | "bar"; -type SomeType = { - [prop in K]: any; -} & { - a: string; -};` -}) diff --git a/tests/cases/fourslash/codeFixConvertToMappedObjectType3.ts b/tests/cases/fourslash/codeFixConvertToMappedObjectType3.ts deleted file mode 100644 index b916eaca9b62f..0000000000000 --- a/tests/cases/fourslash/codeFixConvertToMappedObjectType3.ts +++ /dev/null @@ -1,14 +0,0 @@ -/// - -//// type K = "foo" | "bar"; -//// type SomeType = { -//// [prop: K]: any; -//// } - -verify.codeFix({ - description: `Convert 'SomeType' to mapped object type`, - newFileContent: `type K = "foo" | "bar"; -type SomeType = { - [prop in K]: any; -};` -}) diff --git a/tests/cases/fourslash/codeFixConvertToMappedObjectType4.ts b/tests/cases/fourslash/codeFixConvertToMappedObjectType4.ts deleted file mode 100644 index 4077a7c04af28..0000000000000 --- a/tests/cases/fourslash/codeFixConvertToMappedObjectType4.ts +++ /dev/null @@ -1,14 +0,0 @@ -/// - -//// type K = "foo" | "bar"; -//// interface SomeType { -//// [prop: K]: any; -//// } - -verify.codeFix({ - description: `Convert 'SomeType' to mapped object type`, - newFileContent: `type K = "foo" | "bar"; -type SomeType = { - [prop in K]: any; -};` -}) diff --git a/tests/cases/fourslash/codeFixConvertToMappedObjectType5.ts b/tests/cases/fourslash/codeFixConvertToMappedObjectType5.ts deleted file mode 100644 index 869974f9ad2ff..0000000000000 --- a/tests/cases/fourslash/codeFixConvertToMappedObjectType5.ts +++ /dev/null @@ -1,8 +0,0 @@ -/// - -//// type K = "foo" | "bar"; -//// class SomeType { -//// [prop: K]: any; -//// } - -verify.not.codeFixAvailable() diff --git a/tests/cases/fourslash/codeFixConvertToMappedObjectType6.ts b/tests/cases/fourslash/codeFixConvertToMappedObjectType6.ts deleted file mode 100644 index b00f356b48b45..0000000000000 --- a/tests/cases/fourslash/codeFixConvertToMappedObjectType6.ts +++ /dev/null @@ -1,16 +0,0 @@ -/// - -//// type K = "foo" | "bar"; -//// interface Foo { } -//// interface SomeType extends Foo { -//// [prop: K]: any; -//// } - -verify.codeFix({ - description: `Convert 'SomeType' to mapped object type`, - newFileContent: `type K = "foo" | "bar"; -interface Foo { } -type SomeType = Foo & { - [prop in K]: any; -};` -}) diff --git a/tests/cases/fourslash/codeFixConvertToMappedObjectType7.ts b/tests/cases/fourslash/codeFixConvertToMappedObjectType7.ts deleted file mode 100644 index a0a1e4eeccb69..0000000000000 --- a/tests/cases/fourslash/codeFixConvertToMappedObjectType7.ts +++ /dev/null @@ -1,18 +0,0 @@ -/// - -//// type K = "foo" | "bar"; -//// interface Foo { } -//// interface Bar { } -//// interface SomeType extends Foo, Bar { -//// [prop: K]: any; -//// } - -verify.codeFix({ - description: `Convert 'SomeType' to mapped object type`, - newFileContent: `type K = "foo" | "bar"; -interface Foo { } -interface Bar { } -type SomeType = Foo & Bar & { - [prop in K]: any; -};` -}) diff --git a/tests/cases/fourslash/codeFixConvertToMappedObjectType8.ts b/tests/cases/fourslash/codeFixConvertToMappedObjectType8.ts deleted file mode 100644 index 6ee6c9f0aadde..0000000000000 --- a/tests/cases/fourslash/codeFixConvertToMappedObjectType8.ts +++ /dev/null @@ -1,21 +0,0 @@ -/// - -//// type K = "foo" | "bar"; -//// interface Foo { } -//// interface Bar { } -//// interface SomeType extends Foo, Bar { -//// a: number; -//// [prop: K]: any; -//// } - -verify.codeFix({ - description: `Convert 'SomeType' to mapped object type`, - newFileContent: `type K = "foo" | "bar"; -interface Foo { } -interface Bar { } -type SomeType = Foo & Bar & { - [prop in K]: any; -} & { - a: number; -};` -}) diff --git a/tests/cases/fourslash/codeFixConvertToMappedObjectType9.ts b/tests/cases/fourslash/codeFixConvertToMappedObjectType9.ts deleted file mode 100644 index 095296481f57d..0000000000000 --- a/tests/cases/fourslash/codeFixConvertToMappedObjectType9.ts +++ /dev/null @@ -1,21 +0,0 @@ -/// - -//// type K = "foo" | "bar"; -//// interface Foo { } -//// interface Bar { bar: T; } -//// interface SomeType extends Foo, Bar { -//// a: number; -//// [prop: K]: any; -//// } - -verify.codeFix({ - description: `Convert 'SomeType' to mapped object type`, - newFileContent: `type K = "foo" | "bar"; -interface Foo { } -interface Bar { bar: T; } -type SomeType = Foo & Bar & { - [prop in K]: any; -} & { - a: number; -};` -})