From cb1e630952ed51502755fd4fea2067d9e38709c4 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 23 Aug 2018 17:36:09 -0700 Subject: [PATCH 01/11] Heavy WIP --- src/compiler/checker.ts | 803 ++++++++++-------- src/compiler/diagnosticMessages.json | 8 +- src/compiler/symbolWalker.ts | 13 +- src/compiler/types.ts | 15 +- src/server/session.ts | 174 ++-- .../fixClassIncorrectlyImplementsInterface.ts | 19 +- .../codefixes/fixInvalidImportSyntax.ts | 5 +- src/services/codefixes/inferFromUsage.ts | 4 +- src/services/completions.ts | 4 +- src/services/goToDefinition.ts | 8 +- src/services/services.ts | 7 +- src/services/types.ts | 3 +- ...eInferenceOnlySymbolsIfSymbolsSpecified.ts | 50 ++ 13 files changed, 645 insertions(+), 468 deletions(-) create mode 100644 tests/cases/compiler/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 269f8b26f0a72..47e77d95b7d8c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -110,9 +110,9 @@ namespace ts { getPropertiesOfType, getPropertyOfType: (type, name) => getPropertyOfType(type, escapeLeadingUnderscores(name)), getTypeOfPropertyOfType: (type, name) => getTypeOfPropertyOfType(type, escapeLeadingUnderscores(name)), - getIndexInfoOfType, + getIndexInfosOfType: (type, indexType?) => indexType ? getApplicableIndexInfosOfIndexOnType(type, indexType) : getIndexInfosOfType(type), getSignaturesOfType, - getIndexTypeOfType, + getIndexTypeOfType: (type, indexType) => getResultingTypeOfIndexOnType(type, indexType), getBaseTypes, getBaseTypeOfLiteralType, getWidenedType, @@ -251,7 +251,7 @@ namespace ts { resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, - getIndexTypeOfStructuredType, + getIndexInfosOfType, getConstraintOfTypeParameter, getFirstIdentifier, ), @@ -274,7 +274,7 @@ namespace ts { }, getApparentType, getUnionType, - createAnonymousType, + createAnonymousType: (symbol, members, call, construct, stringInfo, numberInfo) => createAnonymousType(symbol, members, call, construct, stringInfo && numberInfo ? [stringInfo, numberInfo] : stringInfo ? [stringInfo] : numberInfo ? [numberInfo] : undefined), createSignature, createSymbol, createIndexInfo, @@ -403,23 +403,23 @@ namespace ts { const stringNumberSymbolType = getUnionType([stringType, numberType, esSymbolType]); const keyofConstraintType = keyofStringsOnly ? stringType : stringNumberSymbolType; - const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined); const emptyTypeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, InternalSymbolName.Type); emptyTypeLiteralSymbol.members = createSymbolTable(); - const emptyTypeLiteralType = createAnonymousType(emptyTypeLiteralSymbol, emptySymbols, emptyArray, emptyArray, undefined, undefined); + const emptyTypeLiteralType = createAnonymousType(emptyTypeLiteralSymbol, emptySymbols, emptyArray, emptyArray, undefined); - const emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + const emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined); emptyGenericType.instantiations = createMap(); - const anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + const anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined); // The anyFunctionType contains the anyFunctionType by definition. The flag is further propagated // in getPropagatingFlagsOfTypes, and it is checked in inferFromTypes. anyFunctionType.flags |= TypeFlags.ContainsAnyFunctionType; - const noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); - const circularConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); - const resolvingDefaultType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + const noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined); + const circularConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined); + const resolvingDefaultType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined); const markerSuperType = createType(TypeFlags.TypeParameter); const markerSubType = createType(TypeFlags.TypeParameter); @@ -434,7 +434,7 @@ namespace ts { const silentNeverSignature = createSignature(undefined, undefined, undefined, emptyArray, silentNeverType, /*resolvedTypePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false); const resolvingSignaturesArray = [resolvingSignature]; - const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true); + const enumNumberIndexInfo = createIndexInfo(numberType, stringType, /*isReadonly*/ true); const globals = createSymbolTable(); let amalgamatedDuplicates: Map<{ firstFile: SourceFile, secondFile: SourceFile, firstFileInstances: Map<{ instances: Node[], blockScoped: boolean }>, secondFileInstances: Map<{ instances: Node[], blockScoped: boolean }> }> | undefined; @@ -609,6 +609,7 @@ namespace ts { const subtypeRelation = createMap(); const assignableRelation = createMap(); const definitelyAssignableRelation = createMap(); + const indexAssignableRelation = createMap(); const comparableRelation = createMap(); const identityRelation = createMap(); const enumRelation = createMap(); @@ -2327,7 +2328,7 @@ namespace ts { if (symbol.members) result.members = cloneMap(symbol.members); if (symbol.exports) result.exports = cloneMap(symbol.exports); const resolvedModuleType = resolveStructuredTypeMembers(moduleType as StructuredType); // Should already be resolved from the signature checks above - result.type = createAnonymousType(result, resolvedModuleType.members, emptyArray, emptyArray, resolvedModuleType.stringIndexInfo, resolvedModuleType.numberIndexInfo); + result.type = createAnonymousType(result, resolvedModuleType.members, emptyArray, emptyArray, resolvedModuleType.indexInfos); return result; } } @@ -2586,8 +2587,7 @@ namespace ts { type.properties = undefined; type.callSignatures = undefined; type.constructSignatures = undefined; - type.stringIndexInfo = undefined; - type.numberIndexInfo = undefined; + type.indexInfos = undefined; return type; } @@ -2616,19 +2616,18 @@ namespace ts { return result || emptyArray; } - function setStructuredTypeMembers(type: StructuredType, members: SymbolTable, callSignatures: ReadonlyArray, constructSignatures: ReadonlyArray, stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): ResolvedType { + function setStructuredTypeMembers(type: StructuredType, members: SymbolTable, callSignatures: ReadonlyArray, constructSignatures: ReadonlyArray, indexInfos: IndexInfo[] | undefined): ResolvedType { (type).members = members; (type).properties = members === emptySymbols ? emptyArray : getNamedMembers(members); (type).callSignatures = callSignatures; (type).constructSignatures = constructSignatures; - (type).stringIndexInfo = stringIndexInfo; - (type).numberIndexInfo = numberIndexInfo; + (type).indexInfos = indexInfos; return type; } - function createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: ReadonlyArray, constructSignatures: ReadonlyArray, stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): ResolvedType { + function createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: ReadonlyArray, constructSignatures: ReadonlyArray, indexInfos: IndexInfo[] | undefined): ResolvedType { return setStructuredTypeMembers(createObjectType(ObjectFlags.Anonymous, symbol), - members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); + members, callSignatures, constructSignatures, indexInfos); } function forEachSymbolTableInScope(enclosingDeclaration: Node | undefined, callback: (symbolTable: SymbolTable) => T): T { @@ -3046,8 +3045,8 @@ namespace ts { return { typeToTypeNode: (type: Type, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => typeToTypeNodeHelper(type, context)), - indexInfoToIndexSignatureDeclaration: (indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => - withContext(enclosingDeclaration, flags, tracker, context => indexInfoToIndexSignatureDeclarationHelper(indexInfo, kind, context))!, // TODO: GH#18217 + indexInfoToIndexSignatureDeclaration: (indexInfo: IndexInfo, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => + withContext(enclosingDeclaration, flags, tracker, context => indexInfoToIndexSignatureDeclarationHelper(indexInfo, context))!, // TODO: GH#18217 signatureToSignatureDeclaration: (signature: Signature, kind: SyntaxKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => signatureToSignatureDeclarationHelper(signature, kind, context)), symbolToEntityName: (symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => @@ -3353,7 +3352,7 @@ namespace ts { } const resolved = resolveStructuredTypeMembers(type); - if (!resolved.properties.length && !resolved.stringIndexInfo && !resolved.numberIndexInfo) { + if (!resolved.properties.length && !length(resolved.indexInfos)) { if (!resolved.callSignatures.length && !resolved.constructSignatures.length) { context.approximateLength += 2; return setEmitFlags(createTypeLiteralNode(/*members*/ undefined), EmitFlags.SingleLine); @@ -3510,14 +3509,13 @@ namespace ts { for (const signature of resolvedType.constructSignatures) { typeElements.push(signatureToSignatureDeclarationHelper(signature, SyntaxKind.ConstructSignature, context)); } - if (resolvedType.stringIndexInfo) { - const indexInfo = resolvedType.objectFlags & ObjectFlags.ReverseMapped ? - createIndexInfo(anyType, resolvedType.stringIndexInfo.isReadonly, resolvedType.stringIndexInfo.declaration) : - resolvedType.stringIndexInfo; - typeElements.push(indexInfoToIndexSignatureDeclarationHelper(indexInfo, IndexKind.String, context)); - } - if (resolvedType.numberIndexInfo) { - typeElements.push(indexInfoToIndexSignatureDeclarationHelper(resolvedType.numberIndexInfo, IndexKind.Number, context)); + if (resolvedType.indexInfos) { + for (let info of resolvedType.indexInfos) { + if (info.indexType === stringType && resolvedType.objectFlags & ObjectFlags.ReverseMapped) { + info = createIndexInfo(stringType, anyType, info.isReadonly, info.declaration); + } + typeElements.push(indexInfoToIndexSignatureDeclarationHelper(info, context)); + } } const properties = resolvedType.properties; @@ -3637,9 +3635,9 @@ namespace ts { } } - function indexInfoToIndexSignatureDeclarationHelper(indexInfo: IndexInfo, kind: IndexKind, context: NodeBuilderContext): IndexSignatureDeclaration { + function indexInfoToIndexSignatureDeclarationHelper(indexInfo: IndexInfo, context: NodeBuilderContext): IndexSignatureDeclaration { const name = getNameFromIndexInfo(indexInfo) || "x"; - const indexerTypeNode = createKeywordTypeNode(kind === IndexKind.String ? SyntaxKind.StringKeyword : SyntaxKind.NumberKeyword); + const indexerTypeNode = typeToTypeNodeHelper(indexInfo.indexType, context); const indexingParameter = createParameter( /*decorators*/ undefined, @@ -4482,9 +4480,8 @@ namespace ts { members.set(prop.escapedName, getNonReadonlySymbol(prop)); } } - const stringIndexInfo = getIndexInfoOfType(source, IndexKind.String); - const numberIndexInfo = getIndexInfoOfType(source, IndexKind.Number); - return createAnonymousType(symbol, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); + const indexInfos = getIndexInfosOfType(source); + return createAnonymousType(symbol, members, emptyArray, emptyArray, indexInfos); } /** Return the inferred type for a binding element */ @@ -4533,9 +4530,9 @@ namespace ts { } return anyType; } - const indexerType = isTypeAssignableToKind(exprType, TypeFlags.NumberLike) && getIndexTypeOfType(parentType, IndexKind.Number) || getIndexTypeOfType(parentType, IndexKind.String); + const indexerType = getResultingTypeOfIndexOnType(parentType, exprType); if (!indexerType && noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors) { - if (getIndexTypeOfType(parentType, IndexKind.Number)) { + if (getResultingIndexInfoOfIndexOnType(parentType, numberType)) { error(declaration, Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number); } else { @@ -4563,9 +4560,7 @@ namespace ts { return anyType; } const declaredType = getConstraintForLocation(getTypeOfPropertyOfType(parentType, text), declaration.name); - type = declaredType && getFlowTypeOfReference(declaration, declaredType) || - isNumericLiteralName(text) && getIndexTypeOfType(parentType, IndexKind.Number) || - getIndexTypeOfType(parentType, IndexKind.String); + type = declaredType && getFlowTypeOfReference(declaration, declaredType) || getResultingTypeOfIndexOnType(parentType, getLiteralType(isNumericLiteralName(text) ? +text : unescapeLeadingUnderscores(text))); if (!type) { error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name)); return errorType; @@ -4810,7 +4805,7 @@ namespace ts { if (s && hasEntries(s.exports)) { mergeSymbolTable(exports, s.exports); } - const type = createAnonymousType(symbol, exports, emptyArray, emptyArray, undefined, undefined); + const type = createAnonymousType(symbol, exports, emptyArray, emptyArray, undefined); type.objectFlags |= ObjectFlags.JSLiteral; return type; } @@ -4857,8 +4852,7 @@ namespace ts { members, exportedType.callSignatures, exportedType.constructSignatures, - exportedType.stringIndexInfo, - exportedType.numberIndexInfo); + exportedType.indexInfos); result.objectFlags |= (getObjectFlags(type) & ObjectFlags.JSLiteral); // Propagate JSLiteral flag return result; } @@ -4934,7 +4928,7 @@ namespace ts { return; } if (e.dotDotDotToken) { - stringIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false); + stringIndexInfo = createIndexInfo(stringType, anyType, /*isReadonly*/ false); return; } @@ -4945,7 +4939,7 @@ namespace ts { symbol.bindingElement = e; members.set(symbol.escapedName, symbol); }); - const result = createAnonymousType(undefined, members, emptyArray, emptyArray, stringIndexInfo, undefined); + const result = createAnonymousType(undefined, members, emptyArray, emptyArray, stringIndexInfo && [stringIndexInfo]); result.flags |= TypeFlags.ContainsObjectLiteral; result.objectFlags |= objectFlags; if (includePatternInType) { @@ -5055,7 +5049,7 @@ namespace ts { const fileSymbol = getSymbolOfNode(getSourceFileOfNode(symbol.valueDeclaration)); const members = createSymbolTable(); members.set("exports" as __String, fileSymbol); - return createAnonymousType(symbol, members, emptyArray, emptyArray, undefined, undefined); + return createAnonymousType(symbol, members, emptyArray, emptyArray, undefined); } // Handle catch clause variables const declaration = symbol.valueDeclaration; @@ -6017,8 +6011,7 @@ namespace ts { (type).declaredCallSignatures = getSignaturesOfSymbol(members.get(InternalSymbolName.Call)); (type).declaredConstructSignatures = getSignaturesOfSymbol(members.get(InternalSymbolName.New)); - (type).declaredStringIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.String); - (type).declaredNumberIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.Number); + (type).declaredIndexInfos = getIndexInfosOfSymbol(symbol); } return type; } @@ -6264,45 +6257,44 @@ namespace ts { let members: SymbolTable; let callSignatures: ReadonlyArray; let constructSignatures: ReadonlyArray | undefined; - let stringIndexInfo: IndexInfo | undefined; - let numberIndexInfo: IndexInfo | undefined; + let indexInfos: IndexInfo[] | undefined; if (rangeEquals(typeParameters, typeArguments, 0, typeParameters.length)) { mapper = identityMapper; members = source.symbol ? getMembersOfSymbol(source.symbol) : createSymbolTable(source.declaredProperties); callSignatures = source.declaredCallSignatures; constructSignatures = source.declaredConstructSignatures; - stringIndexInfo = source.declaredStringIndexInfo; - numberIndexInfo = source.declaredNumberIndexInfo; + indexInfos = source.declaredIndexInfos; } else { mapper = createTypeMapper(typeParameters, typeArguments); members = createInstantiatedSymbolTable(source.declaredProperties, mapper, /*mappingThisOnly*/ typeParameters.length === 1); callSignatures = instantiateSignatures(source.declaredCallSignatures, mapper); constructSignatures = instantiateSignatures(source.declaredConstructSignatures, mapper); - stringIndexInfo = instantiateIndexInfo(source.declaredStringIndexInfo, mapper); - numberIndexInfo = instantiateIndexInfo(source.declaredNumberIndexInfo, mapper); + indexInfos = instantiateIndexInfos(source.declaredIndexInfos, mapper); } const baseTypes = getBaseTypes(source); if (baseTypes.length) { if (source.symbol && members === getMembersOfSymbol(source.symbol)) { members = createSymbolTable(source.declaredProperties); } - setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); + setStructuredTypeMembers(type, members, callSignatures, constructSignatures, indexInfos); const thisArgument = lastOrUndefined(typeArguments); for (const baseType of baseTypes) { const instantiatedBaseType = thisArgument ? getTypeWithThisArgument(instantiateType(baseType, mapper), thisArgument) : baseType; addInheritedMembers(members, getPropertiesOfType(instantiatedBaseType)); callSignatures = concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Call)); constructSignatures = concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Construct)); - if (!stringIndexInfo) { - stringIndexInfo = instantiatedBaseType === anyType ? - createIndexInfo(anyType, /*isReadonly*/ false) : - getIndexInfoOfType(instantiatedBaseType, IndexKind.String); + const baseInfos = getIndexInfosOfType(instantiatedBaseType); + indexInfos = intersectIndexInfos(indexInfos, baseInfos); + if (!resolveIndexOnIndexInfos(stringType, indexInfos)) { + if (instantiatedBaseType === anyType) { + indexInfos = indexInfos || []; + indexInfos.push(createIndexInfo(stringType, anyType, /*isReadonly*/ false)); + } } - numberIndexInfo = numberIndexInfo || getIndexInfoOfType(instantiatedBaseType, IndexKind.Number); } } - setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); + setStructuredTypeMembers(type, members, callSignatures, constructSignatures, indexInfos); } function resolveClassOrInterfaceMembers(type: InterfaceType): void { @@ -6463,18 +6455,19 @@ namespace ts { return result || emptyArray; } - function getUnionIndexInfo(types: ReadonlyArray, kind: IndexKind): IndexInfo | undefined { - const indexTypes: Type[] = []; - let isAnyReadonly = false; + function getUnionIndexInfos(types: ReadonlyArray): IndexInfo[] | undefined { + let finalInfos: IndexInfo[] | undefined; for (const type of types) { - const indexInfo = getIndexInfoOfType(type, kind); - if (!indexInfo) { - return undefined; + const infos = getIndexInfosOfType(type); + if (!infos) { + return; + } + finalInfos = finalInfos ? unionIndexInfos(finalInfos, infos) : infos; + if (!finalInfos) { + return; } - indexTypes.push(indexInfo.type); - isAnyReadonly = isAnyReadonly || indexInfo.isReadonly; } - return createIndexInfo(getUnionType(indexTypes, UnionReduction.Subtype), isAnyReadonly); + return finalInfos; } function resolveUnionTypeMembers(type: UnionType) { @@ -6482,9 +6475,8 @@ namespace ts { // type use getPropertiesOfType (only the language service uses this). const callSignatures = getUnionSignatures(type.types, SignatureKind.Call); const constructSignatures = getUnionSignatures(type.types, SignatureKind.Construct); - const stringIndexInfo = getUnionIndexInfo(type.types, IndexKind.String); - const numberIndexInfo = getUnionIndexInfo(type.types, IndexKind.Number); - setStructuredTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); + const indexInfos = getUnionIndexInfos(type.types); + setStructuredTypeMembers(type, emptySymbols, callSignatures, constructSignatures, indexInfos); } function intersectTypes(type1: Type, type2: Type): Type; @@ -6493,14 +6485,51 @@ namespace ts { return !type1 ? type2 : !type2 ? type1 : getIntersectionType([type1, type2]); } - function intersectIndexInfos(info1: IndexInfo | undefined, info2: IndexInfo | undefined): IndexInfo | undefined { - return !info1 ? info2 : !info2 ? info1 : createIndexInfo( - getIntersectionType([info1.type, info2.type]), info1.isReadonly && info2.isReadonly); + function intersectIndexInfos(infos1: IndexInfo[] | undefined, infos2: IndexInfo[] | undefined): IndexInfo[] | undefined { + if (!infos1) { + return infos2; + } + if (!infos2) { + return infos1; + } + let infos: IndexInfo[] | undefined; + for (const info1 of infos1) { + for (const info2 of infos2) { + const intersectedKeys = getIntersectionType([info1.indexType, info2.indexType]); + // Merge all index signatures which overlap + if (intersectedKeys && intersectedKeys !== neverType && !(intersectedKeys.flags & TypeFlags.Intersection)) { + infos = concatenate(infos, [createIndexInfo(intersectedKeys, getIntersectionType([info1.type, info2.type]), info1.isReadonly && info2.isReadonly)]); + } + } + } + let baseInfos: IndexInfo[] | undefined; + for (const originalInfos of [infos1, infos2]) { + for (const info of originalInfos) { + // And also add all index signatures which did not get perfectly subsumed by another signature + if (!some(infos, i => i.indexType === info.indexType)) { + baseInfos = concatenate(baseInfos, [info]); + } + } + } + return concatenate(infos, baseInfos); } - function unionSpreadIndexInfos(info1: IndexInfo | undefined, info2: IndexInfo | undefined): IndexInfo | undefined { - return info1 && info2 && createIndexInfo( - getUnionType([info1.type, info2.type]), info1.isReadonly || info2.isReadonly); + function unionIndexInfos(infos1: IndexInfo[] | undefined, infos2: IndexInfo[] | undefined): IndexInfo[] | undefined { + if (!infos1 || !infos2) { + return; + } + let infos: IndexInfo[] | undefined; + for (const info1 of infos1) { + for (const info2 of infos2) { + const intersectedKeys = getIntersectionType([info1.indexType, info2.indexType]); + // Merge all index signatures which overlap + if (intersectedKeys && intersectedKeys !== neverType && !(intersectedKeys.flags & TypeFlags.Intersection)) { + infos = concatenate(infos, [createIndexInfo(intersectedKeys, getUnionType([info1.type, info2.type]), info1.isReadonly || info2.isReadonly)]); + } + } + } + // And drop the rest + return infos; } function includeMixinType(type: Type, types: ReadonlyArray, index: number): Type { @@ -6521,8 +6550,7 @@ namespace ts { // intersection type use getPropertiesOfType (only the language service uses this). let callSignatures: ReadonlyArray = emptyArray; let constructSignatures: ReadonlyArray = emptyArray; - let stringIndexInfo: IndexInfo | undefined; - let numberIndexInfo: IndexInfo | undefined; + let indexInfos: IndexInfo[] | undefined; const types = type.types; const mixinCount = countWhere(types, isMixinConstructorType); for (let i = 0; i < types.length; i++) { @@ -6544,10 +6572,9 @@ namespace ts { constructSignatures = concatenate(constructSignatures, signatures); } callSignatures = concatenate(callSignatures, getSignaturesOfType(t, SignatureKind.Call)); - stringIndexInfo = intersectIndexInfos(stringIndexInfo, getIndexInfoOfType(t, IndexKind.String)); - numberIndexInfo = intersectIndexInfos(numberIndexInfo, getIndexInfoOfType(t, IndexKind.Number)); + indexInfos = intersectIndexInfos(indexInfos, getIndexInfosOfType(t)); } - setStructuredTypeMembers(type, emptySymbols, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); + setStructuredTypeMembers(type, emptySymbols, callSignatures, constructSignatures, indexInfos); } /** @@ -6556,31 +6583,29 @@ namespace ts { function resolveAnonymousTypeMembers(type: AnonymousType) { const symbol = type.symbol; if (type.target) { - setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined, undefined); + setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined); const members = createInstantiatedSymbolTable(getPropertiesOfObjectType(type.target), type.mapper!, /*mappingThisOnly*/ false); const callSignatures = instantiateSignatures(getSignaturesOfType(type.target, SignatureKind.Call), type.mapper!); const constructSignatures = instantiateSignatures(getSignaturesOfType(type.target, SignatureKind.Construct), type.mapper!); - const stringIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, IndexKind.String), type.mapper!); - const numberIndexInfo = instantiateIndexInfo(getIndexInfoOfType(type.target, IndexKind.Number), type.mapper!); - setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); + const indexInfos = instantiateIndexInfos(getIndexInfosOfType(type.target), type.mapper!); + setStructuredTypeMembers(type, members, callSignatures, constructSignatures, indexInfos); } else if (symbol.flags & SymbolFlags.TypeLiteral) { - setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined, undefined); + setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined); const members = getMembersOfSymbol(symbol); const callSignatures = getSignaturesOfSymbol(members.get(InternalSymbolName.Call)); const constructSignatures = getSignaturesOfSymbol(members.get(InternalSymbolName.New)); - const stringIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.String); - const numberIndexInfo = getIndexInfoOfSymbol(symbol, IndexKind.Number); - setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); + const indexInfos = getIndexInfosOfSymbol(symbol); + setStructuredTypeMembers(type, members, callSignatures, constructSignatures, indexInfos); } else { // Combinations of function, class, enum and module let members = emptySymbols; - let stringIndexInfo: IndexInfo | undefined; + let indexInfos: IndexInfo[] | undefined; if (symbol.exports) { members = getExportsOfSymbol(symbol); } - setStructuredTypeMembers(type, members, emptyArray, emptyArray, undefined, undefined); + setStructuredTypeMembers(type, members, emptyArray, emptyArray, undefined); if (symbol.flags & SymbolFlags.Class) { const classType = getDeclaredTypeOfClassOrInterface(symbol); const baseConstructorType = getBaseConstructorTypeOfClass(classType); @@ -6589,11 +6614,14 @@ namespace ts { addInheritedMembers(members, getPropertiesOfType(baseConstructorType)); } else if (baseConstructorType === anyType) { - stringIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false); + indexInfos = [createIndexInfo(stringType, anyType, /*isReadonly*/ false)]; } } - const numberIndexInfo = symbol.flags & SymbolFlags.Enum ? enumNumberIndexInfo : undefined; - setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); + if (symbol.flags & SymbolFlags.Enum) { + indexInfos = indexInfos || []; + indexInfos.push(enumNumberIndexInfo); + } + setStructuredTypeMembers(type, members, emptyArray, emptyArray, indexInfos); // We resolve the members before computing the signatures because a signature may use // typeof with a qualified name expression that circularly references the type we are // in the process of resolving (see issue #6072). The temporarily empty signature list @@ -6614,11 +6642,13 @@ namespace ts { } function resolveReverseMappedTypeMembers(type: ReverseMappedType) { - const indexInfo = getIndexInfoOfType(type.source, IndexKind.String); + const indexInfos = getIndexInfosOfType(type.source); const modifiers = getMappedTypeModifiers(type.mappedType); const readonlyMask = modifiers & MappedTypeModifiers.IncludeReadonly ? false : true; const optionalMask = modifiers & MappedTypeModifiers.IncludeOptional ? 0 : SymbolFlags.Optional; - const stringIndexInfo = indexInfo && createIndexInfo(inferReverseMappedType(indexInfo.type, type.mappedType), readonlyMask && indexInfo.isReadonly); + const mappedIndexInfos = indexInfos && map(indexInfos, indexInfo => + createIndexInfo(indexInfo.indexType, inferReverseMappedType(indexInfo.type, type.mappedType), readonlyMask && indexInfo.isReadonly) + ); const members = createSymbolTable(); for (const prop of getPropertiesOfType(type.source)) { const checkFlags = CheckFlags.ReverseMapped | (readonlyMask && isReadonlySymbol(prop) ? CheckFlags.Readonly : 0); @@ -6629,16 +6659,15 @@ namespace ts { inferredProp.mappedType = type.mappedType; members.set(prop.escapedName, inferredProp); } - setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, undefined); + setStructuredTypeMembers(type, members, emptyArray, emptyArray, mappedIndexInfos); } /** Resolve the members of a mapped type { [P in K]: T } */ function resolveMappedTypeMembers(type: MappedType) { const members: SymbolTable = createSymbolTable(); - let stringIndexInfo: IndexInfo | undefined; - let numberIndexInfo: IndexInfo | undefined; + let indexInfos: IndexInfo[] | undefined; // Resolve upfront such that recursive references see an empty object type. - setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined, undefined); + setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined); // In { [P in K]: T }, we refer to P as the type parameter type, K as the constraint type, // and T as the template type. const typeParameter = getTypeParameterFromMappedType(type); @@ -6652,11 +6681,14 @@ namespace ts { for (const prop of getPropertiesOfType(modifiersType)) { addMemberForKeyType(getLiteralTypeFromPropertyName(prop, include)); } - if (modifiersType.flags & TypeFlags.Any || getIndexInfoOfType(modifiersType, IndexKind.String)) { - addMemberForKeyType(stringType); + const infos = getIndexInfosOfType(modifiersType); + if (infos) { + for (const info of infos) { + forEachType(info.indexType, !keyofStringsOnly ? addMemberForKeyType : t => isTypeAssignableTo(t, stringType) ? addMemberForKeyType(t) : void 0); + } } - if (!keyofStringsOnly && getIndexInfoOfType(modifiersType, IndexKind.Number)) { - addMemberForKeyType(numberType); + if (modifiersType.flags & TypeFlags.Any) { + addMemberForKeyType(stringType); } } else { @@ -6667,7 +6699,7 @@ namespace ts { const iterationType = keyType.flags & TypeFlags.Index ? getIndexType(getApparentType((keyType).type)) : keyType; forEachType(iterationType, addMemberForKeyType); } - setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); + setStructuredTypeMembers(type, members, emptyArray, emptyArray, indexInfos); function addMemberForKeyType(t: Type) { // Create a mapper from T to the current iteration type constituent. Then, if the @@ -6698,11 +6730,13 @@ namespace ts { prop.nameType = t; members.set(propName, prop); } - else if (t.flags & (TypeFlags.Any | TypeFlags.String)) { - stringIndexInfo = createIndexInfo(propType, !!(templateModifiers & MappedTypeModifiers.IncludeReadonly)); - } - else if (t.flags & TypeFlags.Number) { - numberIndexInfo = createIndexInfo(propType, !!(templateModifiers & MappedTypeModifiers.IncludeReadonly)); + else { + indexInfos = indexInfos || []; + if (isTypeAny(t)) { + // Legacy behavior. TODO: Remove. + t = stringType; + } + indexInfos.push(createIndexInfo(t, propType, !!(templateModifiers & MappedTypeModifiers.IncludeReadonly))); } } } @@ -7193,7 +7227,9 @@ namespace ts { } } else if (isUnion) { - const index = !isLateBoundName(name) && ((isNumericLiteralName(name) && getIndexInfoOfType(type, IndexKind.Number)) || getIndexInfoOfType(type, IndexKind.String)); + const index = !isLateBoundName(name) && ( + getResultingIndexInfoOfIndexOnType(type, getLiteralType(isNumericLiteralName(name) ? +name : "" + name)) + ); if (index) { checkFlags |= index.isReadonly ? CheckFlags.Readonly : 0; indexTypes = append(indexTypes, index.type); @@ -7319,35 +7355,51 @@ namespace ts { return getSignaturesOfStructuredType(getApparentType(type), kind); } - function getIndexInfoOfStructuredType(type: Type, kind: IndexKind): IndexInfo | undefined { + function getIndexInfosOfStructuredType(type: Type): IndexInfo[] | undefined { if (type.flags & TypeFlags.StructuredType) { const resolved = resolveStructuredTypeMembers(type); - return kind === IndexKind.String ? resolved.stringIndexInfo : resolved.numberIndexInfo; + return resolved.indexInfos; } } - function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type | undefined { - const info = getIndexInfoOfStructuredType(type, kind); - return info && info.type; - } - // Return the indexing info of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. - function getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined { - return getIndexInfoOfStructuredType(getApparentType(type), kind); + function getIndexInfosOfType(type: Type): IndexInfo[] | undefined { + return getIndexInfosOfStructuredType(getApparentType(type)); } - // Return the index type of the given kind in the given type. Creates synthetic union index types when necessary and - // maps primitive types and type parameters are to their apparent types. - function getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined { - return getIndexTypeOfStructuredType(getApparentType(type), kind); + // TODO (weswigham): Ensure all callers handle unions of `type` _before_ calling this + function getResultingIndexInfoOfIndexOnType(type: Type, indexType: Type): IndexInfo | undefined { + return resolveIndexOnIndexInfos(indexType, getIndexInfosOfType(type)); + } + + function getApplicableIndexInfosOfIndexOnType(type: Type, indexType: Type): IndexInfo[] | undefined { + if (!(indexType.flags & TypeFlags.Union)) { + const result = getResultingIndexInfoOfIndexOnType(type, indexType); + return result && [result]; + } + let resultList: IndexInfo[] | undefined; + for (const nameType of (indexType as UnionType).types) { + const result = getResultingIndexInfoOfIndexOnType(type, nameType); + if (!result) { + return; + } + resultList = appendIfUnique(resultList, result); + } + return resultList; + } + + function getResultingTypeOfIndexOnType(type: Type, indexType: Type): Type | undefined { + const resultInfos = getApplicableIndexInfosOfIndexOnType(type, indexType); + return resultInfos && getUnionType(map(resultInfos, i => i.type)); } - function getImplicitIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined { + function getImplicitIndexTypeOfType(type: Type, targetIndexType: Type): Type | undefined { if (isObjectTypeWithInferableIndex(type)) { const propTypes: Type[] = []; for (const prop of getPropertiesOfType(type)) { - if (kind === IndexKind.String || isNumericLiteralName(prop.escapedName)) { + const nameType = getLiteralTypeFromPropertyName(prop, TypeFlags.StringOrNumberLiteralOrUnique); + if (isTypeIndexAssignableTo(nameType, targetIndexType)) { propTypes.push(getTypeOfSymbol(prop)); } } @@ -7790,7 +7842,7 @@ namespace ts { function tryGetRestTypeOfSignature(signature: Signature): Type | undefined { const type = getTypeOfRestParameter(signature); - return type && getIndexTypeOfType(type, IndexKind.Number); + return type && getResultingTypeOfIndexOnType(type, numberType); } function getSignatureInstantiation(signature: Signature, typeArguments: Type[] | undefined, isJavascript: boolean): Signature { @@ -7875,33 +7927,61 @@ namespace ts { return symbol.members!.get(InternalSymbolName.Index); } - function getIndexDeclarationOfSymbol(symbol: Symbol, kind: IndexKind): IndexSignatureDeclaration | undefined { - const syntaxKind = kind === IndexKind.Number ? SyntaxKind.NumberKeyword : SyntaxKind.StringKeyword; + function getIndexDeclarationsOfSymbol(symbol: Symbol): IndexSignatureDeclaration[] | undefined { const indexSymbol = getIndexSymbol(symbol); + let result: IndexSignatureDeclaration[] | undefined; if (indexSymbol) { for (const decl of indexSymbol.declarations) { const node = cast(decl, isIndexSignatureDeclaration); if (node.parameters.length === 1) { const parameter = node.parameters[0]; - if (parameter.type && parameter.type.kind === syntaxKind) { - return node; + if (parameter.type) { + result = concatenate(result, [node]); } } } } - return undefined; - } - - function createIndexInfo(type: Type, isReadonly: boolean, declaration?: IndexSignatureDeclaration): IndexInfo { - return { type, isReadonly, declaration }; + return result; } - function getIndexInfoOfSymbol(symbol: Symbol, kind: IndexKind): IndexInfo | undefined { - const declaration = getIndexDeclarationOfSymbol(symbol, kind); - if (declaration) { - return createIndexInfo(declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, - hasModifier(declaration, ModifierFlags.Readonly), declaration); + /** + * Given a single type and a list of index infos, if that type is applicable to one or more of them, + * returns the index info to which it is the most applicable + */ + function resolveIndexOnIndexInfos(indexType: Type, infos: IndexInfo[] | undefined): IndexInfo | undefined { + Debug.assert(!(indexType.flags & TypeFlags.Union)); + const applicable = filter(infos, info => isTypeIndexAssignableTo(indexType, info.indexType)); + if (!length(applicable)) return; + // OK, now for the hard part - ranking the derivedness of an index signature! + let candidate = applicable![0]; + let filteredCandidateIndexType = filterType(candidate.indexType, c => isTypeIndexAssignableTo(indexType, c)); + for (const info of applicable!) { + if (info === candidate) continue; + const filteredInfoIndexType = filterType(info.indexType, c => isTypeIndexAssignableTo(indexType, c)); + // The identity check is here so that in situations where multiple index signatures with the same index type are present + // (which is usually an error), we'll align with older behavior and use the type from the first signature we encountered + if (!isTypeIdenticalTo(filteredInfoIndexType, filteredCandidateIndexType) && isTypeIndexAssignableTo(filteredInfoIndexType, filteredCandidateIndexType)) { + candidate = info; + filteredCandidateIndexType = filteredInfoIndexType; + } + } + return candidate; + } + + function createIndexInfo(indexType: Type, type: Type, isReadonly: boolean, declaration?: IndexSignatureDeclaration): IndexInfo { + return { indexType, type, isReadonly, declaration }; + } + + function getIndexInfosOfSymbol(symbol: Symbol): IndexInfo[] | undefined { + const declarations = getIndexDeclarationsOfSymbol(symbol); + if (declarations) { + return map(declarations, declaration => createIndexInfo( + getTypeFromTypeNode(declaration.parameters[0].type!), + declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, + hasModifier(declaration, ModifierFlags.Readonly), + declaration) + ); } return undefined; } @@ -8295,8 +8375,8 @@ namespace ts { if (isJSDocIndexSignature(node)) { const indexed = getTypeFromTypeNode(typeArgs[0]); const target = getTypeFromTypeNode(typeArgs[1]); - const index = createIndexInfo(target, /*isReadonly*/ false); - return createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, indexed === stringType ? index : undefined, indexed === numberType ? index : undefined); + const index = createIndexInfo(indexed, target, /*isReadonly*/ false); + return createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, [index]); } return anyType; } @@ -8547,8 +8627,7 @@ namespace ts { type.declaredProperties = properties; type.declaredCallSignatures = emptyArray; type.declaredConstructSignatures = emptyArray; - type.declaredStringIndexInfo = undefined; - type.declaredNumberIndexInfo = undefined; + type.declaredIndexInfos = emptyArray; type.minLength = minLength; type.hasRestElement = hasRestElement; type.associatedNames = associatedNames; @@ -8581,7 +8660,7 @@ namespace ts { const minLength = findLastIndex(node.elementTypes, n => n.kind !== SyntaxKind.OptionalType && n !== restElement) + 1; const elementTypes = map(node.elementTypes, n => { const type = getTypeFromTypeNode(n); - return n === restElement && getIndexTypeOfType(type, IndexKind.Number) || type; + return n === restElement && getResultingTypeOfIndexOnType(type, numberType) || type; }); links.resolvedType = createTupleType(elementTypes, minLength, !!restElement); } @@ -9066,9 +9145,15 @@ namespace ts { return getUnionType(map(getPropertiesOfType(type), t => getLiteralTypeFromPropertyName(t, include))); } - function getNonEnumNumberIndexInfo(type: Type) { - const numberIndexInfo = getIndexInfoOfType(type, IndexKind.Number); - return numberIndexInfo !== enumNumberIndexInfo ? numberIndexInfo : undefined; + function calculateIndexTypeForObjectType(type: Type, stringsOnly: boolean) { + const base = getUnionType([ + filterType(getUnionType(map(filter(getIndexInfosOfType(type) || emptyArray, info => info !== enumNumberIndexInfo), t => t.indexType)), t => !stringsOnly || isTypeAssignableTo(t, stringType)), + getLiteralTypeFromPropertyNames(type, stringsOnly ? TypeFlags.StringLiteral : TypeFlags.StringOrNumberLiteralOrUnique), + ]) + if (!stringsOnly && maybeTypeOfKind(base, TypeFlags.String)) { + return getUnionType([base, numberType]); + } + return base; } function getIndexType(type: Type, stringsOnly = keyofStringsOnly): Type { @@ -9078,10 +9163,7 @@ namespace ts { getObjectFlags(type) & ObjectFlags.Mapped ? getConstraintTypeFromMappedType(type) : type === wildcardType ? wildcardType : type.flags & TypeFlags.Any ? keyofConstraintType : - stringsOnly ? getIndexInfoOfType(type, IndexKind.String) ? stringType : getLiteralTypeFromPropertyNames(type, TypeFlags.StringLiteral) : - getIndexInfoOfType(type, IndexKind.String) ? getUnionType([stringType, numberType, getLiteralTypeFromPropertyNames(type, TypeFlags.UniqueESSymbol)]) : - getNonEnumNumberIndexInfo(type) ? getUnionType([numberType, getLiteralTypeFromPropertyNames(type, TypeFlags.StringLiteral | TypeFlags.UniqueESSymbol)]) : - getLiteralTypeFromPropertyNames(type, TypeFlags.StringOrNumberLiteralOrUnique); + calculateIndexTypeForObjectType(type, stringsOnly); } function getExtractStringType(type: Type) { @@ -9182,11 +9264,9 @@ namespace ts { if (objectType.flags & (TypeFlags.Any | TypeFlags.Never)) { return objectType; } - const indexInfo = isTypeAssignableToKind(indexType, TypeFlags.NumberLike) && getIndexInfoOfType(objectType, IndexKind.Number) || - getIndexInfoOfType(objectType, IndexKind.String) || - undefined; + const indexInfo = getResultingIndexInfoOfIndexOnType(objectType, indexType); if (indexInfo) { - if (accessNode && !isTypeAssignableToKind(indexType, TypeFlags.String | TypeFlags.Number)) { + if (accessNode && !isTypeAssignableToKind(indexType, TypeFlags.String | TypeFlags.Number | TypeFlags.ESSymbol)) { const indexNode = accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode.argumentExpression : accessNode.indexType; error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType)); } @@ -9206,7 +9286,7 @@ namespace ts { if (propName !== undefined && typeHasStaticProperty(propName, objectType)) { error(accessExpression, Diagnostics.Property_0_is_a_static_member_of_type_1, propName as string, typeToString(objectType)); } - else if (getIndexTypeOfType(objectType, IndexKind.Number)) { + else if (getResultingIndexInfoOfIndexOnType(objectType, numberType)) { error(accessExpression.argumentExpression, Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number); } else { @@ -9257,7 +9337,7 @@ namespace ts { const t = resolveStructuredTypeMembers(type); return t.properties.length === 0 && t.callSignatures.length === 0 && t.constructSignatures.length === 0 && - !!t.stringIndexInfo && !t.numberIndexInfo; + some(t.indexInfos, info => info.indexType === stringType); } return false; } @@ -9290,7 +9370,7 @@ namespace ts { const stringIndexTypes: Type[] = []; for (const t of (objectType).types) { if (isStringIndexOnlyType(t)) { - stringIndexTypes.push(getIndexTypeOfType(t, IndexKind.String)!); + stringIndexTypes.push(getResultingTypeOfIndexOnType(t, stringType)!); } else { regularTypes.push(t); @@ -9672,16 +9752,13 @@ namespace ts { const members = createSymbolTable(); const skippedPrivateMembers = createUnderscoreEscapedMap(); - let stringIndexInfo: IndexInfo | undefined; - let numberIndexInfo: IndexInfo | undefined; + let indexInfos: IndexInfo[] | undefined; if (left === emptyObjectType) { // for the first spread element, left === emptyObjectType, so take the right's string indexer - stringIndexInfo = getIndexInfoOfType(right, IndexKind.String); - numberIndexInfo = getIndexInfoOfType(right, IndexKind.Number); + indexInfos = getIndexInfosOfType(right); } else { - stringIndexInfo = unionSpreadIndexInfos(getIndexInfoOfType(left, IndexKind.String), getIndexInfoOfType(right, IndexKind.String)); - numberIndexInfo = unionSpreadIndexInfos(getIndexInfoOfType(left, IndexKind.Number), getIndexInfoOfType(right, IndexKind.Number)); + indexInfos = unionIndexInfos(getIndexInfosOfType(left), getIndexInfosOfType(right)); } for (const rightProp of getPropertiesOfType(right)) { @@ -9722,8 +9799,7 @@ namespace ts { members, emptyArray, emptyArray, - getNonReadonlyIndexSignature(stringIndexInfo), - getNonReadonlyIndexSignature(numberIndexInfo)); + map(indexInfos, getNonReadonlyIndexSignature)); spread.flags |= typeFlags | TypeFlags.ContainsObjectLiteral; (spread as ObjectType).objectFlags |= objectFlags | (ObjectFlags.ObjectLiteral | ObjectFlags.ContainsSpread); return spread; @@ -9749,9 +9825,9 @@ namespace ts { return result; } - function getNonReadonlyIndexSignature(index: IndexInfo | undefined) { - if (index && index.isReadonly) { - return createIndexInfo(index.type, /*isReadonly*/ false, index.declaration); + function getNonReadonlyIndexSignature(index: IndexInfo) { + if (index.isReadonly) { + return createIndexInfo(index.indexType, index.type, /*isReadonly*/ false, index.declaration); } return index; } @@ -10367,8 +10443,12 @@ namespace ts { type.wildcardInstantiation || (type.wildcardInstantiation = instantiateType(type, wildcardMapper)); } - function instantiateIndexInfo(info: IndexInfo | undefined, mapper: TypeMapper): IndexInfo | undefined { - return info && createIndexInfo(instantiateType(info.type, mapper), info.isReadonly, info.declaration); + function instantiateIndexInfo(info: IndexInfo, mapper: TypeMapper): IndexInfo { + return createIndexInfo(info.indexType, instantiateType(info.type, mapper), info.isReadonly, info.declaration); + } + + function instantiateIndexInfos(infos: IndexInfo[] | undefined, mapper: TypeMapper): IndexInfo[] | undefined { + return map(infos, i => instantiateIndexInfo(i, mapper)); } // Returns true if the given expression contains (at any level of nesting) a function or arrow expression @@ -10482,6 +10562,10 @@ namespace ts { return isTypeRelatedTo(source, target, assignableRelation); } + function isTypeIndexAssignableTo(source: Type, target: Type): boolean { + return isTypeRelatedTo(source, target, indexAssignableRelation); + } + // An object type S is considered to be derived from an object type T if // S is a union type and every constituent of S is derived from T, // T is a union type and S is derived from at least one constituent of T, or @@ -10590,9 +10674,7 @@ namespace ts { let issuedElaboration = false; if (!targetProp) { - const indexInfo = isTypeAssignableToKind(nameType, TypeFlags.NumberLike) && getIndexInfoOfType(target, IndexKind.Number) || - getIndexInfoOfType(target, IndexKind.String) || - undefined; + const indexInfo = getResultingIndexInfoOfIndexOnType(target, nameType); if (indexInfo && indexInfo.declaration) { issuedElaboration = true; addRelatedInfo(reportedDiag, createDiagnosticForNode(indexInfo.declaration, Diagnostics.The_expected_type_comes_from_this_index_signature)); @@ -10871,8 +10953,7 @@ namespace ts { return t.properties.length === 0 && t.callSignatures.length === 0 && t.constructSignatures.length === 0 && - !t.stringIndexInfo && - !t.numberIndexInfo; + !length(t.indexInfos) } function isEmptyObjectType(type: Type): boolean { @@ -10943,7 +11024,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) { + if (relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation || relation === indexAssignableRelation) { 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 @@ -10951,6 +11032,10 @@ namespace ts { if (s & (TypeFlags.Number | TypeFlags.NumberLiteral) && !(s & TypeFlags.EnumLiteral) && ( t & TypeFlags.Enum || t & TypeFlags.NumberLiteral && t & TypeFlags.EnumLiteral)) return true; } + if (relation === indexAssignableRelation) { + 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; + } return false; } @@ -11332,7 +11417,7 @@ namespace ts { } if (maybeTypeOfKind(target, TypeFlags.Object) && !(getObjectFlags(target) & ObjectFlags.ObjectLiteralPatternWithComputedProperties)) { const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes); - if ((relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation) && + if ((relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation || relation === indexAssignableRelation) && (isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) { return false; } @@ -11341,7 +11426,7 @@ namespace ts { return hasExcessProperties(source, discriminant, /*discriminant*/ undefined, reportErrors); } for (const prop of getPropertiesOfObjectType(source)) { - if (!isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) { + if (!isKnownProperty(target, getLiteralTypeFromPropertyName(prop, TypeFlags.StringOrNumberLiteralOrUnique), prop.escapedName, isComparingJsxAttributes)) { if (reportErrors) { // We know *exactly* where things went wrong when comparing the types. // Use this property as the error node as this will be more helpful in @@ -11832,10 +11917,7 @@ namespace ts { if (result) { result &= signaturesRelatedTo(source, target, SignatureKind.Construct, reportStructuralErrors); if (result) { - result &= indexTypesRelatedTo(source, target, IndexKind.String, sourceIsPrimitive, reportStructuralErrors); - if (result) { - result &= indexTypesRelatedTo(source, target, IndexKind.Number, sourceIsPrimitive, reportStructuralErrors); - } + result &= indexTypesRelatedTo(source, target, sourceIsPrimitive, reportStructuralErrors); } } } @@ -12005,7 +12087,7 @@ namespace ts { if (type.flags & TypeFlags.Object) { const resolved = resolveStructuredTypeMembers(type); return resolved.callSignatures.length === 0 && resolved.constructSignatures.length === 0 && - !resolved.stringIndexInfo && !resolved.numberIndexInfo && + !length(resolved.indexInfos) && resolved.properties.length > 0 && every(resolved.properties, p => !!(p.flags & SymbolFlags.Optional)); } @@ -12018,7 +12100,7 @@ namespace ts { function hasCommonProperties(source: Type, target: Type) { const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes); for (const prop of getPropertiesOfType(source)) { - if (isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) { + if (isKnownProperty(target, getLiteralTypeFromPropertyName(prop, TypeFlags.StringOrNumberLiteralOrUnique), prop.escapedName, isComparingJsxAttributes)) { return true; } } @@ -12156,18 +12238,15 @@ namespace ts { return result; } - function eachPropertyRelatedTo(source: Type, target: Type, kind: IndexKind, reportErrors: boolean): Ternary { + function eachPropertyRelatedToIndexesOf(source: Type, target: Type, sourceIsPrimitive: boolean, reportErrors: boolean): Ternary { let result = Ternary.True; for (const prop of getPropertiesOfObjectType(source)) { if (isIgnoredJsxProperty(source, prop, /*targetMemberType*/ undefined)) { continue; } - // Skip over symbol-named members - if (prop.nameType && prop.nameType.flags & TypeFlags.UniqueESSymbol) { - continue; - } - if (kind === IndexKind.String || isNumericLiteralName(prop.escapedName)) { - const related = isRelatedTo(getTypeOfSymbol(prop), target, reportErrors); + const targetType = getResultingTypeOfIndexOnType(target, getLiteralTypeFromPropertyName(prop, TypeFlags.StringOrNumberLiteralOrUnique)); + if (targetType) { + const related = isIndexTypeRelatedTo(getTypeOfSymbol(prop), targetType, sourceIsPrimitive, reportErrors); if (!related) { if (reportErrors) { reportError(Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop)); @@ -12180,45 +12259,35 @@ namespace ts { return result; } - function indexInfoRelatedTo(sourceInfo: IndexInfo, targetInfo: IndexInfo, reportErrors: boolean) { - const related = isRelatedTo(sourceInfo.type, targetInfo.type, reportErrors); - if (!related && reportErrors) { - reportError(Diagnostics.Index_signatures_are_incompatible); - } - return related; - } - - function indexTypesRelatedTo(source: Type, target: Type, kind: IndexKind, sourceIsPrimitive: boolean, reportErrors: boolean): Ternary { + function indexTypesRelatedTo(source: Type, target: Type, sourceIsPrimitive: boolean, reportErrors: boolean): Ternary { if (relation === identityRelation) { - return indexTypesIdenticalTo(source, target, kind); + return indexInfosRelated(getIndexInfosOfType(source), getIndexInfosOfType(target), sourceIsPrimitive, reportErrors); } - const targetInfo = getIndexInfoOfType(target, kind); - if (!targetInfo || targetInfo.type.flags & TypeFlags.AnyOrUnknown && !sourceIsPrimitive) { - // Index signature of type any permits assignment from everything but primitives + const targetInfo = getIndexInfosOfType(target); + if (!targetInfo) { return Ternary.True; } - const sourceInfo = getIndexInfoOfType(source, kind) || - kind === IndexKind.Number && getIndexInfoOfType(source, IndexKind.String); + const sourceInfo = getIndexInfosOfType(source) if (sourceInfo) { - return indexInfoRelatedTo(sourceInfo, targetInfo, reportErrors); + return indexInfosRelated(sourceInfo, targetInfo, sourceIsPrimitive, reportErrors); } if (isGenericMappedType(source)) { // A generic mapped type { [P in K]: T } is related to an index signature { [x: string]: U } // if T is related to U. - return (kind === IndexKind.String && isRelatedTo(getTemplateTypeFromMappedType(source), targetInfo.type, reportErrors)) as any as Ternary; // TODO: GH#18217 + const result = getResultingTypeOfIndexOnType(target, getConstraintTypeFromMappedType(source)); + return result ? isIndexTypeRelatedTo(getTemplateTypeFromMappedType(source), result, sourceIsPrimitive, reportErrors) : Ternary.False; } if (isObjectTypeWithInferableIndex(source)) { - let related = Ternary.True; - if (kind === IndexKind.String) { - const sourceNumberInfo = getIndexInfoOfType(source, IndexKind.Number); - if (sourceNumberInfo) { - related = indexInfoRelatedTo(sourceNumberInfo, targetInfo, reportErrors); - } - } - if (related) { - related &= eachPropertyRelatedTo(source, targetInfo.type, kind, reportErrors); + return eachPropertyRelatedToIndexesOf(source, target, sourceIsPrimitive, reportErrors); + } + let hasTypedSignature = false; + for (const info of targetInfo) { + if (!(!sourceIsPrimitive && info.type.flags & TypeFlags.AnyOrUnknown)) { + hasTypedSignature = true; } - return related; + } + if (!hasTypedSignature) { + return Ternary.True; } if (reportErrors) { reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); @@ -12226,14 +12295,48 @@ namespace ts { return Ternary.False; } - function indexTypesIdenticalTo(source: Type, target: Type, indexKind: IndexKind): Ternary { - const targetInfo = getIndexInfoOfType(target, indexKind); - const sourceInfo = getIndexInfoOfType(source, indexKind); - if (!sourceInfo && !targetInfo) { + function isIndexTypeRelatedTo(source: Type, target: Type, sourceIsPrimitive: boolean, reportErrors: boolean): Ternary { + // Index signature of type any permits assignment from everything but primitives + if (!sourceIsPrimitive && target.flags & TypeFlags.AnyOrUnknown) { return Ternary.True; } - if (sourceInfo && targetInfo && sourceInfo.isReadonly === targetInfo.isReadonly) { - return isRelatedTo(sourceInfo.type, targetInfo.type); + const related = isRelatedTo(source, target, reportErrors); + if (!related && reportErrors) { + reportError(Diagnostics.Index_signatures_are_incompatible); + } + return related; + } + + function indexInfosRelated(sourceInfos: IndexInfo[] | undefined, targetInfos: IndexInfo[] | undefined, sourceIsPrimitive: boolean, reportErrors: boolean): Ternary { + if (!sourceInfos && !targetInfos) { + return Ternary.True; + } + if (sourceInfos && targetInfos) { + const isIndexRelatedToHelper = identityRelation ? isRelatedTo : isTypeIndexAssignableTo; + // If for every index signature in S there exists a related signature in T + targetLoop: for (const targetInfo of targetInfos) { + for (const sourceInfo of sourceInfos) { + if (isIndexRelatedToHelper(sourceInfo.indexType, targetInfo.indexType) && isIndexTypeRelatedTo(sourceInfo.type, targetInfo.type, sourceIsPrimitive, reportErrors)) { + if (relation === identityRelation && sourceInfo.isReadonly !== targetInfo.isReadonly) return Ternary.False; + continue targetLoop; + } + } + return identityRelation ? Ternary.False : Ternary.True; + } + if (relation === identityRelation) { + // And for every index signature in T there exists and identical signature in S + sourceLoop: for (const sourceInfo of sourceInfos) { + for (const targetInfo of targetInfos) { + if (isIndexRelatedToHelper(sourceInfo.indexType, targetInfo.indexType) && isIndexTypeRelatedTo(sourceInfo.type, targetInfo.type, sourceIsPrimitive, /*reportErrors*/ false)) { + if (sourceInfo.isReadonly !== targetInfo.isReadonly) return Ternary.False; + continue sourceLoop; + } + } + return Ternary.False; + } + } + // Then the signature lists are related + return Ternary.True; } return Ternary.False; } @@ -12826,8 +12929,7 @@ namespace ts { members, resolved.callSignatures, resolved.constructSignatures, - resolved.stringIndexInfo, - resolved.numberIndexInfo); + resolved.indexInfos); regularNew.flags = resolved.flags & ~TypeFlags.FreshLiteral; regularNew.objectFlags |= ObjectFlags.ObjectLiteral | (getObjectFlags(resolved) & ObjectFlags.JSLiteral); (type).regularType = regularNew; @@ -12906,11 +13008,9 @@ namespace ts { } } } - const stringIndexInfo = getIndexInfoOfType(type, IndexKind.String); - const numberIndexInfo = getIndexInfoOfType(type, IndexKind.Number); + const indexInfos = getIndexInfosOfType(type); const result = createAnonymousType(type.symbol, members, emptyArray, emptyArray, - stringIndexInfo && createIndexInfo(getWidenedType(stringIndexInfo.type), stringIndexInfo.isReadonly), - numberIndexInfo && createIndexInfo(getWidenedType(numberIndexInfo.type), numberIndexInfo.isReadonly)); + map(indexInfos, indexInfo => createIndexInfo(indexInfo.indexType, getWidenedType(indexInfo.type), indexInfo.isReadonly))); result.objectFlags |= (getObjectFlags(type) & ObjectFlags.JSLiteral); // Retain js literal flag through widening return result; } @@ -13141,8 +13241,8 @@ namespace ts { } members.set(name, literalProp); }); - const indexInfo = type.flags & TypeFlags.String ? createIndexInfo(emptyObjectType, /*isReadonly*/ false) : undefined; - return createAnonymousType(undefined, members, emptyArray, emptyArray, indexInfo, undefined); + const indexInfos = type.flags & TypeFlags.String ? [createIndexInfo(type, emptyObjectType, /*isReadonly*/ false)] : undefined; + return createAnonymousType(undefined, members, emptyArray, emptyArray, indexInfos); } /** @@ -13164,7 +13264,7 @@ namespace ts { function createReverseMappedType(source: Type, target: MappedType) { const properties = getPropertiesOfType(source); - if (properties.length === 0 && !getIndexInfoOfType(source, IndexKind.String)) { + if (properties.length === 0 && !getResultingIndexInfoOfIndexOnType(source, stringType)) { return undefined; } // If any property contains context sensitive functions that have been skipped, the source type @@ -13568,21 +13668,27 @@ namespace ts { } function inferFromIndexTypes(source: Type, target: Type) { - const targetStringIndexType = getIndexTypeOfType(target, IndexKind.String); - if (targetStringIndexType) { - const sourceIndexType = getIndexTypeOfType(source, IndexKind.String) || - getImplicitIndexTypeOfType(source, IndexKind.String); - if (sourceIndexType) { - inferFromTypes(sourceIndexType, targetStringIndexType); + const targetInfos = getIndexInfosOfType(target); + if (!targetInfos) { + return; + } + const sourceInfos = getIndexInfosOfType(source); + if (!sourceInfos) { + for (const targetInfo of targetInfos) { + const implicitIndexType = getImplicitIndexTypeOfType(source, targetInfo.indexType); + if (implicitIndexType) { + inferFromTypes(implicitIndexType, targetInfo.type); + } } + return; } - const targetNumberIndexType = getIndexTypeOfType(target, IndexKind.Number); - if (targetNumberIndexType) { - const sourceIndexType = getIndexTypeOfType(source, IndexKind.Number) || - getIndexTypeOfType(source, IndexKind.String) || - getImplicitIndexTypeOfType(source, IndexKind.Number); - if (sourceIndexType) { - inferFromTypes(sourceIndexType, targetNumberIndexType); + for (const sourceInfo of sourceInfos) { + for (const targetInfo of targetInfos) { + // if this source info is applicable to the target info + if (isTypeIndexAssignableTo(sourceInfo.indexType, targetInfo.indexType)) { + // then infer + inferFromTypes(sourceInfo.type, targetInfo.type); + } } } } @@ -14043,8 +14149,7 @@ namespace ts { function getTypeOfDestructuredProperty(type: Type, name: PropertyName) { const text = getTextOfPropertyName(name); return getConstraintForLocation(getTypeOfPropertyOfType(type, text), name) || - isNumericLiteralName(text) && getIndexTypeOfType(type, IndexKind.Number) || - getIndexTypeOfType(type, IndexKind.String) || + getResultingTypeOfIndexOnType(type, getLiteralType(isNumericLiteralName(text) ? +text : unescapeLeadingUnderscores(text))) || errorType; } @@ -14775,7 +14880,7 @@ namespace ts { } function isTypePresencePossible(type: Type, propName: __String, assumeTrue: boolean) { - if (getIndexInfoOfType(type, IndexKind.String)) { + if (getResultingIndexInfoOfIndexOnType(type, stringType)) { return true; } const prop = getPropertyOfType(type, propName); @@ -16142,8 +16247,8 @@ namespace ts { }, /*noReductions*/ true); } - function getIndexTypeOfContextualType(type: Type, kind: IndexKind) { - return mapType(type, t => getIndexTypeOfStructuredType(t, kind), /*noReductions*/ true); + function getIndexTypeOfContextualType(type: Type, indexType: Type) { + return mapType(type, t => getResultingTypeOfIndexOnType(t, indexType), /*noReductions*/ true); } // Return true if the given contextual type is a tuple-like type @@ -16179,8 +16284,7 @@ namespace ts { } } - return isNumericName(element.name!) && getIndexTypeOfContextualType(type, IndexKind.Number) || - getIndexTypeOfContextualType(type, IndexKind.String); + return getIndexTypeOfContextualType(type, isNumericName(element.name!) ? numberType : stringType); } return undefined; @@ -16193,7 +16297,7 @@ namespace ts { function getContextualTypeForElementExpression(arrayContextualType: Type | undefined, index: number): Type | undefined { return arrayContextualType && ( getTypeOfPropertyOfContextualType(arrayContextualType, "" + index as __String) - || getIndexTypeOfContextualType(arrayContextualType, IndexKind.Number) + || getIndexTypeOfContextualType(arrayContextualType, getLiteralType(index)) || getIteratedTypeOrElementType(arrayContextualType, /*errorNode*/ undefined, /*allowStringInput*/ false, /*allowAsyncIterables*/ false, /*checkAssignability*/ false)); } @@ -16400,7 +16504,7 @@ namespace ts { if (intrinsicProp) { return getTypeOfSymbol(intrinsicProp); } - const indexSignatureType = getIndexTypeOfType(intrinsicElementsType, IndexKind.String); + const indexSignatureType = getResultingTypeOfIndexOnType(intrinsicElementsType, stringType); if (indexSignatureType) { return indexSignatureType; } @@ -16647,7 +16751,7 @@ namespace ts { // getContextualTypeForElementExpression, which will crucially not error // if there is no index type / iterated type. const restArrayType = checkExpression((e).expression, checkMode); - const restElementType = getIndexTypeOfType(restArrayType, IndexKind.Number) || + const restElementType = getResultingTypeOfIndexOnType(restArrayType, numberType) || getIteratedTypeOrElementType(restArrayType, /*errorNode*/ undefined, /*allowStringInput*/ false, /*allowAsyncIterables*/ false, /*checkAssignability*/ false); if (restElementType) { elementTypes.push(restElementType); @@ -16779,7 +16883,7 @@ namespace ts { } } const unionType = propTypes.length ? getUnionType(propTypes, UnionReduction.Subtype) : undefinedType; - return createIndexInfo(unionType, /*isReadonly*/ false); + return createIndexInfo(kind === IndexKind.Number ? numberType : stringType, unionType, /*isReadonly*/ false); } function checkObjectLiteral(node: ObjectLiteralExpression, checkMode?: CheckMode): Type { @@ -16854,7 +16958,7 @@ namespace ts { prop.flags |= impliedProp.flags & SymbolFlags.Optional; } - else if (!compilerOptions.suppressExcessPropertyErrors && !getIndexInfoOfType(contextualType!, IndexKind.String)) { + else if (!compilerOptions.suppressExcessPropertyErrors && !getResultingIndexInfoOfIndexOnType(contextualType!, nameType || stringType)) { error(memberDecl.name, Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(member), typeToString(contextualType!)); } @@ -16945,9 +17049,14 @@ namespace ts { return createObjectLiteralType(); function createObjectLiteralType() { - const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo(node.properties, offset, propertiesArray, IndexKind.String) : undefined; - const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node.properties, offset, propertiesArray, IndexKind.Number) : undefined; - const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); + let indexInfos: IndexInfo[] | undefined; + if (hasComputedStringProperty) { + indexInfos = append(indexInfos, getObjectLiteralIndexInfo(node.properties, offset, propertiesArray, IndexKind.String)); + } + if (hasComputedNumberProperty) { + indexInfos = append(indexInfos, getObjectLiteralIndexInfo(node.properties, offset, propertiesArray, IndexKind.Number)); + } + const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, indexInfos); const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral; result.flags |= TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags); result.objectFlags |= ObjectFlags.ObjectLiteral; @@ -17117,7 +17226,7 @@ namespace ts { createArrayType(getUnionType(childrenTypes)); const childPropMap = createSymbolTable(); childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol); - spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined), + spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, emptyArray, emptyArray, /*indexInfos*/ undefined), attributes.symbol, /*typeFlags*/ 0, ObjectFlags.JsxAttributes); } @@ -17137,7 +17246,7 @@ namespace ts { * @param attributesTable a symbol table of attributes property */ function createJsxAttributesType() { - const result = createAnonymousType(attributes.symbol, attributesTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined); + const result = createAnonymousType(attributes.symbol, attributesTable, emptyArray, emptyArray, /*indexInfos*/ undefined); result.flags |= TypeFlags.ContainsObjectLiteral; result.objectFlags |= ObjectFlags.ObjectLiteral | ObjectFlags.JsxAttributes; return result; @@ -17197,7 +17306,7 @@ namespace ts { } // Intrinsic string indexer case - const indexSignatureType = getIndexTypeOfType(intrinsicElementsType, IndexKind.String); + const indexSignatureType = getResultingIndexInfoOfIndexOnType(intrinsicElementsType, stringType); if (indexSignatureType) { links.jsxFlags |= JsxFlags.IntrinsicIndexedElement; return links.resolvedSymbol = intrinsicElementsType.symbol; @@ -17534,7 +17643,7 @@ namespace ts { if (intrinsicProp) { return getTypeOfSymbol(intrinsicProp); } - const indexSignatureType = getIndexTypeOfType(intrinsicElementsType, IndexKind.String); + const indexSignatureType = getResultingTypeOfIndexOnType(intrinsicElementsType, stringType); if (indexSignatureType) { return indexSignatureType; } @@ -17585,7 +17694,7 @@ namespace ts { return links.resolvedJsxElementAttributesType = getTypeOfSymbol(symbol); } else if (links.jsxFlags & JsxFlags.IntrinsicIndexedElement) { - return links.resolvedJsxElementAttributesType = getIndexInfoOfSymbol(symbol, IndexKind.String)!.type; + return links.resolvedJsxElementAttributesType = resolveIndexOnIndexInfos(stringType, getIndexInfosOfSymbol(symbol))!.type; } else { return links.resolvedJsxElementAttributesType = errorType; @@ -17725,14 +17834,14 @@ namespace ts { * 4. In a union or intersection type, * a property is considered known if it is known in any constituent type. * @param targetType a type to search a given name in + * @param nameType type of a property name to search * @param name a property name to search * @param isComparingJsxAttributes a boolean flag indicating whether we are searching in JsxAttributesType */ - function isKnownProperty(targetType: Type, name: __String, isComparingJsxAttributes: boolean): boolean { + function isKnownProperty(targetType: Type, nameType: Type, name: __String, isComparingJsxAttributes: boolean): boolean { if (targetType.flags & TypeFlags.Object) { const resolved = resolveStructuredTypeMembers(targetType as ObjectType); - if (resolved.stringIndexInfo || - resolved.numberIndexInfo && isNumericLiteralName(name) || + if (getResultingIndexInfoOfIndexOnType(resolved, nameType) || getPropertyOfObjectType(targetType, name) || isComparingJsxAttributes && !isUnhyphenatedJsxName(name)) { // For JSXAttributes, if the attribute has a hyphenated name, consider that the attribute to be known. @@ -17741,14 +17850,14 @@ namespace ts { } else if (targetType.flags & TypeFlags.UnionOrIntersection) { for (const t of (targetType as UnionOrIntersectionType).types) { - if (isKnownProperty(t, name, isComparingJsxAttributes)) { + if (isKnownProperty(t, nameType, name, isComparingJsxAttributes)) { return true; } } } else if (targetType.flags & TypeFlags.Conditional) { - return isKnownProperty((targetType as ConditionalType).root.trueType, name, isComparingJsxAttributes) || - isKnownProperty((targetType as ConditionalType).root.falseType, name, isComparingJsxAttributes); + return isKnownProperty((targetType as ConditionalType).root.trueType, nameType, name, isComparingJsxAttributes) || + isKnownProperty((targetType as ConditionalType).root.falseType, nameType, name, isComparingJsxAttributes); } return false; } @@ -17788,7 +17897,7 @@ namespace ts { } const attrName = attribute.name; const isNotIgnoredJsxProperty = (isUnhyphenatedJsxName(idText(attrName)) || !!(getPropertyOfType(targetAttributesType, attrName.escapedText))); - if (isNotIgnoredJsxProperty && !isKnownProperty(targetAttributesType, attrName.escapedText, /*isComparingJsxAttributes*/ true)) { + if (isNotIgnoredJsxProperty && !isKnownProperty(targetAttributesType, getLiteralType(unescapeLeadingUnderscores(attrName.escapedText)), attrName.escapedText, /*isComparingJsxAttributes*/ true)) { error(attribute, Diagnostics.Property_0_does_not_exist_on_type_1, idText(attrName), typeToString(targetAttributesType)); // We break here so that errors won't be cascading break; @@ -18016,7 +18125,7 @@ namespace ts { markAliasReferenced(parentSymbol, node); } if (!prop) { - const indexInfo = getIndexInfoOfType(apparentType, IndexKind.String); + const indexInfo = getResultingIndexInfoOfIndexOnType(apparentType, getLiteralType(unescapeLeadingUnderscores(right.escapedText))); if (!(indexInfo && indexInfo.type)) { if (isJSLiteralType(leftType)) { return anyType; @@ -18335,7 +18444,7 @@ namespace ts { * Return true if the given type is considered to have numeric property names. */ function hasNumericPropertyNames(type: Type) { - return getIndexTypeOfType(type, IndexKind.Number) && !getIndexTypeOfType(type, IndexKind.String); + return getResultingIndexInfoOfIndexOnType(type, numberType) && !getResultingIndexInfoOfIndexOnType(type, stringType); } /** @@ -18601,7 +18710,7 @@ namespace ts { if (type.flags & TypeFlags.Object) { const resolved = resolveStructuredTypeMembers(type); if (resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0 && - resolved.properties.length === 0 && !resolved.stringIndexInfo && !resolved.numberIndexInfo) { + resolved.properties.length === 0 && !length(resolved.indexInfos)) { return resolved.callSignatures[0]; } } @@ -18716,7 +18825,7 @@ namespace ts { checkExpressionWithContextualType((arg).expression, restType, context); } } - const contextualType = getIndexTypeOfType(restType, IndexKind.Number) || anyType; + const contextualType = getResultingTypeOfIndexOnType(restType, numberType) || anyType; const hasPrimitiveContextualType = maybeTypeOfKind(contextualType, TypeFlags.Primitive | TypeFlags.Index); const types = []; let spreadIndex = -1; @@ -19839,7 +19948,7 @@ namespace ts { function getInferredClassType(symbol: Symbol) { const links = getSymbolLinks(symbol); if (!links.inferredClassType) { - links.inferredClassType = createAnonymousType(symbol, getMembersOfSymbol(symbol) || emptySymbols, emptyArray, emptyArray, /*stringIndexType*/ undefined, /*numberIndexType*/ undefined); + links.inferredClassType = createAnonymousType(symbol, getMembersOfSymbol(symbol) || emptySymbols, emptyArray, emptyArray, /*indexInfos*/ undefined); } return links.inferredClassType; } @@ -19910,7 +20019,7 @@ namespace ts { if (decl) { const jsSymbol = getSymbolOfNode(decl); if (jsSymbol && hasEntries(jsSymbol.exports)) { - jsAssignmentType = createAnonymousType(jsSymbol, jsSymbol.exports, emptyArray, emptyArray, undefined, undefined); + jsAssignmentType = createAnonymousType(jsSymbol, jsSymbol.exports, emptyArray, emptyArray, undefined); (jsAssignmentType as ObjectType).objectFlags |= ObjectFlags.JSLiteral; } } @@ -19978,7 +20087,7 @@ namespace ts { newSymbol.target = resolveSymbol(symbol); memberTable.set(InternalSymbolName.Default, newSymbol); const anonymousSymbol = createSymbol(SymbolFlags.TypeLiteral, InternalSymbolName.Type); - const defaultContainingObject = createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined); + const defaultContainingObject = createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, /*indexInfos*/ undefined); anonymousSymbol.type = defaultContainingObject; synthType.syntheticType = isValidSpreadType(type) ? getSpreadType(type, defaultContainingObject, anonymousSymbol, /*typeFLags*/ 0, /*objectFlags*/ 0) : defaultContainingObject; } @@ -20135,7 +20244,7 @@ namespace ts { } return getRestTypeOfTupleType(restType); } - return getIndexTypeOfType(restType, IndexKind.Number); + return getResultingTypeOfIndexOnType(restType, getLiteralType(pos)); } return undefined; } @@ -20577,7 +20686,7 @@ namespace ts { } const returnType = getReturnTypeFromBody(node, checkMode); const singleReturnSignature = createSignature(undefined, undefined, undefined, emptyArray, returnType, /*resolvedTypePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false); - return links.contextFreeType = createAnonymousType(node.symbol, emptySymbols, [singleReturnSignature], emptyArray, undefined, undefined); + return links.contextFreeType = createAnonymousType(node.symbol, emptySymbols, [singleReturnSignature], emptyArray, undefined); } return anyFunctionType; } @@ -20995,9 +21104,9 @@ namespace ts { checkPropertyAccessibility(property, /*isSuper*/ false, objectLiteralType, prop); type = getTypeOfSymbol(prop); } - type = type || (isNumericLiteralName(text) ? getIndexTypeOfType(objectLiteralType, IndexKind.Number) : undefined); + type = type || (isNumericLiteralName(text) ? getResultingTypeOfIndexOnType(objectLiteralType, getLiteralType(+text)) : undefined); } - return type || getIndexTypeOfType(objectLiteralType, IndexKind.String); + return type || getResultingTypeOfIndexOnType(objectLiteralType, getLiteralType(unescapeLeadingUnderscores(text))); } function checkArrayLiteralAssignment(node: ArrayLiteralExpression, sourceType: Type, checkMode?: CheckMode): Type { @@ -22580,7 +22689,7 @@ namespace ts { } // Check if we're indexing with a numeric type and if either object or index types // is a generic type with a constraint that has a numeric index signature. - if (getIndexInfoOfType(getApparentType(objectType), IndexKind.Number) && isTypeAssignableToKind(indexType, TypeFlags.NumberLike)) { + if (getResultingIndexInfoOfIndexOnType(objectType, indexType)) { return type; } error(accessNode, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(objectType)); @@ -24662,7 +24771,7 @@ namespace ts { return hasStringConstituent ? stringType : undefined; } - const arrayElementType = getIndexTypeOfType(arrayType, IndexKind.Number); + const arrayElementType = getResultingTypeOfIndexOnType(arrayType, numberType); if (hasStringConstituent && arrayElementType) { // This is just an optimization for the case where arrayOrStringType is string | string[] if (arrayElementType.flags & TypeFlags.StringLike) { @@ -25094,17 +25203,13 @@ namespace ts { } function checkIndexConstraints(type: Type) { - const declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, IndexKind.Number); - const declaredStringIndexer = getIndexDeclarationOfSymbol(type.symbol, IndexKind.String); - - const stringIndexType = getIndexTypeOfType(type, IndexKind.String); - const numberIndexType = getIndexTypeOfType(type, IndexKind.Number); - - if (stringIndexType || numberIndexType) { + const declaredIndexers = getIndexDeclarationsOfSymbol(type.symbol); + const indexInfos = getIndexInfosOfType(type); + + if (indexInfos) { forEach(getPropertiesOfObjectType(type), prop => { const propType = getTypeOfSymbol(prop); - checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, IndexKind.String); - checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, IndexKind.Number); + checkIndexConstraintForProperty(prop, propType, type, declaredIndexers); }); const classDeclaration = type.symbol.valueDeclaration; @@ -25116,48 +25221,75 @@ namespace ts { if (!hasModifier(member, ModifierFlags.Static) && hasNonBindableDynamicName(member)) { const symbol = getSymbolOfNode(member); const propType = getTypeOfSymbol(symbol); - checkIndexConstraintForProperty(symbol, propType, type, declaredStringIndexer, stringIndexType, IndexKind.String); - checkIndexConstraintForProperty(symbol, propType, type, declaredNumberIndexer, numberIndexType, IndexKind.Number); + checkIndexConstraintForProperty(symbol, propType, type, declaredIndexers); } } } } - let errorNode: Node | undefined; - if (stringIndexType && numberIndexType) { - errorNode = declaredNumberIndexer || declaredStringIndexer; - // condition 'errorNode === undefined' may appear if types does not declare nor string neither number indexer - if (!errorNode && (getObjectFlags(type) & ObjectFlags.Interface)) { - const someBaseTypeHasBothIndexers = forEach(getBaseTypes(type), base => getIndexTypeOfType(base, IndexKind.String) && getIndexTypeOfType(base, IndexKind.Number)); - errorNode = someBaseTypeHasBothIndexers ? undefined : type.symbol.declarations[0]; - } + if (length(indexInfos) <= 1) { + return; // No errors because no index signatures can conflict } - if (errorNode && !isTypeAssignableTo(numberIndexType!, stringIndexType!)) { // TODO: GH#18217 - error(errorNode, Diagnostics.Numeric_index_type_0_is_not_assignable_to_string_index_type_1, - typeToString(numberIndexType!), typeToString(stringIndexType!)); + for (const info1 of indexInfos!) { + for (const info2 of indexInfos!) { + if (info1 === info2) continue; + if (getObjectFlags(type) & ObjectFlags.Interface) { + const someBaseTypeHasBothIndexers = some(getBaseTypes(type), base => { + const baseInfos = getIndexInfosOfType(base); + return contains(baseInfos, info1) && contains(baseInfos, info2); + }); + if (someBaseTypeHasBothIndexers) continue; + } + forEachType(info1.indexType, indexType => { + if (isTypeIndexAssignableTo(indexType, info2.indexType)) { + if (!isTypeAssignableTo(info1.type, info2.type)) { + // Error - not compatable + const errorNode = (contains(declaredIndexers, info1.declaration) + ? info1.declaration + : contains(declaredIndexers, info2.declaration) + ? info2.declaration + : undefined) || type.symbol.declarations[0]; + const rootChain = () => chainDiagnosticMessages( + /*details*/ undefined, + Diagnostics._0_index_type_1_is_not_assignable_to_2_index_type_3, + typeToString(info1.indexType), + typeToString(info1.type), + typeToString(info2.indexType), + typeToString(info2.type) + ); + checkTypeAssignableTo(info1.type, info2.type, errorNode, undefined, rootChain); + } + } + }) + } } function checkIndexConstraintForProperty( prop: Symbol, propertyType: Type, containingType: Type, - indexDeclaration: Declaration | undefined, - indexType: Type | undefined, - indexKind: IndexKind): void { - - // ESSymbol properties apply to neither string nor numeric indexers. - if (!indexType || isKnownSymbol(prop)) { + indexDeclarations: Declaration[] | undefined + ): void { + // TODO: Well known symbols should _probably_ be subject to a symbol indexer, but unfortunately they have no associated literal + // type right now, so they're very difficult to check/flow. They're on the chopping block for removal thanks to advancements, + // and other issues though, so it's probably OK to just let their removal and simultaneous replacement with `unique symbol`s + // fix this. + if (isKnownSymbol(prop)) { return; } - const propDeclaration = prop.valueDeclaration; - const name = propDeclaration && getNameOfDeclaration(propDeclaration); + const propName = getLiteralTypeFromPropertyName(prop, TypeFlags.StringOrNumberLiteralOrUnique); - // index is numeric and property name is not valid numeric literal - if (indexKind === IndexKind.Number && !(name ? isNumericName(name) : isNumericLiteralName(prop.escapedName))) { - return; + const indexInfos = getIndexInfosOfType(containingType); + const resolvedInfo = resolveIndexOnIndexInfos(propName, indexInfos); + if (!resolvedInfo || isTypeIndexAssignableTo(propertyType, resolvedInfo.type)) { + return; // No errors } + const indexDeclaration = contains(indexDeclarations, resolvedInfo.declaration) ? resolvedInfo.declaration : undefined; + + const propDeclaration = prop.valueDeclaration; + const name = propDeclaration && getNameOfDeclaration(propDeclaration); // perform property check if property or indexer is declared in 'type' // this allows us to rule out cases when both property and indexer are inherited from the base class @@ -25175,16 +25307,19 @@ namespace ts { // for interfaces property and indexer might be inherited from different bases // check if any base class already has both property and indexer. // check should be performed only if 'type' is the first type that brings property\indexer together - const someBaseClassHasBothPropertyAndIndexer = forEach(getBaseTypes(containingType), base => getPropertyOfObjectType(base, prop.escapedName) && getIndexTypeOfType(base, indexKind)); + const someBaseClassHasBothPropertyAndIndexer = forEach(getBaseTypes(containingType), base => getPropertyOfObjectType(base, prop.escapedName) && getResultingTypeOfIndexOnType(base, propName)); errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0]; } - if (errorNode && !isTypeAssignableTo(propertyType, indexType)) { - const errorMessage = - indexKind === IndexKind.String - ? Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2 - : Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2; - error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType)); + if (errorNode) { + error( + errorNode, + Diagnostics.Property_0_of_type_1_is_not_assignable_to_2_index_type_3, + symbolToString(prop), + typeToString(propertyType), + typeToString(resolvedInfo.indexType), + typeToString(resolvedInfo.type) + ); } } } @@ -28210,7 +28345,7 @@ namespace ts { autoArrayType = createArrayType(autoType); if (autoArrayType === emptyObjectType) { // autoArrayType is used as a marker, so even if global Array type is not defined, it needs to be a unique type - autoArrayType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + autoArrayType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined); } globalReadonlyArrayType = getGlobalTypeOrUndefined("ReadonlyArray" as __String, /*arity*/ 1); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 32a07c0818dcf..014e3c4ead4a3 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1432,15 +1432,11 @@ "category": "Error", "code": 2410 }, - "Property '{0}' of type '{1}' is not assignable to string index type '{2}'.": { + "Property '{0}' of type '{1}' is not assignable to '{2}' index type '{3}'.": { "category": "Error", "code": 2411 }, - "Property '{0}' of type '{1}' is not assignable to numeric index type '{2}'.": { - "category": "Error", - "code": 2412 - }, - "Numeric index type '{0}' is not assignable to string index type '{1}'.": { + "'{0}' index type '{1}' is not assignable to '{2}' index type '{3}'.": { "category": "Error", "code": 2413 }, diff --git a/src/compiler/symbolWalker.ts b/src/compiler/symbolWalker.ts index 1f6930076bef0..94985e5cdead4 100644 --- a/src/compiler/symbolWalker.ts +++ b/src/compiler/symbolWalker.ts @@ -8,7 +8,7 @@ namespace ts { resolveStructuredTypeMembers: (type: ObjectType) => ResolvedType, getTypeOfSymbol: (sym: Symbol) => Type, getResolvedSymbol: (node: Node) => Symbol, - getIndexTypeOfStructuredType: (type: Type, kind: IndexKind) => Type | undefined, + getIndexInfosOfType: (type: Type) => IndexInfo[] | undefined, getConstraintOfTypeParameter: (typeParameter: TypeParameter) => Type | undefined, getFirstIdentifier: (node: EntityNameOrEntityNameExpression) => Identifier) { @@ -139,10 +139,13 @@ namespace ts { } function visitObjectType(type: ObjectType): void { - const stringIndexType = getIndexTypeOfStructuredType(type, IndexKind.String); - visitType(stringIndexType); - const numberIndexType = getIndexTypeOfStructuredType(type, IndexKind.Number); - visitType(numberIndexType); + const infos = getIndexInfosOfType(type); + if (infos) { + for (const info of infos) { + visitType(info.indexType); + visitType(info.type); + } + } // The two checks above *should* have already resolved the type (if needed), so this should be cached const resolved = resolveStructuredTypeMembers(type); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4330a776d0421..46431e8da4a23 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2906,9 +2906,9 @@ namespace ts { getPropertiesOfType(type: Type): Symbol[]; getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; /* @internal */ getTypeOfPropertyOfType(type: Type, propertyName: string): Type | undefined; - getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined; + getIndexInfosOfType(type: Type, indexType?: Type): IndexInfo[] | undefined; getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray; - getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined; + getIndexTypeOfType(type: Type, indexType: Type): Type | undefined; getBaseTypes(type: InterfaceType): BaseType[]; getBaseTypeOfLiteralType(type: Type): Type; getWidenedType(type: Type): Type; @@ -2930,7 +2930,7 @@ namespace ts { /** Note that the resulting nodes cannot be checked. */ signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): SignatureDeclaration & {typeArguments?: NodeArray} | undefined; /** Note that the resulting nodes cannot be checked. */ - indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): IndexSignatureDeclaration | undefined; + indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): IndexSignatureDeclaration | undefined; /** Note that the resulting nodes cannot be checked. */ symbolToEntityName(symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): EntityName | undefined; /** Note that the resulting nodes cannot be checked. */ @@ -3055,7 +3055,7 @@ namespace ts { hasLiteralTypes: boolean, ): Signature; /* @internal */ createSymbol(flags: SymbolFlags, name: __String): TransientSymbol; - /* @internal */ createIndexInfo(type: Type, isReadonly: boolean, declaration?: SignatureDeclaration): IndexInfo; + /* @internal */ createIndexInfo(indexType: Type, type: Type, isReadonly: boolean, declaration?: IndexSignatureDeclaration): IndexInfo; /* @internal */ isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult; /* @internal */ tryFindAmbientModuleWithoutAugmentations(moduleName: string): Symbol | undefined; @@ -3842,8 +3842,7 @@ namespace ts { /* @internal */ properties?: Symbol[]; // Properties /* @internal */ callSignatures?: ReadonlyArray; // Call signatures of type /* @internal */ constructSignatures?: ReadonlyArray; // Construct signatures of type - /* @internal */ stringIndexInfo?: IndexInfo; // String indexing info - /* @internal */ numberIndexInfo?: IndexInfo; // Numeric indexing info + /* @internal */ indexInfos?: IndexInfo[]; // Index infos } /** Class and interface types (ObjectFlags.Class and ObjectFlags.Interface). */ @@ -3865,8 +3864,7 @@ namespace ts { declaredProperties: Symbol[]; // Declared members declaredCallSignatures: Signature[]; // Declared call signatures declaredConstructSignatures: Signature[]; // Declared construct signatures - declaredStringIndexInfo?: IndexInfo; // Declared string indexing info - declaredNumberIndexInfo?: IndexInfo; // Declared numeric indexing info + declaredIndexInfos?: IndexInfo[]; // Declared indexing infos } /** @@ -4133,6 +4131,7 @@ namespace ts { } export interface IndexInfo { + indexType: Type; type: Type; isReadonly: boolean; declaration?: IndexSignatureDeclaration; diff --git a/src/server/session.ts b/src/server/session.ts index 8d2fbe9e190a1..e4c2a8ab09b18 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1952,26 +1952,26 @@ namespace ts.server { } private handlers = createMapFromTemplate<(request: protocol.Request) => HandlerResponse>({ - [CommandNames.Status]: () => { + [protocol.CommandTypes.Status]: () => { const response: protocol.StatusResponseBody = { version }; return this.requiredResponse(response); }, - [CommandNames.OpenExternalProject]: (request: protocol.OpenExternalProjectRequest) => { + [protocol.CommandTypes.OpenExternalProject]: (request: protocol.OpenExternalProjectRequest) => { this.projectService.openExternalProject(request.arguments); // TODO: GH#20447 report errors return this.requiredResponse(/*response*/ true); }, - [CommandNames.OpenExternalProjects]: (request: protocol.OpenExternalProjectsRequest) => { + [protocol.CommandTypes.OpenExternalProjects]: (request: protocol.OpenExternalProjectsRequest) => { this.projectService.openExternalProjects(request.arguments.projects); // TODO: GH#20447 report errors return this.requiredResponse(/*response*/ true); }, - [CommandNames.CloseExternalProject]: (request: protocol.CloseExternalProjectRequest) => { + [protocol.CommandTypes.CloseExternalProject]: (request: protocol.CloseExternalProjectRequest) => { this.projectService.closeExternalProject(request.arguments.projectFileName); // TODO: GH#20447 report errors return this.requiredResponse(/*response*/ true); }, - [CommandNames.SynchronizeProjectList]: (request: protocol.SynchronizeProjectListRequest) => { + [protocol.CommandTypes.SynchronizeProjectList]: (request: protocol.SynchronizeProjectListRequest) => { const result = this.projectService.synchronizeProjectList(request.arguments.knownProjects); if (!result.some(p => p.projectErrors && p.projectErrors.length !== 0)) { return this.requiredResponse(result); @@ -1989,56 +1989,56 @@ namespace ts.server { }); return this.requiredResponse(converted); }, - [CommandNames.ApplyChangedToOpenFiles]: (request: protocol.ApplyChangedToOpenFilesRequest) => { + [protocol.CommandTypes.ApplyChangedToOpenFiles]: (request: protocol.ApplyChangedToOpenFilesRequest) => { this.changeSeq++; this.projectService.applyChangesInOpenFiles(request.arguments.openFiles, request.arguments.changedFiles!, request.arguments.closedFiles!); // TODO: GH#18217 // TODO: report errors return this.requiredResponse(/*response*/ true); }, - [CommandNames.Exit]: () => { + [protocol.CommandTypes.Exit]: () => { this.exit(); return this.notRequired(); }, - [CommandNames.Definition]: (request: protocol.DefinitionRequest) => { + [protocol.CommandTypes.Definition]: (request: protocol.DefinitionRequest) => { return this.requiredResponse(this.getDefinition(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.DefinitionFull]: (request: protocol.DefinitionRequest) => { + [protocol.CommandTypes.DefinitionFull]: (request: protocol.DefinitionRequest) => { return this.requiredResponse(this.getDefinition(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.DefinitionAndBoundSpan]: (request: protocol.DefinitionRequest) => { + [protocol.CommandTypes.DefinitionAndBoundSpan]: (request: protocol.DefinitionRequest) => { return this.requiredResponse(this.getDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.DefinitionAndBoundSpanFull]: (request: protocol.DefinitionRequest) => { + [protocol.CommandTypes.DefinitionAndBoundSpanFull]: (request: protocol.DefinitionRequest) => { return this.requiredResponse(this.getDefinitionAndBoundSpan(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.EmitOutput]: (request: protocol.EmitOutputRequest) => { + [protocol.CommandTypes.EmitOutput]: (request: protocol.EmitOutputRequest) => { return this.requiredResponse(this.getEmitOutput(request.arguments)); }, - [CommandNames.TypeDefinition]: (request: protocol.FileLocationRequest) => { + [protocol.CommandTypes.TypeDefinition]: (request: protocol.FileLocationRequest) => { return this.requiredResponse(this.getTypeDefinition(request.arguments)); }, - [CommandNames.Implementation]: (request: protocol.Request) => { + [protocol.CommandTypes.Implementation]: (request: protocol.Request) => { return this.requiredResponse(this.getImplementation(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.ImplementationFull]: (request: protocol.Request) => { + [protocol.CommandTypes.ImplementationFull]: (request: protocol.Request) => { return this.requiredResponse(this.getImplementation(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.References]: (request: protocol.FileLocationRequest) => { + [protocol.CommandTypes.References]: (request: protocol.FileLocationRequest) => { return this.requiredResponse(this.getReferences(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.ReferencesFull]: (request: protocol.FileLocationRequest) => { + [protocol.CommandTypes.ReferencesFull]: (request: protocol.FileLocationRequest) => { return this.requiredResponse(this.getReferences(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.Rename]: (request: protocol.RenameRequest) => { + [protocol.CommandTypes.Rename]: (request: protocol.RenameRequest) => { return this.requiredResponse(this.getRenameLocations(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.RenameLocationsFull]: (request: protocol.RenameFullRequest) => { + [protocol.CommandTypes.RenameLocationsFull]: (request: protocol.RenameFullRequest) => { return this.requiredResponse(this.getRenameLocations(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.RenameInfoFull]: (request: protocol.FileLocationRequest) => { + [protocol.CommandTypes.RenameInfoFull]: (request: protocol.FileLocationRequest) => { return this.requiredResponse(this.getRenameInfo(request.arguments)); }, - [CommandNames.Open]: (request: protocol.OpenRequest) => { + [protocol.CommandTypes.Open]: (request: protocol.OpenRequest) => { this.openClientFile( toNormalizedPath(request.arguments.file), request.arguments.fileContent, @@ -2046,215 +2046,215 @@ namespace ts.server { request.arguments.projectRootPath ? toNormalizedPath(request.arguments.projectRootPath) : undefined); return this.notRequired(); }, - [CommandNames.Quickinfo]: (request: protocol.QuickInfoRequest) => { + [protocol.CommandTypes.Quickinfo]: (request: protocol.QuickInfoRequest) => { return this.requiredResponse(this.getQuickInfoWorker(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.QuickinfoFull]: (request: protocol.QuickInfoRequest) => { + [protocol.CommandTypes.QuickinfoFull]: (request: protocol.QuickInfoRequest) => { return this.requiredResponse(this.getQuickInfoWorker(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.GetOutliningSpans]: (request: protocol.FileRequest) => { + [protocol.CommandTypes.GetOutliningSpans]: (request: protocol.FileRequest) => { return this.requiredResponse(this.getOutliningSpans(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.GetOutliningSpansFull]: (request: protocol.FileRequest) => { + [protocol.CommandTypes.GetOutliningSpansFull]: (request: protocol.FileRequest) => { return this.requiredResponse(this.getOutliningSpans(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.TodoComments]: (request: protocol.TodoCommentRequest) => { + [protocol.CommandTypes.TodoComments]: (request: protocol.TodoCommentRequest) => { return this.requiredResponse(this.getTodoComments(request.arguments)); }, - [CommandNames.Indentation]: (request: protocol.IndentationRequest) => { + [protocol.CommandTypes.Indentation]: (request: protocol.IndentationRequest) => { return this.requiredResponse(this.getIndentation(request.arguments)); }, - [CommandNames.NameOrDottedNameSpan]: (request: protocol.FileLocationRequest) => { + [protocol.CommandTypes.NameOrDottedNameSpan]: (request: protocol.FileLocationRequest) => { return this.requiredResponse(this.getNameOrDottedNameSpan(request.arguments)); }, - [CommandNames.BreakpointStatement]: (request: protocol.FileLocationRequest) => { + [protocol.CommandTypes.BreakpointStatement]: (request: protocol.FileLocationRequest) => { return this.requiredResponse(this.getBreakpointStatement(request.arguments)); }, - [CommandNames.BraceCompletion]: (request: protocol.BraceCompletionRequest) => { + [protocol.CommandTypes.BraceCompletion]: (request: protocol.BraceCompletionRequest) => { return this.requiredResponse(this.isValidBraceCompletion(request.arguments)); }, - [CommandNames.DocCommentTemplate]: (request: protocol.DocCommentTemplateRequest) => { + [protocol.CommandTypes.DocCommentTemplate]: (request: protocol.DocCommentTemplateRequest) => { return this.requiredResponse(this.getDocCommentTemplate(request.arguments)); }, - [CommandNames.GetSpanOfEnclosingComment]: (request: protocol.SpanOfEnclosingCommentRequest) => { + [protocol.CommandTypes.GetSpanOfEnclosingComment]: (request: protocol.SpanOfEnclosingCommentRequest) => { return this.requiredResponse(this.getSpanOfEnclosingComment(request.arguments)); }, - [CommandNames.Format]: (request: protocol.FormatRequest) => { + [protocol.CommandTypes.Format]: (request: protocol.FormatRequest) => { return this.requiredResponse(this.getFormattingEditsForRange(request.arguments)); }, - [CommandNames.Formatonkey]: (request: protocol.FormatOnKeyRequest) => { + [protocol.CommandTypes.Formatonkey]: (request: protocol.FormatOnKeyRequest) => { return this.requiredResponse(this.getFormattingEditsAfterKeystroke(request.arguments)); }, - [CommandNames.FormatFull]: (request: protocol.FormatRequest) => { + [protocol.CommandTypes.FormatFull]: (request: protocol.FormatRequest) => { return this.requiredResponse(this.getFormattingEditsForDocumentFull(request.arguments)); }, - [CommandNames.FormatonkeyFull]: (request: protocol.FormatOnKeyRequest) => { + [protocol.CommandTypes.FormatonkeyFull]: (request: protocol.FormatOnKeyRequest) => { return this.requiredResponse(this.getFormattingEditsAfterKeystrokeFull(request.arguments)); }, - [CommandNames.FormatRangeFull]: (request: protocol.FormatRequest) => { + [protocol.CommandTypes.FormatRangeFull]: (request: protocol.FormatRequest) => { return this.requiredResponse(this.getFormattingEditsForRangeFull(request.arguments)); }, - [CommandNames.CompletionInfo]: (request: protocol.CompletionsRequest) => { + [protocol.CommandTypes.CompletionInfo]: (request: protocol.CompletionsRequest) => { return this.requiredResponse(this.getCompletions(request.arguments, CommandNames.CompletionInfo)); }, - [CommandNames.Completions]: (request: protocol.CompletionsRequest) => { + [protocol.CommandTypes.Completions]: (request: protocol.CompletionsRequest) => { return this.requiredResponse(this.getCompletions(request.arguments, CommandNames.Completions)); }, - [CommandNames.CompletionsFull]: (request: protocol.CompletionsRequest) => { + [protocol.CommandTypes.CompletionsFull]: (request: protocol.CompletionsRequest) => { return this.requiredResponse(this.getCompletions(request.arguments, CommandNames.CompletionsFull)); }, - [CommandNames.CompletionDetails]: (request: protocol.CompletionDetailsRequest) => { + [protocol.CommandTypes.CompletionDetails]: (request: protocol.CompletionDetailsRequest) => { return this.requiredResponse(this.getCompletionEntryDetails(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.CompletionDetailsFull]: (request: protocol.CompletionDetailsRequest) => { + [protocol.CommandTypes.CompletionDetailsFull]: (request: protocol.CompletionDetailsRequest) => { return this.requiredResponse(this.getCompletionEntryDetails(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.CompileOnSaveAffectedFileList]: (request: protocol.CompileOnSaveAffectedFileListRequest) => { + [protocol.CommandTypes.CompileOnSaveAffectedFileList]: (request: protocol.CompileOnSaveAffectedFileListRequest) => { return this.requiredResponse(this.getCompileOnSaveAffectedFileList(request.arguments)); }, - [CommandNames.CompileOnSaveEmitFile]: (request: protocol.CompileOnSaveEmitFileRequest) => { + [protocol.CommandTypes.CompileOnSaveEmitFile]: (request: protocol.CompileOnSaveEmitFileRequest) => { return this.requiredResponse(this.emitFile(request.arguments)); }, - [CommandNames.SignatureHelp]: (request: protocol.SignatureHelpRequest) => { + [protocol.CommandTypes.SignatureHelp]: (request: protocol.SignatureHelpRequest) => { return this.requiredResponse(this.getSignatureHelpItems(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.SignatureHelpFull]: (request: protocol.SignatureHelpRequest) => { + [protocol.CommandTypes.SignatureHelpFull]: (request: protocol.SignatureHelpRequest) => { return this.requiredResponse(this.getSignatureHelpItems(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.CompilerOptionsDiagnosticsFull]: (request: protocol.CompilerOptionsDiagnosticsRequest) => { + [protocol.CommandTypes.CompilerOptionsDiagnosticsFull]: (request: protocol.CompilerOptionsDiagnosticsRequest) => { return this.requiredResponse(this.getCompilerOptionsDiagnostics(request.arguments)); }, - [CommandNames.EncodedSemanticClassificationsFull]: (request: protocol.EncodedSemanticClassificationsRequest) => { + [protocol.CommandTypes.EncodedSemanticClassificationsFull]: (request: protocol.EncodedSemanticClassificationsRequest) => { return this.requiredResponse(this.getEncodedSemanticClassifications(request.arguments)); }, - [CommandNames.Cleanup]: () => { + [protocol.CommandTypes.Cleanup]: () => { this.cleanup(); return this.requiredResponse(/*response*/ true); }, - [CommandNames.SemanticDiagnosticsSync]: (request: protocol.SemanticDiagnosticsSyncRequest) => { + [protocol.CommandTypes.SemanticDiagnosticsSync]: (request: protocol.SemanticDiagnosticsSyncRequest) => { return this.requiredResponse(this.getSemanticDiagnosticsSync(request.arguments)); }, - [CommandNames.SyntacticDiagnosticsSync]: (request: protocol.SyntacticDiagnosticsSyncRequest) => { + [protocol.CommandTypes.SyntacticDiagnosticsSync]: (request: protocol.SyntacticDiagnosticsSyncRequest) => { return this.requiredResponse(this.getSyntacticDiagnosticsSync(request.arguments)); }, - [CommandNames.SuggestionDiagnosticsSync]: (request: protocol.SuggestionDiagnosticsSyncRequest) => { + [protocol.CommandTypes.SuggestionDiagnosticsSync]: (request: protocol.SuggestionDiagnosticsSyncRequest) => { return this.requiredResponse(this.getSuggestionDiagnosticsSync(request.arguments)); }, - [CommandNames.Geterr]: (request: protocol.GeterrRequest) => { + [protocol.CommandTypes.Geterr]: (request: protocol.GeterrRequest) => { this.errorCheck.startNew(next => this.getDiagnostics(next, request.arguments.delay, request.arguments.files)); return this.notRequired(); }, - [CommandNames.GeterrForProject]: (request: protocol.GeterrForProjectRequest) => { + [protocol.CommandTypes.GeterrForProject]: (request: protocol.GeterrForProjectRequest) => { this.errorCheck.startNew(next => this.getDiagnosticsForProject(next, request.arguments.delay, request.arguments.file)); return this.notRequired(); }, - [CommandNames.Change]: (request: protocol.ChangeRequest) => { + [protocol.CommandTypes.Change]: (request: protocol.ChangeRequest) => { this.change(request.arguments); return this.notRequired(); }, - [CommandNames.Configure]: (request: protocol.ConfigureRequest) => { + [protocol.CommandTypes.Configure]: (request: protocol.ConfigureRequest) => { this.projectService.setHostConfiguration(request.arguments); this.doOutput(/*info*/ undefined, CommandNames.Configure, request.seq, /*success*/ true); return this.notRequired(); }, - [CommandNames.Reload]: (request: protocol.ReloadRequest) => { + [protocol.CommandTypes.Reload]: (request: protocol.ReloadRequest) => { this.reload(request.arguments, request.seq); return this.requiredResponse({ reloadFinished: true }); }, - [CommandNames.Saveto]: (request: protocol.Request) => { + [protocol.CommandTypes.Saveto]: (request: protocol.Request) => { const savetoArgs = request.arguments; this.saveToTmp(savetoArgs.file, savetoArgs.tmpfile); return this.notRequired(); }, - [CommandNames.Close]: (request: protocol.Request) => { + [protocol.CommandTypes.Close]: (request: protocol.Request) => { const closeArgs = request.arguments; this.closeClientFile(closeArgs.file); return this.notRequired(); }, - [CommandNames.Navto]: (request: protocol.NavtoRequest) => { + [protocol.CommandTypes.Navto]: (request: protocol.NavtoRequest) => { return this.requiredResponse(this.getNavigateToItems(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.NavtoFull]: (request: protocol.NavtoRequest) => { + [protocol.CommandTypes.NavtoFull]: (request: protocol.NavtoRequest) => { return this.requiredResponse(this.getNavigateToItems(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.Brace]: (request: protocol.FileLocationRequest) => { + [protocol.CommandTypes.Brace]: (request: protocol.FileLocationRequest) => { return this.requiredResponse(this.getBraceMatching(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.BraceFull]: (request: protocol.FileLocationRequest) => { + [protocol.CommandTypes.BraceFull]: (request: protocol.FileLocationRequest) => { return this.requiredResponse(this.getBraceMatching(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.NavBar]: (request: protocol.FileRequest) => { + [protocol.CommandTypes.NavBar]: (request: protocol.FileRequest) => { return this.requiredResponse(this.getNavigationBarItems(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.NavBarFull]: (request: protocol.FileRequest) => { + [protocol.CommandTypes.NavBarFull]: (request: protocol.FileRequest) => { return this.requiredResponse(this.getNavigationBarItems(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.NavTree]: (request: protocol.FileRequest) => { + [protocol.CommandTypes.NavTree]: (request: protocol.FileRequest) => { return this.requiredResponse(this.getNavigationTree(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.NavTreeFull]: (request: protocol.FileRequest) => { + [protocol.CommandTypes.NavTreeFull]: (request: protocol.FileRequest) => { return this.requiredResponse(this.getNavigationTree(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.Occurrences]: (request: protocol.FileLocationRequest) => { + [protocol.CommandTypes.Occurrences]: (request: protocol.FileLocationRequest) => { return this.requiredResponse(this.getOccurrences(request.arguments)); }, - [CommandNames.DocumentHighlights]: (request: protocol.DocumentHighlightsRequest) => { + [protocol.CommandTypes.DocumentHighlights]: (request: protocol.DocumentHighlightsRequest) => { return this.requiredResponse(this.getDocumentHighlights(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.DocumentHighlightsFull]: (request: protocol.DocumentHighlightsRequest) => { + [protocol.CommandTypes.DocumentHighlightsFull]: (request: protocol.DocumentHighlightsRequest) => { return this.requiredResponse(this.getDocumentHighlights(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.CompilerOptionsForInferredProjects]: (request: protocol.SetCompilerOptionsForInferredProjectsRequest) => { + [protocol.CommandTypes.CompilerOptionsForInferredProjects]: (request: protocol.SetCompilerOptionsForInferredProjectsRequest) => { this.setCompilerOptionsForInferredProjects(request.arguments); return this.requiredResponse(/*response*/ true); }, - [CommandNames.ProjectInfo]: (request: protocol.ProjectInfoRequest) => { + [protocol.CommandTypes.ProjectInfo]: (request: protocol.ProjectInfoRequest) => { return this.requiredResponse(this.getProjectInfo(request.arguments)); }, - [CommandNames.ReloadProjects]: () => { + [protocol.CommandTypes.ReloadProjects]: () => { this.projectService.reloadProjects(); return this.notRequired(); }, - [CommandNames.JsxClosingTag]: (request: protocol.JsxClosingTagRequest) => { + [protocol.CommandTypes.JsxClosingTag]: (request: protocol.JsxClosingTagRequest) => { return this.requiredResponse(this.getJsxClosingTag(request.arguments)); }, - [CommandNames.GetCodeFixes]: (request: protocol.CodeFixRequest) => { + [protocol.CommandTypes.GetCodeFixes]: (request: protocol.CodeFixRequest) => { return this.requiredResponse(this.getCodeFixes(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.GetCodeFixesFull]: (request: protocol.CodeFixRequest) => { + [protocol.CommandTypes.GetCodeFixesFull]: (request: protocol.CodeFixRequest) => { return this.requiredResponse(this.getCodeFixes(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.GetCombinedCodeFix]: (request: protocol.GetCombinedCodeFixRequest) => { + [protocol.CommandTypes.GetCombinedCodeFix]: (request: protocol.GetCombinedCodeFixRequest) => { return this.requiredResponse(this.getCombinedCodeFix(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.GetCombinedCodeFixFull]: (request: protocol.GetCombinedCodeFixRequest) => { + [protocol.CommandTypes.GetCombinedCodeFixFull]: (request: protocol.GetCombinedCodeFixRequest) => { return this.requiredResponse(this.getCombinedCodeFix(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.ApplyCodeActionCommand]: (request: protocol.ApplyCodeActionCommandRequest) => { + [protocol.CommandTypes.ApplyCodeActionCommand]: (request: protocol.ApplyCodeActionCommandRequest) => { return this.requiredResponse(this.applyCodeActionCommand(request.arguments)); }, - [CommandNames.GetSupportedCodeFixes]: () => { + [protocol.CommandTypes.GetSupportedCodeFixes]: () => { return this.requiredResponse(this.getSupportedCodeFixes()); }, - [CommandNames.GetApplicableRefactors]: (request: protocol.GetApplicableRefactorsRequest) => { + [protocol.CommandTypes.GetApplicableRefactors]: (request: protocol.GetApplicableRefactorsRequest) => { return this.requiredResponse(this.getApplicableRefactors(request.arguments)); }, - [CommandNames.GetEditsForRefactor]: (request: protocol.GetEditsForRefactorRequest) => { + [protocol.CommandTypes.GetEditsForRefactor]: (request: protocol.GetEditsForRefactorRequest) => { return this.requiredResponse(this.getEditsForRefactor(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.GetEditsForRefactorFull]: (request: protocol.GetEditsForRefactorRequest) => { + [protocol.CommandTypes.GetEditsForRefactorFull]: (request: protocol.GetEditsForRefactorRequest) => { return this.requiredResponse(this.getEditsForRefactor(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.OrganizeImports]: (request: protocol.OrganizeImportsRequest) => { + [protocol.CommandTypes.OrganizeImports]: (request: protocol.OrganizeImportsRequest) => { return this.requiredResponse(this.organizeImports(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.OrganizeImportsFull]: (request: protocol.OrganizeImportsRequest) => { + [protocol.CommandTypes.OrganizeImportsFull]: (request: protocol.OrganizeImportsRequest) => { return this.requiredResponse(this.organizeImports(request.arguments, /*simplifiedResult*/ false)); }, - [CommandNames.GetEditsForFileRename]: (request: protocol.GetEditsForFileRenameRequest) => { + [protocol.CommandTypes.GetEditsForFileRename]: (request: protocol.GetEditsForFileRenameRequest) => { return this.requiredResponse(this.getEditsForFileRename(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.GetEditsForFileRenameFull]: (request: protocol.GetEditsForFileRenameRequest) => { + [protocol.CommandTypes.GetEditsForFileRenameFull]: (request: protocol.GetEditsForFileRenameRequest) => { return this.requiredResponse(this.getEditsForFileRename(request.arguments, /*simplifiedResult*/ false)); }, }); diff --git a/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts b/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts index 4401625000aa0..58ca8167cea46 100644 --- a/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts +++ b/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts @@ -53,19 +53,18 @@ namespace ts.codefix { const classType = checker.getTypeAtLocation(classDeclaration); - if (!classType.getNumberIndexType()) { - createMissingIndexSignatureDeclaration(implementedType, IndexKind.Number); - } - if (!classType.getStringIndexType()) { - createMissingIndexSignatureDeclaration(implementedType, IndexKind.String); - } + createMissingIndexSignatureDeclarations(implementedType, classType); createMissingMemberNodes(classDeclaration, nonPrivateAndNotExistedInHeritageClauseMembers, checker, preferences, member => changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, member)); - function createMissingIndexSignatureDeclaration(type: InterfaceType, kind: IndexKind): void { - const indexInfoOfKind = checker.getIndexInfoOfType(type, kind); - if (indexInfoOfKind) { - changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, checker.indexInfoToIndexSignatureDeclaration(indexInfoOfKind, kind, classDeclaration)!); + function createMissingIndexSignatureDeclarations(type: InterfaceType, implementingType: Type): void { + const indexInfos = checker.getIndexInfosOfType(type); + if (indexInfos) { + for (const info of indexInfos) { + if (!checker.getIndexTypeOfType(implementingType, info.indexType)) { + changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, checker.indexInfoToIndexSignatureDeclaration(info, classDeclaration)!); + } + } } } } diff --git a/src/services/codefixes/fixInvalidImportSyntax.ts b/src/services/codefixes/fixInvalidImportSyntax.ts index 85dff7fb09be6..5852207ecf213 100644 --- a/src/services/codefixes/fixInvalidImportSyntax.ts +++ b/src/services/codefixes/fixInvalidImportSyntax.ts @@ -56,9 +56,8 @@ namespace ts.codefix { Diagnostics.Type_0_is_not_assignable_to_type_1.code, Diagnostics.Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated.code, Diagnostics.Type_predicate_0_is_not_assignable_to_1.code, - Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2.code, - Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2.code, - Diagnostics.Numeric_index_type_0_is_not_assignable_to_string_index_type_1.code, + Diagnostics.Property_0_of_type_1_is_not_assignable_to_2_index_type_3.code, + Diagnostics._0_index_type_1_is_not_assignable_to_2_index_type_3.code, Diagnostics.Property_0_in_type_1_is_not_assignable_to_the_same_property_in_base_type_2.code, Diagnostics.Property_0_in_type_1_is_not_assignable_to_type_2.code, Diagnostics.Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property.code, diff --git a/src/services/codefixes/inferFromUsage.ts b/src/services/codefixes/inferFromUsage.ts index f7b5edc5ca72e..3ad13bf3896fa 100644 --- a/src/services/codefixes/inferFromUsage.ts +++ b/src/services/codefixes/inferFromUsage.ts @@ -562,11 +562,11 @@ namespace ts.codefix { } if (usageContext.numberIndexContext) { - numberIndexInfo = checker.createIndexInfo(getTypeFromUsageContext(usageContext.numberIndexContext, checker) || checker.getAnyType(), /*isReadonly*/ false); + numberIndexInfo = checker.createIndexInfo(checker.getNumberType(), getTypeFromUsageContext(usageContext.numberIndexContext, checker) || checker.getAnyType(), /*isReadonly*/ false); } if (usageContext.stringIndexContext) { - stringIndexInfo = checker.createIndexInfo(getTypeFromUsageContext(usageContext.stringIndexContext, checker) || checker.getAnyType(), /*isReadonly*/ false); + stringIndexInfo = checker.createIndexInfo(checker.getStringType(), getTypeFromUsageContext(usageContext.stringIndexContext, checker) || checker.getAnyType(), /*isReadonly*/ false); } return checker.createAnonymousType(/*symbol*/ undefined!, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); // TODO: GH#18217 diff --git a/src/services/completions.ts b/src/services/completions.ts index 2b213361418d2..9785a9648e456 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1112,7 +1112,7 @@ namespace ts.Completions { } function addTypeProperties(type: Type): void { - isNewIdentifierLocation = !!type.getStringIndexType(); + isNewIdentifierLocation = !!type.getTypeIndexedByType(typeChecker.getStringType()); if (isUncheckedFile) { // In javascript files, for union types, we don't just get the members that @@ -2239,7 +2239,7 @@ namespace ts.Completions { } function hasIndexSignature(type: Type): boolean { - return !!type.getStringIndexType() || !!type.getNumberIndexType(); + return !!length(type.checker.getIndexInfosOfType(type)); } function isValidTrigger(sourceFile: SourceFile, triggerCharacter: CompletionsTriggerCharacter, contextToken: Node, position: number): boolean { diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index 973c040a769f6..8cd55f50453f4 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -188,10 +188,10 @@ namespace ts.GoToDefinition { function getDefinitionInfoForIndexSignatures(node: Node, checker: TypeChecker): DefinitionInfo[] | undefined { if (!isPropertyAccessExpression(node.parent) || node.parent.name !== node) return; const type = checker.getTypeAtLocation(node.parent.expression); - return mapDefined(type.isUnionOrIntersection() ? type.types : [type], nonUnionType => { - const info = checker.getIndexInfoOfType(nonUnionType, IndexKind.String); - return info && info.declaration && createDefinitionFromSignatureDeclaration(checker, info.declaration); - }); + return flatten(mapDefined(type.isUnionOrIntersection() ? type.types : [type], nonUnionType => { + const infos = checker.getIndexInfosOfType(nonUnionType, checker.getStringType()); // TODO: Pass in literal name + return mapDefined(infos, info => info.declaration && createDefinitionFromSignatureDeclaration(checker, info.declaration)); + })); } function getSymbol(node: Node, checker: TypeChecker): Symbol | undefined { diff --git a/src/services/services.ts b/src/services/services.ts index dcc321b00d58c..e3bf6aef2135b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -397,11 +397,8 @@ namespace ts { getConstructSignatures(): ReadonlyArray { return this.checker.getSignaturesOfType(this, SignatureKind.Construct); } - getStringIndexType(): Type | undefined { - return this.checker.getIndexTypeOfType(this, IndexKind.String); - } - getNumberIndexType(): Type | undefined { - return this.checker.getIndexTypeOfType(this, IndexKind.Number); + getTypeIndexedByType(indexType: Type): Type | undefined { + return this.checker.getIndexTypeOfType(this, indexType); } getBaseTypes(): BaseType[] | undefined { return this.isClassOrInterface() ? this.checker.getBaseTypes(this) : undefined; diff --git a/src/services/types.ts b/src/services/types.ts index 51c98724c0957..d3999b8cfcfa2 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -46,8 +46,7 @@ namespace ts { getApparentProperties(): Symbol[]; getCallSignatures(): ReadonlyArray; getConstructSignatures(): ReadonlyArray; - getStringIndexType(): Type | undefined; - getNumberIndexType(): Type | undefined; + getTypeIndexedByType(indexType: Type): Type | undefined; getBaseTypes(): BaseType[] | undefined; getNonNullableType(): Type; getConstraint(): Type | undefined; diff --git a/tests/cases/compiler/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts b/tests/cases/compiler/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts new file mode 100644 index 0000000000000..b8534aa99fad6 --- /dev/null +++ b/tests/cases/compiler/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts @@ -0,0 +1,50 @@ +const directive = Symbol('directive'); +declare function foo(options: + {[x in string]: (arg: TArg) => TRet} + & {[directive]?: TDir} +): [TArg, TRet, TDir]; + + +let case1 = foo({ + [directive]: (x: string) => 'str', + addOne: (x: number) => x + 1, + double: (x: number) => x + x, +}); // [number, number, string => string] + +let case2 = foo({ + addOne: (x: number) => x + 1, + double: (x: number) => x + x, + [directive]: (x: string) => 'str', +}); // [number, number, string => string] + +let case3 = foo({ + [directive]: 'str', + addOne: (x: number) => x + 1, + double: (x: number) => x + x, +}); // [number, number, string] + +const strdirective = "directive"; +declare function bar(options: + {[x in symbol]: (arg: TArg) => TRet} + & {[strdirective]?: TDir} +): [TArg, TRet, TDir]; + +const s1 = Symbol("s1"); +const s2 = Symbol("s2"); +let case4 = bar({ + [strdirective]: (x: string) => 'str', + [s1]: (x: number) => x + 1, + [s2]: (x: number) => x + x, +}); // [number, number, string => string] + +let case5 = bar({ + [s1]: (x: number) => x + 1, + [s2]: (x: number) => x + x, + [strdirective]: (x: string) => 'str', +}); // [number, number, string => string] + +let case6 = bar({ + [strdirective]: 'str', + [s1]: (x: number) => x + 1, + [s2]: (x: number) => x + x, +}); // [number, number, string] From 8a6154a0d27796fc029e3a6bc7a887069791615b Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 28 Aug 2018 13:07:53 -0700 Subject: [PATCH 02/11] Adjustments, fixes, and edits, oh my --- src/compiler/checker.ts | 145 ++++++++++++------ src/compiler/diagnosticMessages.json | 2 +- .../types/mapped/mappedTypeRelationships.ts | 4 +- tests/cases/fourslash/indexerReturnTypes1.ts | 20 ++- 4 files changed, 120 insertions(+), 51 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5529254173730..a9b9edce2e6b2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3522,8 +3522,8 @@ namespace ts { } if (resolvedType.indexInfos) { for (let info of resolvedType.indexInfos) { - if (info.indexType === stringType && resolvedType.objectFlags & ObjectFlags.ReverseMapped) { - info = createIndexInfo(stringType, anyType, info.isReadonly, info.declaration); + if (resolvedType.objectFlags & ObjectFlags.ReverseMapped) { + info = createIndexInfo(info.indexType, anyType, info.isReadonly, info.declaration); } typeElements.push(indexInfoToIndexSignatureDeclarationHelper(info, context)); } @@ -6302,7 +6302,9 @@ namespace ts { callSignatures = concatenate(callSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Call)); constructSignatures = concatenate(constructSignatures, getSignaturesOfType(instantiatedBaseType, SignatureKind.Construct)); const baseInfos = getIndexInfosOfType(instantiatedBaseType); - indexInfos = intersectIndexInfos(indexInfos, baseInfos); + if (baseInfos) { + indexInfos = overrideIndexInfos(baseInfos, indexInfos); + } if (!resolveIndexOnIndexInfos(stringType, indexInfos)) { if (instantiatedBaseType === anyType) { indexInfos = indexInfos || []; @@ -6502,6 +6504,35 @@ namespace ts { return !type1 ? type2 : !type2 ? type1 : getIntersectionType([type1, type2]); } + function overrideIndexInfos(infos1: IndexInfo[] | undefined, infos2: IndexInfo[] | undefined): IndexInfo[] | undefined { + if (!infos1) { + return infos2; + } + if (!infos2) { + return infos1; + } + let infos: IndexInfo[] | undefined; + for (const info1 of infos1) { + for (const info2 of infos2) { + const intersectedKeys = getIntersectionType([info1.indexType, info2.indexType]); + // Merge all index signatures which overlap, taking the second to override the first (as with class inheritance) + if (intersectedKeys && !(intersectedKeys.flags & TypeFlags.Never) && !(intersectedKeys.flags & TypeFlags.Intersection)) { + infos = appendIfUnique(infos, info2); + } + } + } + let baseInfos: IndexInfo[] | undefined; + for (const originalInfos of [infos1, infos2]) { + for (const info of originalInfos) { + // And also add all index signatures which did not get perfectly subsumed by another signature + if (!some(infos, i => i.indexType === info.indexType)) { + baseInfos = append(baseInfos, info); + } + } + } + return concatenate(infos, baseInfos); + } + function intersectIndexInfos(infos1: IndexInfo[] | undefined, infos2: IndexInfo[] | undefined): IndexInfo[] | undefined { if (!infos1) { return infos2; @@ -6514,8 +6545,8 @@ namespace ts { for (const info2 of infos2) { const intersectedKeys = getIntersectionType([info1.indexType, info2.indexType]); // Merge all index signatures which overlap - if (intersectedKeys && intersectedKeys !== neverType && !(intersectedKeys.flags & TypeFlags.Intersection)) { - infos = concatenate(infos, [createIndexInfo(intersectedKeys, getIntersectionType([info1.type, info2.type]), info1.isReadonly && info2.isReadonly)]); + if (intersectedKeys && !(intersectedKeys.flags & TypeFlags.Never) && !(intersectedKeys.flags & TypeFlags.Intersection)) { + infos = append(infos, createIndexInfo(intersectedKeys, getIntersectionType([info1.type, info2.type]), info1.isReadonly && info2.isReadonly)); } } } @@ -6524,7 +6555,7 @@ namespace ts { for (const info of originalInfos) { // And also add all index signatures which did not get perfectly subsumed by another signature if (!some(infos, i => i.indexType === info.indexType)) { - baseInfos = concatenate(baseInfos, [info]); + baseInfos = append(baseInfos, info); } } } @@ -6540,8 +6571,8 @@ namespace ts { for (const info2 of infos2) { const intersectedKeys = getIntersectionType([info1.indexType, info2.indexType]); // Merge all index signatures which overlap - if (intersectedKeys && intersectedKeys !== neverType && !(intersectedKeys.flags & TypeFlags.Intersection)) { - infos = concatenate(infos, [createIndexInfo(intersectedKeys, getUnionType([info1.type, info2.type]), info1.isReadonly || info2.isReadonly)]); + if (intersectedKeys && !(intersectedKeys.flags & TypeFlags.Never) && !(intersectedKeys.flags & TypeFlags.Intersection)) { + infos = append(infos, createIndexInfo(intersectedKeys, getUnionType([info1.type, info2.type]), info1.isReadonly || info2.isReadonly)); } } } @@ -6663,9 +6694,11 @@ namespace ts { const modifiers = getMappedTypeModifiers(type.mappedType); const readonlyMask = modifiers & MappedTypeModifiers.IncludeReadonly ? false : true; const optionalMask = modifiers & MappedTypeModifiers.IncludeOptional ? 0 : SymbolFlags.Optional; - const mappedIndexInfos = indexInfos && map(indexInfos, indexInfo => - createIndexInfo(indexInfo.indexType, inferReverseMappedType(indexInfo.type, type.mappedType), readonlyMask && indexInfo.isReadonly) - ); + // TODO: Fix #26724 using the below once #26725 is fixed and `mappedRecursiveInference.ts` doesn't blow up with the change + //const mappedIndexInfos = indexInfos && map(indexInfos, indexInfo => + // createIndexInfo(indexInfo.indexType, inferReverseMappedType(indexInfo.type, type.mappedType), readonlyMask && indexInfo.isReadonly) + //); + const mappedIndexInfos = map(filter(indexInfos, i => !!(i.indexType.flags & TypeFlags.String)), i => createIndexInfo(i.indexType, inferReverseMappedType(i.type, type.mappedType), readonlyMask && i.isReadonly)); const members = createSymbolTable(); for (const prop of getPropertiesOfType(type.source)) { const checkFlags = CheckFlags.ReverseMapped | (readonlyMask && isReadonlySymbol(prop) ? CheckFlags.Readonly : 0); @@ -6712,7 +6745,7 @@ namespace ts { // First, if the constraint type is a type parameter, obtain the base constraint. Then, // if the key type is a 'keyof X', obtain 'keyof C' where C is the base constraint of X. // Finally, iterate over the constituents of the resulting iteration type. - const keyType = constraintType.flags & TypeFlags.InstantiableNonPrimitive ? getApparentType(constraintType) : constraintType; + const keyType = constraintType.flags & TypeFlags.InstantiableNonPrimitive ? getBaseConstraintOrType(constraintType) : constraintType; const iterationType = keyType.flags & TypeFlags.Index ? getIndexType(getApparentType((keyType).type)) : keyType; forEachType(iterationType, addMemberForKeyType); } @@ -6747,7 +6780,9 @@ namespace ts { prop.nameType = t; members.set(propName, prop); } - else { + // Well-known symbols produce a key type of never when pushed through `getLiteralTypeFromPropertyName` right now, so we need to handle that + // Gracefully by _not_ making a `never` indexer (which would be a huge problem for assignability) + else if (!(t.flags & TypeFlags.Never)) { indexInfos = indexInfos || []; if (isTypeAny(t)) { // Legacy behavior. TODO: Remove. @@ -7392,7 +7427,7 @@ namespace ts { return resolveIndexOnIndexInfos(indexType, getIndexInfosOfType(type)); } - function getApplicableIndexInfosOfIndexOnType(type: Type, indexType: Type): IndexInfo[] | undefined { + function getApplicableIndexInfosOfIndexOnType(type: Type, indexType: Type, contravariant?: boolean): IndexInfo[] | undefined { if (!(indexType.flags & TypeFlags.Union)) { const result = getResultingIndexInfoOfIndexOnType(type, indexType); return result && [result]; @@ -7400,16 +7435,18 @@ namespace ts { let resultList: IndexInfo[] | undefined; for (const nameType of (indexType as UnionType).types) { const result = getResultingIndexInfoOfIndexOnType(type, nameType); - if (!result) { + if (!result && !contravariant) { return; } - resultList = appendIfUnique(resultList, result); + if (result) { + resultList = appendIfUnique(resultList, result); + } } return resultList; } - function getResultingTypeOfIndexOnType(type: Type, indexType: Type): Type | undefined { - const resultInfos = getApplicableIndexInfosOfIndexOnType(type, indexType); + function getResultingTypeOfIndexOnType(type: Type, indexType: Type, contravariant?: boolean): Type | undefined { + const resultInfos = getApplicableIndexInfosOfIndexOnType(type, indexType, contravariant); return resultInfos && getUnionType(map(resultInfos, i => i.type)); } @@ -7970,6 +8007,12 @@ namespace ts { */ function resolveIndexOnIndexInfos(indexType: Type, infos: IndexInfo[] | undefined): IndexInfo | undefined { Debug.assert(!(indexType.flags & TypeFlags.Union)); + if (indexType.flags & TypeFlags.StringLiteral) { + // Prioritize equivalent numeric representation over the string one, since the "number"s in this case _are_ just a subdomain of the strings + if (isNumericLiteralName((indexType as StringLiteralType).value)) { + indexType = getLiteralType(+(indexType as StringLiteralType).value); + } + } const applicable = filter(infos, info => isTypeIndexAssignableTo(indexType, info.indexType)); if (!length(applicable)) return; // OK, now for the hard part - ranking the derivedness of an index signature! @@ -12239,7 +12282,7 @@ namespace ts { } const targetType = getResultingTypeOfIndexOnType(target, getLiteralTypeFromPropertyName(prop, TypeFlags.StringOrNumberLiteralOrUnique)); if (targetType) { - const related = isIndexTypeRelatedTo(getTypeOfSymbol(prop), targetType, sourceIsPrimitive, reportErrors); + const related = isIndexTypeRelatedTo(getTypeOfSymbol(prop), targetType, sourceIsPrimitive, reportErrors, /*skipIndexError*/ true); if (!related) { if (reportErrors) { reportError(Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop)); @@ -12261,14 +12304,31 @@ namespace ts { return Ternary.True; } const sourceInfo = getIndexInfosOfType(source) - if (sourceInfo) { - return indexInfosRelated(sourceInfo, targetInfo, sourceIsPrimitive, reportErrors); + const result = sourceInfo && indexInfosRelated(sourceInfo, targetInfo, sourceIsPrimitive, reportErrors); + if (result !== undefined && result !== Ternary.Maybe) { + return result; } if (isGenericMappedType(source)) { // A generic mapped type { [P in K]: T } is related to an index signature { [x: string]: U } // if T is related to U. - const result = getResultingTypeOfIndexOnType(target, getConstraintTypeFromMappedType(source)); - return result ? isIndexTypeRelatedTo(getTemplateTypeFromMappedType(source), result, sourceIsPrimitive, reportErrors) : Ternary.False; + const keyType = getBaseConstraintOrType(getConstraintTypeFromMappedType(source)); + let hadSomeMatch = false; + const failed = forEachType(keyType, key => { + const result = getResultingTypeOfIndexOnType(target, key); + if (!result) { + return; + } + hadSomeMatch = true; + // TODO: Revise? For each type in `K`'s constraint, instantiate T with the key type being compared? + // const instantiated = instantiateType(getTemplateTypeFromMappedType(source), makeUnaryTypeMapper(getTypeParameterFromMappedType(source), key)); + if (!isIndexTypeRelatedTo(getTemplateTypeFromMappedType(source), result, sourceIsPrimitive, reportErrors)) { + return true; + } + }); + if (failed) { + return Ternary.False; + } + return hadSomeMatch ? Ternary.True : Ternary.False; } if (isObjectTypeWithInferableIndex(source)) { return eachPropertyRelatedToIndexesOf(source, target, sourceIsPrimitive, reportErrors); @@ -12288,13 +12348,13 @@ namespace ts { return Ternary.False; } - function isIndexTypeRelatedTo(source: Type, target: Type, sourceIsPrimitive: boolean, reportErrors: boolean): Ternary { + function isIndexTypeRelatedTo(source: Type, target: Type, sourceIsPrimitive: boolean, reportErrors: boolean, skipIndexError?: boolean): Ternary { // Index signature of type any permits assignment from everything but primitives if (!sourceIsPrimitive && target.flags & TypeFlags.AnyOrUnknown) { return Ternary.True; } const related = isRelatedTo(source, target, reportErrors); - if (!related && reportErrors) { + if (!related && reportErrors && !skipIndexError) { reportError(Diagnostics.Index_signatures_are_incompatible); } return related; @@ -12305,16 +12365,17 @@ namespace ts { return Ternary.True; } if (sourceInfos && targetInfos) { - const isIndexRelatedToHelper = identityRelation ? isRelatedTo : isTypeIndexAssignableTo; + const isIndexRelatedToHelper = relation === identityRelation ? isRelatedTo : isTypeIndexAssignableTo; // If for every index signature in S there exists a related signature in T targetLoop: for (const targetInfo of targetInfos) { for (const sourceInfo of sourceInfos) { - if (isIndexRelatedToHelper(sourceInfo.indexType, targetInfo.indexType) && isIndexTypeRelatedTo(sourceInfo.type, targetInfo.type, sourceIsPrimitive, reportErrors)) { + if (isIndexRelatedToHelper(sourceInfo.indexType, targetInfo.indexType)) { + if (!isIndexTypeRelatedTo(sourceInfo.type, targetInfo.type, sourceIsPrimitive, reportErrors)) return Ternary.False; if (relation === identityRelation && sourceInfo.isReadonly !== targetInfo.isReadonly) return Ternary.False; continue targetLoop; } } - return identityRelation ? Ternary.False : Ternary.True; + return relation === identityRelation ? Ternary.False : Ternary.Maybe; } if (relation === identityRelation) { // And for every index signature in T there exists and identical signature in S @@ -13257,7 +13318,7 @@ namespace ts { function createReverseMappedType(source: Type, target: MappedType) { const properties = getPropertiesOfType(source); - if (properties.length === 0 && !getResultingIndexInfoOfIndexOnType(source, stringType)) { + if (properties.length === 0 && !getIndexInfosOfType(source)) { return undefined; } // If any property contains context sensitive functions that have been skipped, the source type @@ -22705,7 +22766,7 @@ namespace ts { } // Check if we're indexing with a numeric type and if either object or index types // is a generic type with a constraint that has a numeric index signature. - if (getResultingIndexInfoOfIndexOnType(objectType, indexType)) { + if (getApplicableIndexInfosOfIndexOnType(objectType, getBaseConstraintOrType(indexType))) { return type; } error(accessNode, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(objectType)); @@ -25225,7 +25286,14 @@ namespace ts { if (indexInfos) { forEach(getPropertiesOfObjectType(type), prop => { const propType = getTypeOfSymbol(prop); - checkIndexConstraintForProperty(prop, propType, type, declaredIndexers); + // TODO: Well known symbols should _probably_ be subject to a symbol indexer, but unfortunately they have no associated literal + // type right now, so they're very difficult to check/flow. They're on the chopping block for removal thanks to advancements, + // and other issues though, so it's probably OK to just let their removal and simultaneous replacement with `unique symbol`s + // fix this. + if (isKnownSymbol(prop)) { + return; + } + checkIndexConstraintForProperty(prop, getLiteralTypeFromPropertyName(prop, TypeFlags.StringOrNumberLiteralOrUnique), propType, type, declaredIndexers); }); const classDeclaration = type.symbol.valueDeclaration; @@ -25237,7 +25305,7 @@ namespace ts { if (!hasModifier(member, ModifierFlags.Static) && hasNonBindableDynamicName(member)) { const symbol = getSymbolOfNode(member); const propType = getTypeOfSymbol(symbol); - checkIndexConstraintForProperty(symbol, propType, type, declaredIndexers); + checkIndexConstraintForProperty(symbol, checkExpressionCached((member as DynamicNamedDeclaration).name.expression), propType, type, declaredIndexers); } } } @@ -25283,23 +25351,14 @@ namespace ts { function checkIndexConstraintForProperty( prop: Symbol, + propName: Type, propertyType: Type, containingType: Type, indexDeclarations: Declaration[] | undefined ): void { - // TODO: Well known symbols should _probably_ be subject to a symbol indexer, but unfortunately they have no associated literal - // type right now, so they're very difficult to check/flow. They're on the chopping block for removal thanks to advancements, - // and other issues though, so it's probably OK to just let their removal and simultaneous replacement with `unique symbol`s - // fix this. - if (isKnownSymbol(prop)) { - return; - } - - const propName = getLiteralTypeFromPropertyName(prop, TypeFlags.StringOrNumberLiteralOrUnique); - const indexInfos = getIndexInfosOfType(containingType); const resolvedInfo = resolveIndexOnIndexInfos(propName, indexInfos); - if (!resolvedInfo || isTypeIndexAssignableTo(propertyType, resolvedInfo.type)) { + if (!resolvedInfo || isTypeAssignableTo(propertyType, resolvedInfo.type)) { return; // No errors } const indexDeclaration = contains(indexDeclarations, resolvedInfo.declaration) ? resolvedInfo.declaration : undefined; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 014e3c4ead4a3..34b1153490c5c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1432,7 +1432,7 @@ "category": "Error", "code": 2410 }, - "Property '{0}' of type '{1}' is not assignable to '{2}' index type '{3}'.": { + "Property '{0}' of type '{1}' is not assignable to {2} index type '{3}'.": { "category": "Error", "code": 2411 }, diff --git a/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts b/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts index 9e8639bbb9e6f..01d33d59f83a5 100644 --- a/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts +++ b/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts @@ -99,12 +99,12 @@ type ItemMap = { [x: string]: Item; } -function f50(obj: T, key: keyof T) { +function f50(obj: T, key: keyof T & string) { let item: Item = obj[key]; return obj[key].name; } -function f51(obj: T, key: K) { +function f51(obj: T, key: K) { let item: Item = obj[key]; return obj[key].name; } diff --git a/tests/cases/fourslash/indexerReturnTypes1.ts b/tests/cases/fourslash/indexerReturnTypes1.ts index cb38a79598eac..09083efe89757 100644 --- a/tests/cases/fourslash/indexerReturnTypes1.ts +++ b/tests/cases/fourslash/indexerReturnTypes1.ts @@ -46,36 +46,46 @@ //// ////var /*1*/r1 = numeric[1]; ////var /*2*/r2 = numeric['1']; +////var /*2a*/r2a = numeric['1' as string]; ////var /*3*/r3 = stringy[1]; ////var /*4*/r4 = stringy['1']; ////var /*5*/r5 = numericPlus[1]; ////var /*6*/r6 = numericPlus['1']; +////var /*6a*/r6a = numericPlus['1' as string]; ////var /*7*/r7 = stringPlus[1]; ////var /*8*/r8 = stringPlus['1']; ////var /*9*/r9 = numericG[1]; ////var /*10*/r10 = numericG['1']; +////var /*10a*/r10a = numericG['1' as string]; ////var /*11*/r11 = stringyG[1]; ////var /*12*/r12 = stringyG['1']; ////var /*13*/r13 = ty[1]; ////var /*14*/r14 = ty['1']; +////var /*14a*/r14a = ty['1' as string]; ////var /*15*/r15 = ty2[1]; ////var /*16*/r16 = ty2['1']; +////var /*16a*/r16a = ty2['1' as string]; verify.quickInfos({ 1: "var r1: Date", - 2: "var r2: any", + 2: "var r2: Date", + "2a": "var r2a: any", 3: "var r3: RegExp", 4: "var r4: RegExp", 5: "var r5: Date", - 6: "var r6: any", + 6: "var r6: Date", + "6a": "var r6a: any", 7: "var r7: RegExp", 8: "var r8: RegExp", 9: "var r9: Date", - 10: "var r10: any", + 10: "var r10: Date", + "10a": "var r10a: any", 11: "var r11: Date", 12: "var r12: Date", 13: "var r13: Ty", - 14: "var r14: any", + 14: "var r14: Ty", + "14a": "var r14a: any", 15: "var r15: {\n [x: number]: Date;\n}", - 16: "var r16: any" + 16: "var r16: {\n [x: number]: Date;\n}", + "16a": "var r16a: any" }); From 8bdcc78a2c64141ffb4aae350e3af6bcef52bb1f Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 28 Aug 2018 18:16:08 -0700 Subject: [PATCH 03/11] Accept most baselines --- src/compiler/checker.ts | 89 ++++--- src/compiler/diagnosticMessages.json | 8 +- .../reference/api/tsserverlibrary.d.ts | 13 +- tests/baselines/reference/api/typescript.d.ts | 13 +- .../reference/arrayLiterals.errors.txt | 4 +- .../reference/arraySigChecking.types | 2 +- ...ignmentCompatWithNumericIndexer.errors.txt | 24 +- ...gnmentCompatWithNumericIndexer2.errors.txt | 24 +- ...gnmentCompatWithNumericIndexer3.errors.txt | 12 +- ...signmentCompatWithStringIndexer.errors.txt | 32 +-- ...ignmentCompatWithStringIndexer2.errors.txt | 32 +-- ...ignmentCompatWithStringIndexer3.errors.txt | 8 +- .../reference/classIndexer2.errors.txt | 4 +- .../reference/classIndexer3.errors.txt | 4 +- .../reference/classIndexer4.errors.txt | 4 +- .../computedPropertyNames36_ES5.errors.txt | 4 +- .../computedPropertyNames36_ES6.errors.txt | 4 +- .../computedPropertyNames38_ES5.errors.txt | 4 +- .../computedPropertyNames38_ES6.errors.txt | 4 +- .../computedPropertyNames39_ES5.errors.txt | 4 +- .../computedPropertyNames39_ES6.errors.txt | 4 +- .../computedPropertyNames40_ES5.errors.txt | 4 +- .../computedPropertyNames40_ES6.errors.txt | 4 +- .../computedPropertyNames42_ES5.errors.txt | 4 +- .../computedPropertyNames42_ES6.errors.txt | 4 +- .../computedPropertyNames43_ES5.errors.txt | 4 +- .../computedPropertyNames43_ES6.errors.txt | 4 +- .../computedPropertyNames44_ES5.errors.txt | 8 +- .../computedPropertyNames44_ES6.errors.txt | 8 +- .../computedPropertyNames45_ES5.errors.txt | 8 +- .../computedPropertyNames45_ES6.errors.txt | 8 +- ...opertyNamesContextualType10_ES5.errors.txt | 4 +- ...opertyNamesContextualType10_ES6.errors.txt | 4 +- ...utedPropertyNamesContextualType7_ES5.types | 2 +- ...utedPropertyNamesContextualType7_ES6.types | 2 +- ...ropertyNamesContextualType9_ES5.errors.txt | 4 +- ...ropertyNamesContextualType9_ES6.errors.txt | 4 +- ...ontextualTypingOfArrayLiterals1.errors.txt | 4 +- .../declFileTypeAnnotationTypeLiteral.types | 2 +- ...ypeAnnotationVisibilityErrorTypeLiteral.js | 2 +- ...AnnotationVisibilityErrorTypeLiteral.types | 6 +- ...faceIncompatibleWithBaseIndexer.errors.txt | 28 +-- ...rivedTypeIncompatibleSignatures.errors.txt | 8 +- .../reference/duplicateNumericIndexers.types | 2 +- .../reference/duplicateStringIndexers.types | 2 +- ...sNotASubtypeOfAnythingButNumber.errors.txt | 64 ++--- ...nAndInterfaceWithSeparateErrors.errors.txt | 4 +- ...ricCallWithObjectTypeArgsAndIndexers.types | 4 +- ...lWithObjectTypeArgsAndIndexersErrors.types | 4 +- ...icTypeReferenceWithoutTypeArgument.d.types | 2 +- ...ericTypeReferenceWithoutTypeArgument.types | 2 +- ...ricTypeReferenceWithoutTypeArgument2.types | 2 +- ...ricTypeReferenceWithoutTypeArgument3.types | 2 +- .../indexSignatureAndMappedType.errors.txt | 6 +- .../reference/indexTypeCheck.errors.txt | 22 +- .../reference/indexerConstraints.errors.txt | 26 +- .../reference/indexerConstraints2.errors.txt | 20 +- ...dexSignaturesFromDifferentBases.errors.txt | 24 +- ...gIndexersFromDifferentBaseTypes.errors.txt | 8 +- ...IndexersFromDifferentBaseTypes2.errors.txt | 8 +- .../interfaceExtendingClass2.errors.txt | 4 +- ...ExtendsObjectIntersectionErrors.errors.txt | 18 +- .../interfaceMemberValidation.errors.txt | 4 +- ...ingIndexerHidingBaseTypeIndexer.errors.txt | 4 +- ...ngIndexerHidingBaseTypeIndexer2.errors.txt | 4 +- ...ngIndexerHidingBaseTypeIndexer3.errors.txt | 4 +- .../interfacedeclWithIndexerErrors.errors.txt | 20 +- ...nvariantGenericErrorElaboration.errors.txt | 2 +- .../invariantGenericErrorElaboration.js | 2 +- .../invariantGenericErrorElaboration.symbols | 10 +- .../invariantGenericErrorElaboration.types | 2 +- .../reference/keyofAndIndexedAccess.js | 8 +- .../reference/keyofAndIndexedAccess.symbols | 16 +- .../reference/keyofAndIndexedAccess.types | 18 +- .../keyofAndIndexedAccessErrors.types | 6 +- .../keyofDoesntContainSymbols.errors.txt | 8 +- .../reference/keyofDoesntContainSymbols.types | 2 +- .../reference/mappedTypeErrors.errors.txt | 8 +- ...eInferenceOnlySymbolsIfSymbolsSpecified.js | 88 +++++++ ...renceOnlySymbolsIfSymbolsSpecified.symbols | 199 +++++++++++++++ ...ferenceOnlySymbolsIfSymbolsSpecified.types | 238 ++++++++++++++++++ .../mappedTypeRelationships.errors.txt | 4 +- .../reference/mappedTypeRelationships.js | 8 +- .../reference/mappedTypeRelationships.symbols | 16 +- .../reference/mappedTypeRelationships.types | 18 +- .../mergedInterfacesWithIndexers.types | 4 +- .../mergedInterfacesWithIndexers2.errors.txt | 14 +- .../reference/multipleNumericIndexers.types | 4 +- .../reference/multipleStringIndexers.types | 4 +- ...tiveConstraintOfIndexAccessType.errors.txt | 2 - ...rConstrainsPropertyDeclarations.errors.txt | 16 +- ...ConstrainsPropertyDeclarations2.errors.txt | 12 +- .../numericIndexerConstraint.errors.txt | 4 +- .../reference/numericIndexingResults.types | 28 +-- ...peHidingMembersOfExtendedObject.errors.txt | 32 +-- ...tringIndexerHidingObjectIndexer.errors.txt | 28 +-- .../reference/parserES5SymbolIndexer3.types | 2 +- .../reference/parserIndexSignature8.types | 4 +- .../reference/parserSymbolIndexer4.types | 2 +- .../propertiesAndIndexers.errors.txt | 76 +++--- .../propertiesAndIndexers2.errors.txt | 35 +-- ...rtiesAndIndexersForNumericNames.errors.txt | 32 +-- .../reference/readonlyMembers.errors.txt | 4 +- .../baselines/reference/readonlyMembers.types | 6 +- .../reference/recursiveTypesWithTypeof.types | 18 +- .../stringIndexerAndConstructor.errors.txt | 8 +- .../stringIndexerAndConstructor1.errors.txt | 4 +- ...rConstrainsPropertyDeclarations.errors.txt | 84 +++---- ...ConstrainsPropertyDeclarations2.errors.txt | 24 +- ...sOfTypeParameterWithConstraints.errors.txt | 40 +-- ...OfTypeParameterWithConstraints4.errors.txt | 20 +- ...rameterWithRecursiveConstraints.errors.txt | 48 ++-- .../reference/subtypesOfUnion.errors.txt | 116 ++++----- .../subtypingWithNumericIndexer.errors.txt | 8 +- .../subtypingWithNumericIndexer2.errors.txt | 16 +- .../subtypingWithNumericIndexer3.errors.txt | 16 +- .../subtypingWithNumericIndexer4.errors.txt | 12 +- .../subtypingWithNumericIndexer5.errors.txt | 16 +- .../subtypingWithStringIndexer.errors.txt | 8 +- .../subtypingWithStringIndexer2.errors.txt | 16 +- .../subtypingWithStringIndexer3.errors.txt | 16 +- .../subtypingWithStringIndexer4.errors.txt | 12 +- .../templateStringInIndexExpression.types | 2 +- .../templateStringInIndexExpressionES6.types | 2 +- .../baselines/reference/typeName1.errors.txt | 8 +- .../typeOfEnumAndVarRedeclarations.errors.txt | 4 +- ...IfEveryConstituentTypeIsSubtype.errors.txt | 120 ++++----- .../invariantGenericErrorElaboration.ts | 2 +- ...eInferenceOnlySymbolsIfSymbolsSpecified.ts | 1 + .../types/keyof/keyofAndIndexedAccess.ts | 4 +- 130 files changed, 1414 insertions(+), 856 deletions(-) create mode 100644 tests/baselines/reference/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.js create mode 100644 tests/baselines/reference/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.symbols create mode 100644 tests/baselines/reference/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.types diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a9b9edce2e6b2..dfe2fe34a8007 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -621,6 +621,7 @@ namespace ts { const subtypeRelation = createMap(); const assignableRelation = createMap(); const definitelyAssignableRelation = createMap(); + const indexAccessAssignableRelation = createMap(); const indexAssignableRelation = createMap(); const comparableRelation = createMap(); const identityRelation = createMap(); @@ -7455,7 +7456,7 @@ namespace ts { const propTypes: Type[] = []; for (const prop of getPropertiesOfType(type)) { const nameType = getLiteralTypeFromPropertyName(prop, TypeFlags.StringOrNumberLiteralOrUnique); - if (isTypeIndexAssignableTo(nameType, targetIndexType)) { + if (isTypeIndexAccessAssignableTo(nameType, targetIndexType)) { propTypes.push(getTypeOfSymbol(prop)); } } @@ -8013,17 +8014,17 @@ namespace ts { indexType = getLiteralType(+(indexType as StringLiteralType).value); } } - const applicable = filter(infos, info => isTypeIndexAssignableTo(indexType, info.indexType)); + const applicable = filter(infos, info => isTypeIndexAccessAssignableTo(indexType, info.indexType)); if (!length(applicable)) return; // OK, now for the hard part - ranking the derivedness of an index signature! let candidate = applicable![0]; - let filteredCandidateIndexType = filterType(candidate.indexType, c => isTypeIndexAssignableTo(indexType, c)); + let filteredCandidateIndexType = filterType(candidate.indexType, c => isTypeIndexAccessAssignableTo(indexType, c)); for (const info of applicable!) { if (info === candidate) continue; - const filteredInfoIndexType = filterType(info.indexType, c => isTypeIndexAssignableTo(indexType, c)); + const filteredInfoIndexType = filterType(info.indexType, c => isTypeIndexAccessAssignableTo(indexType, c)); // The identity check is here so that in situations where multiple index signatures with the same index type are present // (which is usually an error), we'll align with older behavior and use the type from the first signature we encountered - if (!isTypeIdenticalTo(filteredInfoIndexType, filteredCandidateIndexType) && isTypeIndexAssignableTo(filteredInfoIndexType, filteredCandidateIndexType)) { + if (!isTypeIdenticalTo(filteredInfoIndexType, filteredCandidateIndexType) && isTypeIndexAccessAssignableTo(filteredInfoIndexType, filteredCandidateIndexType)) { candidate = info; filteredCandidateIndexType = filteredInfoIndexType; } @@ -10588,6 +10589,10 @@ namespace ts { return isTypeRelatedTo(source, target, assignableRelation); } + function isTypeIndexAccessAssignableTo(source: Type, target: Type): boolean { + return isTypeRelatedTo(source, target, indexAccessAssignableRelation); + } + function isTypeIndexAssignableTo(source: Type, target: Type): boolean { return isTypeRelatedTo(source, target, indexAssignableRelation); } @@ -11054,7 +11059,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) { + if (relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation || relation === indexAssignableRelation || relation === indexAccessAssignableRelation) { 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 @@ -11062,10 +11067,14 @@ namespace ts { if (s & (TypeFlags.Number | TypeFlags.NumberLiteral) && !(s & TypeFlags.EnumLiteral) && ( t & TypeFlags.Enum || t & TypeFlags.NumberLiteral && t & TypeFlags.EnumLiteral)) return true; } - if (relation === indexAssignableRelation) { + if (relation === indexAccessAssignableRelation) { 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.String && t & TypeFlags.Number) return true; + if (s & TypeFlags.StringLiteral && t & TypeFlags.NumberLiteral) return +(source as LiteralType).value === (target as LiteralType).value; + } return false; } @@ -11421,7 +11430,7 @@ namespace ts { } if (maybeTypeOfKind(target, TypeFlags.Object) && !(getObjectFlags(target) & ObjectFlags.ObjectLiteralPatternWithComputedProperties)) { const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes); - if ((relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation || relation === indexAssignableRelation) && + if ((relation === assignableRelation || relation === definitelyAssignableRelation || relation === comparableRelation || relation === indexAssignableRelation || relation === indexAccessAssignableRelation) && (isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) { return false; } @@ -12274,7 +12283,7 @@ namespace ts { return result; } - function eachPropertyRelatedToIndexesOf(source: Type, target: Type, sourceIsPrimitive: boolean, reportErrors: boolean): Ternary { + function eachPropertyRelatedToIndexesOf(source: Type, target: Type, reportErrors: boolean): Ternary { let result = Ternary.True; for (const prop of getPropertiesOfObjectType(source)) { if (isIgnoredJsxProperty(source, prop, /*targetMemberType*/ undefined)) { @@ -12282,7 +12291,7 @@ namespace ts { } const targetType = getResultingTypeOfIndexOnType(target, getLiteralTypeFromPropertyName(prop, TypeFlags.StringOrNumberLiteralOrUnique)); if (targetType) { - const related = isIndexTypeRelatedTo(getTypeOfSymbol(prop), targetType, sourceIsPrimitive, reportErrors, /*skipIndexError*/ true); + const related = isRelatedTo(getTypeOfSymbol(prop), targetType, reportErrors); if (!related) { if (reportErrors) { reportError(Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop)); @@ -12297,7 +12306,7 @@ namespace ts { function indexTypesRelatedTo(source: Type, target: Type, sourceIsPrimitive: boolean, reportErrors: boolean): Ternary { if (relation === identityRelation) { - return indexInfosRelated(getIndexInfosOfType(source), getIndexInfosOfType(target), sourceIsPrimitive, reportErrors); + return indexInfosIdentical(getIndexInfosOfType(source), getIndexInfosOfType(target)); } const targetInfo = getIndexInfosOfType(target); if (!targetInfo) { @@ -12321,7 +12330,7 @@ namespace ts { hadSomeMatch = true; // TODO: Revise? For each type in `K`'s constraint, instantiate T with the key type being compared? // const instantiated = instantiateType(getTemplateTypeFromMappedType(source), makeUnaryTypeMapper(getTypeParameterFromMappedType(source), key)); - if (!isIndexTypeRelatedTo(getTemplateTypeFromMappedType(source), result, sourceIsPrimitive, reportErrors)) { + if (!isRelatedTo(getTemplateTypeFromMappedType(source), result, reportErrors)) { return true; } }); @@ -12331,7 +12340,7 @@ namespace ts { return hadSomeMatch ? Ternary.True : Ternary.False; } if (isObjectTypeWithInferableIndex(source)) { - return eachPropertyRelatedToIndexesOf(source, target, sourceIsPrimitive, reportErrors); + return eachPropertyRelatedToIndexesOf(source, target, reportErrors); } let hasTypedSignature = false; for (const info of targetInfo) { @@ -12348,45 +12357,58 @@ namespace ts { return Ternary.False; } - function isIndexTypeRelatedTo(source: Type, target: Type, sourceIsPrimitive: boolean, reportErrors: boolean, skipIndexError?: boolean): Ternary { + function isIndexTypeRelatedTo(source: IndexInfo, target: IndexInfo, sourceIsPrimitive: boolean, reportErrors: boolean, skipIndexError?: boolean): Ternary { // Index signature of type any permits assignment from everything but primitives - if (!sourceIsPrimitive && target.flags & TypeFlags.AnyOrUnknown) { + if (!sourceIsPrimitive && target.type.flags & TypeFlags.AnyOrUnknown) { return Ternary.True; } - const related = isRelatedTo(source, target, reportErrors); + const related = isRelatedTo(source.type, target.type, reportErrors); if (!related && reportErrors && !skipIndexError) { - reportError(Diagnostics.Index_signatures_are_incompatible); + const sourceType = typeToString(source.indexType); + const targetType = typeToString(target.indexType); + reportError(sourceType === targetType ? Diagnostics._0_index_signatures_are_incompatible : Diagnostics._0_and_1_index_signatures_are_incompatible, sourceType, targetType); } return related; } + function indexInfosIdentical(sourceInfos: IndexInfo[] | undefined, targetInfos: IndexInfo[] | undefined) { + if (length(sourceInfos) !== length(targetInfos)) return Ternary.False; + if (!sourceInfos || !targetInfos) return Ternary.True; + targetLoop: for (const targetInfo of targetInfos) { + for (const sourceInfo of sourceInfos) { + if (isRelatedTo(sourceInfo.indexType, targetInfo.indexType) && isRelatedTo(sourceInfo.type, targetInfo.type) && sourceInfo.isReadonly === targetInfo.isReadonly) { + continue targetLoop; + } + } + return Ternary.False; + } + sourceLoop: for (const sourceInfo of sourceInfos) { + for (const targetInfo of targetInfos) { + if (isRelatedTo(sourceInfo.indexType, targetInfo.indexType) && isRelatedTo(sourceInfo.type, targetInfo.type) && sourceInfo.isReadonly === targetInfo.isReadonly) { + continue sourceLoop; + } + } + return Ternary.False; + } + return Ternary.True; + } + function indexInfosRelated(sourceInfos: IndexInfo[] | undefined, targetInfos: IndexInfo[] | undefined, sourceIsPrimitive: boolean, reportErrors: boolean): Ternary { if (!sourceInfos && !targetInfos) { return Ternary.True; } if (sourceInfos && targetInfos) { - const isIndexRelatedToHelper = relation === identityRelation ? isRelatedTo : isTypeIndexAssignableTo; // If for every index signature in S there exists a related signature in T targetLoop: for (const targetInfo of targetInfos) { for (const sourceInfo of sourceInfos) { - if (isIndexRelatedToHelper(sourceInfo.indexType, targetInfo.indexType)) { - if (!isIndexTypeRelatedTo(sourceInfo.type, targetInfo.type, sourceIsPrimitive, reportErrors)) return Ternary.False; + if (isTypeIndexAssignableTo(sourceInfo.indexType, targetInfo.indexType)) { + if (!isIndexTypeRelatedTo(sourceInfo, targetInfo, sourceIsPrimitive, reportErrors)) return Ternary.False; if (relation === identityRelation && sourceInfo.isReadonly !== targetInfo.isReadonly) return Ternary.False; continue targetLoop; } } - return relation === identityRelation ? Ternary.False : Ternary.Maybe; - } - if (relation === identityRelation) { - // And for every index signature in T there exists and identical signature in S - sourceLoop: for (const sourceInfo of sourceInfos) { - for (const targetInfo of targetInfos) { - if (isIndexRelatedToHelper(sourceInfo.indexType, targetInfo.indexType) && isIndexTypeRelatedTo(sourceInfo.type, targetInfo.type, sourceIsPrimitive, /*reportErrors*/ false)) { - if (sourceInfo.isReadonly !== targetInfo.isReadonly) return Ternary.False; - continue sourceLoop; - } - } - return Ternary.False; + if (targetInfo === targetInfos[targetInfos.length - 1]) { + return Ternary.Maybe; // Iterated over every target signature without a definitive yes or no on every signature; allow fallback to inferred signature } } // Then the signature lists are related @@ -13741,6 +13763,7 @@ namespace ts { for (const sourceInfo of sourceInfos) { for (const targetInfo of targetInfos) { // if this source info is applicable to the target info + // Infers from string -> number, as a string signature can fulfill a number one if (isTypeIndexAssignableTo(sourceInfo.indexType, targetInfo.indexType)) { // then infer inferFromTypes(sourceInfo.type, targetInfo.type); @@ -25326,7 +25349,7 @@ namespace ts { if (someBaseTypeHasBothIndexers) continue; } forEachType(info1.indexType, indexType => { - if (isTypeIndexAssignableTo(indexType, info2.indexType)) { + if (isTypeIndexAccessAssignableTo(indexType, info2.indexType)) { if (!isTypeAssignableTo(info1.type, info2.type)) { // Error - not compatable const errorNode = (contains(declaredIndexers, info1.declaration) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 34b1153490c5c..3c2ff84bf3b0b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1112,7 +1112,7 @@ "category": "Error", "code": 2329 }, - "Index signatures are incompatible.": { + "'{0}' and '{1}' index signatures are incompatible.": { "category": "Error", "code": 2330 }, @@ -1432,7 +1432,7 @@ "category": "Error", "code": 2410 }, - "Property '{0}' of type '{1}' is not assignable to {2} index type '{3}'.": { + "Property '{0}' of type '{1}' is not assignable to '{2}' index type '{3}'.": { "category": "Error", "code": 2411 }, @@ -1460,6 +1460,10 @@ "category": "Error", "code": 2418 }, + "'{0}' index signatures are incompatible.": { + "category": "Error", + "code": 2419 + }, "Class '{0}' incorrectly implements interface '{1}'.": { "category": "Error", "code": 2420 diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 584557e8b0f37..57aadbc9bec67 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1864,9 +1864,9 @@ declare namespace ts { getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; - getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined; + getIndexInfosOfType(type: Type, indexType?: Type): IndexInfo[] | undefined; getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray; - getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined; + getIndexTypeOfType(type: Type, indexType: Type): Type | undefined; getBaseTypes(type: InterfaceType): BaseType[]; getBaseTypeOfLiteralType(type: Type): Type; getWidenedType(type: Type): Type; @@ -1880,7 +1880,7 @@ declare namespace ts { typeArguments?: NodeArray; }) | undefined; /** Note that the resulting nodes cannot be checked. */ - indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): IndexSignatureDeclaration | undefined; + indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): IndexSignatureDeclaration | undefined; /** Note that the resulting nodes cannot be checked. */ symbolToEntityName(symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): EntityName | undefined; /** Note that the resulting nodes cannot be checked. */ @@ -2251,8 +2251,7 @@ declare namespace ts { declaredProperties: Symbol[]; declaredCallSignatures: Signature[]; declaredConstructSignatures: Signature[]; - declaredStringIndexInfo?: IndexInfo; - declaredNumberIndexInfo?: IndexInfo; + declaredIndexInfos?: IndexInfo[]; } /** * Type references (ObjectFlags.Reference). When a class or interface has type parameters or @@ -2342,6 +2341,7 @@ declare namespace ts { Number = 1 } interface IndexInfo { + indexType: Type; type: Type; isReadonly: boolean; declaration?: IndexSignatureDeclaration; @@ -4527,8 +4527,7 @@ declare namespace ts { getApparentProperties(): Symbol[]; getCallSignatures(): ReadonlyArray; getConstructSignatures(): ReadonlyArray; - getStringIndexType(): Type | undefined; - getNumberIndexType(): Type | undefined; + getTypeIndexedByType(indexType: Type): Type | undefined; getBaseTypes(): BaseType[] | undefined; getNonNullableType(): Type; getConstraint(): Type | undefined; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 32761156558fd..30fff2d378e15 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1864,9 +1864,9 @@ declare namespace ts { getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; - getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined; + getIndexInfosOfType(type: Type, indexType?: Type): IndexInfo[] | undefined; getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray; - getIndexTypeOfType(type: Type, kind: IndexKind): Type | undefined; + getIndexTypeOfType(type: Type, indexType: Type): Type | undefined; getBaseTypes(type: InterfaceType): BaseType[]; getBaseTypeOfLiteralType(type: Type): Type; getWidenedType(type: Type): Type; @@ -1880,7 +1880,7 @@ declare namespace ts { typeArguments?: NodeArray; }) | undefined; /** Note that the resulting nodes cannot be checked. */ - indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): IndexSignatureDeclaration | undefined; + indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): IndexSignatureDeclaration | undefined; /** Note that the resulting nodes cannot be checked. */ symbolToEntityName(symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration?: Node, flags?: NodeBuilderFlags): EntityName | undefined; /** Note that the resulting nodes cannot be checked. */ @@ -2251,8 +2251,7 @@ declare namespace ts { declaredProperties: Symbol[]; declaredCallSignatures: Signature[]; declaredConstructSignatures: Signature[]; - declaredStringIndexInfo?: IndexInfo; - declaredNumberIndexInfo?: IndexInfo; + declaredIndexInfos?: IndexInfo[]; } /** * Type references (ObjectFlags.Reference). When a class or interface has type parameters or @@ -2342,6 +2341,7 @@ declare namespace ts { Number = 1 } interface IndexInfo { + indexType: Type; type: Type; isReadonly: boolean; declaration?: IndexSignatureDeclaration; @@ -4527,8 +4527,7 @@ declare namespace ts { getApparentProperties(): Symbol[]; getCallSignatures(): ReadonlyArray; getConstructSignatures(): ReadonlyArray; - getStringIndexType(): Type | undefined; - getNumberIndexType(): Type | undefined; + getTypeIndexedByType(indexType: Type): Type | undefined; getBaseTypes(): BaseType[] | undefined; getNonNullableType(): Type; getConstraint(): Type | undefined; diff --git a/tests/baselines/reference/arrayLiterals.errors.txt b/tests/baselines/reference/arrayLiterals.errors.txt index f5fe71b79a6e7..c46fd767632f5 100644 --- a/tests/baselines/reference/arrayLiterals.errors.txt +++ b/tests/baselines/reference/arrayLiterals.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(24,77): error TS2322: Type '({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]' is not assignable to type '{ [n: number]: { a: string; b: number; }; }'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type '{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }' is not assignable to type '{ a: string; b: number; }'. Type '{ a: string; b: number; c: string; }' is not assignable to type '{ a: string; b: number; }'. Object literal may only specify known properties, and 'c' does not exist in type '{ a: string; b: number; }'. @@ -32,7 +32,7 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals.ts(24,77): error var context1: { [n: number]: { a: string; b: number; }; } = [{ a: '', b: 0, c: '' }, { a: "", b: 3, c: 0 }]; ~~~~~ !!! error TS2322: Type '({ a: string; b: number; c: string; } | { a: string; b: number; c: number; })[]' is not assignable to type '{ [n: number]: { a: string; b: number; }; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type '{ a: string; b: number; c: string; } | { a: string; b: number; c: number; }' is not assignable to type '{ a: string; b: number; }'. !!! error TS2322: Type '{ a: string; b: number; c: string; }' is not assignable to type '{ a: string; b: number; }'. !!! error TS2322: Object literal may only specify known properties, and 'c' does not exist in type '{ a: string; b: number; }'. diff --git a/tests/baselines/reference/arraySigChecking.types b/tests/baselines/reference/arraySigChecking.types index bfd8b878bca67..d1367783609b3 100644 --- a/tests/baselines/reference/arraySigChecking.types +++ b/tests/baselines/reference/arraySigChecking.types @@ -18,7 +18,7 @@ declare module M { } var foo: { [index: any]; }; // expect an error here ->foo : {} +>foo : { [index: any]: any; } >index : any } diff --git a/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt b/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt index c5987a93ddf7f..bd63d965c5308 100644 --- a/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt @@ -1,23 +1,23 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(14,1): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(18,1): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived2'. Property 'baz' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(32,9): error TS2322: Type '{ [x: number]: Derived; }' is not assignable to type 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(33,9): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'T' is not assignable to type 'Derived'. Type 'Base' is not assignable to type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(36,9): error TS2322: Type '{ [x: number]: Derived2; }' is not assignable to type 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts(37,9): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'T' is not assignable to type 'Derived2'. Type 'Base' is not assignable to type 'Derived2'. @@ -39,7 +39,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b = a; // error ~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived'. !!! error TS2322: Property 'bar' is missing in type 'Base'. @@ -48,7 +48,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b2 = a; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. !!! error TS2322: Property 'baz' is missing in type 'Base'. @@ -67,12 +67,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme a = b; // error ~ !!! error TS2322: Type '{ [x: number]: Derived; }' is not assignable to type 'A'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'Derived' is not assignable to type 'T'. b = a; // error ~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived'. !!! error TS2322: Type 'Base' is not assignable to type 'Derived'. @@ -80,12 +80,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme a = b2; // error ~ !!! error TS2322: Type '{ [x: number]: Derived2; }' is not assignable to type 'A'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'Derived2' is not assignable to type 'T'. b2 = a; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived2'. !!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. diff --git a/tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt b/tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt index f91d0dd0c1505..7065dc442dafa 100644 --- a/tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithNumericIndexer2.errors.txt @@ -1,23 +1,23 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(14,1): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(18,1): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived2'. Property 'baz' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(32,9): error TS2322: Type '{ [x: number]: Derived; }' is not assignable to type 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(33,9): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'T' is not assignable to type 'Derived'. Type 'Base' is not assignable to type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(36,9): error TS2322: Type '{ [x: number]: Derived2; }' is not assignable to type 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts(37,9): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'T' is not assignable to type 'Derived2'. Type 'Base' is not assignable to type 'Derived2'. @@ -39,7 +39,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b = a; // error ~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived'. !!! error TS2322: Property 'bar' is missing in type 'Base'. @@ -48,7 +48,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b2 = a; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. !!! error TS2322: Property 'baz' is missing in type 'Base'. @@ -67,12 +67,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme a = b; // error ~ !!! error TS2322: Type '{ [x: number]: Derived; }' is not assignable to type 'A'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'Derived' is not assignable to type 'T'. b = a; // error ~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived'. !!! error TS2322: Type 'Base' is not assignable to type 'Derived'. @@ -80,12 +80,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme a = b2; // error ~ !!! error TS2322: Type '{ [x: number]: Derived2; }' is not assignable to type 'A'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'Derived2' is not assignable to type 'T'. b2 = a; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived2'. !!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. diff --git a/tests/baselines/reference/assignmentCompatWithNumericIndexer3.errors.txt b/tests/baselines/reference/assignmentCompatWithNumericIndexer3.errors.txt index 61f9e082a481c..d61dc6d536bf6 100644 --- a/tests/baselines/reference/assignmentCompatWithNumericIndexer3.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithNumericIndexer3.errors.txt @@ -1,13 +1,13 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3.ts(14,1): error TS2322: Type '{ [x: number]: Base; }' is not assignable to type 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3.ts(23,1): error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Derived' is not assignable to type 'Derived2'. Property 'baz' is missing in type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3.ts(33,9): error TS2322: Type '{ [x: number]: Derived; }' is not assignable to type 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. @@ -28,7 +28,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme a = b; // error ~ !!! error TS2322: Type '{ [x: number]: Base; }' is not assignable to type 'A'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived'. !!! error TS2322: Property 'bar' is missing in type 'Base'. b = a; // ok @@ -42,7 +42,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b2 = a; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: number]: Derived2; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'Derived' is not assignable to type 'Derived2'. !!! error TS2322: Property 'baz' is missing in type 'Derived'. @@ -57,7 +57,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme a = b; // error ~ !!! error TS2322: Type '{ [x: number]: Derived; }' is not assignable to type 'A'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'Derived' is not assignable to type 'T'. b = a; // ok diff --git a/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt b/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt index 51762bb941834..97f559356e701 100644 --- a/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt @@ -1,29 +1,29 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(15,1): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(19,1): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived2'. Property 'baz' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(33,5): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(41,5): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived2'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(46,9): error TS2322: Type '{ [x: string]: Derived; }' is not assignable to type 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(47,9): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'T' is not assignable to type 'Derived'. Type 'Base' is not assignable to type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(50,9): error TS2322: Type '{ [x: string]: Derived2; }' is not assignable to type 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts(51,9): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'T' is not assignable to type 'Derived2'. Type 'Base' is not assignable to type 'Derived2'. @@ -46,7 +46,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b = a; // error ~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived'. !!! error TS2322: Property 'bar' is missing in type 'Base'. @@ -55,7 +55,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b2 = a; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. !!! error TS2322: Property 'baz' is missing in type 'Base'. @@ -74,7 +74,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b1 = a1; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived'. class B2 extends A { @@ -86,7 +86,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b2 = a1; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. function foo() { @@ -95,12 +95,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme a3 = b3; // error ~~ !!! error TS2322: Type '{ [x: string]: Derived; }' is not assignable to type 'A'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'Derived' is not assignable to type 'T'. b3 = a3; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived'. !!! error TS2322: Type 'Base' is not assignable to type 'Derived'. @@ -108,12 +108,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme a3 = b4; // error ~~ !!! error TS2322: Type '{ [x: string]: Derived2; }' is not assignable to type 'A'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'Derived2' is not assignable to type 'T'. b4 = a3; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived2'. !!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. } diff --git a/tests/baselines/reference/assignmentCompatWithStringIndexer2.errors.txt b/tests/baselines/reference/assignmentCompatWithStringIndexer2.errors.txt index 0b0d70d01bb51..d0d90fa09a9f8 100644 --- a/tests/baselines/reference/assignmentCompatWithStringIndexer2.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithStringIndexer2.errors.txt @@ -1,29 +1,29 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(15,1): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(19,1): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived2'. Property 'baz' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(33,5): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(41,5): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived2'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(46,9): error TS2322: Type '{ [x: string]: Derived; }' is not assignable to type 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(47,9): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'T' is not assignable to type 'Derived'. Type 'Base' is not assignable to type 'Derived'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(50,9): error TS2322: Type '{ [x: string]: Derived2; }' is not assignable to type 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts(51,9): error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'T' is not assignable to type 'Derived2'. Type 'Base' is not assignable to type 'Derived2'. @@ -46,7 +46,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b = a; // error ~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived'. !!! error TS2322: Property 'bar' is missing in type 'Base'. @@ -55,7 +55,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b2 = a; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. !!! error TS2322: Property 'baz' is missing in type 'Base'. @@ -74,7 +74,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b1 = a1; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived'. interface B2 extends A { @@ -86,7 +86,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme b2 = a1; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. function foo() { @@ -95,12 +95,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme a3 = b3; // error ~~ !!! error TS2322: Type '{ [x: string]: Derived; }' is not assignable to type 'A'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'Derived' is not assignable to type 'T'. b3 = a3; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived'. !!! error TS2322: Type 'Base' is not assignable to type 'Derived'. @@ -108,12 +108,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme a3 = b4; // error ~~ !!! error TS2322: Type '{ [x: string]: Derived2; }' is not assignable to type 'A'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'Derived2' is not assignable to type 'T'. b4 = a3; // error ~~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: Derived2; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'Derived2'. !!! error TS2322: Type 'Base' is not assignable to type 'Derived2'. } diff --git a/tests/baselines/reference/assignmentCompatWithStringIndexer3.errors.txt b/tests/baselines/reference/assignmentCompatWithStringIndexer3.errors.txt index 4b4c03678d7eb..3b80d390c05d4 100644 --- a/tests/baselines/reference/assignmentCompatWithStringIndexer3.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithStringIndexer3.errors.txt @@ -1,9 +1,9 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer3.ts(7,8): error TS2304: Cannot find name 'A'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer3.ts(20,9): error TS2322: Type '{ [x: string]: string; }' is not assignable to type 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'string' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer3.ts(21,9): error TS2322: Type 'A' is not assignable to type '{ [x: string]: string; }'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'T' is not assignable to type 'string'. Type 'Derived' is not assignable to type 'string'. @@ -33,12 +33,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme a = b; // error ~ !!! error TS2322: Type '{ [x: string]: string; }' is not assignable to type 'A'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'string' is not assignable to type 'T'. b = a; // error ~ !!! error TS2322: Type 'A' is not assignable to type '{ [x: string]: string; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'T' is not assignable to type 'string'. !!! error TS2322: Type 'Derived' is not assignable to type 'string'. } diff --git a/tests/baselines/reference/classIndexer2.errors.txt b/tests/baselines/reference/classIndexer2.errors.txt index c916ca27846b4..3d4288ec67686 100644 --- a/tests/baselines/reference/classIndexer2.errors.txt +++ b/tests/baselines/reference/classIndexer2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/classIndexer2.ts(4,5): error TS2411: Property 'y' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/classIndexer2.ts(4,5): error TS2411: Property 'y' of type 'string' is not assignable to 'string' index type 'number'. ==== tests/cases/compiler/classIndexer2.ts (1 errors) ==== @@ -7,7 +7,7 @@ tests/cases/compiler/classIndexer2.ts(4,5): error TS2411: Property 'y' of type ' x: number; y: string; ~ -!!! error TS2411: Property 'y' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property 'y' of type 'string' is not assignable to 'string' index type 'number'. constructor() { } } \ No newline at end of file diff --git a/tests/baselines/reference/classIndexer3.errors.txt b/tests/baselines/reference/classIndexer3.errors.txt index fbd4b35327fd6..e26993de3f8da 100644 --- a/tests/baselines/reference/classIndexer3.errors.txt +++ b/tests/baselines/reference/classIndexer3.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/classIndexer3.ts(9,5): error TS2411: Property 'y' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/classIndexer3.ts(9,5): error TS2411: Property 'y' of type 'string' is not assignable to 'string' index type 'number'. ==== tests/cases/compiler/classIndexer3.ts (1 errors) ==== @@ -12,5 +12,5 @@ tests/cases/compiler/classIndexer3.ts(9,5): error TS2411: Property 'y' of type ' x: number; y: string; ~ -!!! error TS2411: Property 'y' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property 'y' of type 'string' is not assignable to 'string' index type 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/classIndexer4.errors.txt b/tests/baselines/reference/classIndexer4.errors.txt index 5375f9610d739..d962f959f683d 100644 --- a/tests/baselines/reference/classIndexer4.errors.txt +++ b/tests/baselines/reference/classIndexer4.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/classIndexer4.ts(9,5): error TS2411: Property 'y' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/classIndexer4.ts(9,5): error TS2411: Property 'y' of type 'string' is not assignable to 'string' index type 'number'. ==== tests/cases/compiler/classIndexer4.ts (1 errors) ==== @@ -12,5 +12,5 @@ tests/cases/compiler/classIndexer4.ts(9,5): error TS2411: Property 'y' of type ' x: number; y: string; ~ -!!! error TS2411: Property 'y' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property 'y' of type 'string' is not assignable to 'string' index type 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames36_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames36_ES5.errors.txt index 506a9ca15d157..8eb67ef790d94 100644 --- a/tests/baselines/reference/computedPropertyNames36_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames36_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames36_ES5.ts(8,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames36_ES5.ts(8,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames36_ES5.ts (1 errors) ==== @@ -11,6 +11,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames36_ES5.ts(8, // Computed properties get ["get1"]() { return new Foo } ~~~~~~~~ -!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. set ["set1"](p: Foo2) { } } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames36_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames36_ES6.errors.txt index cf50807ac5403..dff4c670ec9b4 100644 --- a/tests/baselines/reference/computedPropertyNames36_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames36_ES6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames36_ES6.ts(8,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames36_ES6.ts(8,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames36_ES6.ts (1 errors) ==== @@ -11,6 +11,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames36_ES6.ts(8, // Computed properties get ["get1"]() { return new Foo } ~~~~~~~~ -!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. set ["set1"](p: Foo2) { } } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames38_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames38_ES5.errors.txt index 2e5313caa4108..63bd17dadb7a6 100644 --- a/tests/baselines/reference/computedPropertyNames38_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames38_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames38_ES5.ts(8,9): error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames38_ES5.ts(8,9): error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames38_ES5.ts (1 errors) ==== @@ -11,6 +11,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames38_ES5.ts(8, // Computed properties get [1 << 6]() { return new Foo } ~~~~~~~~ -!!! error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. set [1 << 6](p: Foo2) { } } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames38_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames38_ES6.errors.txt index 4c6e78c5b04f5..be02438c91008 100644 --- a/tests/baselines/reference/computedPropertyNames38_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames38_ES6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames38_ES6.ts(8,9): error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames38_ES6.ts(8,9): error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames38_ES6.ts (1 errors) ==== @@ -11,6 +11,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames38_ES6.ts(8, // Computed properties get [1 << 6]() { return new Foo } ~~~~~~~~ -!!! error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. set [1 << 6](p: Foo2) { } } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames39_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames39_ES5.errors.txt index a204ef4ae3402..ebc1eada2f0c2 100644 --- a/tests/baselines/reference/computedPropertyNames39_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames39_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames39_ES5.ts(8,9): error TS2412: Property '[1 << 6]' of type 'Foo' is not assignable to numeric index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames39_ES5.ts(8,9): error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to 'number' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames39_ES5.ts (1 errors) ==== @@ -11,6 +11,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames39_ES5.ts(8, // Computed properties get [1 << 6]() { return new Foo } ~~~~~~~~ -!!! error TS2412: Property '[1 << 6]' of type 'Foo' is not assignable to numeric index type 'Foo2'. +!!! error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to 'number' index type 'Foo2'. set [1 << 6](p: Foo2) { } } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames39_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames39_ES6.errors.txt index d2e2494c87ab5..471f4f32e5652 100644 --- a/tests/baselines/reference/computedPropertyNames39_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames39_ES6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames39_ES6.ts(8,9): error TS2412: Property '[1 << 6]' of type 'Foo' is not assignable to numeric index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames39_ES6.ts(8,9): error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to 'number' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames39_ES6.ts (1 errors) ==== @@ -11,6 +11,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames39_ES6.ts(8, // Computed properties get [1 << 6]() { return new Foo } ~~~~~~~~ -!!! error TS2412: Property '[1 << 6]' of type 'Foo' is not assignable to numeric index type 'Foo2'. +!!! error TS2411: Property '[1 << 6]' of type 'Foo' is not assignable to 'number' index type 'Foo2'. set [1 << 6](p: Foo2) { } } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames40_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames40_ES5.errors.txt index 40a9e9a2e3d0f..5141b2d373d5e 100644 --- a/tests/baselines/reference/computedPropertyNames40_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames40_ES5.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES5.ts(8,5): error TS2393: Duplicate function implementation. -tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES5.ts(8,5): error TS2411: Property '[""]' of type '() => Foo' is not assignable to string index type '() => Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES5.ts(8,5): error TS2411: Property '[""]' of type '() => Foo' is not assignable to 'string' index type '() => Foo2'. tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES5.ts(9,5): error TS2393: Duplicate function implementation. @@ -15,7 +15,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES5.ts(9, ~~~~ !!! error TS2393: Duplicate function implementation. ~~~~ -!!! error TS2411: Property '[""]' of type '() => Foo' is not assignable to string index type '() => Foo2'. +!!! error TS2411: Property '[""]' of type '() => Foo' is not assignable to 'string' index type '() => Foo2'. [""]() { return new Foo2 } ~~~~ !!! error TS2393: Duplicate function implementation. diff --git a/tests/baselines/reference/computedPropertyNames40_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames40_ES6.errors.txt index 10c0a456dbea8..52f5515d3081b 100644 --- a/tests/baselines/reference/computedPropertyNames40_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames40_ES6.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES6.ts(8,5): error TS2393: Duplicate function implementation. -tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES6.ts(8,5): error TS2411: Property '[""]' of type '() => Foo' is not assignable to string index type '() => Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES6.ts(8,5): error TS2411: Property '[""]' of type '() => Foo' is not assignable to 'string' index type '() => Foo2'. tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES6.ts(9,5): error TS2393: Duplicate function implementation. @@ -15,7 +15,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames40_ES6.ts(9, ~~~~ !!! error TS2393: Duplicate function implementation. ~~~~ -!!! error TS2411: Property '[""]' of type '() => Foo' is not assignable to string index type '() => Foo2'. +!!! error TS2411: Property '[""]' of type '() => Foo' is not assignable to 'string' index type '() => Foo2'. [""]() { return new Foo2 } ~~~~ !!! error TS2393: Duplicate function implementation. diff --git a/tests/baselines/reference/computedPropertyNames42_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames42_ES5.errors.txt index 0eeff51837e5f..1804df306fcbb 100644 --- a/tests/baselines/reference/computedPropertyNames42_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames42_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES5.ts(8,5): error TS2411: Property '[""]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES5.ts(8,5): error TS2411: Property '[""]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES5.ts (1 errors) ==== @@ -11,5 +11,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES5.ts(8, // Computed properties [""]: Foo; ~~~~ -!!! error TS2411: Property '[""]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '[""]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames42_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames42_ES6.errors.txt index 3dcd6e898ed9b..3459652914ff0 100644 --- a/tests/baselines/reference/computedPropertyNames42_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames42_ES6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES6.ts(8,5): error TS2411: Property '[""]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES6.ts(8,5): error TS2411: Property '[""]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES6.ts (1 errors) ==== @@ -11,5 +11,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES6.ts(8, // Computed properties [""]: Foo; ~~~~ -!!! error TS2411: Property '[""]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '[""]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames43_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames43_ES5.errors.txt index d777ae659defd..4b5546487f2c7 100644 --- a/tests/baselines/reference/computedPropertyNames43_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames43_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames43_ES5.ts(10,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames43_ES5.ts(10,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames43_ES5.ts (1 errors) ==== @@ -13,6 +13,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames43_ES5.ts(10 // Computed properties get ["get1"]() { return new Foo } ~~~~~~~~ -!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. set ["set1"](p: Foo2) { } } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames43_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames43_ES6.errors.txt index 6af43ebfa5cb3..7110b7f6c76db 100644 --- a/tests/baselines/reference/computedPropertyNames43_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames43_ES6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames43_ES6.ts(10,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames43_ES6.ts(10,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames43_ES6.ts (1 errors) ==== @@ -13,6 +13,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames43_ES6.ts(10 // Computed properties get ["get1"]() { return new Foo } ~~~~~~~~ -!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. set ["set1"](p: Foo2) { } } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames44_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames44_ES5.errors.txt index 43801ab3d627b..1c22a30588daf 100644 --- a/tests/baselines/reference/computedPropertyNames44_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames44_ES5.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames44_ES5.ts(6,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames44_ES5.ts(10,9): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames44_ES5.ts(6,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames44_ES5.ts(10,9): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames44_ES5.ts (2 errors) ==== @@ -10,11 +10,11 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames44_ES5.ts(10 [s: string]: Foo2; get ["get1"]() { return new Foo } ~~~~~~~~ -!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. } class D extends C { set ["set1"](p: Foo) { } ~~~~~~~~ -!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames44_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames44_ES6.errors.txt index 28b861347a37e..d602cdbe6620c 100644 --- a/tests/baselines/reference/computedPropertyNames44_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames44_ES6.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames44_ES6.ts(6,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames44_ES6.ts(10,9): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames44_ES6.ts(6,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames44_ES6.ts(10,9): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames44_ES6.ts (2 errors) ==== @@ -10,11 +10,11 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames44_ES6.ts(10 [s: string]: Foo2; get ["get1"]() { return new Foo } ~~~~~~~~ -!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. } class D extends C { set ["set1"](p: Foo) { } ~~~~~~~~ -!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames45_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames45_ES5.errors.txt index f06d199ba5af5..dca0d5f5a16ba 100644 --- a/tests/baselines/reference/computedPropertyNames45_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames45_ES5.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(5,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(11,9): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(5,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(11,9): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts (2 errors) ==== @@ -9,7 +9,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(11 class C { get ["get1"]() { return new Foo } ~~~~~~~~ -!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. } class D extends C { @@ -17,5 +17,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(11 [s: string]: Foo2; set ["set1"](p: Foo) { } ~~~~~~~~ -!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNames45_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames45_ES6.errors.txt index 626ed14ad1ad3..5bd2d5caa4a44 100644 --- a/tests/baselines/reference/computedPropertyNames45_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames45_ES6.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(5,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. -tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(11,9): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(5,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(11,9): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts (2 errors) ==== @@ -9,7 +9,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(11 class C { get ["get1"]() { return new Foo } ~~~~~~~~ -!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. } class D extends C { @@ -17,5 +17,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(11 [s: string]: Foo2; set ["set1"](p: Foo) { } ~~~~~~~~ -!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to string index type 'Foo2'. +!!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.errors.txt index 7fa95fe942616..dbcdb5acada0a 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesContextualType10_ES5.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType10_ES5.ts(5,5): error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'string | number' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. @@ -12,7 +12,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualTy var o: I = { ~ !!! error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. !!! error TS2322: Type 'string' is not assignable to type 'boolean'. [+"foo"]: "", diff --git a/tests/baselines/reference/computedPropertyNamesContextualType10_ES6.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType10_ES6.errors.txt index 116cd1a25311e..bb84b1a83e866 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType10_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesContextualType10_ES6.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType10_ES6.ts(5,5): error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'string | number' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. @@ -12,7 +12,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualTy var o: I = { ~ !!! error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. !!! error TS2322: Type 'string' is not assignable to type 'boolean'. [+"foo"]: "", diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types index fa02a5466786a..c95df02ee2870 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types @@ -17,7 +17,7 @@ declare function g(obj: J): T; >obj : J foo({ ->foo({ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | (() => void) | number[] +>foo({ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | boolean | (() => void) | number[] >foo : (obj: I) => T >{ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: number | boolean | (() => void) | number[]; [x: number]: number | (() => void) | number[]; 0: () => void; } diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types index d597cf031f900..065c26e84b39c 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types @@ -17,7 +17,7 @@ declare function g(obj: J): T; >obj : J foo({ ->foo({ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | (() => void) | number[] +>foo({ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | boolean | (() => void) | number[] >foo : (obj: I) => T >{ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: number | boolean | (() => void) | number[]; [x: number]: number | (() => void) | number[]; 0: () => void; } diff --git a/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.errors.txt index e76b3a704dc6e..a5f5ece12ebd1 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9_ES5.ts(6,5): error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'string | number' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. @@ -13,7 +13,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualTy var o: I = { ~ !!! error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. !!! error TS2322: Type 'string' is not assignable to type 'boolean'. [+"foo"]: "", diff --git a/tests/baselines/reference/computedPropertyNamesContextualType9_ES6.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType9_ES6.errors.txt index 468ad400c26cc..1580cba2b7deb 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType9_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesContextualType9_ES6.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9_ES6.ts(6,5): error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'string | number' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. @@ -13,7 +13,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualTy var o: I = { ~ !!! error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. !!! error TS2322: Type 'string' is not assignable to type 'boolean'. [+"foo"]: "", diff --git a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt index be73de51f138b..1eca3b140a896 100644 --- a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt +++ b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '(number | Date)[]' is not assignable to type 'I'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'number | Date' is not assignable to type 'Date'. Type 'number' is not assignable to type 'Date'. @@ -12,7 +12,7 @@ tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Typ var x3: I = [new Date(), 1]; ~~ !!! error TS2322: Type '(number | Date)[]' is not assignable to type 'I'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'number' index signatures are incompatible. !!! error TS2322: Type 'number | Date' is not assignable to type 'Date'. !!! error TS2322: Type 'number' is not assignable to type 'Date'. var r2 = x3[1]; diff --git a/tests/baselines/reference/declFileTypeAnnotationTypeLiteral.types b/tests/baselines/reference/declFileTypeAnnotationTypeLiteral.types index 30d386b6c17d2..72dbb5251d20f 100644 --- a/tests/baselines/reference/declFileTypeAnnotationTypeLiteral.types +++ b/tests/baselines/reference/declFileTypeAnnotationTypeLiteral.types @@ -15,7 +15,7 @@ module m { // Object literal with everything var x: { ->x : { (a: number): c; (a: string): g; new (a: number): c; new (a: string): m.c; [n: string]: c; [n: number]: c; a: c; b: g; m1(): g; m2(a: string, b?: number, ...c: c[]): string; } +>x : { (a: number): c; (a: string): g; new (a: number): c; new (a: string): m.c; [n: number]: c; [n: string]: c; a: c; b: g; m1(): g; m2(a: string, b?: number, ...c: c[]): string; } // Call signatures (a: number): c; diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js index ecb3e035e2a39..91dd33f2c11dd 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js @@ -86,8 +86,8 @@ declare module m { }; var x3: { (): m2.public1[]; - [s: string]: m2.public1; [n: number]: private1; + [s: string]: m2.public1; x: private1; y: m2.public1; method(): private1; diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.types b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.types index 7acd7e779f072..e5be6e753fe70 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.types +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.types @@ -14,7 +14,7 @@ module m { } export var x: { ->x : { (): m2.public1[]; [s: string]: m2.public1; [n: number]: private1; x: private1; y: m2.public1; method(): private1; } +>x : { (): m2.public1[]; [n: number]: private1; [s: string]: m2.public1; x: private1; y: m2.public1; method(): private1; } x: private1; >x : private1 @@ -62,8 +62,8 @@ module m { } }; export var x3 = x; ->x3 : { (): m2.public1[]; [s: string]: m2.public1; [n: number]: private1; x: private1; y: m2.public1; method(): private1; } ->x : { (): m2.public1[]; [s: string]: m2.public1; [n: number]: private1; x: private1; y: m2.public1; method(): private1; } +>x3 : { (): m2.public1[]; [n: number]: private1; [s: string]: m2.public1; x: private1; y: m2.public1; method(): private1; } +>x : { (): m2.public1[]; [n: number]: private1; [s: string]: m2.public1; x: private1; y: m2.public1; method(): private1; } // Function type export var y: (a: private1) => m2.public1; diff --git a/tests/baselines/reference/derivedInterfaceIncompatibleWithBaseIndexer.errors.txt b/tests/baselines/reference/derivedInterfaceIncompatibleWithBaseIndexer.errors.txt index 904a6f5fe34f2..27688dcaf86b1 100644 --- a/tests/baselines/reference/derivedInterfaceIncompatibleWithBaseIndexer.errors.txt +++ b/tests/baselines/reference/derivedInterfaceIncompatibleWithBaseIndexer.errors.txt @@ -1,13 +1,11 @@ -tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(7,5): error TS2411: Property '1' of type '{ y: number; }' is not assignable to string index type '{ x: number; }'. -tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(7,5): error TS2412: Property '1' of type '{ y: number; }' is not assignable to numeric index type '{ x: number; y: number; }'. -tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(11,5): error TS2411: Property ''1'' of type '{ y: number; }' is not assignable to string index type '{ x: number; }'. -tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(11,5): error TS2412: Property ''1'' of type '{ y: number; }' is not assignable to numeric index type '{ x: number; y: number; }'. -tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(15,5): error TS2411: Property 'foo' of type '{ y: number; }' is not assignable to string index type '{ x: number; }'. -tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(19,5): error TS2411: Property 'foo' of type '() => { x: number; }' is not assignable to string index type '{ x: number; }'. -tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(24,5): error TS2412: Property '1' of type '{ x: number; }' is not assignable to numeric index type '{ x: number; y: number; }'. +tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(7,5): error TS2411: Property '1' of type '{ y: number; }' is not assignable to 'number' index type '{ x: number; y: number; }'. +tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(11,5): error TS2411: Property ''1'' of type '{ y: number; }' is not assignable to 'number' index type '{ x: number; y: number; }'. +tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(15,5): error TS2411: Property 'foo' of type '{ y: number; }' is not assignable to 'string' index type '{ x: number; }'. +tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(19,5): error TS2411: Property 'foo' of type '() => { x: number; }' is not assignable to 'string' index type '{ x: number; }'. +tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(24,5): error TS2411: Property '1' of type '{ x: number; }' is not assignable to 'number' index type '{ x: number; y: number; }'. -==== tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts (7 errors) ==== +==== tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts (5 errors) ==== interface Base { [x: number]: { x: number; y: number; }; [x: string]: { x: number; } @@ -16,36 +14,32 @@ tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompa interface Derived extends Base { 1: { y: number } // error ~ -!!! error TS2411: Property '1' of type '{ y: number; }' is not assignable to string index type '{ x: number; }'. - ~ -!!! error TS2412: Property '1' of type '{ y: number; }' is not assignable to numeric index type '{ x: number; y: number; }'. +!!! error TS2411: Property '1' of type '{ y: number; }' is not assignable to 'number' index type '{ x: number; y: number; }'. } interface Derived2 extends Base { '1': { y: number } // error ~~~ -!!! error TS2411: Property ''1'' of type '{ y: number; }' is not assignable to string index type '{ x: number; }'. - ~~~ -!!! error TS2412: Property ''1'' of type '{ y: number; }' is not assignable to numeric index type '{ x: number; y: number; }'. +!!! error TS2411: Property ''1'' of type '{ y: number; }' is not assignable to 'number' index type '{ x: number; y: number; }'. } interface Derived3 extends Base { foo: { y: number } // error ~~~ -!!! error TS2411: Property 'foo' of type '{ y: number; }' is not assignable to string index type '{ x: number; }'. +!!! error TS2411: Property 'foo' of type '{ y: number; }' is not assignable to 'string' index type '{ x: number; }'. } interface Derived4 extends Base { foo(): { x: number } // error ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo' of type '() => { x: number; }' is not assignable to string index type '{ x: number; }'. +!!! error TS2411: Property 'foo' of type '() => { x: number; }' is not assignable to 'string' index type '{ x: number; }'. } // satisifies string indexer but not numeric indexer interface Derived5 extends Base { 1: { x: number } // error ~ -!!! error TS2412: Property '1' of type '{ x: number; }' is not assignable to numeric index type '{ x: number; y: number; }'. +!!! error TS2411: Property '1' of type '{ x: number; }' is not assignable to 'number' index type '{ x: number; y: number; }'. } interface Derived5 extends Base { diff --git a/tests/baselines/reference/derivedTypeIncompatibleSignatures.errors.txt b/tests/baselines/reference/derivedTypeIncompatibleSignatures.errors.txt index 71fe36660c496..f02bfa2bc14fd 100644 --- a/tests/baselines/reference/derivedTypeIncompatibleSignatures.errors.txt +++ b/tests/baselines/reference/derivedTypeIncompatibleSignatures.errors.txt @@ -1,8 +1,8 @@ tests/cases/compiler/derivedTypeIncompatibleSignatures.ts(21,11): error TS2430: Interface 'F' incorrectly extends interface 'E'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'number' is not assignable to type 'string'. tests/cases/compiler/derivedTypeIncompatibleSignatures.ts(29,11): error TS2430: Interface 'H' incorrectly extends interface 'G'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'number' is not assignable to type 'string'. @@ -30,7 +30,7 @@ tests/cases/compiler/derivedTypeIncompatibleSignatures.ts(29,11): error TS2430: interface F extends E { ~ !!! error TS2430: Interface 'F' incorrectly extends interface 'E'. -!!! error TS2430: Index signatures are incompatible. +!!! error TS2430: 'string' index signatures are incompatible. !!! error TS2430: Type 'number' is not assignable to type 'string'. [a: string]: number; // Number is not a subtype of string. Should error. } @@ -42,7 +42,7 @@ tests/cases/compiler/derivedTypeIncompatibleSignatures.ts(29,11): error TS2430: interface H extends G { ~ !!! error TS2430: Interface 'H' incorrectly extends interface 'G'. -!!! error TS2430: Index signatures are incompatible. +!!! error TS2430: 'number' index signatures are incompatible. !!! error TS2430: Type 'number' is not assignable to type 'string'. [a: number]: number; // Should error for the same reason } \ No newline at end of file diff --git a/tests/baselines/reference/duplicateNumericIndexers.types b/tests/baselines/reference/duplicateNumericIndexers.types index 1afadfe1bdae7..4e12db0474207 100644 --- a/tests/baselines/reference/duplicateNumericIndexers.types +++ b/tests/baselines/reference/duplicateNumericIndexers.types @@ -44,7 +44,7 @@ interface I { } var a: { ->a : { [x: number]: string; } +>a : { [x: number]: string; [x: number]: string; } [x: number]: string; >x : number diff --git a/tests/baselines/reference/duplicateStringIndexers.types b/tests/baselines/reference/duplicateStringIndexers.types index d1381878aad96..749e5dd17bfbf 100644 --- a/tests/baselines/reference/duplicateStringIndexers.types +++ b/tests/baselines/reference/duplicateStringIndexers.types @@ -47,7 +47,7 @@ module test { } var a: { ->a : { [x: string]: string; } +>a : { [x: string]: string; [x: string]: string; } [x: string]: string; >x : string diff --git a/tests/baselines/reference/enumIsNotASubtypeOfAnythingButNumber.errors.txt b/tests/baselines/reference/enumIsNotASubtypeOfAnythingButNumber.errors.txt index 225c0d811bc04..04115bcfb04f0 100644 --- a/tests/baselines/reference/enumIsNotASubtypeOfAnythingButNumber.errors.txt +++ b/tests/baselines/reference/enumIsNotASubtypeOfAnythingButNumber.errors.txt @@ -1,19 +1,19 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(18,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'string'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(24,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'boolean'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(30,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(36,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'RegExp'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(42,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type '{ bar: number; }'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(48,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'number[]'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(54,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'I8'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(60,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'A'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(66,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'A2'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(72,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type '(x: any) => number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(78,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type '(x: T) => T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(85,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'E2'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(95,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'typeof f'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(105,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'typeof c'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(111,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(117,5): error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(18,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(24,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'boolean'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(30,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'Date'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(36,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'RegExp'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(42,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type '{ bar: number; }'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(48,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'number[]'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(54,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'I8'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(60,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'A'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(66,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'A2'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(72,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type '(x: any) => number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(78,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type '(x: T) => T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(85,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'E2'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(95,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'typeof f'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(105,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'typeof c'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(111,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts(117,5): error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'U'. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotASubtypeOfAnythingButNumber.ts (16 errors) ==== @@ -36,7 +36,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: string; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'string'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'string'. } @@ -44,7 +44,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: boolean; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'boolean'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'boolean'. } @@ -52,7 +52,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: Date; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'Date'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'Date'. } @@ -60,7 +60,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: RegExp; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'RegExp'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'RegExp'. } @@ -68,7 +68,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: { bar: number }; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type '{ bar: number; }'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type '{ bar: number; }'. } @@ -76,7 +76,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: number[]; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'number[]'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'number[]'. } @@ -84,7 +84,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: I8; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'I8'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'I8'. } class A { foo: number; } @@ -92,7 +92,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: A; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'A'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'A'. } class A2 { foo: T; } @@ -100,7 +100,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: A2; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'A2'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'A2'. } @@ -108,7 +108,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: (x) => number; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type '(x: any) => number'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type '(x: any) => number'. } @@ -116,7 +116,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: (x: T) => T; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type '(x: T) => T'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type '(x: T) => T'. } @@ -125,7 +125,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: E2; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'E2'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'E2'. } @@ -137,7 +137,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: typeof f; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'typeof f'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'typeof f'. } @@ -149,7 +149,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: typeof c; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'typeof c'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'typeof c'. } @@ -157,7 +157,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: T; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'T'. } @@ -165,7 +165,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/enumIsNotA [x: string]: U; foo: E; ~~~ -!!! error TS2411: Property 'foo' of type 'E' is not assignable to string index type 'U'. +!!! error TS2411: Property 'foo' of type 'E' is not assignable to 'string' index type 'U'. } diff --git a/tests/baselines/reference/functionAndInterfaceWithSeparateErrors.errors.txt b/tests/baselines/reference/functionAndInterfaceWithSeparateErrors.errors.txt index a87dc989178c5..479a543cbb2b2 100644 --- a/tests/baselines/reference/functionAndInterfaceWithSeparateErrors.errors.txt +++ b/tests/baselines/reference/functionAndInterfaceWithSeparateErrors.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/functionAndInterfaceWithSeparateErrors.ts(1,10): error TS2394: Overload signature is not compatible with function implementation. -tests/cases/compiler/functionAndInterfaceWithSeparateErrors.ts(6,5): error TS2411: Property 'prop' of type 'number' is not assignable to string index type 'string'. +tests/cases/compiler/functionAndInterfaceWithSeparateErrors.ts(6,5): error TS2411: Property 'prop' of type 'number' is not assignable to 'string' index type 'string'. ==== tests/cases/compiler/functionAndInterfaceWithSeparateErrors.ts (2 errors) ==== @@ -12,5 +12,5 @@ tests/cases/compiler/functionAndInterfaceWithSeparateErrors.ts(6,5): error TS241 [s: string]: string; prop: number; ~~~~ -!!! error TS2411: Property 'prop' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property 'prop' of type 'number' is not assignable to 'string' index type 'string'. } \ No newline at end of file diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexers.types b/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexers.types index 64b15afb8f155..fb9eed9d9a1b6 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexers.types +++ b/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexers.types @@ -52,8 +52,8 @@ function other(arg: T) { >1 : 1 var e = r2['1']; ->e : Object ->r2['1'] : Object +>e : T +>r2['1'] : T >r2 : { [x: string]: Object; [x: number]: T; } >'1' : "1" } diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexersErrors.types b/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexersErrors.types index 1e9b5d82c634e..7006fe613e109 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexersErrors.types +++ b/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexersErrors.types @@ -57,8 +57,8 @@ function other3(arg: T) { >1 : 1 var e = r2['1']; ->e : Object ->r2['1'] : Object +>e : T +>r2['1'] : T >r2 : { [x: string]: Object; [x: number]: T; } >'1' : "1" diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.types b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.types index 8763804f1b06c..171463fcdd96a 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.types +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.types @@ -21,7 +21,7 @@ declare var b: { (x: C): C }; >x : any declare var d: { [x: C]: C }; ->d : {} +>d : { [x: any]: any; } >x : any declare function f(x: C): C; diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.types b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.types index 3c32c79b5aabe..8075a2c93e6b0 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.types +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.types @@ -21,7 +21,7 @@ var b: { (x: C): C }; >x : any var d: { [x: C]: C }; ->d : {} +>d : { [x: any]: any; } >x : any var e = (x: C) => { var y: C; return y; } diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.types b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.types index 8aaf6e9585cac..634597893ff72 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.types +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.types @@ -19,7 +19,7 @@ var b: { (x: I): I }; >x : any var d: { [x: I]: I }; ->d : {} +>d : { [x: any]: any; } >x : any var e = (x: I) => { var y: I; return y; } diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.types b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.types index fd5c4c348cc8e..434314906e150 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.types +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.types @@ -21,7 +21,7 @@ declare var b: { (x: C): C }; >x : any declare var d: { [x: C]: C }; ->d : {} +>d : { [x: any]: any; } >x : any declare function f(x: C): C; diff --git a/tests/baselines/reference/indexSignatureAndMappedType.errors.txt b/tests/baselines/reference/indexSignatureAndMappedType.errors.txt index 623fcd11bd050..c077a5786869e 100644 --- a/tests/baselines/reference/indexSignatureAndMappedType.errors.txt +++ b/tests/baselines/reference/indexSignatureAndMappedType.errors.txt @@ -1,6 +1,7 @@ tests/cases/compiler/indexSignatureAndMappedType.ts(6,5): error TS2322: Type '{ [key: string]: T; }' is not assignable to type 'Record'. tests/cases/compiler/indexSignatureAndMappedType.ts(15,5): error TS2322: Type 'Record' is not assignable to type '{ [key: string]: T; }'. - Type 'U' is not assignable to type 'T'. + 'string' index signatures are incompatible. + Type 'U' is not assignable to type 'T'. tests/cases/compiler/indexSignatureAndMappedType.ts(16,5): error TS2322: Type '{ [key: string]: T; }' is not assignable to type 'Record'. @@ -24,7 +25,8 @@ tests/cases/compiler/indexSignatureAndMappedType.ts(16,5): error TS2322: Type '{ x = y; // Error ~ !!! error TS2322: Type 'Record' is not assignable to type '{ [key: string]: T; }'. -!!! error TS2322: Type 'U' is not assignable to type 'T'. +!!! error TS2322: 'string' index signatures are incompatible. +!!! error TS2322: Type 'U' is not assignable to type 'T'. y = x; // Error ~ !!! error TS2322: Type '{ [key: string]: T; }' is not assignable to type 'Record'. diff --git a/tests/baselines/reference/indexTypeCheck.errors.txt b/tests/baselines/reference/indexTypeCheck.errors.txt index 9d839e9eb3022..6b82a1a2570a0 100644 --- a/tests/baselines/reference/indexTypeCheck.errors.txt +++ b/tests/baselines/reference/indexTypeCheck.errors.txt @@ -1,8 +1,13 @@ tests/cases/compiler/indexTypeCheck.ts(2,2): error TS1021: An index signature must have a type annotation. tests/cases/compiler/indexTypeCheck.ts(3,2): error TS1021: An index signature must have a type annotation. -tests/cases/compiler/indexTypeCheck.ts(17,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. -tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'. -tests/cases/compiler/indexTypeCheck.ts(27,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. +tests/cases/compiler/indexTypeCheck.ts(17,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(22,2): error TS2413: 'number' index type 'Orange' is not assignable to 'string' index type 'Yellow'. + Type 'Orange' is not assignable to type 'Yellow'. + 'number' index signatures are incompatible. + Type 'number' is not assignable to type 'Red'. +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(51,8): error TS2538: Type 'Blue' cannot be used as an index type. @@ -31,21 +36,26 @@ tests/cases/compiler/indexTypeCheck.ts(51,8): error TS2538: Type 'Blue' cannot b interface Orange { [n:number]: number; // ok ~~~~~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. +!!! error TS2413: 'number' index type 'number' is not assignable to 'string' index type 'string'. +!!! error TS2413: Type 'number' is not assignable to type 'string'. [s:string]: string; // error } interface Green { [n:number]: Orange; // error ~~~~~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'. +!!! error TS2413: 'number' index type 'Orange' is not assignable to 'string' index type 'Yellow'. +!!! error TS2413: Type 'Orange' is not assignable to type 'Yellow'. +!!! error TS2413: 'number' index signatures are incompatible. +!!! error TS2413: Type 'number' is not assignable to type 'Red'. [s:string]: Yellow; // ok } interface Cyan { [n:number]: number; // error ~~~~~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'number' is not assignable to string index type 'string'. +!!! error TS2413: 'number' index type 'number' is not assignable to 'string' index type 'string'. +!!! error TS2413: Type 'number' is not assignable to type 'string'. [s:string]: string; // ok } diff --git a/tests/baselines/reference/indexerConstraints.errors.txt b/tests/baselines/reference/indexerConstraints.errors.txt index cb7785535d18a..3652d5bcf0086 100644 --- a/tests/baselines/reference/indexerConstraints.errors.txt +++ b/tests/baselines/reference/indexerConstraints.errors.txt @@ -1,7 +1,12 @@ -tests/cases/compiler/indexerConstraints.ts(17,5): error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. -tests/cases/compiler/indexerConstraints.ts(25,5): error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. -tests/cases/compiler/indexerConstraints.ts(33,5): error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. -tests/cases/compiler/indexerConstraints.ts(41,5): error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. +tests/cases/compiler/indexerConstraints.ts(17,5): error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'. + Type 'A' is not assignable to type 'B'. + Property 'b' is missing in type 'A'. +tests/cases/compiler/indexerConstraints.ts(25,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/indexerConstraints.ts(33,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/indexerConstraints.ts(41,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/indexerConstraints.ts (4 errors) ==== @@ -23,7 +28,9 @@ tests/cases/compiler/indexerConstraints.ts(41,5): error TS2413: Numeric index ty interface E { [n: number]: A; ~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. +!!! error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'. +!!! error TS2413: Type 'A' is not assignable to type 'B'. +!!! error TS2413: Property 'b' is missing in type 'A'. } // Inheritance @@ -33,7 +40,8 @@ tests/cases/compiler/indexerConstraints.ts(41,5): error TS2413: Numeric index ty interface G extends F { [n: number]: A; ~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. +!!! error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'. +!!! error TS2413: Type 'A' is not assignable to type 'B'. } // Other way @@ -43,7 +51,8 @@ tests/cases/compiler/indexerConstraints.ts(41,5): error TS2413: Numeric index ty interface I extends H { [s: string]: B; ~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. +!!! error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'. +!!! error TS2413: Type 'A' is not assignable to type 'B'. } // With hidden indexer @@ -53,6 +62,7 @@ tests/cases/compiler/indexerConstraints.ts(41,5): error TS2413: Numeric index ty interface K extends J { [n: number]: A; ~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. +!!! error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'. +!!! error TS2413: Type 'A' is not assignable to type 'B'. [s: string]: B; } \ No newline at end of file diff --git a/tests/baselines/reference/indexerConstraints2.errors.txt b/tests/baselines/reference/indexerConstraints2.errors.txt index 7e104e77f9865..da7bca6f437d2 100644 --- a/tests/baselines/reference/indexerConstraints2.errors.txt +++ b/tests/baselines/reference/indexerConstraints2.errors.txt @@ -1,6 +1,10 @@ -tests/cases/compiler/indexerConstraints2.ts(9,5): error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. -tests/cases/compiler/indexerConstraints2.ts(17,5): error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. -tests/cases/compiler/indexerConstraints2.ts(26,5): error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. +tests/cases/compiler/indexerConstraints2.ts(9,5): error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'. + Type 'A' is not assignable to type 'B'. + Property 'b' is missing in type 'A'. +tests/cases/compiler/indexerConstraints2.ts(17,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(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'. @@ -22,7 +26,9 @@ tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signat class G extends F { [n: number]: A ~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. +!!! error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'. +!!! error TS2413: Type 'A' is not assignable to type 'B'. +!!! error TS2413: Property 'b' is missing in type 'A'. } // Other way @@ -32,7 +38,8 @@ tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signat class I extends H { [s: string]: B ~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. +!!! error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'. +!!! error TS2413: Type 'A' is not assignable to type 'B'. } // With hidden indexer @@ -43,7 +50,8 @@ tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signat class K extends J { [n: number]: A; ~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'A' is not assignable to string index type 'B'. +!!! error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'. +!!! error TS2413: Type 'A' is not assignable to type 'B'. [s: string]: B; } diff --git a/tests/baselines/reference/inheritedMembersAndIndexSignaturesFromDifferentBases.errors.txt b/tests/baselines/reference/inheritedMembersAndIndexSignaturesFromDifferentBases.errors.txt index d2ad69730dad7..89a6c91d79db3 100644 --- a/tests/baselines/reference/inheritedMembersAndIndexSignaturesFromDifferentBases.errors.txt +++ b/tests/baselines/reference/inheritedMembersAndIndexSignaturesFromDifferentBases.errors.txt @@ -1,12 +1,10 @@ -tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(17,11): error TS2411: Property 'm' of type '{}' is not assignable to string index type '{ a: any; }'. -tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(23,11): error TS2411: Property '0' of type '{}' is not assignable to string index type '{ a: any; }'. -tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(23,11): error TS2412: Property '0' of type '{}' is not assignable to numeric index type '{ a: any; b: any; }'. -tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(25,11): error TS2411: Property '0' of type '{}' is not assignable to string index type '{ a: any; }'. -tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(25,11): error TS2411: Property 'm' of type '{}' is not assignable to string index type '{ a: any; }'. -tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(25,11): error TS2412: Property '0' of type '{}' is not assignable to numeric index type '{ a: any; b: any; }'. +tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(17,11): error TS2411: Property 'm' of type '{}' is not assignable to 'string' index type '{ a: any; }'. +tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(23,11): error TS2411: Property '0' of type '{}' is not assignable to 'number' index type '{ a: any; b: any; }'. +tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(25,11): error TS2411: Property '0' of type '{}' is not assignable to 'number' index type '{ a: any; b: any; }'. +tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(25,11): error TS2411: Property 'm' of type '{}' is not assignable to 'string' index type '{ a: any; }'. -==== tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts (6 errors) ==== +==== tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts (4 errors) ==== // indexer in B is a subtype of indexer in A interface A { [s: string]: { @@ -25,7 +23,7 @@ tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(25, interface D extends A, B, C { } // error because m is not a subtype of {a;} ~ -!!! error TS2411: Property 'm' of type '{}' is not assignable to string index type '{ a: any; }'. +!!! error TS2411: Property 'm' of type '{}' is not assignable to 'string' index type '{ a: any; }'. interface E { 0: {}; @@ -33,16 +31,12 @@ tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(25, interface F extends A, B, E { } // error because 0 is not a subtype of {a; b;} ~ -!!! error TS2411: Property '0' of type '{}' is not assignable to string index type '{ a: any; }'. - ~ -!!! error TS2412: Property '0' of type '{}' is not assignable to numeric index type '{ a: any; b: any; }'. +!!! error TS2411: Property '0' of type '{}' is not assignable to 'number' index type '{ a: any; b: any; }'. interface G extends A, B, C, E { } // should only report one error ~ -!!! error TS2411: Property '0' of type '{}' is not assignable to string index type '{ a: any; }'. - ~ -!!! error TS2411: Property 'm' of type '{}' is not assignable to string index type '{ a: any; }'. +!!! error TS2411: Property '0' of type '{}' is not assignable to 'number' index type '{ a: any; b: any; }'. ~ -!!! error TS2412: Property '0' of type '{}' is not assignable to numeric index type '{ a: any; b: any; }'. +!!! error TS2411: Property 'm' of type '{}' is not assignable to 'string' index type '{ a: any; }'. interface H extends A, F { } // Should report no error at all because error is internal to F \ No newline at end of file diff --git a/tests/baselines/reference/inheritedStringIndexersFromDifferentBaseTypes.errors.txt b/tests/baselines/reference/inheritedStringIndexersFromDifferentBaseTypes.errors.txt index b99efb5e157ce..26cd375f6ebef 100644 --- a/tests/baselines/reference/inheritedStringIndexersFromDifferentBaseTypes.errors.txt +++ b/tests/baselines/reference/inheritedStringIndexersFromDifferentBaseTypes.errors.txt @@ -1,8 +1,8 @@ tests/cases/compiler/inheritedStringIndexersFromDifferentBaseTypes.ts(13,11): error TS2430: Interface 'E' incorrectly extends interface 'D'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'number' is not assignable to type 'string'. tests/cases/compiler/inheritedStringIndexersFromDifferentBaseTypes.ts(28,11): error TS2430: Interface 'E2' incorrectly extends interface 'D2'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'number' is not assignable to type 'string'. @@ -22,7 +22,7 @@ tests/cases/compiler/inheritedStringIndexersFromDifferentBaseTypes.ts(28,11): er interface E extends A, D { } // error ~ !!! error TS2430: Interface 'E' incorrectly extends interface 'D'. -!!! error TS2430: Index signatures are incompatible. +!!! error TS2430: 'string' index signatures are incompatible. !!! error TS2430: Type 'number' is not assignable to type 'string'. @@ -41,5 +41,5 @@ tests/cases/compiler/inheritedStringIndexersFromDifferentBaseTypes.ts(28,11): er interface E2 extends A2, D2 { } // error ~~ !!! error TS2430: Interface 'E2' incorrectly extends interface 'D2'. -!!! error TS2430: Index signatures are incompatible. +!!! error TS2430: 'number' index signatures are incompatible. !!! error TS2430: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/inheritedStringIndexersFromDifferentBaseTypes2.errors.txt b/tests/baselines/reference/inheritedStringIndexersFromDifferentBaseTypes2.errors.txt index 8e6fc5b3158e3..16a0af7f79b3c 100644 --- a/tests/baselines/reference/inheritedStringIndexersFromDifferentBaseTypes2.errors.txt +++ b/tests/baselines/reference/inheritedStringIndexersFromDifferentBaseTypes2.errors.txt @@ -1,4 +1,6 @@ -tests/cases/compiler/inheritedStringIndexersFromDifferentBaseTypes2.ts(18,11): error TS2413: Numeric index type '{}' is not assignable to string index type '{ a: any; }'. +tests/cases/compiler/inheritedStringIndexersFromDifferentBaseTypes2.ts(18,11): error TS2413: 'number' index type '{}' is not assignable to 'string' index type '{ a: any; }'. + Type '{}' is not assignable to type '{ a: any; }'. + Property 'a' is missing in type '{}'. ==== tests/cases/compiler/inheritedStringIndexersFromDifferentBaseTypes2.ts (1 errors) ==== @@ -21,7 +23,9 @@ tests/cases/compiler/inheritedStringIndexersFromDifferentBaseTypes2.ts(18,11): e } interface E extends A, D { } // error ~ -!!! error TS2413: Numeric index type '{}' is not assignable to string index type '{ a: any; }'. +!!! error TS2413: 'number' index type '{}' is not assignable to 'string' index type '{ a: any; }'. +!!! error TS2413: Type '{}' is not assignable to type '{ a: any; }'. +!!! error TS2413: Property 'a' is missing in type '{}'. interface F extends A, D { [s: number]: { diff --git a/tests/baselines/reference/interfaceExtendingClass2.errors.txt b/tests/baselines/reference/interfaceExtendingClass2.errors.txt index 8c15a845ce845..117da5411d655 100644 --- a/tests/baselines/reference/interfaceExtendingClass2.errors.txt +++ b/tests/baselines/reference/interfaceExtendingClass2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(11,5): error TS2411: Property 'a' of type '{ toString: () => {}; }' is not assignable to string index type 'Object'. +tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(11,5): error TS2411: Property 'a' of type '{ toString: () => {}; }' is not assignable to 'string' index type 'Object'. tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(13,13): error TS1131: Property or signature expected. tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(14,9): error TS1128: Declaration or statement expected. tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClass2.ts(15,5): error TS1128: Declaration or statement expected. @@ -17,7 +17,7 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtending interface I2 extends Foo { // error a: { ~ -!!! error TS2411: Property 'a' of type '{ toString: () => {}; }' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'a' of type '{ toString: () => {}; }' is not assignable to 'string' index type 'Object'. toString: () => { return 1; ~~~~~~ diff --git a/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt b/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt index 87faadeb4a6db..a4598a54f029f 100644 --- a/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt +++ b/tests/baselines/reference/interfaceExtendsObjectIntersectionErrors.errors.txt @@ -33,10 +33,11 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(32,11): error TS2430: Interface 'I12' incorrectly extends interface 'typeof NX'. Types of property 'a' are incompatible. Type 'number' is not assignable to type '"hello"'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(33,29): error TS2411: Property 'a' of type 'string' is not assignable to string index type 'number'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(33,29): error TS2411: Property 'prototype' of type 'CX' is not assignable to string index type 'number'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(34,29): error TS2413: Numeric index type 'string' is not assignable to string index type 'number'. -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(35,29): error TS2411: Property 'a' of type '"hello"' is not assignable to string index type 'number'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(33,29): error TS2411: Property 'a' of type 'string' is not assignable to 'string' index type 'number'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(33,29): error TS2411: Property 'prototype' of type 'CX' is not assignable to 'string' index type 'number'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(34,29): error TS2413: 'number' index type 'string' is not assignable to 'string' index type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(35,29): error TS2411: Property 'a' of type '"hello"' is not assignable to 'string' index type 'number'. tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.ts(39,11): error TS2430: Interface 'I20' incorrectly extends interface 'Partial'. Types of property 'a' are incompatible. Type 'string' is not assignable to type 'number | undefined'. @@ -138,15 +139,16 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectI !!! error TS2430: Type 'number' is not assignable to type '"hello"'. interface I14 extends TCX { [x: string]: number } ~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'a' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property 'a' of type 'string' is not assignable to 'string' index type 'number'. ~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'prototype' of type 'CX' is not assignable to string index type 'number'. +!!! error TS2411: Property 'prototype' of type 'CX' is not assignable to 'string' index type 'number'. interface I15 extends TEX { [x: string]: number } ~~~~~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'string' is not assignable to string index type 'number'. +!!! error TS2413: 'number' index type 'string' is not assignable to 'string' index type 'number'. +!!! error TS2413: Type 'string' is not assignable to type 'number'. interface I16 extends TNX { [x: string]: number } ~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'a' of type '"hello"' is not assignable to string index type 'number'. +!!! error TS2411: Property 'a' of type '"hello"' is not assignable to 'string' index type 'number'. type Identifiable = { _id: string } & T; diff --git a/tests/baselines/reference/interfaceMemberValidation.errors.txt b/tests/baselines/reference/interfaceMemberValidation.errors.txt index 3b2b1d1874c21..53274b7592fce 100644 --- a/tests/baselines/reference/interfaceMemberValidation.errors.txt +++ b/tests/baselines/reference/interfaceMemberValidation.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/interfaceMemberValidation.ts(2,11): error TS2430: Interface 'i2' incorrectly extends interface 'i1'. Types of property 'name' are incompatible. Type 'number' is not assignable to type 'string'. -tests/cases/compiler/interfaceMemberValidation.ts(5,2): error TS2411: Property 'bar' of type '{ (): any; (): any; }' is not assignable to string index type 'number'. +tests/cases/compiler/interfaceMemberValidation.ts(5,2): error TS2411: Property 'bar' of type '{ (): any; (): any; }' is not assignable to 'string' index type 'number'. tests/cases/compiler/interfaceMemberValidation.ts(10,2): error TS2374: Duplicate string index signature. @@ -16,7 +16,7 @@ tests/cases/compiler/interfaceMemberValidation.ts(10,2): error TS2374: Duplicate interface foo { bar():any; ~~~~~~~~~~ -!!! error TS2411: Property 'bar' of type '{ (): any; (): any; }' is not assignable to string index type 'number'. +!!! error TS2411: Property 'bar' of type '{ (): any; (): any; }' is not assignable to 'string' index type 'number'. bar():any; new():void; new():void; diff --git a/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer.errors.txt b/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer.errors.txt index a604a7dc2ec65..7de34bae4e8bc 100644 --- a/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer.errors.txt +++ b/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringIndexerHidingBaseTypeIndexer.ts(13,5): error TS2411: Property 'y' of type '{ a: number; }' is not assignable to string index type '{ a: number; b: number; }'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringIndexerHidingBaseTypeIndexer.ts(13,5): error TS2411: Property 'y' of type '{ a: number; }' is not assignable to 'string' index type '{ a: number; b: number; }'. ==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringIndexerHidingBaseTypeIndexer.ts (1 errors) ==== @@ -16,7 +16,7 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringInde // error y: { ~ -!!! error TS2411: Property 'y' of type '{ a: number; }' is not assignable to string index type '{ a: number; b: number; }'. +!!! error TS2411: Property 'y' of type '{ a: number; }' is not assignable to 'string' index type '{ a: number; b: number; }'. a: number; } } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer2.errors.txt b/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer2.errors.txt index a7043f93821db..5446d05c18f95 100644 --- a/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer2.errors.txt +++ b/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringIndexerHidingBaseTypeIndexer2.ts(17,5): error TS2412: Property '1' of type '{ a: number; }' is not assignable to numeric index type '{ a: number; b: number; }'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringIndexerHidingBaseTypeIndexer2.ts(17,5): error TS2411: Property '1' of type '{ a: number; }' is not assignable to 'number' index type '{ a: number; b: number; }'. ==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringIndexerHidingBaseTypeIndexer2.ts (1 errors) ==== @@ -20,7 +20,7 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringInde // error 1: { ~ -!!! error TS2412: Property '1' of type '{ a: number; }' is not assignable to numeric index type '{ a: number; b: number; }'. +!!! error TS2411: Property '1' of type '{ a: number; }' is not assignable to 'number' index type '{ a: number; b: number; }'. a: number; } } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer3.errors.txt b/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer3.errors.txt index b70d4b4a12d81..651ad7ee16298 100644 --- a/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer3.errors.txt +++ b/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer3.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringIndexerHidingBaseTypeIndexer3.ts(13,5): error TS2412: Property '2' of type '{ a: number; }' is not assignable to numeric index type '{ a: number; b: number; }'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringIndexerHidingBaseTypeIndexer3.ts(13,5): error TS2411: Property '2' of type '{ a: number; }' is not assignable to 'number' index type '{ a: number; b: number; }'. ==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringIndexerHidingBaseTypeIndexer3.ts (1 errors) ==== @@ -16,7 +16,7 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringInde // error 2: { ~ -!!! error TS2412: Property '2' of type '{ a: number; }' is not assignable to numeric index type '{ a: number; b: number; }'. +!!! error TS2411: Property '2' of type '{ a: number; }' is not assignable to 'number' index type '{ a: number; b: number; }'. a: number; } } \ No newline at end of file diff --git a/tests/baselines/reference/interfacedeclWithIndexerErrors.errors.txt b/tests/baselines/reference/interfacedeclWithIndexerErrors.errors.txt index b13b98a1da0b8..2939a04948a49 100644 --- a/tests/baselines/reference/interfacedeclWithIndexerErrors.errors.txt +++ b/tests/baselines/reference/interfacedeclWithIndexerErrors.errors.txt @@ -1,8 +1,8 @@ -tests/cases/compiler/interfacedeclWithIndexerErrors.ts(12,5): error TS2411: Property 'p2' of type 'string' is not assignable to string index type '() => string'. -tests/cases/compiler/interfacedeclWithIndexerErrors.ts(14,5): error TS2411: Property 'p4' of type 'number' is not assignable to string index type '() => string'. -tests/cases/compiler/interfacedeclWithIndexerErrors.ts(15,5): error TS2411: Property 'p5' of type '(s: number) => string' is not assignable to string index type '() => string'. -tests/cases/compiler/interfacedeclWithIndexerErrors.ts(19,5): error TS2411: Property 'f3' of type '(a: string) => number' is not assignable to string index type '() => string'. -tests/cases/compiler/interfacedeclWithIndexerErrors.ts(20,5): error TS2411: Property 'f4' of type '(s: number) => string' is not assignable to string index type '() => string'. +tests/cases/compiler/interfacedeclWithIndexerErrors.ts(12,5): error TS2411: Property 'p2' of type 'string' is not assignable to 'string' index type '() => string'. +tests/cases/compiler/interfacedeclWithIndexerErrors.ts(14,5): error TS2411: Property 'p4' of type 'number' is not assignable to 'string' index type '() => string'. +tests/cases/compiler/interfacedeclWithIndexerErrors.ts(15,5): error TS2411: Property 'p5' of type '(s: number) => string' is not assignable to 'string' index type '() => string'. +tests/cases/compiler/interfacedeclWithIndexerErrors.ts(19,5): error TS2411: Property 'f3' of type '(a: string) => number' is not assignable to 'string' index type '() => string'. +tests/cases/compiler/interfacedeclWithIndexerErrors.ts(20,5): error TS2411: Property 'f4' of type '(s: number) => string' is not assignable to 'string' index type '() => string'. ==== tests/cases/compiler/interfacedeclWithIndexerErrors.ts (5 errors) ==== @@ -19,23 +19,23 @@ tests/cases/compiler/interfacedeclWithIndexerErrors.ts(20,5): error TS2411: Prop p1; p2: string; ~~ -!!! error TS2411: Property 'p2' of type 'string' is not assignable to string index type '() => string'. +!!! error TS2411: Property 'p2' of type 'string' is not assignable to 'string' index type '() => string'. p3?; p4?: number; ~~ -!!! error TS2411: Property 'p4' of type 'number' is not assignable to string index type '() => string'. +!!! error TS2411: Property 'p4' of type 'number' is not assignable to 'string' index type '() => string'. p5: (s: number) =>string; ~~ -!!! error TS2411: Property 'p5' of type '(s: number) => string' is not assignable to string index type '() => string'. +!!! error TS2411: Property 'p5' of type '(s: number) => string' is not assignable to 'string' index type '() => string'. f1(); f2? (); f3(a: string): number; ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'f3' of type '(a: string) => number' is not assignable to string index type '() => string'. +!!! error TS2411: Property 'f3' of type '(a: string) => number' is not assignable to 'string' index type '() => string'. f4? (s: number): string; ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'f4' of type '(s: number) => string' is not assignable to string index type '() => string'. +!!! error TS2411: Property 'f4' of type '(s: number) => string' is not assignable to 'string' index type '() => string'. } diff --git a/tests/baselines/reference/invariantGenericErrorElaboration.errors.txt b/tests/baselines/reference/invariantGenericErrorElaboration.errors.txt index 5142b665d7146..2627cf99c7967 100644 --- a/tests/baselines/reference/invariantGenericErrorElaboration.errors.txt +++ b/tests/baselines/reference/invariantGenericErrorElaboration.errors.txt @@ -44,7 +44,7 @@ tests/cases/compiler/invariantGenericErrorElaboration.ts(4,17): error TS2345: Ar } declare const Num: Num - interface Obj }> extends Runtype<{[K in keyof O]: O[K]['witness'] }> {} + interface Obj }> extends Runtype<{[K in string & keyof O]: O[K]['witness'] }> {} declare function Obj }>(fields: O): Obj; interface Constraint> extends Runtype { diff --git a/tests/baselines/reference/invariantGenericErrorElaboration.js b/tests/baselines/reference/invariantGenericErrorElaboration.js index 253c4ab03b77b..38f405c69b923 100644 --- a/tests/baselines/reference/invariantGenericErrorElaboration.js +++ b/tests/baselines/reference/invariantGenericErrorElaboration.js @@ -14,7 +14,7 @@ interface Num extends Runtype { } declare const Num: Num -interface Obj }> extends Runtype<{[K in keyof O]: O[K]['witness'] }> {} +interface Obj }> extends Runtype<{[K in string & keyof O]: O[K]['witness'] }> {} declare function Obj }>(fields: O): Obj; interface Constraint> extends Runtype { diff --git a/tests/baselines/reference/invariantGenericErrorElaboration.symbols b/tests/baselines/reference/invariantGenericErrorElaboration.symbols index cc493d8e51a29..846d3cb3248df 100644 --- a/tests/baselines/reference/invariantGenericErrorElaboration.symbols +++ b/tests/baselines/reference/invariantGenericErrorElaboration.symbols @@ -8,7 +8,7 @@ const wat: Runtype = Num; const Foo = Obj({ foo: Num }) >Foo : Symbol(Foo, Decl(invariantGenericErrorElaboration.ts, 3, 5)) ->Obj : Symbol(Obj, Decl(invariantGenericErrorElaboration.ts, 15, 111), Decl(invariantGenericErrorElaboration.ts, 13, 22)) +>Obj : Symbol(Obj, Decl(invariantGenericErrorElaboration.ts, 15, 120), Decl(invariantGenericErrorElaboration.ts, 13, 22)) >foo : Symbol(foo, Decl(invariantGenericErrorElaboration.ts, 3, 17)) >Num : Symbol(Num, Decl(invariantGenericErrorElaboration.ts, 8, 1), Decl(invariantGenericErrorElaboration.ts, 13, 13)) @@ -36,8 +36,8 @@ declare const Num: Num >Num : Symbol(Num, Decl(invariantGenericErrorElaboration.ts, 8, 1), Decl(invariantGenericErrorElaboration.ts, 13, 13)) >Num : Symbol(Num, Decl(invariantGenericErrorElaboration.ts, 8, 1), Decl(invariantGenericErrorElaboration.ts, 13, 13)) -interface Obj }> extends Runtype<{[K in keyof O]: O[K]['witness'] }> {} ->Obj : Symbol(Obj, Decl(invariantGenericErrorElaboration.ts, 15, 111), Decl(invariantGenericErrorElaboration.ts, 13, 22)) +interface Obj }> extends Runtype<{[K in string & keyof O]: O[K]['witness'] }> {} +>Obj : Symbol(Obj, Decl(invariantGenericErrorElaboration.ts, 15, 120), Decl(invariantGenericErrorElaboration.ts, 13, 22)) >O : Symbol(O, Decl(invariantGenericErrorElaboration.ts, 15, 14)) >_ : Symbol(_, Decl(invariantGenericErrorElaboration.ts, 15, 27)) >Runtype : Symbol(Runtype, Decl(invariantGenericErrorElaboration.ts, 3, 29)) @@ -48,13 +48,13 @@ interface Obj }> extends Runtype<{[K in >K : Symbol(K, Decl(invariantGenericErrorElaboration.ts, 15, 75)) declare function Obj }>(fields: O): Obj; ->Obj : Symbol(Obj, Decl(invariantGenericErrorElaboration.ts, 15, 111), Decl(invariantGenericErrorElaboration.ts, 13, 22)) +>Obj : Symbol(Obj, Decl(invariantGenericErrorElaboration.ts, 15, 120), Decl(invariantGenericErrorElaboration.ts, 13, 22)) >O : Symbol(O, Decl(invariantGenericErrorElaboration.ts, 16, 21)) >_ : Symbol(_, Decl(invariantGenericErrorElaboration.ts, 16, 34)) >Runtype : Symbol(Runtype, Decl(invariantGenericErrorElaboration.ts, 3, 29)) >fields : Symbol(fields, Decl(invariantGenericErrorElaboration.ts, 16, 62)) >O : Symbol(O, Decl(invariantGenericErrorElaboration.ts, 16, 21)) ->Obj : Symbol(Obj, Decl(invariantGenericErrorElaboration.ts, 15, 111), Decl(invariantGenericErrorElaboration.ts, 13, 22)) +>Obj : Symbol(Obj, Decl(invariantGenericErrorElaboration.ts, 15, 120), Decl(invariantGenericErrorElaboration.ts, 13, 22)) >O : Symbol(O, Decl(invariantGenericErrorElaboration.ts, 16, 21)) interface Constraint> extends Runtype { diff --git a/tests/baselines/reference/invariantGenericErrorElaboration.types b/tests/baselines/reference/invariantGenericErrorElaboration.types index 7c4bdd46d037f..beec1f18155fb 100644 --- a/tests/baselines/reference/invariantGenericErrorElaboration.types +++ b/tests/baselines/reference/invariantGenericErrorElaboration.types @@ -28,7 +28,7 @@ interface Num extends Runtype { declare const Num: Num >Num : Num -interface Obj }> extends Runtype<{[K in keyof O]: O[K]['witness'] }> {} +interface Obj }> extends Runtype<{[K in string & keyof O]: O[K]['witness'] }> {} declare function Obj }>(fields: O): Obj; >Obj : ; }>(fields: O) => Obj >_ : string diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index 873fa2a035a78..c2be68e2739c8 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -266,7 +266,7 @@ function f82() { let x2 = f81({ a: { x: 42 } }); // number } -function f83(obj: T, key: K) { +function f83(obj: T, key: K) { return obj[key]['x'] as T[K]['x']; } @@ -505,7 +505,7 @@ function updateIds, K extends string>( // Repro from #13285 -function updateIds2( +function updateIds2( obj: T, key: K, stringMap: { [oldId: string]: string } @@ -1228,7 +1228,7 @@ declare function f83(obj: T, key: K): T[K]["x"]; +}, K extends string & keyof T>(obj: T, key: K): T[K]["x"]; declare function f84(): void; declare class C1 { x: number; @@ -1333,7 +1333,7 @@ declare function updateIds, K extends string>(obj: T }): Record; declare function updateIds2(obj: T, key: K, stringMap: { +}, K extends string & keyof T>(obj: T, key: K, stringMap: { [oldId: string]: string; }): void; declare function head>(list: T): T[0]; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index 15cc704c4817b..b27cb6cc88187 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -1030,21 +1030,21 @@ function f82() { >x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 264, 23)) } -function f83(obj: T, key: K) { +function f83(obj: T, key: K) { >f83 : Symbol(f83, Decl(keyofAndIndexedAccess.ts, 265, 1)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 267, 13)) >x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 267, 26)) >x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 267, 39)) >K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 267, 51)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 267, 13)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 267, 71)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 267, 80)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 267, 13)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 267, 78)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 267, 87)) >K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 267, 51)) return obj[key]['x'] as T[K]['x']; ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 267, 71)) ->key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 267, 78)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 267, 80)) +>key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 267, 87)) >'x' : Symbol(x, Decl(keyofAndIndexedAccess.ts, 267, 39)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 267, 13)) >K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 267, 51)) @@ -1837,7 +1837,7 @@ function updateIds, K extends string>( // Repro from #13285 -function updateIds2( +function updateIds2( >updateIds2 : Symbol(updateIds2, Decl(keyofAndIndexedAccess.ts, 502, 1)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 506, 20)) >x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 506, 33)) @@ -1845,7 +1845,7 @@ function updateIds2( >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 506, 20)) obj: T, ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 506, 74)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 506, 83)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 506, 20)) key: K, @@ -1859,7 +1859,7 @@ function updateIds2( ) { var x = obj[key]; >x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 511, 7)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 506, 74)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 506, 83)) >key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 507, 11)) stringMap[x]; // Should be OK. diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index 58fd74f66014a..2a25973e7e2b5 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -58,7 +58,7 @@ type K00 = keyof any; // string >K00 : string | number | symbol type K01 = keyof string; // "toString" | "charAt" | ... ->K01 : number | "length" | "toString" | "concat" | "slice" | "indexOf" | "lastIndexOf" | "charAt" | "charCodeAt" | "localeCompare" | "match" | "replace" | "search" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" | "valueOf" +>K01 : number | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "toString" | "valueOf" type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... >K02 : "toString" | "toLocaleString" | "valueOf" | "toFixed" | "toExponential" | "toPrecision" @@ -83,7 +83,7 @@ type K10 = keyof Shape; // "name" | "width" | "height" | "visible" >K10 : "name" | "width" | "height" | "visible" type K11 = keyof Shape[]; // "length" | "toString" | ... ->K11 : number | "length" | "toString" | "toLocaleString" | "pop" | "push" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" +>K11 : number | "concat" | "indexOf" | "lastIndexOf" | "slice" | "length" | "toString" | "toLocaleString" | "pop" | "push" | "join" | "reverse" | "shift" | "sort" | "splice" | "unshift" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" type K12 = keyof Dictionary; // string >K12 : string | number @@ -98,7 +98,7 @@ type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... >K15 : "toString" | "toLocaleString" | "valueOf" | "toFixed" | "toExponential" | "toPrecision" type K16 = keyof [string, number]; // "0" | "1" | "length" | "toString" | ... ->K16 : number | "0" | "1" | "length" | "toString" | "toLocaleString" | "pop" | "push" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" +>K16 : number | "0" | "1" | "concat" | "indexOf" | "lastIndexOf" | "slice" | "length" | "toString" | "toLocaleString" | "pop" | "push" | "join" | "reverse" | "shift" | "sort" | "splice" | "unshift" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" type K17 = keyof (Shape | Item); // "name" >K17 : "name" @@ -1066,8 +1066,8 @@ function f82() { >42 : 42 } -function f83(obj: T, key: K) { ->f83 : (obj: T, key: K) => T[K]["x"] +function f83(obj: T, key: K) { +>f83 : (obj: T, key: K) => T[K]["x"] >x : string >x : any >obj : T @@ -1088,7 +1088,7 @@ function f84() { let x1 = f83({ foo: { x: "hello" } }, "foo"); // string >x1 : string >f83({ foo: { x: "hello" } }, "foo") : string ->f83 : (obj: T, key: K) => T[K]["x"] +>f83 : (obj: T, key: K) => T[K]["x"] >{ foo: { x: "hello" } } : { foo: { x: string; }; } >foo : { x: string; } >{ x: "hello" } : { x: string; } @@ -1099,7 +1099,7 @@ function f84() { let x2 = f83({ bar: { x: 42 } }, "bar"); // number >x2 : number >f83({ bar: { x: 42 } }, "bar") : number ->f83 : (obj: T, key: K) => T[K]["x"] +>f83 : (obj: T, key: K) => T[K]["x"] >{ bar: { x: 42 } } : { bar: { x: number; }; } >bar : { x: number; } >{ x: 42 } : { x: number; } @@ -1813,8 +1813,8 @@ function updateIds, K extends string>( // Repro from #13285 -function updateIds2( ->updateIds2 : (obj: T, key: K, stringMap: { [oldId: string]: string; }) => void +function updateIds2( +>updateIds2 : (obj: T, key: K, stringMap: { [oldId: string]: string; }) => void >x : string obj: T, diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.types b/tests/baselines/reference/keyofAndIndexedAccessErrors.types index c15f5ebb6efd3..8682ff9583e83 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.types +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.types @@ -26,19 +26,19 @@ type T01 = keyof Object; >T01 : "toString" | "constructor" | "toLocaleString" | "valueOf" | "hasOwnProperty" | "isPrototypeOf" | "propertyIsEnumerable" type T02 = keyof keyof Object; ->T02 : number | "length" | "toString" | "valueOf" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" +>T02 : number | "length" | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" | "valueOf" type T03 = keyof keyof keyof Object; >T03 : "toString" | "valueOf" type T04 = keyof keyof keyof keyof Object; ->T04 : number | "length" | "toString" | "valueOf" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" +>T04 : number | "length" | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" | "valueOf" type T05 = keyof keyof keyof keyof keyof Object; >T05 : "toString" | "valueOf" type T06 = keyof keyof keyof keyof keyof keyof Object; ->T06 : number | "length" | "toString" | "valueOf" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" +>T06 : number | "length" | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" | "valueOf" type T10 = Shape["name"]; >T10 : string diff --git a/tests/baselines/reference/keyofDoesntContainSymbols.errors.txt b/tests/baselines/reference/keyofDoesntContainSymbols.errors.txt index f87631f9dbae1..73d58efc8bc43 100644 --- a/tests/baselines/reference/keyofDoesntContainSymbols.errors.txt +++ b/tests/baselines/reference/keyofDoesntContainSymbols.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/keyofDoesntContainSymbols.ts(11,30): error TS2345: Argument of type '""' is not assignable to parameter of type 'number'. -tests/cases/compiler/keyofDoesntContainSymbols.ts(14,23): error TS2345: Argument of type 'unique symbol' is not assignable to parameter of type '"str" | "num"'. -tests/cases/compiler/keyofDoesntContainSymbols.ts(17,23): error TS2345: Argument of type '0' is not assignable to parameter of type '"str" | "num"'. +tests/cases/compiler/keyofDoesntContainSymbols.ts(14,23): error TS2345: Argument of type 'unique symbol' is not assignable to parameter of type '"num" | "str"'. +tests/cases/compiler/keyofDoesntContainSymbols.ts(17,23): error TS2345: Argument of type '0' is not assignable to parameter of type '"num" | "str"'. ==== tests/cases/compiler/keyofDoesntContainSymbols.ts (3 errors) ==== @@ -21,12 +21,12 @@ tests/cases/compiler/keyofDoesntContainSymbols.ts(17,23): error TS2345: Argument // Argument of type '""' is not assignable to parameter of type 'number'. const valC = set(obj, sym, sym); ~~~ -!!! error TS2345: Argument of type 'unique symbol' is not assignable to parameter of type '"str" | "num"'. +!!! error TS2345: Argument of type 'unique symbol' is not assignable to parameter of type '"num" | "str"'. // Expect type error // Argument of type 'unique symbol' is not assignable to parameter of type "str" | "num" const valD = set(obj, num, num); ~~~ -!!! error TS2345: Argument of type '0' is not assignable to parameter of type '"str" | "num"'. +!!! error TS2345: Argument of type '0' is not assignable to parameter of type '"num" | "str"'. // Expect type error // Argument of type '0' is not assignable to parameter of type "str" | "num" type KeyofObj = keyof typeof obj; diff --git a/tests/baselines/reference/keyofDoesntContainSymbols.types b/tests/baselines/reference/keyofDoesntContainSymbols.types index ce1ffc9fda9ba..e54f36cc3dbe0 100644 --- a/tests/baselines/reference/keyofDoesntContainSymbols.types +++ b/tests/baselines/reference/keyofDoesntContainSymbols.types @@ -77,7 +77,7 @@ const valD = set(obj, num, num); // Expect type error // Argument of type '0' is not assignable to parameter of type "str" | "num" type KeyofObj = keyof typeof obj; ->KeyofObj : "str" | "num" +>KeyofObj : "num" | "str" >obj : { num: number; str: string; [num]: 0; [sym]: symbol; } // "str" | "num" diff --git a/tests/baselines/reference/mappedTypeErrors.errors.txt b/tests/baselines/reference/mappedTypeErrors.errors.txt index 99d8f9c7ad13d..475dcef56d440 100644 --- a/tests/baselines/reference/mappedTypeErrors.errors.txt +++ b/tests/baselines/reference/mappedTypeErrors.errors.txt @@ -43,9 +43,11 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(130,39): error TS2322: tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,16): error TS2322: Type 'T' is not assignable to type 'string | number | symbol'. Type 'T' is not assignable to type 'symbol'. tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,21): error TS2536: Type 'P' cannot be used to index type 'T'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(142,10): error TS2322: Type '{ x: number; y: boolean; }' is not assignable to type '{ [x: O]: unknown; }'. + Object literal may only specify known properties, and 'x' does not exist in type '{ [x: O]: unknown; }'. -==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (25 errors) ==== +==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (26 errors) ==== interface Shape { name: string; width: number; @@ -261,5 +263,9 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,21): error TS2536: let f: Foo2 = { pf: {x: 7}, pt: {x: 7, y: false}, + ~~~~ +!!! error TS2322: Type '{ x: number; y: boolean; }' is not assignable to type '{ [x: O]: unknown; }'. +!!! error TS2322: Object literal may only specify known properties, and 'x' does not exist in type '{ [x: O]: unknown; }'. +!!! related TS6500 tests/cases/conformance/types/mapped/mappedTypeErrors.ts:136:5: The expected type comes from property 'pt' which is declared here on type 'Foo2' }; \ No newline at end of file diff --git a/tests/baselines/reference/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.js b/tests/baselines/reference/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.js new file mode 100644 index 0000000000000..a2c3621f6b820 --- /dev/null +++ b/tests/baselines/reference/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.js @@ -0,0 +1,88 @@ +//// [mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts] +const directive = Symbol('directive'); +declare function foo(options: + {[x in string]: (arg: TArg) => TRet} + & {[directive]?: TDir} +): [TArg, TRet, TDir]; + + +let case1 = foo({ + [directive]: (x: string) => 'str', + addOne: (x: number) => x + 1, + double: (x: number) => x + x, +}); // [number, number, string => string] + +let case2 = foo({ + addOne: (x: number) => x + 1, + double: (x: number) => x + x, + [directive]: (x: string) => 'str', +}); // [number, number, string => string] + +let case3 = foo({ + [directive]: 'str', + addOne: (x: number) => x + 1, + double: (x: number) => x + x, +}); // [number, number, string] + +const strdirective = "directive"; +declare function bar(options: + {[x in symbol]: (arg: TArg) => TRet} + & {[strdirective]?: TDir} +): [TArg, TRet, TDir]; + +const s1 = Symbol("s1"); +const s2 = Symbol("s2"); +let case4 = bar({ + [strdirective]: (x: string) => 'str', + [s1]: (x: number) => x + 1, + [s2]: (x: number) => x + x, +}); // [number, number, string => string] + +let case5 = bar({ + [s1]: (x: number) => x + 1, + [s2]: (x: number) => x + x, + [strdirective]: (x: string) => 'str', +}); // [number, number, string => string] + +let case6 = bar({ + [strdirective]: 'str', + [s1]: (x: number) => x + 1, + [s2]: (x: number) => x + x, +}); // [number, number, string] + + +//// [mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.js] +const directive = Symbol('directive'); +let case1 = foo({ + [directive]: (x) => 'str', + addOne: (x) => x + 1, + double: (x) => x + x, +}); // [number, number, string => string] +let case2 = foo({ + addOne: (x) => x + 1, + double: (x) => x + x, + [directive]: (x) => 'str', +}); // [number, number, string => string] +let case3 = foo({ + [directive]: 'str', + addOne: (x) => x + 1, + double: (x) => x + x, +}); // [number, number, string] +const strdirective = "directive"; +const s1 = Symbol("s1"); +const s2 = Symbol("s2"); +let case4 = bar({ + [strdirective]: (x) => 'str', + [s1]: (x) => x + 1, + [s2]: (x) => x + x, +}); // [number, number, string => string] +let case5 = bar({ + [s1]: (x) => x + 1, + [s2]: (x) => x + x, + [strdirective]: (x) => 'str', +}); // [number, number, string => string] +let case6 = bar({ + [strdirective]: 'str', + [s1]: (x) => x + 1, + [s2]: (x) => x + x, +}); // [number, number, string] diff --git a/tests/baselines/reference/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.symbols b/tests/baselines/reference/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.symbols new file mode 100644 index 0000000000000..341c36e6d2384 --- /dev/null +++ b/tests/baselines/reference/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.symbols @@ -0,0 +1,199 @@ +=== tests/cases/compiler/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts === +const directive = Symbol('directive'); +>directive : Symbol(directive, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 0, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +declare function foo(options: +>foo : Symbol(foo, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 0, 38)) +>TArg : Symbol(TArg, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 1, 21)) +>TRet : Symbol(TRet, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 1, 26)) +>TDir : Symbol(TDir, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 1, 32)) +>options : Symbol(options, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 1, 39)) + + {[x in string]: (arg: TArg) => TRet} +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 2, 6)) +>arg : Symbol(arg, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 2, 21)) +>TArg : Symbol(TArg, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 1, 21)) +>TRet : Symbol(TRet, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 1, 26)) + + & {[directive]?: TDir} +>[directive] : Symbol([directive], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 3, 7)) +>directive : Symbol(directive, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 0, 5)) +>TDir : Symbol(TDir, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 1, 32)) + +): [TArg, TRet, TDir]; +>TArg : Symbol(TArg, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 1, 21)) +>TRet : Symbol(TRet, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 1, 26)) +>TDir : Symbol(TDir, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 1, 32)) + + +let case1 = foo({ +>case1 : Symbol(case1, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 7, 3)) +>foo : Symbol(foo, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 0, 38)) + + [directive]: (x: string) => 'str', +>[directive] : Symbol([directive], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 7, 17)) +>directive : Symbol(directive, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 0, 5)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 8, 18)) + + addOne: (x: number) => x + 1, +>addOne : Symbol(addOne, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 8, 38)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 9, 13)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 9, 13)) + + double: (x: number) => x + x, +>double : Symbol(double, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 9, 33)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 10, 13)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 10, 13)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 10, 13)) + +}); // [number, number, string => string] + +let case2 = foo({ +>case2 : Symbol(case2, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 13, 3)) +>foo : Symbol(foo, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 0, 38)) + + addOne: (x: number) => x + 1, +>addOne : Symbol(addOne, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 13, 17)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 14, 13)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 14, 13)) + + double: (x: number) => x + x, +>double : Symbol(double, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 14, 33)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 15, 13)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 15, 13)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 15, 13)) + + [directive]: (x: string) => 'str', +>[directive] : Symbol([directive], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 15, 33)) +>directive : Symbol(directive, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 0, 5)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 16, 18)) + +}); // [number, number, string => string] + +let case3 = foo({ +>case3 : Symbol(case3, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 19, 3)) +>foo : Symbol(foo, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 0, 38)) + + [directive]: 'str', +>[directive] : Symbol([directive], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 19, 17)) +>directive : Symbol(directive, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 0, 5)) + + addOne: (x: number) => x + 1, +>addOne : Symbol(addOne, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 20, 23)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 21, 13)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 21, 13)) + + double: (x: number) => x + x, +>double : Symbol(double, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 21, 33)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 22, 13)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 22, 13)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 22, 13)) + +}); // [number, number, string] + +const strdirective = "directive"; +>strdirective : Symbol(strdirective, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 25, 5)) + +declare function bar(options: +>bar : Symbol(bar, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 25, 33)) +>TArg : Symbol(TArg, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 26, 21)) +>TRet : Symbol(TRet, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 26, 26)) +>TDir : Symbol(TDir, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 26, 32)) +>options : Symbol(options, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 26, 39)) + + {[x in symbol]: (arg: TArg) => TRet} +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 27, 6)) +>arg : Symbol(arg, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 27, 21)) +>TArg : Symbol(TArg, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 26, 21)) +>TRet : Symbol(TRet, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 26, 26)) + + & {[strdirective]?: TDir} +>[strdirective] : Symbol([strdirective], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 28, 7)) +>strdirective : Symbol(strdirective, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 25, 5)) +>TDir : Symbol(TDir, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 26, 32)) + +): [TArg, TRet, TDir]; +>TArg : Symbol(TArg, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 26, 21)) +>TRet : Symbol(TRet, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 26, 26)) +>TDir : Symbol(TDir, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 26, 32)) + +const s1 = Symbol("s1"); +>s1 : Symbol(s1, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 31, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +const s2 = Symbol("s2"); +>s2 : Symbol(s2, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 32, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +let case4 = bar({ +>case4 : Symbol(case4, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 33, 3)) +>bar : Symbol(bar, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 25, 33)) + + [strdirective]: (x: string) => 'str', +>[strdirective] : Symbol([strdirective], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 33, 17)) +>strdirective : Symbol(strdirective, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 25, 5)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 34, 21)) + + [s1]: (x: number) => x + 1, +>[s1] : Symbol([s1], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 34, 41)) +>s1 : Symbol(s1, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 31, 5)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 35, 11)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 35, 11)) + + [s2]: (x: number) => x + x, +>[s2] : Symbol([s2], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 35, 31)) +>s2 : Symbol(s2, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 32, 5)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 36, 11)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 36, 11)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 36, 11)) + +}); // [number, number, string => string] + +let case5 = bar({ +>case5 : Symbol(case5, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 39, 3)) +>bar : Symbol(bar, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 25, 33)) + + [s1]: (x: number) => x + 1, +>[s1] : Symbol([s1], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 39, 17)) +>s1 : Symbol(s1, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 31, 5)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 40, 11)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 40, 11)) + + [s2]: (x: number) => x + x, +>[s2] : Symbol([s2], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 40, 31)) +>s2 : Symbol(s2, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 32, 5)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 41, 11)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 41, 11)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 41, 11)) + + [strdirective]: (x: string) => 'str', +>[strdirective] : Symbol([strdirective], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 41, 31)) +>strdirective : Symbol(strdirective, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 25, 5)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 42, 21)) + +}); // [number, number, string => string] + +let case6 = bar({ +>case6 : Symbol(case6, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 45, 3)) +>bar : Symbol(bar, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 25, 33)) + + [strdirective]: 'str', +>[strdirective] : Symbol([strdirective], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 45, 17)) +>strdirective : Symbol(strdirective, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 25, 5)) + + [s1]: (x: number) => x + 1, +>[s1] : Symbol([s1], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 46, 26)) +>s1 : Symbol(s1, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 31, 5)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 47, 11)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 47, 11)) + + [s2]: (x: number) => x + x, +>[s2] : Symbol([s2], Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 47, 31)) +>s2 : Symbol(s2, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 32, 5)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 48, 11)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 48, 11)) +>x : Symbol(x, Decl(mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts, 48, 11)) + +}); // [number, number, string] + diff --git a/tests/baselines/reference/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.types b/tests/baselines/reference/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.types new file mode 100644 index 0000000000000..e88ab97f58990 --- /dev/null +++ b/tests/baselines/reference/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.types @@ -0,0 +1,238 @@ +=== tests/cases/compiler/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts === +const directive = Symbol('directive'); +>directive : unique symbol +>Symbol('directive') : unique symbol +>Symbol : SymbolConstructor +>'directive' : "directive" + +declare function foo(options: +>foo : (options: { [x: string]: (arg: TArg) => TRet; } & { [directive]?: TDir; }) => [TArg, TRet, TDir] +>options : { [x: string]: (arg: TArg) => TRet; } & { [directive]?: TDir; } + + {[x in string]: (arg: TArg) => TRet} +>arg : TArg + + & {[directive]?: TDir} +>[directive] : TDir +>directive : unique symbol + +): [TArg, TRet, TDir]; + + +let case1 = foo({ +>case1 : [number, number, (x: string) => "str"] +>foo({ [directive]: (x: string) => 'str', addOne: (x: number) => x + 1, double: (x: number) => x + x,}) : [number, number, (x: string) => "str"] +>foo : (options: { [x: string]: (arg: TArg) => TRet; } & { [directive]?: TDir; }) => [TArg, TRet, TDir] +>{ [directive]: (x: string) => 'str', addOne: (x: number) => x + 1, double: (x: number) => x + x,} : { [directive]: (x: string) => "str"; addOne: (x: number) => number; double: (x: number) => number; } + + [directive]: (x: string) => 'str', +>[directive] : (x: string) => "str" +>directive : unique symbol +>(x: string) => 'str' : (x: string) => "str" +>x : string +>'str' : "str" + + addOne: (x: number) => x + 1, +>addOne : (x: number) => number +>(x: number) => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 + + double: (x: number) => x + x, +>double : (x: number) => number +>(x: number) => x + x : (x: number) => number +>x : number +>x + x : number +>x : number +>x : number + +}); // [number, number, string => string] + +let case2 = foo({ +>case2 : [number, number, (x: string) => "str"] +>foo({ addOne: (x: number) => x + 1, double: (x: number) => x + x, [directive]: (x: string) => 'str',}) : [number, number, (x: string) => "str"] +>foo : (options: { [x: string]: (arg: TArg) => TRet; } & { [directive]?: TDir; }) => [TArg, TRet, TDir] +>{ addOne: (x: number) => x + 1, double: (x: number) => x + x, [directive]: (x: string) => 'str',} : { addOne: (x: number) => number; double: (x: number) => number; [directive]: (x: string) => "str"; } + + addOne: (x: number) => x + 1, +>addOne : (x: number) => number +>(x: number) => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 + + double: (x: number) => x + x, +>double : (x: number) => number +>(x: number) => x + x : (x: number) => number +>x : number +>x + x : number +>x : number +>x : number + + [directive]: (x: string) => 'str', +>[directive] : (x: string) => "str" +>directive : unique symbol +>(x: string) => 'str' : (x: string) => "str" +>x : string +>'str' : "str" + +}); // [number, number, string => string] + +let case3 = foo({ +>case3 : [number, number, string] +>foo({ [directive]: 'str', addOne: (x: number) => x + 1, double: (x: number) => x + x,}) : [number, number, string] +>foo : (options: { [x: string]: (arg: TArg) => TRet; } & { [directive]?: TDir; }) => [TArg, TRet, TDir] +>{ [directive]: 'str', addOne: (x: number) => x + 1, double: (x: number) => x + x,} : { [directive]: string; addOne: (x: number) => number; double: (x: number) => number; } + + [directive]: 'str', +>[directive] : string +>directive : unique symbol +>'str' : "str" + + addOne: (x: number) => x + 1, +>addOne : (x: number) => number +>(x: number) => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 + + double: (x: number) => x + x, +>double : (x: number) => number +>(x: number) => x + x : (x: number) => number +>x : number +>x + x : number +>x : number +>x : number + +}); // [number, number, string] + +const strdirective = "directive"; +>strdirective : "directive" +>"directive" : "directive" + +declare function bar(options: +>bar : (options: { [x: symbol]: (arg: TArg) => TRet; } & { [strdirective]?: TDir; }) => [TArg, TRet, TDir] +>options : { [x: symbol]: (arg: TArg) => TRet; } & { [strdirective]?: TDir; } + + {[x in symbol]: (arg: TArg) => TRet} +>arg : TArg + + & {[strdirective]?: TDir} +>[strdirective] : TDir +>strdirective : "directive" + +): [TArg, TRet, TDir]; + +const s1 = Symbol("s1"); +>s1 : unique symbol +>Symbol("s1") : unique symbol +>Symbol : SymbolConstructor +>"s1" : "s1" + +const s2 = Symbol("s2"); +>s2 : unique symbol +>Symbol("s2") : unique symbol +>Symbol : SymbolConstructor +>"s2" : "s2" + +let case4 = bar({ +>case4 : [number, number, (x: string) => "str"] +>bar({ [strdirective]: (x: string) => 'str', [s1]: (x: number) => x + 1, [s2]: (x: number) => x + x,}) : [number, number, (x: string) => "str"] +>bar : (options: { [x: symbol]: (arg: TArg) => TRet; } & { [strdirective]?: TDir; }) => [TArg, TRet, TDir] +>{ [strdirective]: (x: string) => 'str', [s1]: (x: number) => x + 1, [s2]: (x: number) => x + x,} : { [strdirective]: (x: string) => "str"; [s1]: (x: number) => number; [s2]: (x: number) => number; } + + [strdirective]: (x: string) => 'str', +>[strdirective] : (x: string) => "str" +>strdirective : "directive" +>(x: string) => 'str' : (x: string) => "str" +>x : string +>'str' : "str" + + [s1]: (x: number) => x + 1, +>[s1] : (x: number) => number +>s1 : unique symbol +>(x: number) => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 + + [s2]: (x: number) => x + x, +>[s2] : (x: number) => number +>s2 : unique symbol +>(x: number) => x + x : (x: number) => number +>x : number +>x + x : number +>x : number +>x : number + +}); // [number, number, string => string] + +let case5 = bar({ +>case5 : [number, number, (x: string) => "str"] +>bar({ [s1]: (x: number) => x + 1, [s2]: (x: number) => x + x, [strdirective]: (x: string) => 'str',}) : [number, number, (x: string) => "str"] +>bar : (options: { [x: symbol]: (arg: TArg) => TRet; } & { [strdirective]?: TDir; }) => [TArg, TRet, TDir] +>{ [s1]: (x: number) => x + 1, [s2]: (x: number) => x + x, [strdirective]: (x: string) => 'str',} : { [s1]: (x: number) => number; [s2]: (x: number) => number; [strdirective]: (x: string) => "str"; } + + [s1]: (x: number) => x + 1, +>[s1] : (x: number) => number +>s1 : unique symbol +>(x: number) => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 + + [s2]: (x: number) => x + x, +>[s2] : (x: number) => number +>s2 : unique symbol +>(x: number) => x + x : (x: number) => number +>x : number +>x + x : number +>x : number +>x : number + + [strdirective]: (x: string) => 'str', +>[strdirective] : (x: string) => "str" +>strdirective : "directive" +>(x: string) => 'str' : (x: string) => "str" +>x : string +>'str' : "str" + +}); // [number, number, string => string] + +let case6 = bar({ +>case6 : [number, number, string] +>bar({ [strdirective]: 'str', [s1]: (x: number) => x + 1, [s2]: (x: number) => x + x,}) : [number, number, string] +>bar : (options: { [x: symbol]: (arg: TArg) => TRet; } & { [strdirective]?: TDir; }) => [TArg, TRet, TDir] +>{ [strdirective]: 'str', [s1]: (x: number) => x + 1, [s2]: (x: number) => x + x,} : { [strdirective]: string; [s1]: (x: number) => number; [s2]: (x: number) => number; } + + [strdirective]: 'str', +>[strdirective] : string +>strdirective : "directive" +>'str' : "str" + + [s1]: (x: number) => x + 1, +>[s1] : (x: number) => number +>s1 : unique symbol +>(x: number) => x + 1 : (x: number) => number +>x : number +>x + 1 : number +>x : number +>1 : 1 + + [s2]: (x: number) => x + x, +>[s2] : (x: number) => number +>s2 : unique symbol +>(x: number) => x + x : (x: number) => number +>x : number +>x + x : number +>x : number +>x : number + +}); // [number, number, string] + diff --git a/tests/baselines/reference/mappedTypeRelationships.errors.txt b/tests/baselines/reference/mappedTypeRelationships.errors.txt index 60a06e000c255..dfdb85a4aa856 100644 --- a/tests/baselines/reference/mappedTypeRelationships.errors.txt +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -219,12 +219,12 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS [x: string]: Item; } - function f50(obj: T, key: keyof T) { + function f50(obj: T, key: keyof T & string) { let item: Item = obj[key]; return obj[key].name; } - function f51(obj: T, key: K) { + function f51(obj: T, key: K) { let item: Item = obj[key]; return obj[key].name; } diff --git a/tests/baselines/reference/mappedTypeRelationships.js b/tests/baselines/reference/mappedTypeRelationships.js index 8bd44da5658ef..08d72676b84f1 100644 --- a/tests/baselines/reference/mappedTypeRelationships.js +++ b/tests/baselines/reference/mappedTypeRelationships.js @@ -97,12 +97,12 @@ type ItemMap = { [x: string]: Item; } -function f50(obj: T, key: keyof T) { +function f50(obj: T, key: keyof T & string) { let item: Item = obj[key]; return obj[key].name; } -function f51(obj: T, key: K) { +function f51(obj: T, key: K) { let item: Item = obj[key]; return obj[key].name; } @@ -341,8 +341,8 @@ declare type Item = { declare type ItemMap = { [x: string]: Item; }; -declare function f50(obj: T, key: keyof T): string; -declare function f51(obj: T, key: K): string; +declare function f50(obj: T, key: keyof T & string): string; +declare function f51(obj: T, key: K): string; declare type T1 = { [P in keyof T]: T[P]; }; diff --git a/tests/baselines/reference/mappedTypeRelationships.symbols b/tests/baselines/reference/mappedTypeRelationships.symbols index 39d82b5b8570d..0ba1748dd4576 100644 --- a/tests/baselines/reference/mappedTypeRelationships.symbols +++ b/tests/baselines/reference/mappedTypeRelationships.symbols @@ -435,7 +435,7 @@ type ItemMap = { >Item : Symbol(Item, Decl(mappedTypeRelationships.ts, 88, 1)) } -function f50(obj: T, key: keyof T) { +function f50(obj: T, key: keyof T & string) { >f50 : Symbol(f50, Decl(mappedTypeRelationships.ts, 96, 1)) >T : Symbol(T, Decl(mappedTypeRelationships.ts, 98, 13)) >ItemMap : Symbol(ItemMap, Decl(mappedTypeRelationships.ts, 92, 1)) @@ -457,27 +457,27 @@ function f50(obj: T, key: keyof T) { >name : Symbol(name, Decl(mappedTypeRelationships.ts, 90, 13)) } -function f51(obj: T, key: K) { +function f51(obj: T, key: K) { >f51 : Symbol(f51, Decl(mappedTypeRelationships.ts, 101, 1)) >T : Symbol(T, Decl(mappedTypeRelationships.ts, 103, 13)) >ItemMap : Symbol(ItemMap, Decl(mappedTypeRelationships.ts, 92, 1)) >K : Symbol(K, Decl(mappedTypeRelationships.ts, 103, 31)) >T : Symbol(T, Decl(mappedTypeRelationships.ts, 103, 13)) ->obj : Symbol(obj, Decl(mappedTypeRelationships.ts, 103, 51)) +>obj : Symbol(obj, Decl(mappedTypeRelationships.ts, 103, 60)) >T : Symbol(T, Decl(mappedTypeRelationships.ts, 103, 13)) ->key : Symbol(key, Decl(mappedTypeRelationships.ts, 103, 58)) +>key : Symbol(key, Decl(mappedTypeRelationships.ts, 103, 67)) >K : Symbol(K, Decl(mappedTypeRelationships.ts, 103, 31)) let item: Item = obj[key]; >item : Symbol(item, Decl(mappedTypeRelationships.ts, 104, 7)) >Item : Symbol(Item, Decl(mappedTypeRelationships.ts, 88, 1)) ->obj : Symbol(obj, Decl(mappedTypeRelationships.ts, 103, 51)) ->key : Symbol(key, Decl(mappedTypeRelationships.ts, 103, 58)) +>obj : Symbol(obj, Decl(mappedTypeRelationships.ts, 103, 60)) +>key : Symbol(key, Decl(mappedTypeRelationships.ts, 103, 67)) return obj[key].name; >obj[key].name : Symbol(name, Decl(mappedTypeRelationships.ts, 90, 13)) ->obj : Symbol(obj, Decl(mappedTypeRelationships.ts, 103, 51)) ->key : Symbol(key, Decl(mappedTypeRelationships.ts, 103, 58)) +>obj : Symbol(obj, Decl(mappedTypeRelationships.ts, 103, 60)) +>key : Symbol(key, Decl(mappedTypeRelationships.ts, 103, 67)) >name : Symbol(name, Decl(mappedTypeRelationships.ts, 90, 13)) } diff --git a/tests/baselines/reference/mappedTypeRelationships.types b/tests/baselines/reference/mappedTypeRelationships.types index 582d777149c56..e0319571903c3 100644 --- a/tests/baselines/reference/mappedTypeRelationships.types +++ b/tests/baselines/reference/mappedTypeRelationships.types @@ -404,27 +404,27 @@ type ItemMap = { >x : string } -function f50(obj: T, key: keyof T) { ->f50 : (obj: T, key: keyof T) => string +function f50(obj: T, key: keyof T & string) { +>f50 : (obj: T, key: keyof T & string) => string >obj : T ->key : keyof T +>key : keyof T & string let item: Item = obj[key]; >item : Item ->obj[key] : T[keyof T] +>obj[key] : T[keyof T & string] >obj : T ->key : keyof T +>key : keyof T & string return obj[key].name; >obj[key].name : string ->obj[key] : T[keyof T] +>obj[key] : T[keyof T & string] >obj : T ->key : keyof T +>key : keyof T & string >name : string } -function f51(obj: T, key: K) { ->f51 : (obj: T, key: K) => string +function f51(obj: T, key: K) { +>f51 : (obj: T, key: K) => string >obj : T >key : K diff --git a/tests/baselines/reference/mergedInterfacesWithIndexers.types b/tests/baselines/reference/mergedInterfacesWithIndexers.types index 73e0ee72c941b..1154fcd72ef1d 100644 --- a/tests/baselines/reference/mergedInterfacesWithIndexers.types +++ b/tests/baselines/reference/mergedInterfacesWithIndexers.types @@ -23,8 +23,8 @@ var r = a[1]; >1 : 1 var r2 = a['1']; ->r2 : { length: number; } ->a['1'] : { length: number; } +>r2 : string +>a['1'] : string >a : A >'1' : "1" diff --git a/tests/baselines/reference/mergedInterfacesWithIndexers2.errors.txt b/tests/baselines/reference/mergedInterfacesWithIndexers2.errors.txt index f649b5469937d..b9104496c74e1 100644 --- a/tests/baselines/reference/mergedInterfacesWithIndexers2.errors.txt +++ b/tests/baselines/reference/mergedInterfacesWithIndexers2.errors.txt @@ -1,6 +1,7 @@ -tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexers2.ts(4,5): error TS2413: Numeric index type 'string' is not assignable to string index type '{ length: string; }'. -tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexers2.ts(14,5): error TS2411: Property ''a'' of type 'number' is not assignable to string index type '{ length: number; }'. -tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexers2.ts(20,5): error TS2412: Property '1' of type '{ length: number; }' is not assignable to numeric index type 'string'. +tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexers2.ts(4,5): error TS2413: 'number' index type 'string' is not assignable to 'string' index type '{ length: string; }'. + Type 'string' is not assignable to type '{ length: string; }'. +tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexers2.ts(14,5): error TS2411: Property ''a'' of type 'number' is not assignable to 'string' index type '{ length: number; }'. +tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexers2.ts(20,5): error TS2411: Property '1' of type '{ length: number; }' is not assignable to 'number' index type 'string'. ==== tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexers2.ts (3 errors) ==== @@ -9,7 +10,8 @@ tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexe interface A { [x: number]: string; // error ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'string' is not assignable to string index type '{ length: string; }'. +!!! error TS2413: 'number' index type 'string' is not assignable to 'string' index type '{ length: string; }'. +!!! error TS2413: Type 'string' is not assignable to type '{ length: string; }'. } @@ -21,7 +23,7 @@ tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexe [x: number]: string; 'a': number; //error ~~~ -!!! error TS2411: Property ''a'' of type 'number' is not assignable to string index type '{ length: number; }'. +!!! error TS2411: Property ''a'' of type 'number' is not assignable to 'string' index type '{ length: number; }'. } @@ -29,6 +31,6 @@ tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexe [x: string]: { length: number }; 1: { length: number }; // error ~ -!!! error TS2412: Property '1' of type '{ length: number; }' is not assignable to numeric index type 'string'. +!!! error TS2411: Property '1' of type '{ length: number; }' is not assignable to 'number' index type 'string'. } \ No newline at end of file diff --git a/tests/baselines/reference/multipleNumericIndexers.types b/tests/baselines/reference/multipleNumericIndexers.types index 1223f5bb0026c..dd22c7e5064d4 100644 --- a/tests/baselines/reference/multipleNumericIndexers.types +++ b/tests/baselines/reference/multipleNumericIndexers.types @@ -20,7 +20,7 @@ interface I { } var a: { ->a : { [x: number]: string; } +>a : { [x: number]: string; [x: number]: string; } [x: number]: string; >x : number @@ -30,7 +30,7 @@ var a: { } var b: { ->b : { [x: number]: string; } +>b : { [x: number]: string; [x: number]: string; } [x: number]: string; >x : number diff --git a/tests/baselines/reference/multipleStringIndexers.types b/tests/baselines/reference/multipleStringIndexers.types index 233d19f030986..1f18f1a9ab196 100644 --- a/tests/baselines/reference/multipleStringIndexers.types +++ b/tests/baselines/reference/multipleStringIndexers.types @@ -20,7 +20,7 @@ interface I { } var a: { ->a : { [x: string]: string; } +>a : { [x: string]: string; [x: string]: string; } [x: string]: string; >x : string @@ -30,7 +30,7 @@ var a: { } var b: { ->b : { [x: string]: string; } +>b : { [x: string]: string; [x: string]: string; } [x: string]: string; >x : string diff --git a/tests/baselines/reference/nonPrimitiveConstraintOfIndexAccessType.errors.txt b/tests/baselines/reference/nonPrimitiveConstraintOfIndexAccessType.errors.txt index 5784d8c46d0b4..14c97cb148c1a 100644 --- a/tests/baselines/reference/nonPrimitiveConstraintOfIndexAccessType.errors.txt +++ b/tests/baselines/reference/nonPrimitiveConstraintOfIndexAccessType.errors.txt @@ -9,7 +9,6 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessTy tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts(24,5): error TS2322: Type 'string' is not assignable to type 'T[P]'. tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts(27,5): error TS2322: Type 'string' is not assignable to type 'T[P]'. tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts(30,5): error TS2322: Type 'string' is not assignable to type 'T[P]'. - Type 'string' is not assignable to type 'number'. ==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessType.ts (10 errors) ==== @@ -64,6 +63,5 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveConstraintOfIndexAccessTy tp = s; ~~ !!! error TS2322: Type 'string' is not assignable to type 'T[P]'. -!!! error TS2322: Type 'string' is not assignable to type 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt index 82a5659c5b0a5..c39ba4d38681d 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(18,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(21,5): error TS2412: Property '3.0' of type 'MyNumber' is not assignable to numeric index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(18,5): error TS2411: Property '2.0' of type 'number' is not assignable to 'number' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(21,5): error TS2411: Property '3.0' of type 'MyNumber' is not assignable to 'number' index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(23,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(26,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(36,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(50,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(50,5): error TS2411: Property '2.0' of type 'number' is not assignable to 'number' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2411: Property '2.0' of type 'number' is not assignable to 'number' index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(85,5): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(88,9): error TS2304: Cannot find name 'Myn'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations.ts(90,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. @@ -31,12 +31,12 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo 1.0: string; // ok 2.0: number; // error ~~~ -!!! error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. +!!! error TS2411: Property '2.0' of type 'number' is not assignable to 'number' index type 'string'. "3.0": string; // ok "4.0": number; // error 3.0: MyNumber // error ~~~ -!!! error TS2412: Property '3.0' of type 'MyNumber' is not assignable to numeric index type 'string'. +!!! error TS2411: Property '3.0' of type 'MyNumber' is not assignable to 'number' index type 'string'. get X() { // ok ~ @@ -73,7 +73,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo 1.0: string; // ok 2.0: number; // error ~~~ -!!! error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. +!!! error TS2411: Property '2.0' of type 'number' is not assignable to 'number' index type 'string'. (): string; // ok (x): number // ok foo(): string; // ok @@ -93,7 +93,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo 1.0: string; // ok 2.0: number; // error ~~~ -!!! error TS2412: Property '2.0' of type 'number' is not assignable to numeric index type 'string'. +!!! error TS2411: Property '2.0' of type 'number' is not assignable to 'number' index type 'string'. (): string; // ok (x): number // ok foo(): string; // ok diff --git a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt index 0807af21960a0..dd071af635c3b 100644 --- a/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/numericIndexerConstrainsPropertyDeclarations2.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(16,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(25,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(34,5): error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(16,5): error TS2411: Property '3.0' of type 'number' is not assignable to 'number' index type 'A'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(25,5): error TS2411: Property '3.0' of type 'number' is not assignable to 'number' index type 'A'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(34,5): error TS2411: Property '3.0' of type 'number' is not assignable to 'number' index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerConstrainsPropertyDeclarations2.ts(43,5): error TS2322: Type 'number' is not assignable to type 'A'. @@ -22,7 +22,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo "2.5": B // ok 3.0: number; // error ~~~ -!!! error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. +!!! error TS2411: Property '3.0' of type 'number' is not assignable to 'number' index type 'A'. "4.0": string; // error } @@ -33,7 +33,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo "2.5": B // ok 3.0: number; // error ~~~ -!!! error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. +!!! error TS2411: Property '3.0' of type 'number' is not assignable to 'number' index type 'A'. "4.0": string; // error } @@ -44,7 +44,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/numericIndexerCo "2.5": B // ok 3.0: number; // error ~~~ -!!! error TS2412: Property '3.0' of type 'number' is not assignable to numeric index type 'A'. +!!! error TS2411: Property '3.0' of type 'number' is not assignable to 'number' index type 'A'. "4.0": string; // error }; diff --git a/tests/baselines/reference/numericIndexerConstraint.errors.txt b/tests/baselines/reference/numericIndexerConstraint.errors.txt index 21d52dee68313..b000eec8b0a1e 100644 --- a/tests/baselines/reference/numericIndexerConstraint.errors.txt +++ b/tests/baselines/reference/numericIndexerConstraint.errors.txt @@ -1,10 +1,10 @@ -tests/cases/compiler/numericIndexerConstraint.ts(2,5): error TS2412: Property '0' of type 'number' is not assignable to numeric index type 'RegExp'. +tests/cases/compiler/numericIndexerConstraint.ts(2,5): error TS2411: Property '0' of type 'number' is not assignable to 'number' index type 'RegExp'. ==== tests/cases/compiler/numericIndexerConstraint.ts (1 errors) ==== class C { 0: number; ~ -!!! error TS2412: Property '0' of type 'number' is not assignable to numeric index type 'RegExp'. +!!! error TS2411: Property '0' of type 'number' is not assignable to 'number' index type 'RegExp'. [x: number]: RegExp; } \ No newline at end of file diff --git a/tests/baselines/reference/numericIndexingResults.types b/tests/baselines/reference/numericIndexingResults.types index f4e0d168e6e22..78f47edbe489c 100644 --- a/tests/baselines/reference/numericIndexingResults.types +++ b/tests/baselines/reference/numericIndexingResults.types @@ -30,8 +30,8 @@ var r2 = c['2']; >'2' : "2" var r3 = c['3']; ->r3 : error ->c['3'] : error +>r3 : string +>c['3'] : string >c : C >'3' : "3" @@ -80,8 +80,8 @@ var r2 = i['2']; >'2' : "2" var r3 = i['3']; ->r3 : error ->i['3'] : error +>r3 : string +>i['3'] : string >i : I >'3' : "3" @@ -129,8 +129,8 @@ var r2 = a['2']; >'2' : "2" var r3 = a['3']; ->r3 : error ->a['3'] : error +>r3 : string +>a['3'] : string >a : { [x: number]: string; 1: string; "2": string; } >'3' : "3" @@ -162,20 +162,20 @@ var b: { [x: number]: string } = { 1: '', "2": '' } >'' : "" var r1a = b['1']; ->r1a : error ->b['1'] : error +>r1a : string +>b['1'] : string >b : { [x: number]: string; } >'1' : "1" var r2a = b['2']; ->r2a : error ->b['2'] : error +>r2a : string +>b['2'] : string >b : { [x: number]: string; } >'2' : "2" var r3 = b['3']; ->r3 : error ->b['3'] : error +>r3 : string +>b['3'] : string >b : { [x: number]: string; } >'3' : "3" @@ -221,8 +221,8 @@ var r2b = b2['2']; >'2' : "2" var r3 = b2['3']; ->r3 : error ->b2['3'] : error +>r3 : string +>b2['3'] : string >b2 : { [x: number]: string; 1: string; "2": string; } >'3' : "3" diff --git a/tests/baselines/reference/objectTypeHidingMembersOfExtendedObject.errors.txt b/tests/baselines/reference/objectTypeHidingMembersOfExtendedObject.errors.txt index 4f27c62e67df2..1c200156bab25 100644 --- a/tests/baselines/reference/objectTypeHidingMembersOfExtendedObject.errors.txt +++ b/tests/baselines/reference/objectTypeHidingMembersOfExtendedObject.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'constructor' of type 'Function' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'data' of type 'A' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'toString' of type '() => string' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'valueOf' of type '() => Object' is not assignable to string index type 'Object'. +tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'constructor' of type 'Function' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'data' of type 'A' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'toString' of type '() => string' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'valueOf' of type '() => Object' is not assignable to 'string' index type 'Object'. ==== tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts (8 errors) ==== @@ -21,21 +21,21 @@ tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts data: A; [x: string]: Object; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'constructor' of type 'Function' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'constructor' of type 'Function' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'data' of type 'A' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'data' of type 'A' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'toString' of type '() => string' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'toString' of type '() => string' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'valueOf' of type '() => Object' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'valueOf' of type '() => Object' is not assignable to 'string' index type 'Object'. } class C { diff --git a/tests/baselines/reference/objectTypeWithStringIndexerHidingObjectIndexer.errors.txt b/tests/baselines/reference/objectTypeWithStringIndexerHidingObjectIndexer.errors.txt index 2fadffd195dda..b07de0c567545 100644 --- a/tests/baselines/reference/objectTypeWithStringIndexerHidingObjectIndexer.errors.txt +++ b/tests/baselines/reference/objectTypeWithStringIndexerHidingObjectIndexer.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'constructor' of type 'Function' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'toString' of type '() => string' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'valueOf' of type '() => Object' is not assignable to string index type 'Object'. +tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'constructor' of type 'Function' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'toString' of type '() => string' is not assignable to 'string' index type 'Object'. +tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'valueOf' of type '() => Object' is not assignable to 'string' index type 'Object'. ==== tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts (7 errors) ==== @@ -14,19 +14,19 @@ tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectInd interface Object { [x: string]: Object; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'constructor' of type 'Function' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'constructor' of type 'Function' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'toString' of type '() => string' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'toString' of type '() => string' is not assignable to 'string' index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'valueOf' of type '() => Object' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'valueOf' of type '() => Object' is not assignable to 'string' index type 'Object'. } var o = {}; var r = o['']; // should be Object diff --git a/tests/baselines/reference/parserES5SymbolIndexer3.types b/tests/baselines/reference/parserES5SymbolIndexer3.types index 3476226e2b77a..a39d1e8f61f71 100644 --- a/tests/baselines/reference/parserES5SymbolIndexer3.types +++ b/tests/baselines/reference/parserES5SymbolIndexer3.types @@ -1,6 +1,6 @@ === tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer3.ts === var x: { ->x : {} +>x : { [s: symbol]: string; } [s: symbol]: string; >s : symbol diff --git a/tests/baselines/reference/parserIndexSignature8.types b/tests/baselines/reference/parserIndexSignature8.types index f8d18d540a181..4e5f4faa6548c 100644 --- a/tests/baselines/reference/parserIndexSignature8.types +++ b/tests/baselines/reference/parserIndexSignature8.types @@ -1,9 +1,9 @@ === tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts === var foo: { [index: any]; }; // expect an error here ->foo : {} +>foo : { [index: any]: any; } >index : any var foo2: { [index: RegExp]; }; // expect an error here ->foo2 : {} +>foo2 : { [index: RegExp]: any; } >index : RegExp diff --git a/tests/baselines/reference/parserSymbolIndexer4.types b/tests/baselines/reference/parserSymbolIndexer4.types index 7509072a12cd2..0745c2c223efc 100644 --- a/tests/baselines/reference/parserSymbolIndexer4.types +++ b/tests/baselines/reference/parserSymbolIndexer4.types @@ -1,6 +1,6 @@ === tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolIndexer4.ts === var x: { ->x : {} +>x : { [s: symbol]: string; } [s: symbol]: string; >s : symbol diff --git a/tests/baselines/reference/propertiesAndIndexers.errors.txt b/tests/baselines/reference/propertiesAndIndexers.errors.txt index a8c5fe04d2af3..9cb3fb74224f4 100644 --- a/tests/baselines/reference/propertiesAndIndexers.errors.txt +++ b/tests/baselines/reference/propertiesAndIndexers.errors.txt @@ -1,25 +1,22 @@ -tests/cases/compiler/propertiesAndIndexers.ts(16,5): error TS2412: Property '1' of type 'Z' is not assignable to numeric index type 'string'. -tests/cases/compiler/propertiesAndIndexers.ts(18,5): error TS2412: Property '3' of type 'boolean' is not assignable to numeric index type 'string'. -tests/cases/compiler/propertiesAndIndexers.ts(19,5): error TS2412: Property '6' of type '() => string' is not assignable to numeric index type 'string'. -tests/cases/compiler/propertiesAndIndexers.ts(23,5): error TS2412: Property '4' of type 'boolean' is not assignable to numeric index type 'string'. -tests/cases/compiler/propertiesAndIndexers.ts(28,5): error TS2411: Property '1' of type 'Z' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers.ts(28,5): error TS2411: Property 'a' of type 'Y' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers.ts(28,5): error TS2411: Property 'b' of type 'X' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers.ts(29,5): error TS2411: Property 'c' of type 'boolean' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers.ts(30,5): error TS2411: Property '3' of type 'boolean' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers.ts(33,11): error TS2411: Property '4' of type 'boolean' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers.ts(33,11): error TS2411: Property '5' of type 'string' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers.ts(33,11): error TS2411: Property '6' of type '() => string' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers.ts(33,11): error TS2413: Numeric index type 'string' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers.ts(34,5): error TS2411: Property '2' of type 'Z' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers.ts(34,5): error TS2412: Property '2' of type 'Z' is not assignable to numeric index type 'string'. -tests/cases/compiler/propertiesAndIndexers.ts(35,5): error TS2412: Property 'Infinity' of type 'number' is not assignable to numeric index type 'string'. -tests/cases/compiler/propertiesAndIndexers.ts(36,5): error TS2411: Property 'zoo' of type 'string' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers.ts(44,5): error TS2411: Property 't' of type 'number' is not assignable to string index type 'string'. -tests/cases/compiler/propertiesAndIndexers.ts(50,5): error TS2412: Property '3' of type 'boolean' is not assignable to numeric index type 'string'. +tests/cases/compiler/propertiesAndIndexers.ts(16,5): error TS2411: Property '1' of type 'Z' is not assignable to 'number' index type 'string'. +tests/cases/compiler/propertiesAndIndexers.ts(18,5): error TS2411: Property '3' of type 'boolean' is not assignable to 'number' index type 'string'. +tests/cases/compiler/propertiesAndIndexers.ts(19,5): error TS2411: Property '6' of type '() => string' is not assignable to 'number' index type 'string'. +tests/cases/compiler/propertiesAndIndexers.ts(23,5): error TS2411: Property '4' of type 'boolean' is not assignable to 'number' index type 'string'. +tests/cases/compiler/propertiesAndIndexers.ts(28,5): error TS2411: Property '1' of type 'Z' is not assignable to 'string' index type 'number'. +tests/cases/compiler/propertiesAndIndexers.ts(28,5): error TS2411: Property 'a' of type 'Y' is not assignable to 'string' index type 'number'. +tests/cases/compiler/propertiesAndIndexers.ts(28,5): error TS2411: Property 'b' of type 'X' is not assignable to 'string' index type 'number'. +tests/cases/compiler/propertiesAndIndexers.ts(29,5): error TS2411: Property 'c' of type 'boolean' is not assignable to 'string' index type 'number'. +tests/cases/compiler/propertiesAndIndexers.ts(30,5): error TS2411: Property '3' of type 'boolean' is not assignable to 'string' index type 'number'. +tests/cases/compiler/propertiesAndIndexers.ts(33,11): error TS2413: 'number' index type 'string' is not assignable to 'string' index type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/propertiesAndIndexers.ts(34,5): error TS2411: Property '2' of type 'Z' is not assignable to 'number' index type 'string'. +tests/cases/compiler/propertiesAndIndexers.ts(35,5): error TS2411: Property 'Infinity' of type 'number' is not assignable to 'number' index type 'string'. +tests/cases/compiler/propertiesAndIndexers.ts(36,5): error TS2411: Property 'zoo' of type 'string' is not assignable to 'string' index type 'number'. +tests/cases/compiler/propertiesAndIndexers.ts(44,5): error TS2411: Property 't' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/compiler/propertiesAndIndexers.ts(50,5): error TS2411: Property '3' of type 'boolean' is not assignable to 'number' index type 'string'. -==== tests/cases/compiler/propertiesAndIndexers.ts (19 errors) ==== +==== tests/cases/compiler/propertiesAndIndexers.ts (15 errors) ==== interface X { } interface Y { n: number; @@ -37,59 +34,52 @@ tests/cases/compiler/propertiesAndIndexers.ts(50,5): error TS2412: Property '3' interface B extends A { [n: number]: string; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2412: Property '1' of type 'Z' is not assignable to numeric index type 'string'. +!!! error TS2411: Property '1' of type 'Z' is not assignable to 'number' index type 'string'. c: boolean; 3: boolean; ~ -!!! error TS2412: Property '3' of type 'boolean' is not assignable to numeric index type 'string'. +!!! error TS2411: Property '3' of type 'boolean' is not assignable to 'number' index type 'string'. 6(): string; ~~~~~~~~~~~~ -!!! error TS2412: Property '6' of type '() => string' is not assignable to numeric index type 'string'. +!!! error TS2411: Property '6' of type '() => string' is not assignable to 'number' index type 'string'. } interface B { 4: boolean; ~ -!!! error TS2412: Property '4' of type 'boolean' is not assignable to numeric index type 'string'. +!!! error TS2411: Property '4' of type 'boolean' is not assignable to 'number' index type 'string'. 5: string; } interface C extends A { [s: string]: number; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property '1' of type 'Z' is not assignable to string index type 'number'. +!!! error TS2411: Property '1' of type 'Z' is not assignable to 'string' index type 'number'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'a' of type 'Y' is not assignable to string index type 'number'. +!!! error TS2411: Property 'a' of type 'Y' is not assignable to 'string' index type 'number'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'b' of type 'X' is not assignable to string index type 'number'. +!!! error TS2411: Property 'b' of type 'X' is not assignable to 'string' index type 'number'. c: boolean; ~ -!!! error TS2411: Property 'c' of type 'boolean' is not assignable to string index type 'number'. +!!! error TS2411: Property 'c' of type 'boolean' is not assignable to 'string' index type 'number'. 3: boolean; ~ -!!! error TS2411: Property '3' of type 'boolean' is not assignable to string index type 'number'. +!!! error TS2411: Property '3' of type 'boolean' is not assignable to 'string' index type 'number'. } interface D extends B, C { ~ -!!! error TS2411: Property '4' of type 'boolean' is not assignable to string index type 'number'. - ~ -!!! error TS2411: Property '5' of type 'string' is not assignable to string index type 'number'. - ~ -!!! error TS2411: Property '6' of type '() => string' is not assignable to string index type 'number'. - ~ -!!! error TS2413: Numeric index type 'string' is not assignable to string index type 'number'. +!!! error TS2413: 'number' index type 'string' is not assignable to 'string' index type 'number'. +!!! error TS2413: Type 'string' is not assignable to type 'number'. 2: Z; ~ -!!! error TS2411: Property '2' of type 'Z' is not assignable to string index type 'number'. - ~ -!!! error TS2412: Property '2' of type 'Z' is not assignable to numeric index type 'string'. +!!! error TS2411: Property '2' of type 'Z' is not assignable to 'number' index type 'string'. Infinity: number; ~~~~~~~~ -!!! error TS2412: Property 'Infinity' of type 'number' is not assignable to numeric index type 'string'. +!!! error TS2411: Property 'Infinity' of type 'number' is not assignable to 'number' index type 'string'. zoo: string; ~~~ -!!! error TS2411: Property 'zoo' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property 'zoo' of type 'string' is not assignable to 'string' index type 'number'. } class P { @@ -99,7 +89,7 @@ tests/cases/compiler/propertiesAndIndexers.ts(50,5): error TS2412: Property '3' class Q extends P { t: number; ~ -!!! error TS2411: Property 't' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property 't' of type 'number' is not assignable to 'string' index type 'string'. } var c: { @@ -107,5 +97,5 @@ tests/cases/compiler/propertiesAndIndexers.ts(50,5): error TS2412: Property '3' c: boolean; 3: boolean; ~ -!!! error TS2412: Property '3' of type 'boolean' is not assignable to numeric index type 'string'. +!!! error TS2411: Property '3' of type 'boolean' is not assignable to 'number' index type 'string'. }; \ No newline at end of file diff --git a/tests/baselines/reference/propertiesAndIndexers2.errors.txt b/tests/baselines/reference/propertiesAndIndexers2.errors.txt index a616075599a77..2bed2c42876d9 100644 --- a/tests/baselines/reference/propertiesAndIndexers2.errors.txt +++ b/tests/baselines/reference/propertiesAndIndexers2.errors.txt @@ -1,19 +1,16 @@ -tests/cases/compiler/propertiesAndIndexers2.ts(2,5): error TS2413: Numeric index type 'string' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers2.ts(8,5): error TS2411: Property 'c' of type 'string' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers2.ts(9,5): error TS2411: Property '3' of type 'string' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers2.ts(10,5): error TS2411: Property 'Infinity' of type 'string' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers2.ts(11,5): error TS2411: Property '"-Infinity"' of type 'string' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers2.ts(12,5): error TS2411: Property 'NaN' of type 'string' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers2.ts(13,5): error TS2411: Property '"-NaN"' of type 'string' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers2.ts(14,5): error TS2411: Property '6' of type '() => string' is not assignable to string index type 'number'. -tests/cases/compiler/propertiesAndIndexers2.ts(14,5): error TS2412: Property '6' of type '() => string' is not assignable to numeric index type 'string'. +tests/cases/compiler/propertiesAndIndexers2.ts(2,5): error TS2413: 'number' index type 'string' is not assignable to 'string' index type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(8,5): error TS2411: Property 'c' of type 'string' is not assignable to 'string' index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(13,5): error TS2411: Property '"-NaN"' of type 'string' is not assignable to 'string' index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(14,5): error TS2411: Property '6' of type '() => string' is not assignable to 'number' index type 'string'. -==== tests/cases/compiler/propertiesAndIndexers2.ts (9 errors) ==== +==== tests/cases/compiler/propertiesAndIndexers2.ts (4 errors) ==== interface A { [n: number]: string; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2413: Numeric index type 'string' is not assignable to string index type 'number'. +!!! error TS2413: 'number' index type 'string' is not assignable to 'string' index type 'number'. +!!! error TS2413: Type 'string' is not assignable to type 'number'. [s: string]: number; } @@ -21,26 +18,16 @@ tests/cases/compiler/propertiesAndIndexers2.ts(14,5): error TS2412: Property '6' interface B extends A { c: string; ~ -!!! error TS2411: Property 'c' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property 'c' of type 'string' is not assignable to 'string' index type 'number'. 3: string; - ~ -!!! error TS2411: Property '3' of type 'string' is not assignable to string index type 'number'. Infinity: string; - ~~~~~~~~ -!!! error TS2411: Property 'Infinity' of type 'string' is not assignable to string index type 'number'. "-Infinity": string; - ~~~~~~~~~~~ -!!! error TS2411: Property '"-Infinity"' of type 'string' is not assignable to string index type 'number'. NaN: string; - ~~~ -!!! error TS2411: Property 'NaN' of type 'string' is not assignable to string index type 'number'. "-NaN": string; ~~~~~~ -!!! error TS2411: Property '"-NaN"' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property '"-NaN"' of type 'string' is not assignable to 'string' index type 'number'. 6(): string; ~~~~~~~~~~~~ -!!! error TS2411: Property '6' of type '() => string' is not assignable to string index type 'number'. - ~~~~~~~~~~~~ -!!! error TS2412: Property '6' of type '() => string' is not assignable to numeric index type 'string'. +!!! error TS2411: Property '6' of type '() => string' is not assignable to 'number' index type 'string'. } \ No newline at end of file diff --git a/tests/baselines/reference/propertiesAndIndexersForNumericNames.errors.txt b/tests/baselines/reference/propertiesAndIndexersForNumericNames.errors.txt index f256cb0f4c18c..03f00bc63a4d7 100644 --- a/tests/baselines/reference/propertiesAndIndexersForNumericNames.errors.txt +++ b/tests/baselines/reference/propertiesAndIndexersForNumericNames.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(6,12): error TS2412: Property '"1"' of type 'string' is not assignable to numeric index type 'number'. -tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(7,12): error TS2412: Property '"-1"' of type 'string' is not assignable to numeric index type 'number'. -tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(8,12): error TS2412: Property '"-2.5"' of type 'string' is not assignable to numeric index type 'number'. -tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(9,12): error TS2412: Property '"3.141592"' of type 'string' is not assignable to numeric index type 'number'. -tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(10,12): error TS2412: Property '"1.2e-20"' of type 'string' is not assignable to numeric index type 'number'. -tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(11,12): error TS2412: Property '"Infinity"' of type 'string' is not assignable to numeric index type 'number'. -tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(12,12): error TS2412: Property '"-Infinity"' of type 'string' is not assignable to numeric index type 'number'. -tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(13,12): error TS2412: Property '"NaN"' of type 'string' is not assignable to numeric index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(6,12): error TS2411: Property '"1"' of type 'string' is not assignable to 'number' index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(7,12): error TS2411: Property '"-1"' of type 'string' is not assignable to 'number' index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(8,12): error TS2411: Property '"-2.5"' of type 'string' is not assignable to 'number' index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(9,12): error TS2411: Property '"3.141592"' of type 'string' is not assignable to 'number' index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(10,12): error TS2411: Property '"1.2e-20"' of type 'string' is not assignable to 'number' index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(11,12): error TS2411: Property '"Infinity"' of type 'string' is not assignable to 'number' index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(12,12): error TS2411: Property '"-Infinity"' of type 'string' is not assignable to 'number' index type 'number'. +tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(13,12): error TS2411: Property '"NaN"' of type 'string' is not assignable to 'number' index type 'number'. ==== tests/cases/compiler/propertiesAndIndexersForNumericNames.ts (8 errors) ==== @@ -16,28 +16,28 @@ tests/cases/compiler/propertiesAndIndexersForNumericNames.ts(13,12): error TS241 // because their types are not compatible with the numeric indexer. public "1": string = "number"; // Error ~~~ -!!! error TS2412: Property '"1"' of type 'string' is not assignable to numeric index type 'number'. +!!! error TS2411: Property '"1"' of type 'string' is not assignable to 'number' index type 'number'. public "-1": string = "negative number"; // Error ~~~~ -!!! error TS2412: Property '"-1"' of type 'string' is not assignable to numeric index type 'number'. +!!! error TS2411: Property '"-1"' of type 'string' is not assignable to 'number' index type 'number'. public "-2.5": string = "negative number"; // Error ~~~~~~ -!!! error TS2412: Property '"-2.5"' of type 'string' is not assignable to numeric index type 'number'. +!!! error TS2411: Property '"-2.5"' of type 'string' is not assignable to 'number' index type 'number'. public "3.141592": string = "pi-sitive number"; // Error ~~~~~~~~~~ -!!! error TS2412: Property '"3.141592"' of type 'string' is not assignable to numeric index type 'number'. +!!! error TS2411: Property '"3.141592"' of type 'string' is not assignable to 'number' index type 'number'. public "1.2e-20": string = "really small number"; // Error ~~~~~~~~~ -!!! error TS2412: Property '"1.2e-20"' of type 'string' is not assignable to numeric index type 'number'. +!!! error TS2411: Property '"1.2e-20"' of type 'string' is not assignable to 'number' index type 'number'. public "Infinity": string = "A gillion"; // Error ~~~~~~~~~~ -!!! error TS2412: Property '"Infinity"' of type 'string' is not assignable to numeric index type 'number'. +!!! error TS2411: Property '"Infinity"' of type 'string' is not assignable to 'number' index type 'number'. public "-Infinity": string = "Negative-a-gillion"; // Error ~~~~~~~~~~~ -!!! error TS2412: Property '"-Infinity"' of type 'string' is not assignable to numeric index type 'number'. +!!! error TS2411: Property '"-Infinity"' of type 'string' is not assignable to 'number' index type 'number'. public "NaN": string = "not a number"; // Error ~~~~~ -!!! error TS2412: Property '"NaN"' of type 'string' is not assignable to numeric index type 'number'. +!!! error TS2411: Property '"NaN"' of type 'string' is not assignable to 'number' index type 'number'. // These all have *partially* numeric names, // but should really be treated as plain string literals. diff --git a/tests/baselines/reference/readonlyMembers.errors.txt b/tests/baselines/reference/readonlyMembers.errors.txt index 9baf37f27e7f1..6e79fcd0e3773 100644 --- a/tests/baselines/reference/readonlyMembers.errors.txt +++ b/tests/baselines/reference/readonlyMembers.errors.txt @@ -12,7 +12,7 @@ tests/cases/compiler/readonlyMembers.ts(39,3): error TS2540: Cannot assign to 'a tests/cases/compiler/readonlyMembers.ts(48,3): error TS2540: Cannot assign to 'A' because it is a constant or a read-only property. tests/cases/compiler/readonlyMembers.ts(55,3): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. tests/cases/compiler/readonlyMembers.ts(61,1): error TS2542: Index signature in type '{ readonly [x: string]: string; }' only permits reading. -tests/cases/compiler/readonlyMembers.ts(64,1): error TS2542: Index signature in type '{ [x: string]: string; readonly [x: number]: string; }' only permits reading. +tests/cases/compiler/readonlyMembers.ts(64,1): error TS2542: Index signature in type '{ readonly [x: number]: string; [x: string]: string; }' only permits reading. ==== tests/cases/compiler/readonlyMembers.ts (15 errors) ==== @@ -109,5 +109,5 @@ tests/cases/compiler/readonlyMembers.ts(64,1): error TS2542: Index signature in let yy: { readonly [x: number]: string, [x: string]: string }; yy[1] = "abc"; // Error ~~~~~ -!!! error TS2542: Index signature in type '{ [x: string]: string; readonly [x: number]: string; }' only permits reading. +!!! error TS2542: Index signature in type '{ readonly [x: number]: string; [x: string]: string; }' only permits reading. yy["foo"] = "abc"; \ No newline at end of file diff --git a/tests/baselines/reference/readonlyMembers.types b/tests/baselines/reference/readonlyMembers.types index 4a69289b710b2..eb71ec9eb59aa 100644 --- a/tests/baselines/reference/readonlyMembers.types +++ b/tests/baselines/reference/readonlyMembers.types @@ -258,21 +258,21 @@ xx["foo"] = "abc"; // Error >"abc" : "abc" let yy: { readonly [x: number]: string, [x: string]: string }; ->yy : { [x: string]: string; readonly [x: number]: string; } +>yy : { readonly [x: number]: string; [x: string]: string; } >x : number >x : string yy[1] = "abc"; // Error >yy[1] = "abc" : "abc" >yy[1] : string ->yy : { [x: string]: string; readonly [x: number]: string; } +>yy : { readonly [x: number]: string; [x: string]: string; } >1 : 1 >"abc" : "abc" yy["foo"] = "abc"; >yy["foo"] = "abc" : "abc" >yy["foo"] : string ->yy : { [x: string]: string; readonly [x: number]: string; } +>yy : { readonly [x: number]: string; [x: string]: string; } >"foo" : "foo" >"abc" : "abc" diff --git a/tests/baselines/reference/recursiveTypesWithTypeof.types b/tests/baselines/reference/recursiveTypesWithTypeof.types index 5625e7919cd2a..1d5db5d85e0c1 100644 --- a/tests/baselines/reference/recursiveTypesWithTypeof.types +++ b/tests/baselines/reference/recursiveTypesWithTypeof.types @@ -123,22 +123,22 @@ var j2 = new j2(j2); // Indexers var k: { [n: number]: typeof k;[s: string]: typeof k }; ->k : { [s: string]: any; [n: number]: any; } +>k : { [n: number]: any; [s: string]: any; } >n : number ->k : { [s: string]: any; [n: number]: any; } +>k : { [n: number]: any; [s: string]: any; } >s : string ->k : { [s: string]: any; [n: number]: any; } +>k : { [n: number]: any; [s: string]: any; } var k = k[0]; ->k : { [s: string]: any; [n: number]: any; } ->k[0] : { [s: string]: any; [n: number]: any; } ->k : { [s: string]: any; [n: number]: any; } +>k : { [n: number]: any; [s: string]: any; } +>k[0] : { [n: number]: any; [s: string]: any; } +>k : { [n: number]: any; [s: string]: any; } >0 : 0 var k = k['']; ->k : { [s: string]: any; [n: number]: any; } ->k[''] : { [s: string]: any; [n: number]: any; } ->k : { [s: string]: any; [n: number]: any; } +>k : { [n: number]: any; [s: string]: any; } +>k[''] : { [n: number]: any; [s: string]: any; } +>k : { [n: number]: any; [s: string]: any; } >'' : "" // Hybrid - contains type literals as well as type arguments diff --git a/tests/baselines/reference/stringIndexerAndConstructor.errors.txt b/tests/baselines/reference/stringIndexerAndConstructor.errors.txt index 66122d93de952..069ff35bad2fe 100644 --- a/tests/baselines/reference/stringIndexerAndConstructor.errors.txt +++ b/tests/baselines/reference/stringIndexerAndConstructor.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/stringIndexerAndConstructor.ts(11,5): error TS2411: Property '""' of type 'string' is not assignable to string index type 'number'. -tests/cases/compiler/stringIndexerAndConstructor.ts(12,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/stringIndexerAndConstructor.ts(11,5): error TS2411: Property '""' of type 'string' is not assignable to 'string' index type 'number'. +tests/cases/compiler/stringIndexerAndConstructor.ts(12,5): error TS2411: Property 'd' of type 'string' is not assignable to 'string' index type 'number'. ==== tests/cases/compiler/stringIndexerAndConstructor.ts (2 errors) ==== @@ -15,8 +15,8 @@ tests/cases/compiler/stringIndexerAndConstructor.ts(12,5): error TS2411: Propert new (): boolean; "": string; ~~ -!!! error TS2411: Property '""' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property '""' of type 'string' is not assignable to 'string' index type 'number'. d: string; ~ -!!! error TS2411: Property 'd' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property 'd' of type 'string' is not assignable to 'string' index type 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/stringIndexerAndConstructor1.errors.txt b/tests/baselines/reference/stringIndexerAndConstructor1.errors.txt index 28783924d2cf5..bb220d75a54f2 100644 --- a/tests/baselines/reference/stringIndexerAndConstructor1.errors.txt +++ b/tests/baselines/reference/stringIndexerAndConstructor1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/stringIndexerAndConstructor1.ts(3,5): error TS2411: Property '""' of type 'string' is not assignable to string index type 'number'. +tests/cases/compiler/stringIndexerAndConstructor1.ts(3,5): error TS2411: Property '""' of type 'string' is not assignable to 'string' index type 'number'. ==== tests/cases/compiler/stringIndexerAndConstructor1.ts (1 errors) ==== @@ -6,5 +6,5 @@ tests/cases/compiler/stringIndexerAndConstructor1.ts(3,5): error TS2411: Propert [s: string]: number; "": string; ~~ -!!! error TS2411: Property '""' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property '""' of type 'string' is not assignable to 'string' index type 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt index 00fc13f186eec..1d07fbfb4498b 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations.errors.txt @@ -1,27 +1,27 @@ -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(13,5): error TS2411: Property 'b' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(14,5): error TS2411: Property 'c' of type '() => {}' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(16,5): error TS2411: Property '"e"' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(18,5): error TS2411: Property '2.0' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(20,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(21,5): error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(13,5): error TS2411: Property 'b' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(14,5): error TS2411: Property 'c' of type '() => {}' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(16,5): error TS2411: Property '"e"' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(18,5): error TS2411: Property '2.0' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(20,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(21,5): error TS2411: Property 'f' of type 'MyString' is not assignable to 'string' index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(23,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(26,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(28,5): error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(28,5): error TS2411: Property 'foo' of type '() => string' is not assignable to 'string' index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(36,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(45,5): error TS2411: Property 'b' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(46,5): error TS2411: Property 'c' of type '() => {}' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(48,5): error TS2411: Property '"e"' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(50,5): error TS2411: Property '2.0' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(53,5): error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(55,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(56,5): error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(63,5): error TS2411: Property 'b' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(64,5): error TS2411: Property 'c' of type '() => {}' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(66,5): error TS2411: Property '"e"' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2411: Property '2.0' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(71,5): error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(74,5): error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(45,5): error TS2411: Property 'b' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(46,5): error TS2411: Property 'c' of type '() => {}' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(48,5): error TS2411: Property '"e"' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(50,5): error TS2411: Property '2.0' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(53,5): error TS2411: Property 'foo' of type '() => string' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(55,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(56,5): error TS2411: Property 'f' of type 'MyString' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(63,5): error TS2411: Property 'b' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(64,5): error TS2411: Property 'c' of type '() => {}' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(66,5): error TS2411: Property '"e"' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(68,5): error TS2411: Property '2.0' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(71,5): error TS2411: Property 'foo' of type '() => string' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(73,5): error TS2411: Property '"4.0"' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(74,5): error TS2411: Property 'f' of type 'MyString' is not assignable to 'string' index type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(80,5): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(81,5): error TS2322: Type '() => void' is not assignable to type 'string'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations.ts(83,5): error TS2322: Type 'number' is not assignable to type 'string'. @@ -48,25 +48,25 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon a: string; // ok b: number; // error ~ -!!! error TS2411: Property 'b' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property 'b' of type 'number' is not assignable to 'string' index type 'string'. c: () => {} // error ~ -!!! error TS2411: Property 'c' of type '() => {}' is not assignable to string index type 'string'. +!!! error TS2411: Property 'c' of type '() => {}' is not assignable to 'string' index type 'string'. "d": string; // ok "e": number; // error ~~~ -!!! error TS2411: Property '"e"' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property '"e"' of type 'number' is not assignable to 'string' index type 'string'. 1.0: string; // ok 2.0: number; // error ~~~ -!!! error TS2411: Property '2.0' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property '2.0' of type 'number' is not assignable to 'string' index type 'string'. "3.0": string; // ok "4.0": number; // error ~~~~~ -!!! error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property '"4.0"' of type 'number' is not assignable to 'string' index type 'string'. f: MyString; // error ~ -!!! error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. +!!! error TS2411: Property 'f' of type 'MyString' is not assignable to 'string' index type 'string'. get X() { // ok ~ @@ -79,7 +79,7 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon foo() { // error ~~~ -!!! error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. +!!! error TS2411: Property 'foo' of type '() => string' is not assignable to 'string' index type 'string'. return ''; } @@ -100,30 +100,30 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon a: string; // ok b: number; // error ~ -!!! error TS2411: Property 'b' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property 'b' of type 'number' is not assignable to 'string' index type 'string'. c: () => {} // error ~ -!!! error TS2411: Property 'c' of type '() => {}' is not assignable to string index type 'string'. +!!! error TS2411: Property 'c' of type '() => {}' is not assignable to 'string' index type 'string'. "d": string; // ok "e": number; // error ~~~ -!!! error TS2411: Property '"e"' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property '"e"' of type 'number' is not assignable to 'string' index type 'string'. 1.0: string; // ok 2.0: number; // error ~~~ -!!! error TS2411: Property '2.0' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property '2.0' of type 'number' is not assignable to 'string' index type 'string'. (): string; // ok (x): number // ok foo(): string; // error ~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. +!!! error TS2411: Property 'foo' of type '() => string' is not assignable to 'string' index type 'string'. "3.0": string; // ok "4.0": number; // error ~~~~~ -!!! error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property '"4.0"' of type 'number' is not assignable to 'string' index type 'string'. f: MyString; // error ~ -!!! error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. +!!! error TS2411: Property 'f' of type 'MyString' is not assignable to 'string' index type 'string'. } var a: { @@ -132,30 +132,30 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon a: string; // ok b: number; // error ~ -!!! error TS2411: Property 'b' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property 'b' of type 'number' is not assignable to 'string' index type 'string'. c: () => {} // error ~ -!!! error TS2411: Property 'c' of type '() => {}' is not assignable to string index type 'string'. +!!! error TS2411: Property 'c' of type '() => {}' is not assignable to 'string' index type 'string'. "d": string; // ok "e": number; // error ~~~ -!!! error TS2411: Property '"e"' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property '"e"' of type 'number' is not assignable to 'string' index type 'string'. 1.0: string; // ok 2.0: number; // error ~~~ -!!! error TS2411: Property '2.0' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property '2.0' of type 'number' is not assignable to 'string' index type 'string'. (): string; // ok (x): number // ok foo(): string; // error ~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo' of type '() => string' is not assignable to string index type 'string'. +!!! error TS2411: Property 'foo' of type '() => string' is not assignable to 'string' index type 'string'. "3.0": string; // ok "4.0": number; // error ~~~~~ -!!! error TS2411: Property '"4.0"' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property '"4.0"' of type 'number' is not assignable to 'string' index type 'string'. f: MyString; // error ~ -!!! error TS2411: Property 'f' of type 'MyString' is not assignable to string index type 'string'. +!!! error TS2411: Property 'f' of type 'MyString' is not assignable to 'string' index type 'string'. } // error diff --git a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt index 3a33fe7405631..6161a05c88356 100644 --- a/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt +++ b/tests/baselines/reference/stringIndexerConstrainsPropertyDeclarations2.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(15,5): error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(16,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(23,5): error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(24,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(31,5): error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'. -tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(32,5): error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(15,5): error TS2411: Property 'c' of type 'number' is not assignable to 'string' index type 'A'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(16,5): error TS2411: Property 'd' of type 'string' is not assignable to 'string' index type 'A'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(23,5): error TS2411: Property 'c' of type 'number' is not assignable to 'string' index type 'A'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(24,5): error TS2411: Property 'd' of type 'string' is not assignable to 'string' index type 'A'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(31,5): error TS2411: Property 'c' of type 'number' is not assignable to 'string' index type 'A'. +tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(32,5): error TS2411: Property 'd' of type 'string' is not assignable to 'string' index type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(37,5): error TS2322: Type 'typeof A' is not assignable to type 'A'. Property 'foo' is missing in type 'typeof A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(38,5): error TS2322: Type 'typeof B' is not assignable to type 'A'. @@ -27,10 +27,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon b: B; // ok c: number; // error ~ -!!! error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'. +!!! error TS2411: Property 'c' of type 'number' is not assignable to 'string' index type 'A'. d: string; // error ~ -!!! error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'. +!!! error TS2411: Property 'd' of type 'string' is not assignable to 'string' index type 'A'. } interface Foo2 { @@ -39,10 +39,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon b: B; // ok c: number; // error ~ -!!! error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'. +!!! error TS2411: Property 'c' of type 'number' is not assignable to 'string' index type 'A'. d: string; // error ~ -!!! error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'. +!!! error TS2411: Property 'd' of type 'string' is not assignable to 'string' index type 'A'. } var a: { @@ -51,10 +51,10 @@ tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerCon b: B; // ok c: number; // error ~ -!!! error TS2411: Property 'c' of type 'number' is not assignable to string index type 'A'. +!!! error TS2411: Property 'c' of type 'number' is not assignable to 'string' index type 'A'. d: string; // error ~ -!!! error TS2411: Property 'd' of type 'string' is not assignable to string index type 'A'. +!!! error TS2411: Property 'd' of type 'string' is not assignable to 'string' index type 'A'. }; // error diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt index 627a887d437ef..3deebe80977c2 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt @@ -1,36 +1,36 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(19,5): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(50,5): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. Type 'V' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(67,5): error TS2416: Property 'foo' in type 'D11' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(72,5): error TS2416: Property 'foo' in type 'D12' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(112,5): error TS2416: Property 'foo' in type 'D19' is not assignable to the same property in base type 'C3'. Type 'U' is not assignable to type 'T'. Type 'V' is not assignable to type 'T'. Type 'Date' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(134,5): error TS2416: Property 'foo' in type 'D23' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'T'. Type 'Date' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(139,5): error TS2416: Property 'foo' in type 'D24' is not assignable to the same property in base type 'C3'. Type 'V' is not assignable to type 'U'. Type 'Date' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2411: Property 'foo' of type 'Date' is not assignable to 'string' index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(156,5): error TS2416: Property 'foo' in type 'D27' is not assignable to the same property in base type 'C3'. Type 'Date' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2411: Property 'foo' of type 'Date' is not assignable to 'string' index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(161,5): error TS2416: Property 'foo' in type 'D28' is not assignable to the same property in base type 'C3'. Type 'Date' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'V'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2411: Property 'foo' of type 'Date' is not assignable to 'string' index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints.ts(166,5): error TS2416: Property 'foo' in type 'D29' is not assignable to the same property in base type 'C3'. Type 'Date' is not assignable to type 'V'. @@ -56,7 +56,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: U; // error ~~~ -!!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'T'. ~~~ !!! error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'U' is not assignable to type 'T'. @@ -92,7 +92,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: U; // error ~~~ -!!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'T'. ~~~ !!! error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'U' is not assignable to type 'T'. @@ -115,7 +115,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: V; // error ~~~ -!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'T'. ~~~ !!! error TS2416: Property 'foo' in type 'D11' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'V' is not assignable to type 'T'. @@ -125,7 +125,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: U; foo: V; // error ~~~ -!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. +!!! error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'U'. ~~~ !!! error TS2416: Property 'foo' in type 'D12' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'V' is not assignable to type 'U'. @@ -170,7 +170,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: U; // error ~~~ -!!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'T'. ~~~ !!! error TS2416: Property 'foo' in type 'D19' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'U' is not assignable to type 'T'. @@ -199,7 +199,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: V; // error ~~~ -!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'T'. ~~~ !!! error TS2416: Property 'foo' in type 'D23' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'V' is not assignable to type 'T'. @@ -210,7 +210,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: U; foo: V; // error ~~~ -!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. +!!! error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'U'. ~~~ !!! error TS2416: Property 'foo' in type 'D24' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'V' is not assignable to type 'U'. @@ -233,7 +233,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: Date; // error ~~~ -!!! error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'Date' is not assignable to 'string' index type 'T'. ~~~ !!! error TS2416: Property 'foo' in type 'D27' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'Date' is not assignable to type 'T'. @@ -243,7 +243,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: U; foo: Date; // error ~~~ -!!! error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'U'. +!!! error TS2411: Property 'foo' of type 'Date' is not assignable to 'string' index type 'U'. ~~~ !!! error TS2416: Property 'foo' in type 'D28' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'Date' is not assignable to type 'U'. @@ -253,7 +253,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: V; foo: Date; // error ~~~ -!!! error TS2411: Property 'foo' of type 'Date' is not assignable to string index type 'V'. +!!! error TS2411: Property 'foo' of type 'Date' is not assignable to 'string' index type 'V'. ~~~ !!! error TS2416: Property 'foo' in type 'D29' is not assignable to the same property in base type 'C3'. !!! error TS2416: Type 'Date' is not assignable to type 'V'. diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt index bdf0473df01a5..a3de3e74f857b 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt @@ -1,18 +1,18 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'Foo'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'Foo'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(47,5): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'Foo'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(57,5): error TS2416: Property 'foo' in type 'D5' is not assignable to the same property in base type 'B1'. Type 'U' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(62,5): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2411: Property 'foo' of type 'T' is not assignable to 'string' index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(67,5): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'B1'. Type 'T' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithConstraints4.ts(77,5): error TS2416: Property 'foo' in type 'D9' is not assignable to the same property in base type 'B1'. Type 'V' is not assignable to type 'U'. @@ -66,7 +66,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: Foo; foo: V; // error ~~~ -!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'Foo'. +!!! error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'Foo'. ~~~ !!! error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'Foo'. @@ -81,7 +81,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: U; // error ~~~ -!!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'T'. ~~~ !!! error TS2416: Property 'foo' in type 'D5' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'U' is not assignable to type 'T'. @@ -92,7 +92,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: V; // error ~~~ -!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'T'. ~~~ !!! error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'T'. @@ -102,7 +102,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: U; foo: T; // error ~~~ -!!! error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. +!!! error TS2411: Property 'foo' of type 'T' is not assignable to 'string' index type 'U'. ~~~ !!! error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'T' is not assignable to type 'U'. @@ -118,7 +118,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: U; foo: V; // error ~~~ -!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. +!!! error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'U'. ~~~ !!! error TS2416: Property 'foo' in type 'D9' is not assignable to the same property in base type 'B1'. !!! error TS2416: Type 'V' is not assignable to type 'U'. diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt index 700076db4d190..813a22da5efc3 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt @@ -1,24 +1,24 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(68,9): error TS2416: Property 'foo' in type 'D2' is not assignable to the same property in base type 'Base'. Type 'U' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(73,9): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base'. Type 'V' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2411: Property 'foo' of type 'T' is not assignable to 'string' index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(78,9): error TS2416: Property 'foo' in type 'D4' is not assignable to the same property in base type 'Base'. Type 'T' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(88,9): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base'. Type 'V' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2411: Property 'foo' of type 'T' is not assignable to 'string' index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(93,9): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base'. Type 'T' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(98,9): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base'. Type 'U' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. @@ -27,32 +27,32 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf Type 'Foo' is not assignable to type 'Foo'. Type 'U' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(120,9): error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(125,9): error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base2'. Type 'V' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'V' is not assignable to type 'T'. Type 'Foo' is not assignable to type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(130,9): error TS2411: Property 'foo' of type 'T' is not assignable to 'string' index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(135,9): error TS2416: Property 'foo' in type 'D5' is not assignable to the same property in base type 'Base2'. Type 'U' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'T' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'U'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(140,9): error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base2'. Type 'V' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'V' is not assignable to type 'U'. Type 'Foo' is not assignable to type 'U'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2411: Property 'foo' of type 'T' is not assignable to 'string' index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(145,9): error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base2'. Type 'T' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. Type 'U' is not assignable to type 'V'. Type 'Foo' is not assignable to type 'V'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'V'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfTypeParameterWithRecursiveConstraints.ts(150,9): error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base2'. Type 'U' is not assignable to type 'Foo'. Type 'Foo' is not assignable to type 'Foo'. @@ -130,7 +130,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: U ~~~ -!!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'T'. ~~~ !!! error TS2416: Property 'foo' in type 'D2' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'U' is not assignable to type 'T'. @@ -141,7 +141,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: V ~~~ -!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'T'. ~~~ !!! error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'V' is not assignable to type 'T'. @@ -152,7 +152,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: U; foo: T ~~~ -!!! error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. +!!! error TS2411: Property 'foo' of type 'T' is not assignable to 'string' index type 'U'. ~~~ !!! error TS2416: Property 'foo' in type 'D4' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'T' is not assignable to type 'U'. @@ -168,7 +168,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: U; foo: V ~~~ -!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. +!!! error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'U'. ~~~ !!! error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'V' is not assignable to type 'U'. @@ -179,7 +179,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: V; foo: T ~~~ -!!! error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'. +!!! error TS2411: Property 'foo' of type 'T' is not assignable to 'string' index type 'V'. ~~~ !!! error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'T' is not assignable to type 'V'. @@ -190,7 +190,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: V; foo: U ~~~ -!!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'. +!!! error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'V'. ~~~ !!! error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base'. !!! error TS2416: Type 'U' is not assignable to type 'V'. @@ -224,14 +224,14 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: T; foo: U ~~~ -!!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'T'. } class D3, U extends Foo, V extends Foo> extends Base2 { [x: string]: T; foo: V ~~~ -!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'T'. ~~~ !!! error TS2416: Property 'foo' in type 'D3' is not assignable to the same property in base type 'Base2'. !!! error TS2416: Type 'V' is not assignable to type 'Foo'. @@ -244,7 +244,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: U; foo: T ~~~ -!!! error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'U'. +!!! error TS2411: Property 'foo' of type 'T' is not assignable to 'string' index type 'U'. } class D5, U extends Foo, V extends Foo> extends Base2 { @@ -262,7 +262,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: U; foo: V ~~~ -!!! error TS2411: Property 'foo' of type 'V' is not assignable to string index type 'U'. +!!! error TS2411: Property 'foo' of type 'V' is not assignable to 'string' index type 'U'. ~~~ !!! error TS2416: Property 'foo' in type 'D6' is not assignable to the same property in base type 'Base2'. !!! error TS2416: Type 'V' is not assignable to type 'Foo'. @@ -275,7 +275,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: V; foo: T ~~~ -!!! error TS2411: Property 'foo' of type 'T' is not assignable to string index type 'V'. +!!! error TS2411: Property 'foo' of type 'T' is not assignable to 'string' index type 'V'. ~~~ !!! error TS2416: Property 'foo' in type 'D7' is not assignable to the same property in base type 'Base2'. !!! error TS2416: Type 'T' is not assignable to type 'Foo'. @@ -288,7 +288,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf [x: string]: V; foo: U ~~~ -!!! error TS2411: Property 'foo' of type 'U' is not assignable to string index type 'V'. +!!! error TS2411: Property 'foo' of type 'U' is not assignable to 'string' index type 'V'. ~~~ !!! error TS2416: Property 'foo' in type 'D8' is not assignable to the same property in base type 'Base2'. !!! error TS2416: Type 'U' is not assignable to type 'Foo'. diff --git a/tests/baselines/reference/subtypesOfUnion.errors.txt b/tests/baselines/reference/subtypesOfUnion.errors.txt index aa30d24f5bdc3..400f3cbe44e99 100644 --- a/tests/baselines/reference/subtypesOfUnion.errors.txt +++ b/tests/baselines/reference/subtypesOfUnion.errors.txt @@ -1,32 +1,32 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(16,5): error TS2411: Property 'foo4' of type 'boolean' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(18,5): error TS2411: Property 'foo6' of type 'Date' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(19,5): error TS2411: Property 'foo7' of type 'RegExp' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(20,5): error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(21,5): error TS2411: Property 'foo9' of type 'I8' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(22,5): error TS2411: Property 'foo10' of type 'A' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(23,5): error TS2411: Property 'foo11' of type 'A2' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(24,5): error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(25,5): error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(26,5): error TS2411: Property 'foo14' of type 'typeof f' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(27,5): error TS2411: Property 'foo15' of type 'typeof c' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(28,5): error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(29,5): error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(30,5): error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(35,5): error TS2411: Property 'foo2' of type 'string' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(37,5): error TS2411: Property 'foo4' of type 'boolean' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(39,5): error TS2411: Property 'foo6' of type 'Date' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(40,5): error TS2411: Property 'foo7' of type 'RegExp' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(41,5): error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(42,5): error TS2411: Property 'foo9' of type 'I8' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(43,5): error TS2411: Property 'foo10' of type 'A' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(44,5): error TS2411: Property 'foo11' of type 'A2' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(45,5): error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(46,5): error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(47,5): error TS2411: Property 'foo14' of type 'typeof f' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(48,5): error TS2411: Property 'foo15' of type 'typeof c' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(49,5): error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(50,5): error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(51,5): error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(16,5): error TS2411: Property 'foo4' of type 'boolean' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(18,5): error TS2411: Property 'foo6' of type 'Date' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(19,5): error TS2411: Property 'foo7' of type 'RegExp' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(20,5): error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(21,5): error TS2411: Property 'foo9' of type 'I8' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(22,5): error TS2411: Property 'foo10' of type 'A' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(23,5): error TS2411: Property 'foo11' of type 'A2' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(24,5): error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(25,5): error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(26,5): error TS2411: Property 'foo14' of type 'typeof f' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(27,5): error TS2411: Property 'foo15' of type 'typeof c' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(28,5): error TS2411: Property 'foo16' of type 'T' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(29,5): error TS2411: Property 'foo17' of type 'Object' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(30,5): error TS2411: Property 'foo18' of type '{}' is not assignable to 'string' index type 'string | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(35,5): error TS2411: Property 'foo2' of type 'string' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(37,5): error TS2411: Property 'foo4' of type 'boolean' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(39,5): error TS2411: Property 'foo6' of type 'Date' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(40,5): error TS2411: Property 'foo7' of type 'RegExp' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(41,5): error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(42,5): error TS2411: Property 'foo9' of type 'I8' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(43,5): error TS2411: Property 'foo10' of type 'A' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(44,5): error TS2411: Property 'foo11' of type 'A2' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(45,5): error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(46,5): error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(47,5): error TS2411: Property 'foo14' of type 'typeof f' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(48,5): error TS2411: Property 'foo15' of type 'typeof c' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(49,5): error TS2411: Property 'foo16' of type 'T' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(50,5): error TS2411: Property 'foo17' of type 'Object' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(51,5): error TS2411: Property 'foo18' of type '{}' is not assignable to 'string' index type 'number'. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts (29 errors) ==== @@ -47,96 +47,96 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf foo3: number; // ok foo4: boolean; // error ~~~~ -!!! error TS2411: Property 'foo4' of type 'boolean' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo4' of type 'boolean' is not assignable to 'string' index type 'string | number'. foo5: E; // ok - subtype of number foo6: Date; // error ~~~~ -!!! error TS2411: Property 'foo6' of type 'Date' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo6' of type 'Date' is not assignable to 'string' index type 'string | number'. foo7: RegExp; // error ~~~~ -!!! error TS2411: Property 'foo7' of type 'RegExp' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo7' of type 'RegExp' is not assignable to 'string' index type 'string | number'. foo8: { bar: number }; // error ~~~~ -!!! error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to 'string' index type 'string | number'. foo9: I8; // error ~~~~ -!!! error TS2411: Property 'foo9' of type 'I8' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo9' of type 'I8' is not assignable to 'string' index type 'string | number'. foo10: A; // error ~~~~~ -!!! error TS2411: Property 'foo10' of type 'A' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo10' of type 'A' is not assignable to 'string' index type 'string | number'. foo11: A2; // error ~~~~~ -!!! error TS2411: Property 'foo11' of type 'A2' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo11' of type 'A2' is not assignable to 'string' index type 'string | number'. foo12: (x) => number; //error ~~~~~ -!!! error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to 'string' index type 'string | number'. foo13: (x: T) => T; // error ~~~~~ -!!! error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to 'string' index type 'string | number'. foo14: typeof f; // error ~~~~~ -!!! error TS2411: Property 'foo14' of type 'typeof f' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo14' of type 'typeof f' is not assignable to 'string' index type 'string | number'. foo15: typeof c; // error ~~~~~ -!!! error TS2411: Property 'foo15' of type 'typeof c' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo15' of type 'typeof c' is not assignable to 'string' index type 'string | number'. foo16: T; // error ~~~~~ -!!! error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo16' of type 'T' is not assignable to 'string' index type 'string | number'. foo17: Object; // error ~~~~~ -!!! error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo17' of type 'Object' is not assignable to 'string' index type 'string | number'. foo18: {}; // error ~~~~~ -!!! error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'string | number'. +!!! error TS2411: Property 'foo18' of type '{}' is not assignable to 'string' index type 'string | number'. } interface I2 { [x: string]: E | number; foo: any; // ok foo2: string; // error ~~~~ -!!! error TS2411: Property 'foo2' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo2' of type 'string' is not assignable to 'string' index type 'number'. foo3: number; // ok foo4: boolean; // error ~~~~ -!!! error TS2411: Property 'foo4' of type 'boolean' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo4' of type 'boolean' is not assignable to 'string' index type 'number'. foo5: E; // ok foo6: Date; // error ~~~~ -!!! error TS2411: Property 'foo6' of type 'Date' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo6' of type 'Date' is not assignable to 'string' index type 'number'. foo7: RegExp; // error ~~~~ -!!! error TS2411: Property 'foo7' of type 'RegExp' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo7' of type 'RegExp' is not assignable to 'string' index type 'number'. foo8: { bar: number }; // error ~~~~ -!!! error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to 'string' index type 'number'. foo9: I8; // error ~~~~ -!!! error TS2411: Property 'foo9' of type 'I8' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo9' of type 'I8' is not assignable to 'string' index type 'number'. foo10: A; // error ~~~~~ -!!! error TS2411: Property 'foo10' of type 'A' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo10' of type 'A' is not assignable to 'string' index type 'number'. foo11: A2; // error ~~~~~ -!!! error TS2411: Property 'foo11' of type 'A2' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo11' of type 'A2' is not assignable to 'string' index type 'number'. foo12: (x) => number; //error ~~~~~ -!!! error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to 'string' index type 'number'. foo13: (x: T) => T; // error ~~~~~ -!!! error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to 'string' index type 'number'. foo14: typeof f; // error ~~~~~ -!!! error TS2411: Property 'foo14' of type 'typeof f' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo14' of type 'typeof f' is not assignable to 'string' index type 'number'. foo15: typeof c; // error ~~~~~ -!!! error TS2411: Property 'foo15' of type 'typeof c' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo15' of type 'typeof c' is not assignable to 'string' index type 'number'. foo16: T; // error ~~~~~ -!!! error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo16' of type 'T' is not assignable to 'string' index type 'number'. foo17: Object; // error ~~~~~ -!!! error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo17' of type 'Object' is not assignable to 'string' index type 'number'. foo18: {}; // error ~~~~~ -!!! error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo18' of type '{}' is not assignable to 'string' index type 'number'. } \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithNumericIndexer.errors.txt b/tests/baselines/reference/subtypingWithNumericIndexer.errors.txt index e5ff0d47ca305..b46f918069b58 100644 --- a/tests/baselines/reference/subtypingWithNumericIndexer.errors.txt +++ b/tests/baselines/reference/subtypingWithNumericIndexer.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer.ts(32,11): error TS2415: Class 'B3' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer.ts(36,11): error TS2415: Class 'B4' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. @@ -41,7 +41,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A { ~~ !!! error TS2415: Class 'B3' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'number' index signatures are incompatible. !!! error TS2415: Type 'Derived' is not assignable to type 'T'. [x: number]: Derived; // error, BUG? } @@ -49,7 +49,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B4 extends A { ~~ !!! error TS2415: Class 'B4' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'number' index signatures are incompatible. !!! error TS2415: Type 'Derived2' is not assignable to type 'T'. [x: number]: Derived2; // error, BUG? } diff --git a/tests/baselines/reference/subtypingWithNumericIndexer2.errors.txt b/tests/baselines/reference/subtypingWithNumericIndexer2.errors.txt index 318b64d933170..cc32a177b29dd 100644 --- a/tests/baselines/reference/subtypingWithNumericIndexer2.errors.txt +++ b/tests/baselines/reference/subtypingWithNumericIndexer2.errors.txt @@ -1,16 +1,16 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2.ts(11,11): error TS2430: Interface 'B' incorrectly extends interface 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2.ts(24,27): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2.ts(32,15): error TS2430: Interface 'B3' incorrectly extends interface 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Base' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2.ts(36,15): error TS2430: Interface 'B4' incorrectly extends interface 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2.ts(40,15): error TS2430: Interface 'B5' incorrectly extends interface 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. @@ -28,7 +28,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface B extends A { ~ !!! error TS2430: Interface 'B' incorrectly extends interface 'A'. -!!! error TS2430: Index signatures are incompatible. +!!! error TS2430: 'number' index signatures are incompatible. !!! error TS2430: Type 'Base' is not assignable to type 'Derived'. !!! error TS2430: Property 'bar' is missing in type 'Base'. [x: number]: Base; // error @@ -56,7 +56,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface B3 extends A { ~~ !!! error TS2430: Interface 'B3' incorrectly extends interface 'A'. -!!! error TS2430: Index signatures are incompatible. +!!! error TS2430: 'number' index signatures are incompatible. !!! error TS2430: Type 'Base' is not assignable to type 'T'. [x: number]: Base; // error } @@ -64,7 +64,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface B4 extends A { ~~ !!! error TS2430: Interface 'B4' incorrectly extends interface 'A'. -!!! error TS2430: Index signatures are incompatible. +!!! error TS2430: 'number' index signatures are incompatible. !!! error TS2430: Type 'Derived' is not assignable to type 'T'. [x: number]: Derived; // error } @@ -72,7 +72,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface B5 extends A { ~~ !!! error TS2430: Interface 'B5' incorrectly extends interface 'A'. -!!! error TS2430: Index signatures are incompatible. +!!! error TS2430: 'number' index signatures are incompatible. !!! error TS2430: Type 'Derived2' is not assignable to type 'T'. [x: number]: Derived2; // error } diff --git a/tests/baselines/reference/subtypingWithNumericIndexer3.errors.txt b/tests/baselines/reference/subtypingWithNumericIndexer3.errors.txt index 6f2684ae93b7e..f0588d533e0db 100644 --- a/tests/baselines/reference/subtypingWithNumericIndexer3.errors.txt +++ b/tests/baselines/reference/subtypingWithNumericIndexer3.errors.txt @@ -1,16 +1,16 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3.ts(11,7): error TS2415: Class 'B' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3.ts(24,23): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3.ts(32,11): error TS2415: Class 'B3' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Base' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3.ts(36,11): error TS2415: Class 'B4' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3.ts(40,11): error TS2415: Class 'B5' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. @@ -28,7 +28,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { ~ !!! error TS2415: Class 'B' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'number' index signatures are incompatible. !!! error TS2415: Type 'Base' is not assignable to type 'Derived'. !!! error TS2415: Property 'bar' is missing in type 'Base'. [x: number]: Base; // error @@ -56,7 +56,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A { ~~ !!! error TS2415: Class 'B3' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'number' index signatures are incompatible. !!! error TS2415: Type 'Base' is not assignable to type 'T'. [x: number]: Base; // error } @@ -64,7 +64,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B4 extends A { ~~ !!! error TS2415: Class 'B4' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'number' index signatures are incompatible. !!! error TS2415: Type 'Derived' is not assignable to type 'T'. [x: number]: Derived; // error } @@ -72,7 +72,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B5 extends A { ~~ !!! error TS2415: Class 'B5' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'number' index signatures are incompatible. !!! error TS2415: Type 'Derived2' is not assignable to type 'T'. [x: number]: Derived2; // error } diff --git a/tests/baselines/reference/subtypingWithNumericIndexer4.errors.txt b/tests/baselines/reference/subtypingWithNumericIndexer4.errors.txt index 3f6de942d2597..e8caa7247ee7d 100644 --- a/tests/baselines/reference/subtypingWithNumericIndexer4.errors.txt +++ b/tests/baselines/reference/subtypingWithNumericIndexer4.errors.txt @@ -1,13 +1,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer4.ts(11,7): error TS2415: Class 'B' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'string' is not assignable to type 'Derived'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer4.ts(20,11): error TS2415: Class 'B' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'string' is not assignable to type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer4.ts(20,23): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer4.ts(24,11): error TS2415: Class 'B3' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'number' index signatures are incompatible. Type 'string' is not assignable to type 'T'. @@ -25,7 +25,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { ~ !!! error TS2415: Class 'B' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'number' index signatures are incompatible. !!! error TS2415: Type 'string' is not assignable to type 'Derived'. [x: number]: string; // error } @@ -38,7 +38,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { ~ !!! error TS2415: Class 'B' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'number' index signatures are incompatible. !!! error TS2415: Type 'string' is not assignable to type 'Base'. ~~~~ !!! error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. @@ -49,7 +49,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A { ~~ !!! error TS2415: Class 'B3' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'number' index signatures are incompatible. !!! error TS2415: Type 'string' is not assignable to type 'T'. [x: number]: string; // error } diff --git a/tests/baselines/reference/subtypingWithNumericIndexer5.errors.txt b/tests/baselines/reference/subtypingWithNumericIndexer5.errors.txt index be4afeafcde66..841c1c775134e 100644 --- a/tests/baselines/reference/subtypingWithNumericIndexer5.errors.txt +++ b/tests/baselines/reference/subtypingWithNumericIndexer5.errors.txt @@ -1,15 +1,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer5.ts(11,7): error TS2420: Class 'B' incorrectly implements interface 'A'. - Index signatures are incompatible. + 'string' and 'number' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer5.ts(32,11): error TS2420: Class 'B3' incorrectly implements interface 'A'. - Index signatures are incompatible. + 'string' and 'number' index signatures are incompatible. Type 'Base' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer5.ts(36,11): error TS2420: Class 'B4' incorrectly implements interface 'A'. - Index signatures are incompatible. + 'string' and 'number' index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer5.ts(40,11): error TS2420: Class 'B5' incorrectly implements interface 'A'. - Index signatures are incompatible. + 'string' and 'number' index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. @@ -27,7 +27,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B implements A { ~ !!! error TS2420: Class 'B' incorrectly implements interface 'A'. -!!! error TS2420: Index signatures are incompatible. +!!! error TS2420: 'string' and 'number' index signatures are incompatible. !!! error TS2420: Type 'Base' is not assignable to type 'Derived'. !!! error TS2420: Property 'bar' is missing in type 'Base'. [x: string]: Base; // error @@ -53,7 +53,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 implements A { ~~ !!! error TS2420: Class 'B3' incorrectly implements interface 'A'. -!!! error TS2420: Index signatures are incompatible. +!!! error TS2420: 'string' and 'number' index signatures are incompatible. !!! error TS2420: Type 'Base' is not assignable to type 'T'. [x: string]: Base; // error } @@ -61,7 +61,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B4 implements A { ~~ !!! error TS2420: Class 'B4' incorrectly implements interface 'A'. -!!! error TS2420: Index signatures are incompatible. +!!! error TS2420: 'string' and 'number' index signatures are incompatible. !!! error TS2420: Type 'Derived' is not assignable to type 'T'. [x: string]: Derived; // error } @@ -69,7 +69,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B5 implements A { ~~ !!! error TS2420: Class 'B5' incorrectly implements interface 'A'. -!!! error TS2420: Index signatures are incompatible. +!!! error TS2420: 'string' and 'number' index signatures are incompatible. !!! error TS2420: Type 'Derived2' is not assignable to type 'T'. [x: string]: Derived2; // error } diff --git a/tests/baselines/reference/subtypingWithStringIndexer.errors.txt b/tests/baselines/reference/subtypingWithStringIndexer.errors.txt index 4ad0f6654255b..32f593ac2b900 100644 --- a/tests/baselines/reference/subtypingWithStringIndexer.errors.txt +++ b/tests/baselines/reference/subtypingWithStringIndexer.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer.ts(32,11): error TS2415: Class 'B3' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer.ts(36,11): error TS2415: Class 'B4' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. @@ -41,7 +41,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A { ~~ !!! error TS2415: Class 'B3' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'string' index signatures are incompatible. !!! error TS2415: Type 'Derived' is not assignable to type 'T'. [x: string]: Derived; // error } @@ -49,7 +49,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B4 extends A { ~~ !!! error TS2415: Class 'B4' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'string' index signatures are incompatible. !!! error TS2415: Type 'Derived2' is not assignable to type 'T'. [x: string]: Derived2; // error } diff --git a/tests/baselines/reference/subtypingWithStringIndexer2.errors.txt b/tests/baselines/reference/subtypingWithStringIndexer2.errors.txt index 82f6229b20c6a..e075726dd1437 100644 --- a/tests/baselines/reference/subtypingWithStringIndexer2.errors.txt +++ b/tests/baselines/reference/subtypingWithStringIndexer2.errors.txt @@ -1,16 +1,16 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2.ts(11,11): error TS2430: Interface 'B' incorrectly extends interface 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2.ts(24,27): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2.ts(32,15): error TS2430: Interface 'B3' incorrectly extends interface 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Base' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2.ts(36,15): error TS2430: Interface 'B4' incorrectly extends interface 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2.ts(40,15): error TS2430: Interface 'B5' incorrectly extends interface 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. @@ -28,7 +28,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface B extends A { ~ !!! error TS2430: Interface 'B' incorrectly extends interface 'A'. -!!! error TS2430: Index signatures are incompatible. +!!! error TS2430: 'string' index signatures are incompatible. !!! error TS2430: Type 'Base' is not assignable to type 'Derived'. !!! error TS2430: Property 'bar' is missing in type 'Base'. [x: string]: Base; // error @@ -56,7 +56,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface B3 extends A { ~~ !!! error TS2430: Interface 'B3' incorrectly extends interface 'A'. -!!! error TS2430: Index signatures are incompatible. +!!! error TS2430: 'string' index signatures are incompatible. !!! error TS2430: Type 'Base' is not assignable to type 'T'. [x: string]: Base; // error } @@ -64,7 +64,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface B4 extends A { ~~ !!! error TS2430: Interface 'B4' incorrectly extends interface 'A'. -!!! error TS2430: Index signatures are incompatible. +!!! error TS2430: 'string' index signatures are incompatible. !!! error TS2430: Type 'Derived' is not assignable to type 'T'. [x: string]: Derived; // error } @@ -72,7 +72,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW interface B5 extends A { ~~ !!! error TS2430: Interface 'B5' incorrectly extends interface 'A'. -!!! error TS2430: Index signatures are incompatible. +!!! error TS2430: 'string' index signatures are incompatible. !!! error TS2430: Type 'Derived2' is not assignable to type 'T'. [x: string]: Derived2; // error } diff --git a/tests/baselines/reference/subtypingWithStringIndexer3.errors.txt b/tests/baselines/reference/subtypingWithStringIndexer3.errors.txt index 205ecf780cb7e..dbd0cfbe17d53 100644 --- a/tests/baselines/reference/subtypingWithStringIndexer3.errors.txt +++ b/tests/baselines/reference/subtypingWithStringIndexer3.errors.txt @@ -1,16 +1,16 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3.ts(11,7): error TS2415: Class 'B' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Base' is not assignable to type 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3.ts(24,23): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3.ts(32,11): error TS2415: Class 'B3' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Base' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3.ts(36,11): error TS2415: Class 'B4' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Derived' is not assignable to type 'T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3.ts(40,11): error TS2415: Class 'B5' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'Derived2' is not assignable to type 'T'. @@ -28,7 +28,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { ~ !!! error TS2415: Class 'B' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'string' index signatures are incompatible. !!! error TS2415: Type 'Base' is not assignable to type 'Derived'. !!! error TS2415: Property 'bar' is missing in type 'Base'. [x: string]: Base; // error @@ -56,7 +56,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A { ~~ !!! error TS2415: Class 'B3' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'string' index signatures are incompatible. !!! error TS2415: Type 'Base' is not assignable to type 'T'. [x: string]: Base; // error } @@ -64,7 +64,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B4 extends A { ~~ !!! error TS2415: Class 'B4' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'string' index signatures are incompatible. !!! error TS2415: Type 'Derived' is not assignable to type 'T'. [x: string]: Derived; // error } @@ -72,7 +72,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B5 extends A { ~~ !!! error TS2415: Class 'B5' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'string' index signatures are incompatible. !!! error TS2415: Type 'Derived2' is not assignable to type 'T'. [x: string]: Derived2; // error } diff --git a/tests/baselines/reference/subtypingWithStringIndexer4.errors.txt b/tests/baselines/reference/subtypingWithStringIndexer4.errors.txt index 8d4328cdd2dba..90c17b2f34046 100644 --- a/tests/baselines/reference/subtypingWithStringIndexer4.errors.txt +++ b/tests/baselines/reference/subtypingWithStringIndexer4.errors.txt @@ -1,13 +1,13 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer4.ts(11,7): error TS2415: Class 'B' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'string' is not assignable to type 'Derived'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer4.ts(20,11): error TS2415: Class 'B' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'string' is not assignable to type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer4.ts(20,23): error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. Property 'bar' is missing in type 'Base'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer4.ts(24,11): error TS2415: Class 'B3' incorrectly extends base class 'A'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'string' is not assignable to type 'T'. @@ -25,7 +25,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { ~ !!! error TS2415: Class 'B' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'string' index signatures are incompatible. !!! error TS2415: Type 'string' is not assignable to type 'Derived'. [x: string]: string; // error } @@ -38,7 +38,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B extends A { ~ !!! error TS2415: Class 'B' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'string' index signatures are incompatible. !!! error TS2415: Type 'string' is not assignable to type 'Base'. ~~~~ !!! error TS2344: Type 'Base' does not satisfy the constraint 'Derived'. @@ -49,7 +49,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingW class B3 extends A { ~~ !!! error TS2415: Class 'B3' incorrectly extends base class 'A'. -!!! error TS2415: Index signatures are incompatible. +!!! error TS2415: 'string' index signatures are incompatible. !!! error TS2415: Type 'string' is not assignable to type 'T'. [x: string]: string; // error } diff --git a/tests/baselines/reference/templateStringInIndexExpression.types b/tests/baselines/reference/templateStringInIndexExpression.types index 9ad6b1e141db0..2e38c933e6e93 100644 --- a/tests/baselines/reference/templateStringInIndexExpression.types +++ b/tests/baselines/reference/templateStringInIndexExpression.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/templates/templateStringInIndexExpression.ts === `abc${0}abc`[`0`]; ->`abc${0}abc`[`0`] : error +>`abc${0}abc`[`0`] : string >`abc${0}abc` : string >0 : 0 >`0` : "0" diff --git a/tests/baselines/reference/templateStringInIndexExpressionES6.types b/tests/baselines/reference/templateStringInIndexExpressionES6.types index d86fb2309e72b..389d3367a3e62 100644 --- a/tests/baselines/reference/templateStringInIndexExpressionES6.types +++ b/tests/baselines/reference/templateStringInIndexExpressionES6.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/templates/templateStringInIndexExpressionES6.ts === `abc${0}abc`[`0`]; ->`abc${0}abc`[`0`] : error +>`abc${0}abc`[`0`] : string >`abc${0}abc` : string >0 : 0 >`0` : "0" diff --git a/tests/baselines/reference/typeName1.errors.txt b/tests/baselines/reference/typeName1.errors.txt index 6d65f1d83c325..a5f8df26036d4 100644 --- a/tests/baselines/reference/typeName1.errors.txt +++ b/tests/baselines/reference/typeName1.errors.txt @@ -6,12 +6,12 @@ tests/cases/compiler/typeName1.ts(13,5): error TS2322: Type '3' is not assignabl tests/cases/compiler/typeName1.ts(14,5): error TS2322: Type '3' is not assignable to type '{ z: number; f: { (n: number): string; (s: string): number; }; }'. tests/cases/compiler/typeName1.ts(15,5): error TS2322: Type '3' is not assignable to type '(s: string) => boolean'. tests/cases/compiler/typeName1.ts(16,5): error TS2322: Type '3' is not assignable to type '{ (): boolean; [s: string]: { x: any; y: any; }; [n: number]: { x: any; y: any; }; z: I; }'. -tests/cases/compiler/typeName1.ts(16,10): error TS2411: Property 'z' of type 'I' is not assignable to string index type '{ x: any; y: any; }'. +tests/cases/compiler/typeName1.ts(16,10): error TS2411: Property 'z' of type 'I' is not assignable to 'string' index type '{ x: any; y: any; }'. tests/cases/compiler/typeName1.ts(17,5): error TS2322: Type '3' is not assignable to type 'I'. tests/cases/compiler/typeName1.ts(18,5): error TS2322: Type '3' is not assignable to type 'I[][][][]'. tests/cases/compiler/typeName1.ts(19,5): error TS2322: Type '3' is not assignable to type '{ z: I; x: boolean; }[][]'. tests/cases/compiler/typeName1.ts(20,5): error TS2322: Type '3' is not assignable to type '{ z: I; x: boolean; y: (s: string) => boolean; w: { (): boolean; [s: string]: { x: any; y: any; }; [n: number]: { x: any; y: any; }; z: I; }; }[][]'. -tests/cases/compiler/typeName1.ts(20,50): error TS2411: Property 'z' of type 'I' is not assignable to string index type '{ x: any; y: any; }'. +tests/cases/compiler/typeName1.ts(20,50): error TS2411: Property 'z' of type 'I' is not assignable to 'string' index type '{ x: any; y: any; }'. tests/cases/compiler/typeName1.ts(21,5): error TS2322: Type '3' is not assignable to type '{ (): {}; new (): number; new (n: number): number; x: string; w: { y: number; }; }'. tests/cases/compiler/typeName1.ts(22,5): error TS2322: Type '3' is not assignable to type '{ (): string; f(x: number): boolean; p: any; q: any; }'. tests/cases/compiler/typeName1.ts(23,5): error TS2322: Type 'typeof C' is not assignable to type 'number'. @@ -51,7 +51,7 @@ tests/cases/compiler/typeName1.ts(23,5): error TS2322: Type 'typeof C' is not as ~~ !!! error TS2322: Type '3' is not assignable to type '{ (): boolean; [s: string]: { x: any; y: any; }; [n: number]: { x: any; y: any; }; z: I; }'. ~ -!!! error TS2411: Property 'z' of type 'I' is not assignable to string index type '{ x: any; y: any; }'. +!!! error TS2411: Property 'z' of type 'I' is not assignable to 'string' index type '{ x: any; y: any; }'. var x9:I=3; ~~ !!! error TS2322: Type '3' is not assignable to type 'I'. @@ -65,7 +65,7 @@ tests/cases/compiler/typeName1.ts(23,5): error TS2322: Type 'typeof C' is not as ~~~ !!! error TS2322: Type '3' is not assignable to type '{ z: I; x: boolean; y: (s: string) => boolean; w: { (): boolean; [s: string]: { x: any; y: any; }; [n: number]: { x: any; y: any; }; z: I; }; }[][]'. ~ -!!! error TS2411: Property 'z' of type 'I' is not assignable to string index type '{ x: any; y: any; }'. +!!! error TS2411: Property 'z' of type 'I' is not assignable to 'string' index type '{ x: any; y: any; }'. var x13:{ new(): number; new(n:number):number; x: string; w: {y: number;}; (): {}; } = 3; ~~~ !!! error TS2322: Type '3' is not assignable to type '{ (): {}; new (): number; new (n: number): number; x: string; w: { y: number; }; }'. diff --git a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt index 89849d3a614a8..7ffdc6a976172 100644 --- a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt +++ b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(8,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'typeof E', but here has type '{ readonly [x: number]: string; readonly a: E; readonly b: E; }'. -tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'typeof E', but here has type '{ readonly [x: number]: string; readonly a: E; readonly b: E; }'. +tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'typeof E', but here has type '{ readonly [x: number]: string; readonly [x: number]: string; readonly a: E; readonly b: E; }'. tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,70): error TS2375: Duplicate number index signature. @@ -17,6 +17,6 @@ tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,70): error TS2375: Dup var y = E; var y: { readonly a: E; readonly b: E; readonly [x: number]: string; readonly [x: number]: string } // two errors: the types are not identical and duplicate signatures ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'typeof E', but here has type '{ readonly [x: number]: string; readonly a: E; readonly b: E; }'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'typeof E', but here has type '{ readonly [x: number]: string; readonly [x: number]: string; readonly a: E; readonly b: E; }'. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2375: Duplicate number index signature. \ No newline at end of file diff --git a/tests/baselines/reference/unionSubtypeIfEveryConstituentTypeIsSubtype.errors.txt b/tests/baselines/reference/unionSubtypeIfEveryConstituentTypeIsSubtype.errors.txt index da2b98f75bb1f..eca747eccceea 100644 --- a/tests/baselines/reference/unionSubtypeIfEveryConstituentTypeIsSubtype.errors.txt +++ b/tests/baselines/reference/unionSubtypeIfEveryConstituentTypeIsSubtype.errors.txt @@ -1,33 +1,33 @@ -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(15,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(21,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'string'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(22,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'string'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(28,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'boolean'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(29,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'boolean'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(35,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(36,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(42,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'RegExp'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(43,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'RegExp'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(49,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type '{ bar: number; }'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(50,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type '{ bar: number; }'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(56,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'number[]'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(57,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'number[]'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(63,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'I8'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(64,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'I8'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(70,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'A'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(71,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'A'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(77,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'A2'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(78,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'A2'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(84,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type '(x: any) => number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(85,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type '(x: any) => number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(91,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type '(x: T) => T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(92,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type '(x: T) => T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(99,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'E2'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(110,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'typeof f'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(111,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'typeof f'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(121,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'typeof c'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(122,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'typeof c'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(128,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(129,5): error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(15,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(21,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(22,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'string'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(28,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'boolean'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(29,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'boolean'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(35,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'Date'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(36,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'Date'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(42,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'RegExp'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(43,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'RegExp'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(49,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type '{ bar: number; }'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(50,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type '{ bar: number; }'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(56,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'number[]'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(57,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'number[]'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(63,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'I8'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(64,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'I8'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(70,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'A'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(71,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'A'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(77,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'A2'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(78,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'A2'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(84,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type '(x: any) => number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(85,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type '(x: any) => number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(91,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type '(x: T) => T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(92,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type '(x: T) => T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(99,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'E2'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(110,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'typeof f'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(111,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'typeof f'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(121,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'typeof c'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(122,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'typeof c'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(128,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(129,5): error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'T'. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts (30 errors) ==== @@ -47,7 +47,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty // S is union type and each constituent type of S is a subtype of T foo: string | number; // error string is not subtype of number ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'number'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'number'. foo2: e | number; // ok e and number both subtype of number } @@ -55,10 +55,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: string; foo: string | number; // error numer is not subtype of string ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'string'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'string'. foo2: e | number; // error e and number both not subtype of string ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'string'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'string'. } // error cases @@ -66,10 +66,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: boolean; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'boolean'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'boolean'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'boolean'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'boolean'. } @@ -77,10 +77,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: Date; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'Date'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'Date'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'Date'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'Date'. } @@ -88,10 +88,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: RegExp; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'RegExp'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'RegExp'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'RegExp'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'RegExp'. } @@ -99,10 +99,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: { bar: number }; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type '{ bar: number; }'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type '{ bar: number; }'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type '{ bar: number; }'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type '{ bar: number; }'. } @@ -110,10 +110,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: number[]; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'number[]'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'number[]'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'number[]'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'number[]'. } @@ -121,10 +121,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: I8; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'I8'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'I8'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'I8'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'I8'. } class A { foo: number; } @@ -132,10 +132,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: A; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'A'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'A'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'A'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'A'. } class A2 { foo: T; } @@ -143,10 +143,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: A2; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'A2'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'A2'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'A2'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'A2'. } @@ -154,10 +154,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: (x) => number; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type '(x: any) => number'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type '(x: any) => number'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type '(x: any) => number'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type '(x: any) => number'. } @@ -165,10 +165,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: (x: T) => T; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type '(x: T) => T'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type '(x: T) => T'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type '(x: T) => T'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type '(x: T) => T'. } @@ -177,7 +177,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: E2; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'E2'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'E2'. foo2: e | number; } @@ -190,10 +190,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: typeof f; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'typeof f'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'typeof f'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'typeof f'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'typeof f'. } @@ -205,10 +205,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: typeof c; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'typeof c'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'typeof c'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'typeof c'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'typeof c'. } @@ -216,10 +216,10 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty [x: string]: T; foo: string | number; ~~~ -!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo' of type 'string | number' is not assignable to 'string' index type 'T'. foo2: e | number; ~~~~ -!!! error TS2411: Property 'foo2' of type 'number' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo2' of type 'number' is not assignable to 'string' index type 'T'. } interface I19 { diff --git a/tests/cases/compiler/invariantGenericErrorElaboration.ts b/tests/cases/compiler/invariantGenericErrorElaboration.ts index 6191949dd8c7e..daecef670542e 100644 --- a/tests/cases/compiler/invariantGenericErrorElaboration.ts +++ b/tests/cases/compiler/invariantGenericErrorElaboration.ts @@ -15,7 +15,7 @@ interface Num extends Runtype { } declare const Num: Num -interface Obj }> extends Runtype<{[K in keyof O]: O[K]['witness'] }> {} +interface Obj }> extends Runtype<{[K in string & keyof O]: O[K]['witness'] }> {} declare function Obj }>(fields: O): Obj; interface Constraint> extends Runtype { diff --git a/tests/cases/compiler/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts b/tests/cases/compiler/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts index b8534aa99fad6..fa42fe28abf10 100644 --- a/tests/cases/compiler/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts +++ b/tests/cases/compiler/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts @@ -1,3 +1,4 @@ +// @target: es6 const directive = Symbol('directive'); declare function foo(options: {[x in string]: (arg: TArg) => TRet} diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index 7748240f80d60..b2d647453d3a3 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -268,7 +268,7 @@ function f82() { let x2 = f81({ a: { x: 42 } }); // number } -function f83(obj: T, key: K) { +function f83(obj: T, key: K) { return obj[key]['x'] as T[K]['x']; } @@ -507,7 +507,7 @@ function updateIds, K extends string>( // Repro from #13285 -function updateIds2( +function updateIds2( obj: T, key: K, stringMap: { [oldId: string]: string } From 0183d390c3ccb6b8a754df64973d8d6ba6e05ea3 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 29 Aug 2018 16:39:16 -0700 Subject: [PATCH 04/11] A whole new paradigm of index signature relating strategies --- src/compiler/checker.ts | 103 +++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 49 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index dfe2fe34a8007..5616028e1a3f3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3524,7 +3524,7 @@ namespace ts { if (resolvedType.indexInfos) { for (let info of resolvedType.indexInfos) { if (resolvedType.objectFlags & ObjectFlags.ReverseMapped) { - info = createIndexInfo(info.indexType, anyType, info.isReadonly, info.declaration); + info = createIndexInfo(info.indexType, anyType, info.isReadonly, info.declaration); } typeElements.push(indexInfoToIndexSignatureDeclarationHelper(info, context)); } @@ -6696,9 +6696,9 @@ namespace ts { const readonlyMask = modifiers & MappedTypeModifiers.IncludeReadonly ? false : true; const optionalMask = modifiers & MappedTypeModifiers.IncludeOptional ? 0 : SymbolFlags.Optional; // TODO: Fix #26724 using the below once #26725 is fixed and `mappedRecursiveInference.ts` doesn't blow up with the change - //const mappedIndexInfos = indexInfos && map(indexInfos, indexInfo => + // const mappedIndexInfos = indexInfos && map(indexInfos, indexInfo => // createIndexInfo(indexInfo.indexType, inferReverseMappedType(indexInfo.type, type.mappedType), readonlyMask && indexInfo.isReadonly) - //); + // ); const mappedIndexInfos = map(filter(indexInfos, i => !!(i.indexType.flags & TypeFlags.String)), i => createIndexInfo(i.indexType, inferReverseMappedType(i.type, type.mappedType), readonlyMask && i.isReadonly)); const members = createSymbolTable(); for (const prop of getPropertiesOfType(type.source)) { @@ -7428,7 +7428,7 @@ namespace ts { return resolveIndexOnIndexInfos(indexType, getIndexInfosOfType(type)); } - function getApplicableIndexInfosOfIndexOnType(type: Type, indexType: Type, contravariant?: boolean): IndexInfo[] | undefined { + function getApplicableIndexInfosOfIndexOnType(type: Type, indexType: Type, returnPartialSuccess?: boolean): IndexInfo[] | undefined { if (!(indexType.flags & TypeFlags.Union)) { const result = getResultingIndexInfoOfIndexOnType(type, indexType); return result && [result]; @@ -7436,7 +7436,7 @@ namespace ts { let resultList: IndexInfo[] | undefined; for (const nameType of (indexType as UnionType).types) { const result = getResultingIndexInfoOfIndexOnType(type, nameType); - if (!result && !contravariant) { + if (!result && !returnPartialSuccess) { return; } if (result) { @@ -7446,8 +7446,8 @@ namespace ts { return resultList; } - function getResultingTypeOfIndexOnType(type: Type, indexType: Type, contravariant?: boolean): Type | undefined { - const resultInfos = getApplicableIndexInfosOfIndexOnType(type, indexType, contravariant); + function getResultingTypeOfIndexOnType(type: Type, indexType: Type, returnPartialSuccess?: boolean): Type | undefined { + const resultInfos = getApplicableIndexInfosOfIndexOnType(type, indexType, returnPartialSuccess); return resultInfos && getUnionType(map(resultInfos, i => i.type)); } @@ -9212,7 +9212,7 @@ namespace ts { const base = getUnionType([ filterType(getUnionType(map(filter(getIndexInfosOfType(type) || emptyArray, info => info !== enumNumberIndexInfo), t => t.indexType)), t => !stringsOnly || isTypeAssignableTo(t, stringType)), getLiteralTypeFromPropertyNames(type, stringsOnly ? TypeFlags.StringLiteral : TypeFlags.StringOrNumberLiteralOrUnique), - ]) + ]); if (!stringsOnly && maybeTypeOfKind(base, TypeFlags.String)) { return getUnionType([base, numberType]); } @@ -10988,7 +10988,7 @@ namespace ts { return t.properties.length === 0 && t.callSignatures.length === 0 && t.constructSignatures.length === 0 && - !length(t.indexInfos) + !length(t.indexInfos); } function isEmptyObjectType(type: Type): boolean { @@ -12289,7 +12289,9 @@ namespace ts { if (isIgnoredJsxProperty(source, prop, /*targetMemberType*/ undefined)) { continue; } - const targetType = getResultingTypeOfIndexOnType(target, getLiteralTypeFromPropertyName(prop, TypeFlags.StringOrNumberLiteralOrUnique)); + const nameType = getLiteralTypeFromPropertyName(prop, TypeFlags.StringOrNumberLiteralOrUnique); + if (nameType.flags & TypeFlags.Never) continue; + const targetType = getResultingTypeOfIndexOnType(target, nameType); if (targetType) { const related = isRelatedTo(getTypeOfSymbol(prop), targetType, reportErrors); if (!related) { @@ -12312,10 +12314,9 @@ namespace ts { if (!targetInfo) { return Ternary.True; } - const sourceInfo = getIndexInfosOfType(source) - const result = sourceInfo && indexInfosRelated(sourceInfo, targetInfo, sourceIsPrimitive, reportErrors); - if (result !== undefined && result !== Ternary.Maybe) { - return result; + const sourceInfo = getIndexInfosOfType(source); + if (sourceInfo) { + return indexInfosRelated(source, target, sourceIsPrimitive, reportErrors); } if (isGenericMappedType(source)) { // A generic mapped type { [P in K]: T } is related to an index signature { [x: string]: U } @@ -12357,20 +12358,6 @@ namespace ts { return Ternary.False; } - function isIndexTypeRelatedTo(source: IndexInfo, target: IndexInfo, sourceIsPrimitive: boolean, reportErrors: boolean, skipIndexError?: boolean): Ternary { - // Index signature of type any permits assignment from everything but primitives - if (!sourceIsPrimitive && target.type.flags & TypeFlags.AnyOrUnknown) { - return Ternary.True; - } - const related = isRelatedTo(source.type, target.type, reportErrors); - if (!related && reportErrors && !skipIndexError) { - const sourceType = typeToString(source.indexType); - const targetType = typeToString(target.indexType); - reportError(sourceType === targetType ? Diagnostics._0_index_signatures_are_incompatible : Diagnostics._0_and_1_index_signatures_are_incompatible, sourceType, targetType); - } - return related; - } - function indexInfosIdentical(sourceInfos: IndexInfo[] | undefined, targetInfos: IndexInfo[] | undefined) { if (length(sourceInfos) !== length(targetInfos)) return Ternary.False; if (!sourceInfos || !targetInfos) return Ternary.True; @@ -12393,28 +12380,46 @@ namespace ts { return Ternary.True; } - function indexInfosRelated(sourceInfos: IndexInfo[] | undefined, targetInfos: IndexInfo[] | undefined, sourceIsPrimitive: boolean, reportErrors: boolean): Ternary { - if (!sourceInfos && !targetInfos) { - return Ternary.True; - } - if (sourceInfos && targetInfos) { - // If for every index signature in S there exists a related signature in T - targetLoop: for (const targetInfo of targetInfos) { - for (const sourceInfo of sourceInfos) { - if (isTypeIndexAssignableTo(sourceInfo.indexType, targetInfo.indexType)) { - if (!isIndexTypeRelatedTo(sourceInfo, targetInfo, sourceIsPrimitive, reportErrors)) return Ternary.False; - if (relation === identityRelation && sourceInfo.isReadonly !== targetInfo.isReadonly) return Ternary.False; - continue targetLoop; - } + function indexInfosRelated(source: Type, target: Type, sourceIsPrimitive: boolean, reportErrors: boolean): Ternary { + const targetInfos = getIndexInfosOfType(target); + if (!targetInfos) return Debug.fail("Existance of index infos in target should have been checked beforehand"); + const sourceHasInferableIndex = isObjectTypeWithInferableIndex(source); + let result = Ternary.True; + for (const targetInfo of targetInfos) { + if (!sourceIsPrimitive && targetInfo.type.flags & TypeFlags.AnyOrUnknown) { + continue; + } + const indexingResult = getResultingTypeOfIndexOnType(source, targetInfo.indexType, sourceHasInferableIndex); + if (!indexingResult) { + if (sourceHasInferableIndex) { + continue; } - if (targetInfo === targetInfos[targetInfos.length - 1]) { - return Ternary.Maybe; // Iterated over every target signature without a definitive yes or no on every signature; allow fallback to inferred signature + if (reportErrors) { + reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } + return Ternary.False; + } + result &= isRelatedTo(indexingResult, targetInfo.type, reportErrors); + if (!result) { + if (reportErrors) { + const sourceInfos = getApplicableIndexInfosOfIndexOnType(source, targetInfo.indexType, sourceHasInferableIndex); + for (const info of sourceInfos!) { + if (!isRelatedTo(info.type, targetInfo.type)) { + const sourceType = typeToString(info.indexType); + const targetType = typeToString(targetInfo.indexType); + reportError(sourceType === targetType ? Diagnostics._0_index_signatures_are_incompatible : Diagnostics._0_and_1_index_signatures_are_incompatible, sourceType, targetType); + break; + } + } + } + return result; } - // Then the signature lists are related - return Ternary.True; } - return Ternary.False; + if (result && sourceHasInferableIndex) { + // A type with an inferable index, provided none of its indexes are strictly incompatible, is compatible so long as its existing props are compatible + result &= eachPropertyRelatedToIndexesOf(source, target, reportErrors); + } + return result; } function constructorVisibilitiesAreCompatible(sourceSignature: Signature, targetSignature: Signature, reportErrors: boolean) { @@ -25305,7 +25310,7 @@ namespace ts { function checkIndexConstraints(type: Type) { const declaredIndexers = getIndexDeclarationsOfSymbol(type.symbol); const indexInfos = getIndexInfosOfType(type); - + if (indexInfos) { forEach(getPropertiesOfObjectType(type), prop => { const propType = getTypeOfSymbol(prop); @@ -25365,10 +25370,10 @@ namespace ts { typeToString(info2.indexType), typeToString(info2.type) ); - checkTypeAssignableTo(info1.type, info2.type, errorNode, undefined, rootChain); + checkTypeAssignableTo(info1.type, info2.type, errorNode, /*diagnosticMessage*/ undefined, rootChain); } } - }) + }); } } From 2c47d31be178d109c9535ae5a58599fe64bdb4b7 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 30 Aug 2018 15:23:12 -0700 Subject: [PATCH 05/11] Remove grammar restriction and add tests --- src/compiler/checker.ts | 36 +- src/compiler/diagnosticMessages.json | 10 +- .../codefixes/convertToMappedObjectType.ts | 56 -- src/services/tsconfig.json | 1 - .../reference/arraySigChecking.errors.txt | 6 +- ...eclarationEmitIndexTypeNotFound.errors.txt | 5 +- ...ndexTypeHasSensibleErrorMessage.errors.txt | 7 - ...eReferenceWithoutTypeArgument.d.errors.txt | 5 +- ...ypeReferenceWithoutTypeArgument.errors.txt | 5 +- ...peReferenceWithoutTypeArgument2.errors.txt | 5 +- ...peReferenceWithoutTypeArgument3.errors.txt | 5 +- .../reference/indexTypeCheck.errors.txt | 13 +- .../reference/indexerConstraints2.errors.txt | 34 +- ...faceWithEnumKeyedIndexSignature.errors.txt | 55 ++ .../interfaceWithEnumKeyedIndexSignature.js | 53 ++ ...terfaceWithEnumKeyedIndexSignature.symbols | 87 +++ ...interfaceWithEnumKeyedIndexSignature.types | 110 ++++ .../parserES5SymbolIndexer1.errors.txt | 9 - .../parserES5SymbolIndexer2.errors.txt | 9 - .../parserES5SymbolIndexer3.errors.txt | 9 - .../parserIndexSignature6.errors.txt | 11 +- .../parserIndexSignature8.errors.txt | 19 +- .../reference/parserSymbolIndexer1.errors.txt | 9 - .../reference/parserSymbolIndexer2.errors.txt | 9 - .../reference/parserSymbolIndexer4.errors.txt | 9 - .../symbolIndexerCompatabilityExamples.js | 179 ++++++ ...symbolIndexerCompatabilityExamples.symbols | 310 ++++++++++ .../symbolIndexerCompatabilityExamples.types | 295 ++++++++++ .../reference/symbolProperty17.errors.txt | 14 - .../reference/symbolProperty29.errors.txt | 12 - .../reference/symbolProperty30.errors.txt | 12 - .../reference/symbolProperty31.errors.txt | 14 - .../reference/symbolProperty32.errors.txt | 14 - .../reference/symbolProperty33.errors.txt | 5 +- .../reference/symbolProperty34.errors.txt | 5 +- ...nionIndexerGeneralAssignability.errors.txt | 419 ++++++++++++++ .../unionIndexerGeneralAssignability.js | 288 ++++++++++ .../unionIndexerGeneralAssignability.symbols | 537 +++++++++++++++++ .../unionIndexerGeneralAssignability.types | 544 ++++++++++++++++++ .../interfaceWithEnumKeyedIndexSignature.ts | 31 + .../symbolIndexerCompatabilityExamples.ts | 104 ++++ .../unionIndexerGeneralAssignability.ts | 185 ++++++ .../codeFixConvertToMappedObjectType1.ts | 17 - .../codeFixConvertToMappedObjectType10.ts | 23 - .../codeFixConvertToMappedObjectType11.ts | 23 - .../codeFixConvertToMappedObjectType12.ts | 12 - .../codeFixConvertToMappedObjectType2.ts | 17 - .../codeFixConvertToMappedObjectType3.ts | 14 - .../codeFixConvertToMappedObjectType4.ts | 14 - .../codeFixConvertToMappedObjectType5.ts | 8 - .../codeFixConvertToMappedObjectType6.ts | 16 - .../codeFixConvertToMappedObjectType7.ts | 18 - .../codeFixConvertToMappedObjectType8.ts | 21 - .../codeFixConvertToMappedObjectType9.ts | 21 - 54 files changed, 3267 insertions(+), 482 deletions(-) delete mode 100644 src/services/codefixes/convertToMappedObjectType.ts delete mode 100644 tests/baselines/reference/genericIndexTypeHasSensibleErrorMessage.errors.txt create mode 100644 tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.errors.txt create mode 100644 tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.js create mode 100644 tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.symbols create mode 100644 tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.types delete mode 100644 tests/baselines/reference/parserES5SymbolIndexer1.errors.txt delete mode 100644 tests/baselines/reference/parserES5SymbolIndexer2.errors.txt delete mode 100644 tests/baselines/reference/parserES5SymbolIndexer3.errors.txt delete mode 100644 tests/baselines/reference/parserSymbolIndexer1.errors.txt delete mode 100644 tests/baselines/reference/parserSymbolIndexer2.errors.txt delete mode 100644 tests/baselines/reference/parserSymbolIndexer4.errors.txt create mode 100644 tests/baselines/reference/symbolIndexerCompatabilityExamples.js create mode 100644 tests/baselines/reference/symbolIndexerCompatabilityExamples.symbols create mode 100644 tests/baselines/reference/symbolIndexerCompatabilityExamples.types delete mode 100644 tests/baselines/reference/symbolProperty17.errors.txt delete mode 100644 tests/baselines/reference/symbolProperty29.errors.txt delete mode 100644 tests/baselines/reference/symbolProperty30.errors.txt delete mode 100644 tests/baselines/reference/symbolProperty31.errors.txt delete mode 100644 tests/baselines/reference/symbolProperty32.errors.txt create mode 100644 tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt create mode 100644 tests/baselines/reference/unionIndexerGeneralAssignability.js create mode 100644 tests/baselines/reference/unionIndexerGeneralAssignability.symbols create mode 100644 tests/baselines/reference/unionIndexerGeneralAssignability.types create mode 100644 tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts create mode 100644 tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts create mode 100644 tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts delete mode 100644 tests/cases/fourslash/codeFixConvertToMappedObjectType1.ts delete mode 100644 tests/cases/fourslash/codeFixConvertToMappedObjectType10.ts delete mode 100644 tests/cases/fourslash/codeFixConvertToMappedObjectType11.ts delete mode 100644 tests/cases/fourslash/codeFixConvertToMappedObjectType12.ts delete mode 100644 tests/cases/fourslash/codeFixConvertToMappedObjectType2.ts delete mode 100644 tests/cases/fourslash/codeFixConvertToMappedObjectType3.ts delete mode 100644 tests/cases/fourslash/codeFixConvertToMappedObjectType4.ts delete mode 100644 tests/cases/fourslash/codeFixConvertToMappedObjectType5.ts delete mode 100644 tests/cases/fourslash/codeFixConvertToMappedObjectType6.ts delete mode 100644 tests/cases/fourslash/codeFixConvertToMappedObjectType7.ts delete mode 100644 tests/cases/fourslash/codeFixConvertToMappedObjectType8.ts delete mode 100644 tests/cases/fourslash/codeFixConvertToMappedObjectType9.ts 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; -};` -}) From d7c45636aa0685a6b8cdba6624e38c30312013db Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 25 Jan 2019 16:13:13 -0800 Subject: [PATCH 06/11] Add missing instantiate call --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 02bf0b6550e00..3323d147553a3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11149,7 +11149,7 @@ namespace ts { } function instantiateIndexInfo(info: IndexInfo, mapper: TypeMapper): IndexInfo { - return createIndexInfo(info.indexType, instantiateType(info.type, mapper), info.isReadonly, info.declaration); + return createIndexInfo(instantiateType(info.indexType, mapper), instantiateType(info.type, mapper), info.isReadonly, info.declaration); } function instantiateIndexInfos(infos: IndexInfo[] | undefined, mapper: TypeMapper): IndexInfo[] | undefined { From dc84515823ae6018471b2d072059945bca5c43fd Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 28 Jan 2019 13:24:15 -0800 Subject: [PATCH 07/11] Resolve index operation on all indexers ratehr than a best indexer --- src/compiler/checker.ts | 109 ++++---- tests/baselines/reference/ES5For-of14.types | 6 +- tests/baselines/reference/ES5For-of15.types | 10 +- .../reference/ES5For-of16.errors.txt | 13 + tests/baselines/reference/ES5For-of16.types | 12 +- tests/baselines/reference/ES5For-of17.types | 4 +- tests/baselines/reference/ES5For-of18.types | 8 +- tests/baselines/reference/ES5For-of19.types | 8 +- tests/baselines/reference/ES5For-of2.types | 6 +- tests/baselines/reference/ES5For-of20.types | 2 +- tests/baselines/reference/ES5For-of21.types | 4 +- tests/baselines/reference/ES5For-of4.types | 10 +- tests/baselines/reference/ES5For-of5.types | 6 +- tests/baselines/reference/ES5For-of6.types | 12 +- .../baselines/reference/ES5For-of7.errors.txt | 4 +- tests/baselines/reference/ES5For-of7.types | 16 +- .../reference/arrayLiteralSpread.types | 2 +- .../arrayLiteralSpreadES5iterable.types | 2 +- .../reference/capturedLetConstInLoop1.types | 28 +-- .../capturedLetConstInLoop2.errors.txt | 189 ++++++++++++++ .../reference/capturedLetConstInLoop2.types | 12 +- .../capturedLetConstInLoop3.errors.txt | 232 ++++++++++++++++++ .../reference/capturedLetConstInLoop3.types | 32 +-- .../capturedLetConstInLoop4.errors.txt | 151 ++++++++++++ .../reference/capturedLetConstInLoop4.types | 36 +-- .../capturedLetConstInLoop5.errors.txt | 14 +- .../reference/capturedLetConstInLoop5.types | 36 +-- .../reference/capturedLetConstInLoop6.types | 36 +-- .../reference/capturedLetConstInLoop7.types | 44 ++-- .../capturedLetConstInLoop9.errors.txt | 144 +++++++++++ .../reference/capturedLetConstInLoop9.types | 46 ++-- .../classWithIndexAllowsNonNumericNames.js | 13 + ...lassWithIndexAllowsNonNumericNames.symbols | 11 + .../classWithIndexAllowsNonNumericNames.types | 11 + .../baselines/reference/commentsInterface.js | 2 +- .../reference/commentsInterface.types | 4 +- ...edPropertyNamesContextualType2_ES5.symbols | 4 - ...utedPropertyNamesContextualType2_ES5.types | 24 +- ...edPropertyNamesContextualType2_ES6.symbols | 4 - ...utedPropertyNamesContextualType2_ES6.types | 24 +- ...derivedClassIncludesInheritedMembers.types | 4 +- ...rivedClassOverridesProtectedMembers2.types | 4 +- .../derivedClassOverridesPublicMembers.types | 4 +- ...faceIncompatibleWithBaseIndexer.errors.txt | 12 +- .../reference/downlevelLetConst16.types | 8 +- .../reference/downlevelLetConst17.types | 4 +- tests/baselines/reference/for-of52.types | 4 +- ...ricCallWithObjectTypeArgsAndIndexers.types | 8 +- ...lWithObjectTypeArgsAndIndexersErrors.types | 10 +- .../reference/indexTypeCheck.errors.txt | 8 +- ...dexSignaturesFromDifferentBases.errors.txt | 8 +- ...ngIndexerHidingBaseTypeIndexer2.errors.txt | 4 +- .../mergedInterfacesWithIndexers.types | 8 +- .../mergedInterfacesWithIndexers2.errors.txt | 4 +- ...tedLoopWithOnlyInnerLetCaptured.errors.txt | 11 + .../nestedLoopWithOnlyInnerLetCaptured.types | 4 +- .../objectLiteralIndexerErrors.errors.txt | 16 +- .../propertiesAndIndexers.errors.txt | 8 +- .../propertiesAndIndexers2.errors.txt | 18 +- .../reference/propertyAccess.errors.txt | 12 +- .../baselines/reference/propertyAccess.types | 18 +- .../reference/readonlyMembers.errors.txt | 5 +- .../restElementWithNullInitializer.types | 2 +- .../trailingCommasInBindingPatterns.types | 2 +- .../tsxElementResolution3.errors.txt | 20 -- ...nionIndexerGeneralAssignability.errors.txt | 23 +- .../unusedLocalsStartingWithUnderscore.types | 4 +- .../classWithIndexAllowsNonNumericNames.ts | 4 + tests/cases/fourslash/duplicateIndexers.ts | 2 +- 69 files changed, 1176 insertions(+), 394 deletions(-) create mode 100644 tests/baselines/reference/ES5For-of16.errors.txt create mode 100644 tests/baselines/reference/capturedLetConstInLoop2.errors.txt create mode 100644 tests/baselines/reference/capturedLetConstInLoop3.errors.txt create mode 100644 tests/baselines/reference/capturedLetConstInLoop4.errors.txt create mode 100644 tests/baselines/reference/capturedLetConstInLoop9.errors.txt create mode 100644 tests/baselines/reference/classWithIndexAllowsNonNumericNames.js create mode 100644 tests/baselines/reference/classWithIndexAllowsNonNumericNames.symbols create mode 100644 tests/baselines/reference/classWithIndexAllowsNonNumericNames.types create mode 100644 tests/baselines/reference/nestedLoopWithOnlyInnerLetCaptured.errors.txt delete mode 100644 tests/baselines/reference/tsxElementResolution3.errors.txt create mode 100644 tests/cases/compiler/classWithIndexAllowsNonNumericNames.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3323d147553a3..676e5defa38bb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -131,7 +131,7 @@ namespace ts { getPropertiesOfType, getPropertyOfType: (type, name) => getPropertyOfType(type, escapeLeadingUnderscores(name)), getTypeOfPropertyOfType: (type, name) => getTypeOfPropertyOfType(type, escapeLeadingUnderscores(name)), - getIndexInfosOfType: (type, indexType?) => indexType ? getApplicableIndexInfosOfIndexOnType(type, indexType) : getIndexInfosOfType(type), + getIndexInfosOfType: (type, indexType?) => indexType ? getResultingIndexInfosOfIndexOnType(type, indexType) : getIndexInfosOfType(type), getSignaturesOfType, getIndexTypeOfType: (type, indexType) => getResultingTypeOfIndexOnType(type, indexType), getBaseTypes, @@ -7778,11 +7778,11 @@ namespace ts { } else if (isUnion) { const index = !isLateBoundName(name) && ( - getResultingIndexInfoOfIndexOnType(type, getLiteralType(isNumericLiteralName(name) ? +name : "" + name)) + getResultingIndexInfosOfIndexOnType(type, getLiteralType(isNumericLiteralName(name) ? +name : "" + name)) ); if (index) { - checkFlags |= index.isReadonly ? CheckFlags.Readonly : 0; - indexTypes = append(indexTypes, isTupleType(type) ? getRestTypeOfTupleType(type) || undefinedType : index.type); + checkFlags |= some(index, i => i.isReadonly) ? CheckFlags.Readonly : 0; + indexTypes = append(indexTypes, isTupleType(type) ? getRestTypeOfTupleType(type) || undefinedType : getIntersectionType(map(index, i => i.type))); } else { checkFlags |= CheckFlags.Partial; @@ -7928,18 +7928,18 @@ namespace ts { } // TODO (weswigham): Ensure all callers handle unions of `type` _before_ calling this - function getResultingIndexInfoOfIndexOnType(type: Type, indexType: Type): IndexInfo | undefined { + function getResultingIndexInfosOfIndexOnType(type: Type, indexType: Type): IndexInfo[] | undefined { return resolveIndexOnIndexInfos(indexType, getIndexInfosOfType(type)); } - function getApplicableIndexInfosOfIndexOnType(type: Type, indexType: Type, returnPartialSuccess?: boolean): IndexInfo[] | undefined { + function getApplicableIndexInfosOfIndexOnType(type: Type, indexType: Type, returnPartialSuccess?: boolean): IndexInfo[][] | undefined { if (!(indexType.flags & TypeFlags.Union)) { - const result = getResultingIndexInfoOfIndexOnType(type, indexType); + const result = getResultingIndexInfosOfIndexOnType(type, indexType); return result && [result]; } - let resultList: IndexInfo[] | undefined; + let resultList: IndexInfo[][] | undefined; for (const nameType of (indexType as UnionType).types) { - const result = getResultingIndexInfoOfIndexOnType(type, nameType); + const result = getResultingIndexInfosOfIndexOnType(type, nameType); if (!result && !returnPartialSuccess) { return; } @@ -7952,7 +7952,7 @@ namespace ts { function getResultingTypeOfIndexOnType(type: Type, indexType: Type, returnPartialSuccess?: boolean): Type | undefined { const resultInfos = getApplicableIndexInfosOfIndexOnType(type, indexType, returnPartialSuccess); - return resultInfos && getUnionType(map(resultInfos, i => i.type)); + return resultInfos && getUnionType(map(resultInfos, applicableInfos => getIntersectionType(map(applicableInfos, i => i.type)))); } function getImplicitIndexTypeOfType(type: Type, targetIndexType: Type): Type | undefined { @@ -8512,7 +8512,7 @@ namespace ts { * Given a single type and a list of index infos, if that type is applicable to one or more of them, * returns the index info to which it is the most applicable */ - function resolveIndexOnIndexInfos(indexType: Type, infos: IndexInfo[] | undefined): IndexInfo | undefined { + function resolveIndexOnIndexInfos(indexType: Type, infos: IndexInfo[] | undefined): IndexInfo[] | undefined { Debug.assert(!(indexType.flags & TypeFlags.Union)); if (indexType.flags & TypeFlags.StringLiteral) { // Prioritize equivalent numeric representation over the string one, since the "number"s in this case _are_ just a subdomain of the strings @@ -8522,20 +8522,7 @@ namespace ts { } const applicable = filter(infos, info => isTypeIndexAccessAssignableTo(indexType, info.indexType)); if (!length(applicable)) return; - // OK, now for the hard part - ranking the derivedness of an index signature! - let candidate = applicable![0]; - let filteredCandidateIndexType = filterType(candidate.indexType, c => isTypeIndexAccessAssignableTo(indexType, c)); - for (const info of applicable!) { - if (info === candidate) continue; - const filteredInfoIndexType = filterType(info.indexType, c => isTypeIndexAccessAssignableTo(indexType, c)); - // The identity check is here so that in situations where multiple index signatures with the same index type are present - // (which is usually an error), we'll align with older behavior and use the type from the first signature we encountered - if (!isTypeIdenticalTo(filteredInfoIndexType, filteredCandidateIndexType) && isTypeIndexAccessAssignableTo(filteredInfoIndexType, filteredCandidateIndexType)) { - candidate = info; - filteredCandidateIndexType = filteredInfoIndexType; - } - } - return candidate; + return applicable; } function createIndexInfo(indexType: Type, type: Type, isReadonly: boolean, declaration?: IndexSignatureDeclaration): IndexInfo { @@ -9752,8 +9739,8 @@ namespace ts { }); } - function getLiteralTypeFromProperty(prop: Symbol, include: TypeFlags) { - if (!(getDeclarationModifierFlagsFromSymbol(prop) & ModifierFlags.NonPublicAccessibilityModifier)) { + function getLiteralTypeFromProperty(prop: Symbol, include: TypeFlags, retainNonpublicNames?: boolean) { + if (retainNonpublicNames || !(getDeclarationModifierFlagsFromSymbol(prop) & ModifierFlags.NonPublicAccessibilityModifier)) { let type = getLateBoundSymbol(prop).nameType; if (!type && !isKnownSymbol(prop)) { if (prop.escapedName === InternalSymbolName.Default) { @@ -9907,16 +9894,16 @@ namespace ts { if (objectType.flags & (TypeFlags.Any | TypeFlags.Never)) { return objectType; } - const indexInfo = getResultingIndexInfoOfIndexOnType(objectType, indexType); + const indexInfo = getResultingIndexInfosOfIndexOnType(objectType, indexType); if (indexInfo) { if (accessNode && !isTypeAssignableToKind(indexType, TypeFlags.String | TypeFlags.Number | TypeFlags.ESSymbol)) { const indexNode = getIndexNodeForAccessExpression(accessNode); error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType)); } - else if (accessExpression && indexInfo.isReadonly && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) { + else if (accessExpression && every(indexInfo, i => i.isReadonly) && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) { error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType)); } - return indexInfo.type; + return getIntersectionType(map(indexInfo, i => i.type)); } if (indexType.flags & TypeFlags.Never) { return neverType; @@ -9929,7 +9916,7 @@ namespace ts { if (propName !== undefined && typeHasStaticProperty(propName, objectType)) { error(accessExpression, Diagnostics.Property_0_is_a_static_member_of_type_1, propName as string, typeToString(objectType)); } - else if (getResultingIndexInfoOfIndexOnType(objectType, numberType)) { + else if (getResultingIndexInfosOfIndexOnType(objectType, numberType)) { error(accessExpression.argumentExpression, Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number); } else { @@ -11462,10 +11449,11 @@ namespace ts { let issuedElaboration = false; if (!targetProp) { - const indexInfo = getResultingIndexInfoOfIndexOnType(target, nameType); - if (indexInfo && indexInfo.declaration && !getSourceFileOfNode(indexInfo.declaration).hasNoDefaultLib) { + const indexInfo = getResultingIndexInfosOfIndexOnType(target, nameType); + const elaboratableInfo = indexInfo && find(indexInfo, i => !!(i.declaration && !getSourceFileOfNode(i.declaration).hasNoDefaultLib)); + if (elaboratableInfo) { issuedElaboration = true; - addRelatedInfo(reportedDiag, createDiagnosticForNode(indexInfo.declaration, Diagnostics.The_expected_type_comes_from_this_index_signature)); + addRelatedInfo(reportedDiag, createDiagnosticForNode(elaboratableInfo.declaration!, Diagnostics.The_expected_type_comes_from_this_index_signature)); } } @@ -11634,7 +11622,7 @@ namespace ts { if (!length(node.properties)) return; for (const prop of node.properties) { if (isSpreadAssignment(prop)) continue; - const type = getLiteralTypeFromProperty(getSymbolOfNode(prop), TypeFlags.StringOrNumberLiteralOrUnique); + const type = getLiteralTypeFromProperty(getSymbolOfNode(prop), TypeFlags.StringOrNumberLiteralOrUnique, /*retainNonPublicNames*/ true); if (!type || (type.flags & TypeFlags.Never)) { continue; } @@ -13222,7 +13210,7 @@ namespace ts { if (isIgnoredJsxProperty(source, prop, /*targetMemberType*/ undefined)) { continue; } - const nameType = getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique); + const nameType = getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique, /*retainNonPublicNames*/ true); if (nameType.flags & TypeFlags.Never) continue; const targetType = getResultingTypeOfIndexOnType(target, nameType); if (targetType) { @@ -13336,11 +13324,17 @@ namespace ts { if (!result) { if (reportErrors) { const sourceInfos = getApplicableIndexInfosOfIndexOnType(source, targetInfo.indexType, sourceHasInferableIndex); - for (const info of sourceInfos!) { - if (!isRelatedTo(info.type, targetInfo.type)) { - const sourceType = typeToString(info.indexType); - const targetType = typeToString(targetInfo.indexType); - reportError(sourceType === targetType ? Diagnostics._0_index_signatures_are_incompatible : Diagnostics._0_and_1_index_signatures_are_incompatible, sourceType, targetType); + for (const applicableInfos of sourceInfos!) { + const applicableType = getIntersectionType(map(applicableInfos, i => i.type)); + if (!isRelatedTo(applicableType, targetInfo.type)) { + for (const info of applicableInfos) { + if (!isRelatedTo(info.type, targetInfo.type)) { + const sourceType = typeToString(info.indexType); + const targetType = typeToString(targetInfo.indexType); + reportError(sourceType === targetType ? Diagnostics._0_index_signatures_are_incompatible : Diagnostics._0_and_1_index_signatures_are_incompatible, sourceType, targetType); + break; + } + } break; } } @@ -16172,7 +16166,7 @@ namespace ts { } function isTypePresencePossible(type: Type, propName: __String, assumeTrue: boolean) { - if (getResultingIndexInfoOfIndexOnType(type, stringType)) { + if (getResultingIndexInfosOfIndexOnType(type, stringType)) { return true; } const prop = getPropertyOfType(type, propName); @@ -18516,7 +18510,7 @@ namespace ts { prop.flags |= impliedProp.flags & SymbolFlags.Optional; } - else if (!compilerOptions.suppressExcessPropertyErrors && !getResultingIndexInfoOfIndexOnType(contextualType!, nameType || stringType)) { + else if (!compilerOptions.suppressExcessPropertyErrors && !getResultingIndexInfosOfIndexOnType(contextualType!, nameType || stringType)) { error(memberDecl.name, Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(member), typeToString(contextualType!)); } @@ -18873,7 +18867,7 @@ namespace ts { } // Intrinsic string indexer case - const indexSignatureType = getResultingIndexInfoOfIndexOnType(intrinsicElementsType, stringType); + const indexSignatureType = getResultingIndexInfosOfIndexOnType(intrinsicElementsType, stringType); if (indexSignatureType) { links.jsxFlags |= JsxFlags.IntrinsicIndexedElement; return links.resolvedSymbol = intrinsicElementsType.symbol; @@ -19058,7 +19052,7 @@ namespace ts { return links.resolvedJsxElementAttributesType = getTypeOfSymbol(symbol); } else if (links.jsxFlags & JsxFlags.IntrinsicIndexedElement) { - return links.resolvedJsxElementAttributesType = resolveIndexOnIndexInfos(stringType, getIndexInfosOfSymbol(symbol))!.type; + return links.resolvedJsxElementAttributesType = getResultingTypeOfIndexOnType(getTypeOfSymbol(symbol), stringType) || errorType; } else { return links.resolvedJsxElementAttributesType = errorType; @@ -19152,7 +19146,7 @@ namespace ts { function isKnownProperty(targetType: Type, nameType: Type, name: __String, isComparingJsxAttributes: boolean): boolean { if (targetType.flags & TypeFlags.Object) { const resolved = resolveStructuredTypeMembers(targetType as ObjectType); - if (getResultingIndexInfoOfIndexOnType(resolved, nameType) || + if (getResultingIndexInfosOfIndexOnType(resolved, nameType) || getPropertyOfObjectType(targetType, name) || isComparingJsxAttributes && !isUnhyphenatedJsxName(name)) { // For JSXAttributes, if the attribute has a hyphenated name, consider that the attribute to be known. @@ -19400,8 +19394,9 @@ namespace ts { markAliasReferenced(parentSymbol, node); } if (!prop) { - const indexInfo = getResultingIndexInfoOfIndexOnType(apparentType, getLiteralType(unescapeLeadingUnderscores(right.escapedText))); - if (!(indexInfo && indexInfo.type)) { + const propNameType = getLiteralType(unescapeLeadingUnderscores(right.escapedText)); + const indexType = getResultingTypeOfIndexOnType(apparentType, propNameType); + if (!indexType) { if (isJSLiteralType(leftType)) { return anyType; } @@ -19410,10 +19405,10 @@ namespace ts { } return errorType; } - if (indexInfo.isReadonly && (isAssignmentTarget(node) || isDeleteTarget(node))) { + if ((isAssignmentTarget(node) || isDeleteTarget(node)) && some(getApplicableIndexInfosOfIndexOnType(apparentType, propNameType), indexes => some(indexes, i => i.isReadonly))) { error(node, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(apparentType)); } - propType = indexInfo.type; + propType = indexType; } else { checkPropertyNotUsedBeforeDeclaration(prop, node, right); @@ -19725,7 +19720,7 @@ namespace ts { * Return true if the given type is considered to have numeric property names. */ function hasNumericPropertyNames(type: Type) { - return getResultingIndexInfoOfIndexOnType(type, numberType) && !getResultingIndexInfoOfIndexOnType(type, stringType); + return getResultingIndexInfosOfIndexOnType(type, numberType) && !getResultingIndexInfosOfIndexOnType(type, stringType); } /** @@ -26742,7 +26737,7 @@ namespace ts { if (isKnownSymbol(prop)) { return; } - checkIndexConstraintForProperty(prop, getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique), propType, type, declaredIndexers); + checkIndexConstraintForProperty(prop, getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique, /*retainNonpublicNames*/ true), propType, type, declaredIndexers); }); const classDeclaration = type.symbol.valueDeclaration; @@ -26805,11 +26800,13 @@ namespace ts { containingType: Type, indexDeclarations: Declaration[] | undefined ): void { - const indexInfos = getIndexInfosOfType(containingType); - const resolvedInfo = resolveIndexOnIndexInfos(propName, indexInfos); - if (!resolvedInfo || isTypeAssignableTo(propertyType, resolvedInfo.type)) { + const resolvedType = getResultingTypeOfIndexOnType(containingType, propName); + if (!resolvedType || isTypeAssignableTo(propertyType, resolvedType)) { return; // No errors } + const indexInfos = getIndexInfosOfType(containingType); + // TODO: Involve all index signatures constraining the property in the error + const resolvedInfo = first(resolveIndexOnIndexInfos(propName, indexInfos)!); const indexDeclaration = contains(indexDeclarations, resolvedInfo.declaration) ? resolvedInfo.declaration : undefined; const propDeclaration = prop.valueDeclaration; @@ -26842,7 +26839,7 @@ namespace ts { symbolToString(prop), typeToString(propertyType), typeToString(resolvedInfo.indexType), - typeToString(resolvedInfo.type) + typeToString(resolvedType) ); } } diff --git a/tests/baselines/reference/ES5For-of14.types b/tests/baselines/reference/ES5For-of14.types index 0a4f9a78453a5..3b46565fe6f86 100644 --- a/tests/baselines/reference/ES5For-of14.types +++ b/tests/baselines/reference/ES5For-of14.types @@ -1,9 +1,9 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of14.ts === for (const v of []) { ->v : any +>v : undefined >[] : undefined[] var x = v; ->x : any ->v : any +>x : undefined +>v : undefined } diff --git a/tests/baselines/reference/ES5For-of15.types b/tests/baselines/reference/ES5For-of15.types index 90409b8b16768..aae39482e01e0 100644 --- a/tests/baselines/reference/ES5For-of15.types +++ b/tests/baselines/reference/ES5For-of15.types @@ -1,17 +1,17 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of15.ts === for (let v of []) { ->v : any +>v : undefined >[] : undefined[] v; ->v : any +>v : undefined for (const v of []) { ->v : any +>v : undefined >[] : undefined[] var x = v; ->x : any ->v : any +>x : undefined +>v : undefined } } diff --git a/tests/baselines/reference/ES5For-of16.errors.txt b/tests/baselines/reference/ES5For-of16.errors.txt new file mode 100644 index 0000000000000..a3802f5d2af51 --- /dev/null +++ b/tests/baselines/reference/ES5For-of16.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/statements/for-ofStatements/ES5For-of16.ts(5,9): error TS2532: Object is possibly 'undefined'. + + +==== tests/cases/conformance/statements/for-ofStatements/ES5For-of16.ts (1 errors) ==== + for (let v of []) { + v; + for (let v of []) { + var x = v; + v++; + ~ +!!! error TS2532: Object is possibly 'undefined'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of16.types b/tests/baselines/reference/ES5For-of16.types index 94f015097118c..8b92dc6365ef0 100644 --- a/tests/baselines/reference/ES5For-of16.types +++ b/tests/baselines/reference/ES5For-of16.types @@ -1,21 +1,21 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of16.ts === for (let v of []) { ->v : any +>v : undefined >[] : undefined[] v; ->v : any +>v : undefined for (let v of []) { ->v : any +>v : undefined >[] : undefined[] var x = v; ->x : any ->v : any +>x : undefined +>v : undefined v++; >v++ : number ->v : any +>v : undefined } } diff --git a/tests/baselines/reference/ES5For-of17.types b/tests/baselines/reference/ES5For-of17.types index 4dafdc0599d37..41c5758258f66 100644 --- a/tests/baselines/reference/ES5For-of17.types +++ b/tests/baselines/reference/ES5For-of17.types @@ -1,10 +1,10 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of17.ts === for (let v of []) { ->v : any +>v : undefined >[] : undefined[] v; ->v : any +>v : undefined for (let v of [v]) { >v : any diff --git a/tests/baselines/reference/ES5For-of18.types b/tests/baselines/reference/ES5For-of18.types index e78bc846df6c9..7f0d3bdb646b5 100644 --- a/tests/baselines/reference/ES5For-of18.types +++ b/tests/baselines/reference/ES5For-of18.types @@ -1,16 +1,16 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of18.ts === for (let v of []) { ->v : any +>v : undefined >[] : undefined[] v; ->v : any +>v : undefined } for (let v of []) { ->v : any +>v : undefined >[] : undefined[] v; ->v : any +>v : undefined } diff --git a/tests/baselines/reference/ES5For-of19.types b/tests/baselines/reference/ES5For-of19.types index d95dc63d2626b..e831b5418b593 100644 --- a/tests/baselines/reference/ES5For-of19.types +++ b/tests/baselines/reference/ES5For-of19.types @@ -1,20 +1,20 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of19.ts === for (let v of []) { ->v : any +>v : undefined >[] : undefined[] v; ->v : any +>v : undefined function foo() { >foo : () => void for (const v of []) { ->v : any +>v : undefined >[] : undefined[] v; ->v : any +>v : undefined } } } diff --git a/tests/baselines/reference/ES5For-of2.types b/tests/baselines/reference/ES5For-of2.types index 3e680c44bc8aa..c14daf0e61769 100644 --- a/tests/baselines/reference/ES5For-of2.types +++ b/tests/baselines/reference/ES5For-of2.types @@ -1,9 +1,9 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of2.ts === for (var v of []) { ->v : any +>v : undefined >[] : undefined[] var x = v; ->x : any ->v : any +>x : undefined +>v : undefined } diff --git a/tests/baselines/reference/ES5For-of20.types b/tests/baselines/reference/ES5For-of20.types index 3b07913c3b006..655a5ec907b3b 100644 --- a/tests/baselines/reference/ES5For-of20.types +++ b/tests/baselines/reference/ES5For-of20.types @@ -1,6 +1,6 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of20.ts === for (let v of []) { ->v : any +>v : undefined >[] : undefined[] let v; diff --git a/tests/baselines/reference/ES5For-of21.types b/tests/baselines/reference/ES5For-of21.types index a15942fd0134e..8233219051f1d 100644 --- a/tests/baselines/reference/ES5For-of21.types +++ b/tests/baselines/reference/ES5For-of21.types @@ -1,9 +1,9 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of21.ts === for (let v of []) { ->v : any +>v : undefined >[] : undefined[] for (let _i of []) { } ->_i : any +>_i : undefined >[] : undefined[] } diff --git a/tests/baselines/reference/ES5For-of4.types b/tests/baselines/reference/ES5For-of4.types index 9396096746c2f..6a54df1aa8d81 100644 --- a/tests/baselines/reference/ES5For-of4.types +++ b/tests/baselines/reference/ES5For-of4.types @@ -1,13 +1,13 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of4.ts === for (var v of []) ->v : any +>v : undefined >[] : undefined[] var x = v; ->x : any ->v : any +>x : undefined +>v : undefined var y = v; ->y : any ->v : any +>y : undefined +>v : undefined diff --git a/tests/baselines/reference/ES5For-of5.types b/tests/baselines/reference/ES5For-of5.types index dd9aa285edba0..fa4da2f1c79aa 100644 --- a/tests/baselines/reference/ES5For-of5.types +++ b/tests/baselines/reference/ES5For-of5.types @@ -1,9 +1,9 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of5.ts === for (var _a of []) { ->_a : any +>_a : undefined >[] : undefined[] var x = _a; ->x : any ->_a : any +>x : undefined +>_a : undefined } diff --git a/tests/baselines/reference/ES5For-of6.types b/tests/baselines/reference/ES5For-of6.types index e2d2f872809d4..e10dbaffda1d2 100644 --- a/tests/baselines/reference/ES5For-of6.types +++ b/tests/baselines/reference/ES5For-of6.types @@ -1,16 +1,16 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of6.ts === for (var w of []) { ->w : any +>w : undefined >[] : undefined[] for (var v of []) { ->v : any +>v : undefined >[] : undefined[] var x = [w, v]; ->x : any[] ->[w, v] : any[] ->w : any ->v : any +>x : undefined[] +>[w, v] : undefined[] +>w : undefined +>v : undefined } } diff --git a/tests/baselines/reference/ES5For-of7.errors.txt b/tests/baselines/reference/ES5For-of7.errors.txt index a3d40f3881416..93abc8e306774 100644 --- a/tests/baselines/reference/ES5For-of7.errors.txt +++ b/tests/baselines/reference/ES5For-of7.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-of7.ts(6,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'any[]'. +tests/cases/conformance/statements/for-ofStatements/ES5For-of7.ts(6,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'undefined', but here has type 'undefined[]'. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-of7.ts (1 errors) ==== @@ -9,5 +9,5 @@ tests/cases/conformance/statements/for-ofStatements/ES5For-of7.ts(6,9): error TS for (var v of []) { var x = [w, v]; ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'any[]'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'undefined', but here has type 'undefined[]'. } \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-of7.types b/tests/baselines/reference/ES5For-of7.types index 6e1fdc25ea994..5f1fb6190bd2a 100644 --- a/tests/baselines/reference/ES5For-of7.types +++ b/tests/baselines/reference/ES5For-of7.types @@ -1,20 +1,20 @@ === tests/cases/conformance/statements/for-ofStatements/ES5For-of7.ts === for (var w of []) { ->w : any +>w : undefined >[] : undefined[] var x = w; ->x : any ->w : any +>x : undefined +>w : undefined } for (var v of []) { ->v : any +>v : undefined >[] : undefined[] var x = [w, v]; ->x : any ->[w, v] : any[] ->w : any ->v : any +>x : undefined +>[w, v] : undefined[] +>w : undefined +>v : undefined } diff --git a/tests/baselines/reference/arrayLiteralSpread.types b/tests/baselines/reference/arrayLiteralSpread.types index fd6ae24326504..f2d4c8e7a2c60 100644 --- a/tests/baselines/reference/arrayLiteralSpread.types +++ b/tests/baselines/reference/arrayLiteralSpread.types @@ -102,7 +102,7 @@ function f2() { >f2 : () => void var a = [...[...[...[...[...[]]]]]]; ->a : any[] +>a : undefined[] >[...[...[...[...[...[]]]]]] : undefined[] >...[...[...[...[...[]]]]] : undefined >[...[...[...[...[]]]]] : undefined[] diff --git a/tests/baselines/reference/arrayLiteralSpreadES5iterable.types b/tests/baselines/reference/arrayLiteralSpreadES5iterable.types index 21c41bb6dcef9..40382b6b60834 100644 --- a/tests/baselines/reference/arrayLiteralSpreadES5iterable.types +++ b/tests/baselines/reference/arrayLiteralSpreadES5iterable.types @@ -102,7 +102,7 @@ function f2() { >f2 : () => void var a = [...[...[...[...[...[]]]]]]; ->a : any[] +>a : undefined[] >[...[...[...[...[...[]]]]]] : undefined[] >...[...[...[...[...[]]]]] : undefined >[...[...[...[...[]]]]] : undefined[] diff --git a/tests/baselines/reference/capturedLetConstInLoop1.types b/tests/baselines/reference/capturedLetConstInLoop1.types index a7d3094268c07..1ba26a3531949 100644 --- a/tests/baselines/reference/capturedLetConstInLoop1.types +++ b/tests/baselines/reference/capturedLetConstInLoop1.types @@ -20,18 +20,18 @@ for (let x in {}) { } for (let x of []) { ->x : any +>x : undefined >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => undefined +>function() { return x} : () => undefined +>x : undefined (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => undefined +>() => x : () => undefined +>x : undefined } for (let x = 0; x < 1; ++x) { @@ -313,18 +313,18 @@ for (const x in {}) { } for (const x of []) { ->x : any +>x : undefined >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => undefined +>function() { return x} : () => undefined +>x : undefined (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => undefined +>() => x : () => undefined +>x : undefined } for (const x = 0; x < 1;) { diff --git a/tests/baselines/reference/capturedLetConstInLoop2.errors.txt b/tests/baselines/reference/capturedLetConstInLoop2.errors.txt new file mode 100644 index 0000000000000..43605150a4b63 --- /dev/null +++ b/tests/baselines/reference/capturedLetConstInLoop2.errors.txt @@ -0,0 +1,189 @@ +tests/cases/compiler/capturedLetConstInLoop2.ts(5,30): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'number'. +tests/cases/compiler/capturedLetConstInLoop2.ts(6,16): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'number'. +tests/cases/compiler/capturedLetConstInLoop2.ts(92,30): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'number'. +tests/cases/compiler/capturedLetConstInLoop2.ts(93,16): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'number'. + + +==== tests/cases/compiler/capturedLetConstInLoop2.ts (4 errors) ==== + // ========let + function foo0(x) { + for (let x of []) { + let a = arguments.length; + (function() { return x + a }); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'number'. + (() => x + a); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'number'. + } + } + + function foo0_1(x) { + for (let x in []) { + let a = arguments.length; + (function() { return x + a }); + (() => x + a); + } + } + + function foo1(x) { + for (let x = 0; x < 1; ++x) { + let a = arguments.length; + (function() { return x + a }); + (() => x + a); + } + } + + function foo2(x) { + while (1 === 1) { + let a = arguments.length; + (function() { return x + a }); + (() => x + a); + } + } + + function foo3(x) { + do { + let x; + let a = arguments.length; + (function() { return x + a }); + (() => x + a); + } while (1 === 1) + } + + function foo4(x) { + for (let y = 0; y < 1; ++y) { + let a = arguments.length; + let x = 1; + (function() { return x + a }); + (() => x + a); + } + } + + function foo5(x) { + for (let x = 0, y = 1; x < 1; ++x) { + let a = arguments.length; + (function() { return x + y + a }); + (() => x + y + a); + } + } + + + function foo6(x) { + while (1 === 1) { + let x, y; + let a = arguments.length; + (function() { return x + y + a }); + (() => x + y + a); + } + } + + function foo7(x) { + do { + let x, y; + let a = arguments.length; + (function() { return x + y + a }); + (() => x + y + a); + } while (1 === 1) + } + + + function foo8(x) { + for (let y = 0; y < 1; ++y) { + let x = 1; + let a = arguments.length; + (function() { return x + y + a }); + (() => x + y + a); + } + } + ///=======const + function foo0_c(x) { + for (const x of []) { + const a = arguments.length; + (function() { return x + a }); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'number'. + (() => x + a); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'number'. + } + } + + function foo0_1_c(x) { + for (const x in []) { + const a = arguments.length; + (function() { return x + a }); + (() => x + a); + } + } + + function foo1_c(x) { + for (const x = 0; x < 1;) { + const a = arguments.length; + (function() { return x + a }); + (() => x + a); + } + } + + function foo2_c(x) { + while (1 === 1) { + const a = arguments.length; + (function() { return x + a }); + (() => x + a); + } + } + + function foo3_c(x) { + do { + const x = 1; + const a = arguments.length; + (function() { return x + a }); + (() => x + a); + } while (1 === 1) + } + + function foo4_c(x) { + for (const y = 0; y < 1;) { + const a = arguments.length; + const x = 1; + (function() { return x + a }); + (() => x + a); + } + } + + function foo5_c(x) { + for (const x = 0, y = 1; x < 1;) { + const a = arguments.length; + (function() { return x + y + a }); + (() => x + y + a); + } + } + + + function foo6_c(x) { + while (1 === 1) { + const x = 1, y =1 ; + const a = arguments.length; + (function() { return x + y + a }); + (() => x + y + a); + } + } + + function foo7_c(x) { + do { + const x = 1, y = 1; + const a = arguments.length; + (function() { return x + y + a }); + (() => x + y + a); + } while (1 === 1) + } + + + function foo8_c(x) { + for (const y = 0; y < 1;) { + const x = 1; + const a = arguments.length; + (function() { return x + y + a }); + (() => x + y + a); + } + } \ No newline at end of file diff --git a/tests/baselines/reference/capturedLetConstInLoop2.types b/tests/baselines/reference/capturedLetConstInLoop2.types index be90b52b334da..f099d268c0d23 100644 --- a/tests/baselines/reference/capturedLetConstInLoop2.types +++ b/tests/baselines/reference/capturedLetConstInLoop2.types @@ -5,7 +5,7 @@ function foo0(x) { >x : any for (let x of []) { ->x : any +>x : undefined >[] : undefined[] let a = arguments.length; @@ -18,14 +18,14 @@ function foo0(x) { >(function() { return x + a }) : () => any >function() { return x + a } : () => any >x + a : any ->x : any +>x : undefined >a : number (() => x + a); >(() => x + a) : () => any >() => x + a : () => any >x + a : any ->x : any +>x : undefined >a : number } } @@ -368,7 +368,7 @@ function foo0_c(x) { >x : any for (const x of []) { ->x : any +>x : undefined >[] : undefined[] const a = arguments.length; @@ -381,14 +381,14 @@ function foo0_c(x) { >(function() { return x + a }) : () => any >function() { return x + a } : () => any >x + a : any ->x : any +>x : undefined >a : number (() => x + a); >(() => x + a) : () => any >() => x + a : () => any >x + a : any ->x : any +>x : undefined >a : number } } diff --git a/tests/baselines/reference/capturedLetConstInLoop3.errors.txt b/tests/baselines/reference/capturedLetConstInLoop3.errors.txt new file mode 100644 index 0000000000000..09d94ff58d73b --- /dev/null +++ b/tests/baselines/reference/capturedLetConstInLoop3.errors.txt @@ -0,0 +1,232 @@ +tests/cases/compiler/capturedLetConstInLoop3.ts(6,30): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. +tests/cases/compiler/capturedLetConstInLoop3.ts(7,16): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. +tests/cases/compiler/capturedLetConstInLoop3.ts(114,30): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. +tests/cases/compiler/capturedLetConstInLoop3.ts(115,16): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. + + +==== tests/cases/compiler/capturedLetConstInLoop3.ts (4 errors) ==== + ///=========let + declare function use(a: any); + function foo0(x) { + for (let x of []) { + var v = x; + (function() { return x + v }); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. + (() => x + v); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. + } + + use(v); + } + + function foo0_1(x) { + for (let x in []) { + var v = x; + (function() { return x + v }); + (() => x + v); + } + + use(v); + } + + function foo1(x) { + for (let x = 0; x < 1; ++x) { + var v = x; + (function() { return x + v }); + (() => x + v); + } + + use(v); + } + + function foo2(x) { + while (1 === 1) { + let x = 1; + var v = x; + (function() { return x + v }); + (() => x + v); + } + + use(v); + } + + function foo3(x) { + do { + let x; + var v; + (function() { return x + v }); + (() => x + v); + } while (1 === 1); + + use(v); + } + + function foo4(x) { + for (let y = 0; y < 1; ++y) { + var v = y; + let x = 1; + (function() { return x + v }); + (() => x + v); + } + + use(v); + } + + function foo5(x) { + for (let x = 0, y = 1; x < 1; ++x) { + var v = x; + (function() { return x + y + v }); + (() => x + y + v); + } + + use(v); + } + + + function foo6(x) { + while (1 === 1) { + let x, y; + var v = x; + (function() { return x + y + v }); + (() => x + y + v); + } + + use(v) + } + + function foo7(x) { + do { + let x, y; + var v = x; + (function() { return x + y + v }); + (() => x + y + v); + } while (1 === 1); + + use(v); + } + + + function foo8(x) { + for (let y = 0; y < 1; ++y) { + let x = 1; + var v = x; + (function() { return x + y + v }); + (() => x + y + v); + } + + use(v); + } + //===const + function foo0_c(x) { + for (const x of []) { + var v = x; + (function() { return x + v }); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. + (() => x + v); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. + } + + use(v); + } + + function foo0_1_c(x) { + for (const x in []) { + var v = x; + (function() { return x + v }); + (() => x + v); + } + + use(v); + } + + function foo1_c(x) { + for (const x = 0; x < 1;) { + var v = x; + (function() { return x + v }); + (() => x + v); + } + + use(v); + } + + function foo2_c(x) { + while (1 === 1) { + const x = 1; + var v = x; + (function() { return x + v }); + (() => x + v); + } + + use(v); + } + + function foo3_c(x) { + do { + const x = 1; + var v; + (function() { return x + v }); + (() => x + v); + } while (1 === 1); + + use(v); + } + + function foo4_c(x) { + for (const y = 0; y < 1;) { + var v = y; + const x = 1; + (function() { return x + v }); + (() => x + v); + } + + use(v); + } + + function foo5_c(x) { + for (const x = 0, y = 1; x < 1;) { + var v = x; + (function() { return x + y + v }); + (() => x + y + v); + } + + use(v); + } + + + function foo6_c(x) { + while (1 === 1) { + const x = 1, y = 1; + var v = x; + (function() { return x + y + v }); + (() => x + y + v); + } + + use(v) + } + + function foo7_c(x) { + do { + const x = 1, y = 1; + var v = x; + (function() { return x + y + v }); + (() => x + y + v); + } while (1 === 1); + + use(v); + } + + + function foo8_c(x) { + for (const y = 0; y < 1;) { + const x = 1; + var v = x; + (function() { return x + y + v }); + (() => x + y + v); + } + + use(v); + } \ No newline at end of file diff --git a/tests/baselines/reference/capturedLetConstInLoop3.types b/tests/baselines/reference/capturedLetConstInLoop3.types index 8ce40ab5f1b5e..b787d0ec8e76f 100644 --- a/tests/baselines/reference/capturedLetConstInLoop3.types +++ b/tests/baselines/reference/capturedLetConstInLoop3.types @@ -9,32 +9,32 @@ function foo0(x) { >x : any for (let x of []) { ->x : any +>x : undefined >[] : undefined[] var v = x; ->v : any ->x : any +>v : undefined +>x : undefined (function() { return x + v }); >(function() { return x + v }) : () => any >function() { return x + v } : () => any >x + v : any ->x : any ->v : any +>x : undefined +>v : undefined (() => x + v); >(() => x + v) : () => any >() => x + v : () => any >x + v : any ->x : any ->v : any +>x : undefined +>v : undefined } use(v); >use(v) : any >use : (a: any) => any ->v : any +>v : undefined } function foo0_1(x) { @@ -405,32 +405,32 @@ function foo0_c(x) { >x : any for (const x of []) { ->x : any +>x : undefined >[] : undefined[] var v = x; ->v : any ->x : any +>v : undefined +>x : undefined (function() { return x + v }); >(function() { return x + v }) : () => any >function() { return x + v } : () => any >x + v : any ->x : any ->v : any +>x : undefined +>v : undefined (() => x + v); >(() => x + v) : () => any >() => x + v : () => any >x + v : any ->x : any ->v : any +>x : undefined +>v : undefined } use(v); >use(v) : any >use : (a: any) => any ->v : any +>v : undefined } function foo0_1_c(x) { diff --git a/tests/baselines/reference/capturedLetConstInLoop4.errors.txt b/tests/baselines/reference/capturedLetConstInLoop4.errors.txt new file mode 100644 index 0000000000000..b4dccc92f49c5 --- /dev/null +++ b/tests/baselines/reference/capturedLetConstInLoop4.errors.txt @@ -0,0 +1,151 @@ +tests/cases/compiler/capturedLetConstInLoop4.ts(8,26): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. +tests/cases/compiler/capturedLetConstInLoop4.ts(79,26): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. + + +==== tests/cases/compiler/capturedLetConstInLoop4.ts (2 errors) ==== + //======let + export function exportedFoo() { + return v0 + v00 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8; + } + + for (let x of []) { + var v0 = x; + (function() { return x + v0}); + ~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. + (() => x); + } + + for (let x in []) { + var v00 = x; + (function() { return x + v00}); + (() => x); + } + + for (let x = 0; x < 1; ++x) { + var v1 = x; + (function() { return x + v1}); + (() => x); + } + + while (1 === 1) { + let x; + var v2 = x; + (function() { return x + v2}); + (() => x); + } + + do { + let x; + var v3 = x; + (function() { return x + v3}); + (() => x); + } while (1 === 1) + + for (let y = 0; y < 1; ++y) { + let x = 1; + var v4 = x; + (function() { return x + v4}); + (() => x); + } + + for (let x = 0, y = 1; x < 1; ++x) { + var v5 = x; + (function() { return x + y + v5}); + (() => x + y); + } + + while (1 === 1) { + let x, y; + var v6 = x; + (function() { return x + y + v6}); + (() => x + y); + } + + do { + let x, y; + var v7 = x; + (function() { return x + y + v7}); + (() => x + y); + } while (1 === 1) + + for (let y = 0; y < 1; ++y) { + let x = 1; + var v8 = x; + (function() { return x + y + v8}); + (() => x + y); + } + + //======const + export function exportedFoo2() { + return v0_c + v00_c + v1_c + v2_c + v3_c + v4_c + v5_c + v6_c + v7_c + v8_c; + } + + for (const x of []) { + var v0_c = x; + (function() { return x + v0_c}); + ~~~~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. + (() => x); + } + + for (const x in []) { + var v00_c = x; + (function() { return x + v00}); + (() => x); + } + + for (const x = 0; x < 1;) { + var v1_c = x; + (function() { return x + v1_c}); + (() => x); + } + + while (1 === 1) { + const x =1; + var v2_c = x; + (function() { return x + v2_c}); + (() => x); + } + + do { + const x = 1; + var v3_c = x; + (function() { return x + v3_c}); + (() => x); + } while (1 === 1) + + for (const y = 0; y < 1;) { + const x = 1; + var v4_c = x; + (function() { return x + v4_c}); + (() => x); + } + + for (const x = 0, y = 1; x < 1;) { + var v5_c = x; + (function() { return x + y + v5_c}); + (() => x + y); + } + + while (1 === 1) { + const x = 1, y = 1; + var v6_c = x; + (function() { return x + y + v6_c}); + (() => x + y); + } + + do { + const x = 1, y = 1; + var v7_c = x; + (function() { return x + y + v7_c}); + (() => x + y); + } while (1 === 1) + + for (const y = 0; y < 1;) { + const x = 1; + var v8_c = x; + (function() { return x + y + v8_c}); + (() => x + y); + } + \ No newline at end of file diff --git a/tests/baselines/reference/capturedLetConstInLoop4.types b/tests/baselines/reference/capturedLetConstInLoop4.types index 2fcff7625a179..5511987b500e6 100644 --- a/tests/baselines/reference/capturedLetConstInLoop4.types +++ b/tests/baselines/reference/capturedLetConstInLoop4.types @@ -13,7 +13,7 @@ export function exportedFoo() { >v0 + v00 + v1 + v2 : string >v0 + v00 + v1 : string >v0 + v00 : string ->v0 : any +>v0 : undefined >v00 : string >v1 : number >v2 : any @@ -26,24 +26,24 @@ export function exportedFoo() { } for (let x of []) { ->x : any +>x : undefined >[] : undefined[] var v0 = x; ->v0 : any ->x : any +>v0 : undefined +>x : undefined (function() { return x + v0}); >(function() { return x + v0}) : () => any >function() { return x + v0} : () => any >x + v0 : any ->x : any ->v0 : any +>x : undefined +>v0 : undefined (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => undefined +>() => x : () => undefined +>x : undefined } for (let x in []) { @@ -313,7 +313,7 @@ export function exportedFoo2() { >v0_c + v00_c + v1_c + v2_c : string >v0_c + v00_c + v1_c : string >v0_c + v00_c : string ->v0_c : any +>v0_c : undefined >v00_c : string >v1_c : number >v2_c : number @@ -326,24 +326,24 @@ export function exportedFoo2() { } for (const x of []) { ->x : any +>x : undefined >[] : undefined[] var v0_c = x; ->v0_c : any ->x : any +>v0_c : undefined +>x : undefined (function() { return x + v0_c}); >(function() { return x + v0_c}) : () => any >function() { return x + v0_c} : () => any >x + v0_c : any ->x : any ->v0_c : any +>x : undefined +>v0_c : undefined (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => undefined +>() => x : () => undefined +>x : undefined } for (const x in []) { diff --git a/tests/baselines/reference/capturedLetConstInLoop5.errors.txt b/tests/baselines/reference/capturedLetConstInLoop5.errors.txt index 7ae1e69be63df..97a3b7310e25d 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5.errors.txt +++ b/tests/baselines/reference/capturedLetConstInLoop5.errors.txt @@ -1,8 +1,12 @@ +tests/cases/compiler/capturedLetConstInLoop5.ts(7,30): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. +tests/cases/compiler/capturedLetConstInLoop5.ts(8,16): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. +tests/cases/compiler/capturedLetConstInLoop5.ts(146,30): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. +tests/cases/compiler/capturedLetConstInLoop5.ts(147,16): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. tests/cases/compiler/capturedLetConstInLoop5.ts(174,13): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap. tests/cases/compiler/capturedLetConstInLoop5.ts(229,13): error TS2367: This condition will always return 'false' since the types '0' and '1' have no overlap. -==== tests/cases/compiler/capturedLetConstInLoop5.ts (2 errors) ==== +==== tests/cases/compiler/capturedLetConstInLoop5.ts (6 errors) ==== declare function use(a: any); //====let @@ -10,7 +14,11 @@ tests/cases/compiler/capturedLetConstInLoop5.ts(229,13): error TS2367: This cond for (let x of []) { var v = x; (function() { return x + v }); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. (() => x + v); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. if (x == 1) { return; } @@ -149,7 +157,11 @@ tests/cases/compiler/capturedLetConstInLoop5.ts(229,13): error TS2367: This cond for (const x of []) { var v = x; (function() { return x + v }); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. (() => x + v); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'undefined'. if (x == 1) { return; } diff --git a/tests/baselines/reference/capturedLetConstInLoop5.types b/tests/baselines/reference/capturedLetConstInLoop5.types index 3ec96ca37daf4..d7788e4e33c2e 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5.types +++ b/tests/baselines/reference/capturedLetConstInLoop5.types @@ -9,30 +9,30 @@ function foo0(x) { >x : any for (let x of []) { ->x : any +>x : undefined >[] : undefined[] var v = x; ->v : any ->x : any +>v : undefined +>x : undefined (function() { return x + v }); >(function() { return x + v }) : () => any >function() { return x + v } : () => any >x + v : any ->x : any ->v : any +>x : undefined +>v : undefined (() => x + v); >(() => x + v) : () => any >() => x + v : () => any >x + v : any ->x : any ->v : any +>x : undefined +>v : undefined if (x == 1) { >x == 1 : boolean ->x : any +>x : undefined >1 : 1 return; @@ -42,7 +42,7 @@ function foo0(x) { use(v); >use(v) : any >use : (a: any) => any ->v : any +>v : undefined } function foo00(x) { @@ -484,30 +484,30 @@ function foo0_c(x) { >x : any for (const x of []) { ->x : any +>x : undefined >[] : undefined[] var v = x; ->v : any ->x : any +>v : undefined +>x : undefined (function() { return x + v }); >(function() { return x + v }) : () => any >function() { return x + v } : () => any >x + v : any ->x : any ->v : any +>x : undefined +>v : undefined (() => x + v); >(() => x + v) : () => any >() => x + v : () => any >x + v : any ->x : any ->v : any +>x : undefined +>v : undefined if (x == 1) { >x == 1 : boolean ->x : any +>x : undefined >1 : 1 return; @@ -517,7 +517,7 @@ function foo0_c(x) { use(v); >use(v) : any >use : (a: any) => any ->v : any +>v : undefined } function foo00_c(x) { diff --git a/tests/baselines/reference/capturedLetConstInLoop6.types b/tests/baselines/reference/capturedLetConstInLoop6.types index c7f6392139e97..3df7f75710232 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6.types +++ b/tests/baselines/reference/capturedLetConstInLoop6.types @@ -1,29 +1,29 @@ === tests/cases/compiler/capturedLetConstInLoop6.ts === // ====let for (let x of []) { ->x : any +>x : undefined >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => undefined +>function() { return x} : () => undefined +>x : undefined (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => undefined +>() => x : () => undefined +>x : undefined if (x == 1) { >x == 1 : boolean ->x : any +>x : undefined >1 : 1 break; } if (x == 2) { >x == 2 : boolean ->x : any +>x : undefined >2 : 2 continue; @@ -366,29 +366,29 @@ for (let y = 0; y < 1; ++y) { // ====const for (const x of []) { ->x : any +>x : undefined >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => undefined +>function() { return x} : () => undefined +>x : undefined (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => undefined +>() => x : () => undefined +>x : undefined if (x == 1) { >x == 1 : boolean ->x : any +>x : undefined >1 : 1 break; } if (x == 2) { >x == 2 : boolean ->x : any +>x : undefined >2 : 2 continue; diff --git a/tests/baselines/reference/capturedLetConstInLoop7.types b/tests/baselines/reference/capturedLetConstInLoop7.types index 39f09100eeb37..4a581be26eb7e 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7.types +++ b/tests/baselines/reference/capturedLetConstInLoop7.types @@ -4,29 +4,29 @@ l0: >l0 : any for (let x of []) { ->x : any +>x : undefined >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => undefined +>function() { return x} : () => undefined +>x : undefined (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => undefined +>() => x : () => undefined +>x : undefined if (x == 1) { >x == 1 : boolean ->x : any +>x : undefined >1 : 1 break; } if (x == 1) { >x == 1 : boolean ->x : any +>x : undefined >1 : 1 break l0; @@ -34,14 +34,14 @@ for (let x of []) { } if (x == 2) { >x == 2 : boolean ->x : any +>x : undefined >2 : 2 continue; } if (x == 2) { >x == 2 : boolean ->x : any +>x : undefined >2 : 2 continue l0; @@ -558,29 +558,29 @@ l0_c: >l0_c : any for (const x of []) { ->x : any +>x : undefined >[] : undefined[] (function() { return x}); ->(function() { return x}) : () => any ->function() { return x} : () => any ->x : any +>(function() { return x}) : () => undefined +>function() { return x} : () => undefined +>x : undefined (() => x); ->(() => x) : () => any ->() => x : () => any ->x : any +>(() => x) : () => undefined +>() => x : () => undefined +>x : undefined if (x == 1) { >x == 1 : boolean ->x : any +>x : undefined >1 : 1 break; } if (x == 1) { >x == 1 : boolean ->x : any +>x : undefined >1 : 1 break l0_c; @@ -588,14 +588,14 @@ for (const x of []) { } if (x == 2) { >x == 2 : boolean ->x : any +>x : undefined >2 : 2 continue; } if (x == 2) { >x == 2 : boolean ->x : any +>x : undefined >2 : 2 continue l0_c; diff --git a/tests/baselines/reference/capturedLetConstInLoop9.errors.txt b/tests/baselines/reference/capturedLetConstInLoop9.errors.txt new file mode 100644 index 0000000000000..d010305e46916 --- /dev/null +++ b/tests/baselines/reference/capturedLetConstInLoop9.errors.txt @@ -0,0 +1,144 @@ +tests/cases/compiler/capturedLetConstInLoop9.ts(136,30): error TS2365: Operator '+' cannot be applied to types 'undefined' and 'number'. + + +==== tests/cases/compiler/capturedLetConstInLoop9.ts (1 errors) ==== + for (let x = 0; x < 1; ++x) { + let x; + (function() { return x }); + { + let x; + (function() { return x }); + } + + try { } + catch (e) { + let x; + (function() { return x }); + } + + switch (x) { + case 1: + let x; + (function() { return x }); + break; + } + + while (1 == 1) { + let x; + (function() { return x }); + } + + class A { + m() { + return x + 1; + } + } + } + + declare function use(a: any); + + function foo() { + l0: + for (let a of []) { + + if (a === 1) { + break; + } + + if (a === 2) { + break l0; + } + + for (let b of []) { + var [{x, y:z}] = [{x:1, y:2}]; + if (b === 1) { + break; + } + + + if (b === 2) { + break l0; + } + + l1: + if (b === 3) { + break l1; + } + + return 50; + } + + for (let b of []) { + var [{x1, y:z1}] = [{x1:1, y:arguments.length}]; + if (b === 1) { + break; + } + + if (b === 2) { + break l0; + } + + () => b + return 100; + } + + + () => a; + } + + use(x); + use(z); + use(x1); + use(z1); + } + + function foo2() { + for (let x of []) { + if (x === 1) { + break; + } + else if (x === 2) { + continue; + } + + while (1 === 1) { + if (x) { + break; + } + else { + continue; + } + } + + switch(x) { + case 1: break; + case 2: continue; + } + + for (let y of []) { + switch(y) { + case 1: break; + case 2: continue; + } + } + } + } + + class C { + constructor(private N: number) { } + foo() { + for (let i = 0; i < 100; i++) { + let f = () => this.N * i; + } + } + } + + function foo3 () { + let x = arguments.length; + for (let y of []) { + let z = arguments.length; + (function() { return y + z + arguments.length; }); + ~~~~~ +!!! error TS2365: Operator '+' cannot be applied to types 'undefined' and 'number'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/capturedLetConstInLoop9.types b/tests/baselines/reference/capturedLetConstInLoop9.types index 486697b8d8409..0ff79e1a46b8b 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9.types +++ b/tests/baselines/reference/capturedLetConstInLoop9.types @@ -94,12 +94,12 @@ function foo() { >l0 : any for (let a of []) { ->a : any +>a : undefined >[] : undefined[] if (a === 1) { >a === 1 : boolean ->a : any +>a : undefined >1 : 1 break; @@ -107,7 +107,7 @@ function foo() { if (a === 2) { >a === 2 : boolean ->a : any +>a : undefined >2 : 2 break l0; @@ -115,7 +115,7 @@ function foo() { } for (let b of []) { ->b : any +>b : undefined >[] : undefined[] var [{x, y:z}] = [{x:1, y:2}]; @@ -131,7 +131,7 @@ function foo() { if (b === 1) { >b === 1 : boolean ->b : any +>b : undefined >1 : 1 break; @@ -140,7 +140,7 @@ function foo() { if (b === 2) { >b === 2 : boolean ->b : any +>b : undefined >2 : 2 break l0; @@ -152,7 +152,7 @@ function foo() { if (b === 3) { >b === 3 : boolean ->b : any +>b : undefined >3 : 3 break l1; @@ -164,7 +164,7 @@ function foo() { } for (let b of []) { ->b : any +>b : undefined >[] : undefined[] var [{x1, y:z1}] = [{x1:1, y:arguments.length}]; @@ -182,7 +182,7 @@ function foo() { if (b === 1) { >b === 1 : boolean ->b : any +>b : undefined >1 : 1 break; @@ -190,7 +190,7 @@ function foo() { if (b === 2) { >b === 2 : boolean ->b : any +>b : undefined >2 : 2 break l0; @@ -198,8 +198,8 @@ function foo() { } () => b ->() => b : () => any ->b : any +>() => b : () => undefined +>b : undefined return 100; >100 : 100 @@ -207,8 +207,8 @@ function foo() { () => a; ->() => a : () => any ->a : any +>() => a : () => undefined +>a : undefined } use(x); @@ -236,19 +236,19 @@ function foo2() { >foo2 : () => void for (let x of []) { ->x : any +>x : undefined >[] : undefined[] if (x === 1) { >x === 1 : boolean ->x : any +>x : undefined >1 : 1 break; } else if (x === 2) { >x === 2 : boolean ->x : any +>x : undefined >2 : 2 continue; @@ -260,7 +260,7 @@ function foo2() { >1 : 1 if (x) { ->x : any +>x : undefined break; } @@ -270,7 +270,7 @@ function foo2() { } switch(x) { ->x : any +>x : undefined case 1: break; >1 : 1 @@ -280,11 +280,11 @@ function foo2() { } for (let y of []) { ->y : any +>y : undefined >[] : undefined[] switch(y) { ->y : any +>y : undefined case 1: break; >1 : 1 @@ -336,7 +336,7 @@ function foo3 () { >length : number for (let y of []) { ->y : any +>y : undefined >[] : undefined[] let z = arguments.length; @@ -350,7 +350,7 @@ function foo3 () { >function() { return y + z + arguments.length; } : () => any >y + z + arguments.length : any >y + z : any ->y : any +>y : undefined >z : number >arguments.length : number >arguments : IArguments diff --git a/tests/baselines/reference/classWithIndexAllowsNonNumericNames.js b/tests/baselines/reference/classWithIndexAllowsNonNumericNames.js new file mode 100644 index 0000000000000..2f25b77c9e1ed --- /dev/null +++ b/tests/baselines/reference/classWithIndexAllowsNonNumericNames.js @@ -0,0 +1,13 @@ +//// [classWithIndexAllowsNonNumericNames.ts] +class Obs { + [idx: number]: string; + private _field: number; +} + + +//// [classWithIndexAllowsNonNumericNames.js] +var Obs = /** @class */ (function () { + function Obs() { + } + return Obs; +}()); diff --git a/tests/baselines/reference/classWithIndexAllowsNonNumericNames.symbols b/tests/baselines/reference/classWithIndexAllowsNonNumericNames.symbols new file mode 100644 index 0000000000000..942335dd1d238 --- /dev/null +++ b/tests/baselines/reference/classWithIndexAllowsNonNumericNames.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/classWithIndexAllowsNonNumericNames.ts === +class Obs { +>Obs : Symbol(Obs, Decl(classWithIndexAllowsNonNumericNames.ts, 0, 0)) + + [idx: number]: string; +>idx : Symbol(idx, Decl(classWithIndexAllowsNonNumericNames.ts, 1, 3)) + + private _field: number; +>_field : Symbol(Obs._field, Decl(classWithIndexAllowsNonNumericNames.ts, 1, 24)) +} + diff --git a/tests/baselines/reference/classWithIndexAllowsNonNumericNames.types b/tests/baselines/reference/classWithIndexAllowsNonNumericNames.types new file mode 100644 index 0000000000000..8711f650b0711 --- /dev/null +++ b/tests/baselines/reference/classWithIndexAllowsNonNumericNames.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/classWithIndexAllowsNonNumericNames.ts === +class Obs { +>Obs : Obs + + [idx: number]: string; +>idx : number + + private _field: number; +>_field : number +} + diff --git a/tests/baselines/reference/commentsInterface.js b/tests/baselines/reference/commentsInterface.js index 3deac9871f183..e09400a6ea010 100644 --- a/tests/baselines/reference/commentsInterface.js +++ b/tests/baselines/reference/commentsInterface.js @@ -136,7 +136,7 @@ declare var i2_i_x: number; declare var i2_i_foo: (b: number) => string; declare var i2_i_foo_r: string; declare var i2_i_i2_si: any; -declare var i2_i_i2_ii: number; +declare var i2_i_i2_ii: any; declare var i2_i_n: any; declare var i2_i_nc_x: number; declare var i2_i_nc_foo: (b: number) => string; diff --git a/tests/baselines/reference/commentsInterface.types b/tests/baselines/reference/commentsInterface.types index 65f1f5f4a38f0..96a5af14b1eff 100644 --- a/tests/baselines/reference/commentsInterface.types +++ b/tests/baselines/reference/commentsInterface.types @@ -87,8 +87,8 @@ var i2_i_i2_si = i2_i["hello"]; >"hello" : "hello" var i2_i_i2_ii = i2_i[30]; ->i2_i_i2_ii : number ->i2_i[30] : number +>i2_i_i2_ii : any +>i2_i[30] : any >i2_i : i2 >30 : 30 diff --git a/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.symbols b/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.symbols index 754ed3cf8da01..7834262a166b0 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.symbols +++ b/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.symbols @@ -18,14 +18,10 @@ var o: I = { [+"foo"](y) { return y.length; }, >[+"foo"] : Symbol([+"foo"], Decl(computedPropertyNamesContextualType2_ES5.ts, 5, 12)) >y : Symbol(y, Decl(computedPropertyNamesContextualType2_ES5.ts, 6, 13)) ->y.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) >y : Symbol(y, Decl(computedPropertyNamesContextualType2_ES5.ts, 6, 13)) ->length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) [+"bar"]: y => y.length >[+"bar"] : Symbol([+"bar"], Decl(computedPropertyNamesContextualType2_ES5.ts, 6, 37)) >y : Symbol(y, Decl(computedPropertyNamesContextualType2_ES5.ts, 7, 13)) ->y.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) >y : Symbol(y, Decl(computedPropertyNamesContextualType2_ES5.ts, 7, 13)) ->length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) } diff --git a/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.types index 75c7538f284a6..394bf238aef57 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType2_ES5.types @@ -11,24 +11,24 @@ interface I { var o: I = { >o : I ->{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: number]: (y: string) => number; } +>{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: number]: (y: any) => any; } [+"foo"](y) { return y.length; }, ->[+"foo"] : (y: string) => number +>[+"foo"] : (y: any) => any >+"foo" : number >"foo" : "foo" ->y : string ->y.length : number ->y : string ->length : number +>y : any +>y.length : any +>y : any +>length : any [+"bar"]: y => y.length ->[+"bar"] : (y: string) => number +>[+"bar"] : (y: any) => any >+"bar" : number >"bar" : "bar" ->y => y.length : (y: string) => number ->y : string ->y.length : number ->y : string ->length : number +>y => y.length : (y: any) => any +>y : any +>y.length : any +>y : any +>length : any } diff --git a/tests/baselines/reference/computedPropertyNamesContextualType2_ES6.symbols b/tests/baselines/reference/computedPropertyNamesContextualType2_ES6.symbols index e44b2ae861e84..8ae328ac4c450 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType2_ES6.symbols +++ b/tests/baselines/reference/computedPropertyNamesContextualType2_ES6.symbols @@ -18,14 +18,10 @@ var o: I = { [+"foo"](y) { return y.length; }, >[+"foo"] : Symbol([+"foo"], Decl(computedPropertyNamesContextualType2_ES6.ts, 5, 12)) >y : Symbol(y, Decl(computedPropertyNamesContextualType2_ES6.ts, 6, 13)) ->y.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) >y : Symbol(y, Decl(computedPropertyNamesContextualType2_ES6.ts, 6, 13)) ->length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) [+"bar"]: y => y.length >[+"bar"] : Symbol([+"bar"], Decl(computedPropertyNamesContextualType2_ES6.ts, 6, 37)) >y : Symbol(y, Decl(computedPropertyNamesContextualType2_ES6.ts, 7, 13)) ->y.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) >y : Symbol(y, Decl(computedPropertyNamesContextualType2_ES6.ts, 7, 13)) ->length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) } diff --git a/tests/baselines/reference/computedPropertyNamesContextualType2_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType2_ES6.types index 70d88c15e702e..e55a324846136 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType2_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType2_ES6.types @@ -11,24 +11,24 @@ interface I { var o: I = { >o : I ->{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: number]: (y: string) => number; } +>{ [+"foo"](y) { return y.length; }, [+"bar"]: y => y.length} : { [x: number]: (y: any) => any; } [+"foo"](y) { return y.length; }, ->[+"foo"] : (y: string) => number +>[+"foo"] : (y: any) => any >+"foo" : number >"foo" : "foo" ->y : string ->y.length : number ->y : string ->length : number +>y : any +>y.length : any +>y : any +>length : any [+"bar"]: y => y.length ->[+"bar"] : (y: string) => number +>[+"bar"] : (y: any) => any >+"bar" : number >"bar" : "bar" ->y => y.length : (y: string) => number ->y : string ->y.length : number ->y : string ->length : number +>y => y.length : (y: any) => any +>y : any +>y.length : any +>y : any +>length : any } diff --git a/tests/baselines/reference/derivedClassIncludesInheritedMembers.types b/tests/baselines/reference/derivedClassIncludesInheritedMembers.types index 4f6230bb45d3f..50d1be0bd76b7 100644 --- a/tests/baselines/reference/derivedClassIncludesInheritedMembers.types +++ b/tests/baselines/reference/derivedClassIncludesInheritedMembers.types @@ -122,8 +122,8 @@ var r7 = d2['']; >'' : "" var r8 = d2[1]; ->r8 : Date ->d2[1] : Date +>r8 : Object & Date +>d2[1] : Object & Date >d2 : Derived2 >1 : 1 diff --git a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.types b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.types index c51e0ab95a275..3a1c4afd1b391 100644 --- a/tests/baselines/reference/derivedClassOverridesProtectedMembers2.types +++ b/tests/baselines/reference/derivedClassOverridesProtectedMembers2.types @@ -227,8 +227,8 @@ var r7 = d2['']; >'' : "" var r8 = d2[1]; ->r8 : { foo: string; bar: string; } ->d2[1] : { foo: string; bar: string; } +>r8 : { foo: string; } & { foo: string; bar: string; } +>d2[1] : { foo: string; } & { foo: string; bar: string; } >d2 : Derived2 >1 : 1 diff --git a/tests/baselines/reference/derivedClassOverridesPublicMembers.types b/tests/baselines/reference/derivedClassOverridesPublicMembers.types index b67017d1f75a6..85b460e254fd9 100644 --- a/tests/baselines/reference/derivedClassOverridesPublicMembers.types +++ b/tests/baselines/reference/derivedClassOverridesPublicMembers.types @@ -226,8 +226,8 @@ var r7 = d2['']; >'' : "" var r8 = d2[1]; ->r8 : { foo: string; bar: string; } ->d2[1] : { foo: string; bar: string; } +>r8 : { foo: string; } & { foo: string; bar: string; } +>d2[1] : { foo: string; } & { foo: string; bar: string; } >d2 : Derived2 >1 : 1 diff --git a/tests/baselines/reference/derivedInterfaceIncompatibleWithBaseIndexer.errors.txt b/tests/baselines/reference/derivedInterfaceIncompatibleWithBaseIndexer.errors.txt index 27688dcaf86b1..aac97717a71fc 100644 --- a/tests/baselines/reference/derivedInterfaceIncompatibleWithBaseIndexer.errors.txt +++ b/tests/baselines/reference/derivedInterfaceIncompatibleWithBaseIndexer.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(7,5): error TS2411: Property '1' of type '{ y: number; }' is not assignable to 'number' index type '{ x: number; y: number; }'. -tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(11,5): error TS2411: Property ''1'' of type '{ y: number; }' is not assignable to 'number' index type '{ x: number; y: number; }'. +tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(7,5): error TS2411: Property '1' of type '{ y: number; }' is not assignable to 'number' index type '{ x: number; y: number; } & { x: number; }'. +tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(11,5): error TS2411: Property ''1'' of type '{ y: number; }' is not assignable to 'number' index type '{ x: number; y: number; } & { x: number; }'. tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(15,5): error TS2411: Property 'foo' of type '{ y: number; }' is not assignable to 'string' index type '{ x: number; }'. tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(19,5): error TS2411: Property 'foo' of type '() => { x: number; }' is not assignable to 'string' index type '{ x: number; }'. -tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(24,5): error TS2411: Property '1' of type '{ x: number; }' is not assignable to 'number' index type '{ x: number; y: number; }'. +tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts(24,5): error TS2411: Property '1' of type '{ x: number; }' is not assignable to 'number' index type '{ x: number; y: number; } & { x: number; }'. ==== tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompatibleWithBaseIndexer.ts (5 errors) ==== @@ -14,13 +14,13 @@ tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompa interface Derived extends Base { 1: { y: number } // error ~ -!!! error TS2411: Property '1' of type '{ y: number; }' is not assignable to 'number' index type '{ x: number; y: number; }'. +!!! error TS2411: Property '1' of type '{ y: number; }' is not assignable to 'number' index type '{ x: number; y: number; } & { x: number; }'. } interface Derived2 extends Base { '1': { y: number } // error ~~~ -!!! error TS2411: Property ''1'' of type '{ y: number; }' is not assignable to 'number' index type '{ x: number; y: number; }'. +!!! error TS2411: Property ''1'' of type '{ y: number; }' is not assignable to 'number' index type '{ x: number; y: number; } & { x: number; }'. } interface Derived3 extends Base { @@ -39,7 +39,7 @@ tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceIncompa interface Derived5 extends Base { 1: { x: number } // error ~ -!!! error TS2411: Property '1' of type '{ x: number; }' is not assignable to 'number' index type '{ x: number; y: number; }'. +!!! error TS2411: Property '1' of type '{ x: number; }' is not assignable to 'number' index type '{ x: number; y: number; } & { x: number; }'. } interface Derived5 extends Base { diff --git a/tests/baselines/reference/downlevelLetConst16.types b/tests/baselines/reference/downlevelLetConst16.types index 450773fd9bb31..e7f88c6600f44 100644 --- a/tests/baselines/reference/downlevelLetConst16.types +++ b/tests/baselines/reference/downlevelLetConst16.types @@ -620,13 +620,13 @@ function foo7() { >foo7 : () => void for (let x of []) { ->x : any +>x : undefined >[] : undefined[] use(x); >use(x) : any >use : (a: any) => any ->x : any +>x : undefined } use(x); >use(x) : any @@ -675,13 +675,13 @@ function foo10() { >foo10 : () => void for (const x of []) { ->x : any +>x : undefined >[] : undefined[] use(x); >use(x) : any >use : (a: any) => any ->x : any +>x : undefined } use(x); >use(x) : any diff --git a/tests/baselines/reference/downlevelLetConst17.types b/tests/baselines/reference/downlevelLetConst17.types index 56e9356556e98..e72fe44e4705d 100644 --- a/tests/baselines/reference/downlevelLetConst17.types +++ b/tests/baselines/reference/downlevelLetConst17.types @@ -159,11 +159,11 @@ for (const x in []) { } for (const x of []) { ->x : any +>x : undefined >[] : undefined[] use(x); >use(x) : any >use : (a: any) => any ->x : any +>x : undefined } diff --git a/tests/baselines/reference/for-of52.types b/tests/baselines/reference/for-of52.types index 0df5aeefa21e8..aa1c99dac8f93 100644 --- a/tests/baselines/reference/for-of52.types +++ b/tests/baselines/reference/for-of52.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/for-ofStatements/for-of52.ts === for (let [v, v] of [[]]) {} ->v : any ->v : any +>v : undefined +>v : undefined >[[]] : undefined[][] >[] : undefined[] diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexers.types b/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexers.types index fb9eed9d9a1b6..4f41c34b8a65f 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexers.types +++ b/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexers.types @@ -46,14 +46,14 @@ function other(arg: T) { >b : { [x: string]: Object; [x: number]: T; } var d = r2[1]; ->d : T ->r2[1] : T +>d : Object & T +>r2[1] : Object & T >r2 : { [x: string]: Object; [x: number]: T; } >1 : 1 var e = r2['1']; ->e : T ->r2['1'] : T +>e : Object & T +>r2['1'] : Object & T >r2 : { [x: string]: Object; [x: number]: T; } >'1' : "1" } diff --git a/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexersErrors.types b/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexersErrors.types index 7006fe613e109..bd9e751d80b19 100644 --- a/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexersErrors.types +++ b/tests/baselines/reference/genericCallWithObjectTypeArgsAndIndexersErrors.types @@ -51,20 +51,20 @@ function other3(arg: T) { >b : { [x: string]: Object; [x: number]: T; } var d = r2[1]; ->d : T ->r2[1] : T +>d : Object & T +>r2[1] : Object & T >r2 : { [x: string]: Object; [x: number]: T; } >1 : 1 var e = r2['1']; ->e : T ->r2['1'] : T +>e : Object & T +>r2['1'] : Object & T >r2 : { [x: string]: Object; [x: number]: T; } >'1' : "1" var u: U = r2[1]; // ok >u : U ->r2[1] : T +>r2[1] : Object & T >r2 : { [x: string]: Object; [x: number]: T; } >1 : 1 } diff --git a/tests/baselines/reference/indexTypeCheck.errors.txt b/tests/baselines/reference/indexTypeCheck.errors.txt index 913e64f7db3b2..69a57f8b77b11 100644 --- a/tests/baselines/reference/indexTypeCheck.errors.txt +++ b/tests/baselines/reference/indexTypeCheck.errors.txt @@ -4,8 +4,8 @@ tests/cases/compiler/indexTypeCheck.ts(17,2): error TS2413: 'number' index type Type 'number' is not assignable to type 'string'. tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: 'number' index type 'Orange' is not assignable to 'string' index type 'Yellow'. Type 'Orange' is not assignable to type 'Yellow'. - 'number' index signatures are incompatible. - Type 'number' is not assignable to type 'Red'. + 'string' index signatures are incompatible. + Type 'string' is not assignable to type 'Red'. 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. @@ -49,8 +49,8 @@ tests/cases/compiler/indexTypeCheck.ts(51,8): error TS2538: Type 'Blue' cannot b ~~~~~~~~~~~~~~~~~~~ !!! error TS2413: 'number' index type 'Orange' is not assignable to 'string' index type 'Yellow'. !!! error TS2413: Type 'Orange' is not assignable to type 'Yellow'. -!!! error TS2413: 'number' index signatures are incompatible. -!!! error TS2413: Type 'number' is not assignable to type 'Red'. +!!! error TS2413: 'string' index signatures are incompatible. +!!! error TS2413: Type 'string' is not assignable to type 'Red'. [s:string]: Yellow; // ok } diff --git a/tests/baselines/reference/inheritedMembersAndIndexSignaturesFromDifferentBases.errors.txt b/tests/baselines/reference/inheritedMembersAndIndexSignaturesFromDifferentBases.errors.txt index 89a6c91d79db3..47fe9cba4f16b 100644 --- a/tests/baselines/reference/inheritedMembersAndIndexSignaturesFromDifferentBases.errors.txt +++ b/tests/baselines/reference/inheritedMembersAndIndexSignaturesFromDifferentBases.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(17,11): error TS2411: Property 'm' of type '{}' is not assignable to 'string' index type '{ a: any; }'. -tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(23,11): error TS2411: Property '0' of type '{}' is not assignable to 'number' index type '{ a: any; b: any; }'. -tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(25,11): error TS2411: Property '0' of type '{}' is not assignable to 'number' index type '{ a: any; b: any; }'. +tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(23,11): error TS2411: Property '0' of type '{}' is not assignable to 'number' index type '{ a: any; b: any; } & { a: any; }'. +tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(25,11): error TS2411: Property '0' of type '{}' is not assignable to 'number' index type '{ a: any; b: any; } & { a: any; }'. tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(25,11): error TS2411: Property 'm' of type '{}' is not assignable to 'string' index type '{ a: any; }'. @@ -31,11 +31,11 @@ tests/cases/compiler/inheritedMembersAndIndexSignaturesFromDifferentBases.ts(25, interface F extends A, B, E { } // error because 0 is not a subtype of {a; b;} ~ -!!! error TS2411: Property '0' of type '{}' is not assignable to 'number' index type '{ a: any; b: any; }'. +!!! error TS2411: Property '0' of type '{}' is not assignable to 'number' index type '{ a: any; b: any; } & { a: any; }'. interface G extends A, B, C, E { } // should only report one error ~ -!!! error TS2411: Property '0' of type '{}' is not assignable to 'number' index type '{ a: any; b: any; }'. +!!! error TS2411: Property '0' of type '{}' is not assignable to 'number' index type '{ a: any; b: any; } & { a: any; }'. ~ !!! error TS2411: Property 'm' of type '{}' is not assignable to 'string' index type '{ a: any; }'. diff --git a/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer2.errors.txt b/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer2.errors.txt index 5446d05c18f95..8b5de4c6f1052 100644 --- a/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer2.errors.txt +++ b/tests/baselines/reference/interfaceWithStringIndexerHidingBaseTypeIndexer2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringIndexerHidingBaseTypeIndexer2.ts(17,5): error TS2411: Property '1' of type '{ a: number; }' is not assignable to 'number' index type '{ a: number; b: number; }'. +tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringIndexerHidingBaseTypeIndexer2.ts(17,5): error TS2411: Property '1' of type '{ a: number; }' is not assignable to 'number' index type '{ a: number; b: number; } & { a: number; }'. ==== tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringIndexerHidingBaseTypeIndexer2.ts (1 errors) ==== @@ -20,7 +20,7 @@ tests/cases/conformance/interfaces/interfaceDeclarations/interfaceWithStringInde // error 1: { ~ -!!! error TS2411: Property '1' of type '{ a: number; }' is not assignable to 'number' index type '{ a: number; b: number; }'. +!!! error TS2411: Property '1' of type '{ a: number; }' is not assignable to 'number' index type '{ a: number; b: number; } & { a: number; }'. a: number; } } \ No newline at end of file diff --git a/tests/baselines/reference/mergedInterfacesWithIndexers.types b/tests/baselines/reference/mergedInterfacesWithIndexers.types index 1154fcd72ef1d..2d5197d75df63 100644 --- a/tests/baselines/reference/mergedInterfacesWithIndexers.types +++ b/tests/baselines/reference/mergedInterfacesWithIndexers.types @@ -17,14 +17,14 @@ var a: A; >a : A var r = a[1]; ->r : string ->a[1] : string +>r : string & { length: number; } +>a[1] : string & { length: number; } >a : A >1 : 1 var r2 = a['1']; ->r2 : string ->a['1'] : string +>r2 : string & { length: number; } +>a['1'] : string & { length: number; } >a : A >'1' : "1" diff --git a/tests/baselines/reference/mergedInterfacesWithIndexers2.errors.txt b/tests/baselines/reference/mergedInterfacesWithIndexers2.errors.txt index b9104496c74e1..82e8a67825785 100644 --- a/tests/baselines/reference/mergedInterfacesWithIndexers2.errors.txt +++ b/tests/baselines/reference/mergedInterfacesWithIndexers2.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexers2.ts(4,5): error TS2413: 'number' index type 'string' is not assignable to 'string' index type '{ length: string; }'. Type 'string' is not assignable to type '{ length: string; }'. tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexers2.ts(14,5): error TS2411: Property ''a'' of type 'number' is not assignable to 'string' index type '{ length: number; }'. -tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexers2.ts(20,5): error TS2411: Property '1' of type '{ length: number; }' is not assignable to 'number' index type 'string'. +tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexers2.ts(20,5): error TS2411: Property '1' of type '{ length: number; }' is not assignable to 'number' index type 'string & { length: number; }'. ==== tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexers2.ts (3 errors) ==== @@ -31,6 +31,6 @@ tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithIndexe [x: string]: { length: number }; 1: { length: number }; // error ~ -!!! error TS2411: Property '1' of type '{ length: number; }' is not assignable to 'number' index type 'string'. +!!! error TS2411: Property '1' of type '{ length: number; }' is not assignable to 'number' index type 'string & { length: number; }'. } \ No newline at end of file diff --git a/tests/baselines/reference/nestedLoopWithOnlyInnerLetCaptured.errors.txt b/tests/baselines/reference/nestedLoopWithOnlyInnerLetCaptured.errors.txt new file mode 100644 index 0000000000000..f54594e00533d --- /dev/null +++ b/tests/baselines/reference/nestedLoopWithOnlyInnerLetCaptured.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/nestedLoopWithOnlyInnerLetCaptured.ts(4,20): error TS2532: Object is possibly 'undefined'. + + +==== tests/cases/compiler/nestedLoopWithOnlyInnerLetCaptured.ts (1 errors) ==== + declare let doSomething; + + for (let a1 of []) + for (let a2 of a1.someArray) + ~~ +!!! error TS2532: Object is possibly 'undefined'. + doSomething(() => a2); \ No newline at end of file diff --git a/tests/baselines/reference/nestedLoopWithOnlyInnerLetCaptured.types b/tests/baselines/reference/nestedLoopWithOnlyInnerLetCaptured.types index 6be9dbf6abf81..e04ea93d4a820 100644 --- a/tests/baselines/reference/nestedLoopWithOnlyInnerLetCaptured.types +++ b/tests/baselines/reference/nestedLoopWithOnlyInnerLetCaptured.types @@ -3,13 +3,13 @@ declare let doSomething; >doSomething : any for (let a1 of []) ->a1 : any +>a1 : undefined >[] : undefined[] for (let a2 of a1.someArray) >a2 : any >a1.someArray : any ->a1 : any +>a1 : undefined >someArray : any doSomething(() => a2); diff --git a/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt b/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt index c32719dd4fe4b..67cd4347fde27 100644 --- a/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralIndexerErrors.errors.txt @@ -1,5 +1,7 @@ -tests/cases/compiler/objectLiteralIndexerErrors.ts(13,54): error TS2741: Property 'y' is missing in type 'A' but required in type 'B'. -tests/cases/compiler/objectLiteralIndexerErrors.ts(14,14): error TS2322: Type 'A' is not assignable to type 'B'. +tests/cases/compiler/objectLiteralIndexerErrors.ts(13,54): error TS2322: Type 'A' is not assignable to type 'A & B'. + Property 'y' is missing in type 'A' but required in type 'B'. +tests/cases/compiler/objectLiteralIndexerErrors.ts(14,14): error TS2322: Type 'A' is not assignable to type 'A & B'. + Type 'A' is not assignable to type 'B'. ==== tests/cases/compiler/objectLiteralIndexerErrors.ts (2 errors) ==== @@ -17,10 +19,12 @@ tests/cases/compiler/objectLiteralIndexerErrors.ts(14,14): error TS2322: Type 'A var o1: { [s: string]: A;[n: number]: B; } = { x: b, 0: a }; // both indexers are A ~ -!!! error TS2741: Property 'y' is missing in type 'A' but required in type 'B'. +!!! error TS2322: Type 'A' is not assignable to type 'A & B'. +!!! error TS2322: Property 'y' is missing in type 'A' but required in type 'B'. !!! related TS2728 tests/cases/compiler/objectLiteralIndexerErrors.ts:6:5: 'y' is declared here. -!!! related TS6501 tests/cases/compiler/objectLiteralIndexerErrors.ts:13:26: The expected type comes from this index signature. +!!! related TS6501 tests/cases/compiler/objectLiteralIndexerErrors.ts:13:11: The expected type comes from this index signature. o1 = { x: c, 0: a }; // string indexer is any, number indexer is A ~ -!!! error TS2322: Type 'A' is not assignable to type 'B'. -!!! related TS6501 tests/cases/compiler/objectLiteralIndexerErrors.ts:13:26: The expected type comes from this index signature. \ No newline at end of file +!!! error TS2322: Type 'A' is not assignable to type 'A & B'. +!!! error TS2322: Type 'A' is not assignable to type 'B'. +!!! related TS6501 tests/cases/compiler/objectLiteralIndexerErrors.ts:13:11: The expected type comes from this index signature. \ No newline at end of file diff --git a/tests/baselines/reference/propertiesAndIndexers.errors.txt b/tests/baselines/reference/propertiesAndIndexers.errors.txt index 9cb3fb74224f4..849bd35b3d9cc 100644 --- a/tests/baselines/reference/propertiesAndIndexers.errors.txt +++ b/tests/baselines/reference/propertiesAndIndexers.errors.txt @@ -9,8 +9,8 @@ tests/cases/compiler/propertiesAndIndexers.ts(29,5): error TS2411: Property 'c' tests/cases/compiler/propertiesAndIndexers.ts(30,5): error TS2411: Property '3' of type 'boolean' is not assignable to 'string' index type 'number'. tests/cases/compiler/propertiesAndIndexers.ts(33,11): error TS2413: 'number' index type 'string' is not assignable to 'string' index type 'number'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/propertiesAndIndexers.ts(34,5): error TS2411: Property '2' of type 'Z' is not assignable to 'number' index type 'string'. -tests/cases/compiler/propertiesAndIndexers.ts(35,5): error TS2411: Property 'Infinity' of type 'number' is not assignable to 'number' index type 'string'. +tests/cases/compiler/propertiesAndIndexers.ts(34,5): error TS2411: Property '2' of type 'Z' is not assignable to 'string' index type 'number & string'. +tests/cases/compiler/propertiesAndIndexers.ts(35,5): error TS2411: Property 'Infinity' of type 'number' is not assignable to 'string' index type 'number & string'. tests/cases/compiler/propertiesAndIndexers.ts(36,5): error TS2411: Property 'zoo' of type 'string' is not assignable to 'string' index type 'number'. tests/cases/compiler/propertiesAndIndexers.ts(44,5): error TS2411: Property 't' of type 'number' is not assignable to 'string' index type 'string'. tests/cases/compiler/propertiesAndIndexers.ts(50,5): error TS2411: Property '3' of type 'boolean' is not assignable to 'number' index type 'string'. @@ -73,10 +73,10 @@ tests/cases/compiler/propertiesAndIndexers.ts(50,5): error TS2411: Property '3' !!! error TS2413: Type 'string' is not assignable to type 'number'. 2: Z; ~ -!!! error TS2411: Property '2' of type 'Z' is not assignable to 'number' index type 'string'. +!!! error TS2411: Property '2' of type 'Z' is not assignable to 'string' index type 'number & string'. Infinity: number; ~~~~~~~~ -!!! error TS2411: Property 'Infinity' of type 'number' is not assignable to 'number' index type 'string'. +!!! error TS2411: Property 'Infinity' of type 'number' is not assignable to 'string' index type 'number & string'. zoo: string; ~~~ !!! error TS2411: Property 'zoo' of type 'string' is not assignable to 'string' index type 'number'. diff --git a/tests/baselines/reference/propertiesAndIndexers2.errors.txt b/tests/baselines/reference/propertiesAndIndexers2.errors.txt index 2bed2c42876d9..4dd835d53ed22 100644 --- a/tests/baselines/reference/propertiesAndIndexers2.errors.txt +++ b/tests/baselines/reference/propertiesAndIndexers2.errors.txt @@ -1,11 +1,15 @@ tests/cases/compiler/propertiesAndIndexers2.ts(2,5): error TS2413: 'number' index type 'string' is not assignable to 'string' index type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/compiler/propertiesAndIndexers2.ts(8,5): error TS2411: Property 'c' of type 'string' is not assignable to 'string' index type 'number'. +tests/cases/compiler/propertiesAndIndexers2.ts(9,5): error TS2411: Property '3' of type 'string' is not assignable to 'number' index type 'string & number'. +tests/cases/compiler/propertiesAndIndexers2.ts(10,5): error TS2411: Property 'Infinity' of type 'string' is not assignable to 'number' index type 'string & number'. +tests/cases/compiler/propertiesAndIndexers2.ts(11,5): error TS2411: Property '"-Infinity"' of type 'string' is not assignable to 'number' index type 'string & number'. +tests/cases/compiler/propertiesAndIndexers2.ts(12,5): error TS2411: Property 'NaN' of type 'string' is not assignable to 'number' index type 'string & number'. tests/cases/compiler/propertiesAndIndexers2.ts(13,5): error TS2411: Property '"-NaN"' of type 'string' is not assignable to 'string' index type 'number'. -tests/cases/compiler/propertiesAndIndexers2.ts(14,5): error TS2411: Property '6' of type '() => string' is not assignable to 'number' index type 'string'. +tests/cases/compiler/propertiesAndIndexers2.ts(14,5): error TS2411: Property '6' of type '() => string' is not assignable to 'number' index type 'string & number'. -==== tests/cases/compiler/propertiesAndIndexers2.ts (4 errors) ==== +==== tests/cases/compiler/propertiesAndIndexers2.ts (8 errors) ==== interface A { [n: number]: string; ~~~~~~~~~~~~~~~~~~~~ @@ -20,14 +24,22 @@ tests/cases/compiler/propertiesAndIndexers2.ts(14,5): error TS2411: Property '6' ~ !!! error TS2411: Property 'c' of type 'string' is not assignable to 'string' index type 'number'. 3: string; + ~ +!!! error TS2411: Property '3' of type 'string' is not assignable to 'number' index type 'string & number'. Infinity: string; + ~~~~~~~~ +!!! error TS2411: Property 'Infinity' of type 'string' is not assignable to 'number' index type 'string & number'. "-Infinity": string; + ~~~~~~~~~~~ +!!! error TS2411: Property '"-Infinity"' of type 'string' is not assignable to 'number' index type 'string & number'. NaN: string; + ~~~ +!!! error TS2411: Property 'NaN' of type 'string' is not assignable to 'number' index type 'string & number'. "-NaN": string; ~~~~~~ !!! error TS2411: Property '"-NaN"' of type 'string' is not assignable to 'string' index type 'number'. 6(): string; ~~~~~~~~~~~~ -!!! error TS2411: Property '6' of type '() => string' is not assignable to 'number' index type 'string'. +!!! error TS2411: Property '6' of type '() => string' is not assignable to 'number' index type 'string & number'. } \ No newline at end of file diff --git a/tests/baselines/reference/propertyAccess.errors.txt b/tests/baselines/reference/propertyAccess.errors.txt index a183ad79c1129..60e3b59694b4b 100644 --- a/tests/baselines/reference/propertyAccess.errors.txt +++ b/tests/baselines/reference/propertyAccess.errors.txt @@ -3,11 +3,13 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(11,55): err tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(45,14): error TS2339: Property 'qqq' does not exist on type '{ 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; }'. tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(80,19): error TS2538: Type '{ name: string; }' cannot be used as an index type. tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(117,18): error TS2538: Type '{ name: string; }' cannot be used as an index type. +tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(125,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'ww' must be of type 'A & B', but here has type 'B'. +tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(129,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'xx' must be of type 'A & B', but here has type 'B'. tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(140,22): error TS2538: Type '{ name: string; }' cannot be used as an index type. -tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(149,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'A | B', but here has type 'A'. +tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(149,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'A | (A & B)', but here has type 'A'. -==== tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts (6 errors) ==== +==== tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts (8 errors) ==== class A { a: number; } @@ -142,10 +144,14 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(149,5): err // Bracket notation property access using enum value on type with numeric index signature and string index signature var ww = bothIndex[Compass.East]; var ww: B; + ~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'ww' must be of type 'A & B', but here has type 'B'. // Bracket notation property access using value of type 'any' on type with numeric index signature and string index signature var xx = bothIndex[null]; var xx: B; + ~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'xx' must be of type 'A & B', but here has type 'B'. // Bracket notation property access using string value on type with numeric index signature and string index signature var yy = bothIndex['foo']; @@ -169,5 +175,5 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(149,5): err var x3 = bothIndex[stringOrNumber]; var x3: A; ~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'A | B', but here has type 'A'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'A | (A & B)', but here has type 'A'. \ No newline at end of file diff --git a/tests/baselines/reference/propertyAccess.types b/tests/baselines/reference/propertyAccess.types index 744ee48b3a30b..d5861af861b89 100644 --- a/tests/baselines/reference/propertyAccess.types +++ b/tests/baselines/reference/propertyAccess.types @@ -351,26 +351,26 @@ var vv: any; // Bracket notation property access using enum value on type with numeric index signature and string index signature var ww = bothIndex[Compass.East]; ->ww : B ->bothIndex[Compass.East] : B +>ww : A & B +>bothIndex[Compass.East] : A & B >bothIndex : { [n: string]: A; [m: number]: B; } >Compass.East : Compass.East >Compass : typeof Compass >East : Compass.East var ww: B; ->ww : B +>ww : A & B // Bracket notation property access using value of type 'any' on type with numeric index signature and string index signature var xx = bothIndex[null]; ->xx : B ->bothIndex[null] : B +>xx : A & B +>bothIndex[null] : A & B >bothIndex : { [n: string]: A; [m: number]: B; } >null : any >null : null var xx: B; ->xx : B +>xx : A & B // Bracket notation property access using string value on type with numeric index signature and string index signature var yy = bothIndex['foo']; @@ -418,11 +418,11 @@ var x2: Compass; >x2 : Compass var x3 = bothIndex[stringOrNumber]; ->x3 : A | B ->bothIndex[stringOrNumber] : A | B +>x3 : A | (A & B) +>bothIndex[stringOrNumber] : A | (A & B) >bothIndex : { [n: string]: A; [m: number]: B; } >stringOrNumber : string | number var x3: A; ->x3 : A | B +>x3 : A | (A & B) diff --git a/tests/baselines/reference/readonlyMembers.errors.txt b/tests/baselines/reference/readonlyMembers.errors.txt index 70f7384318486..5f6c6309c6aba 100644 --- a/tests/baselines/reference/readonlyMembers.errors.txt +++ b/tests/baselines/reference/readonlyMembers.errors.txt @@ -12,10 +12,9 @@ tests/cases/compiler/readonlyMembers.ts(39,3): error TS2540: Cannot assign to 'a tests/cases/compiler/readonlyMembers.ts(48,3): error TS2540: Cannot assign to 'A' because it is a read-only property. tests/cases/compiler/readonlyMembers.ts(55,3): error TS2540: Cannot assign to 'a' because it is a read-only property. tests/cases/compiler/readonlyMembers.ts(61,1): error TS2542: Index signature in type '{ readonly [x: string]: string; }' only permits reading. -tests/cases/compiler/readonlyMembers.ts(64,1): error TS2542: Index signature in type '{ readonly [x: number]: string; [x: string]: string; }' only permits reading. -==== tests/cases/compiler/readonlyMembers.ts (15 errors) ==== +==== tests/cases/compiler/readonlyMembers.ts (14 errors) ==== interface X { readonly a: number; readonly b?: number; @@ -108,6 +107,4 @@ tests/cases/compiler/readonlyMembers.ts(64,1): error TS2542: Index signature in let yy: { readonly [x: number]: string, [x: string]: string }; yy[1] = "abc"; // Error - ~~~~~ -!!! error TS2542: Index signature in type '{ readonly [x: number]: string; [x: string]: string; }' only permits reading. yy["foo"] = "abc"; \ No newline at end of file diff --git a/tests/baselines/reference/restElementWithNullInitializer.types b/tests/baselines/reference/restElementWithNullInitializer.types index c6eebb23d4988..595e3cbb55e0d 100644 --- a/tests/baselines/reference/restElementWithNullInitializer.types +++ b/tests/baselines/reference/restElementWithNullInitializer.types @@ -19,7 +19,7 @@ function foo3([...r] = {}) { function foo4([...r] = []) { >foo4 : ([...r]?: any[]) => void ->r : any[] +>r : undefined[] >[] : undefined[] } diff --git a/tests/baselines/reference/trailingCommasInBindingPatterns.types b/tests/baselines/reference/trailingCommasInBindingPatterns.types index 087bb0c0b31ee..1eb6245d4b80c 100644 --- a/tests/baselines/reference/trailingCommasInBindingPatterns.types +++ b/tests/baselines/reference/trailingCommasInBindingPatterns.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es7/trailingCommasInBindingPatterns.ts === const [...a,] = []; ->a : any[] +>a : undefined[] >[] : undefined[] const {...b,} = {}; diff --git a/tests/baselines/reference/tsxElementResolution3.errors.txt b/tests/baselines/reference/tsxElementResolution3.errors.txt deleted file mode 100644 index f220dbd8a5bdd..0000000000000 --- a/tests/baselines/reference/tsxElementResolution3.errors.txt +++ /dev/null @@ -1,20 +0,0 @@ -tests/cases/conformance/jsx/file.tsx(12,2): error TS2322: Type '{ w: string; }' is not assignable to type '{ n: string; }'. - Property 'w' does not exist on type '{ n: string; }'. - - -==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== - declare module JSX { - interface Element { } - interface IntrinsicElements { - [x: string]: { n: string; }; - } - } - - // OK -
; - - // Error - ; - ~~~~ -!!! error TS2322: Type '{ w: string; }' is not assignable to type '{ n: string; }'. -!!! error TS2322: Property 'w' does not exist on type '{ n: string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt b/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt index a84182a744c61..05a809393bd0c 100644 --- a/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt @@ -61,15 +61,16 @@ tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(164,5) 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'. + Type '"a"' is not assignable to type 'never'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(173,5): error TS2322: Type 'K' is not assignable to type 'J'. + Index signature is missing in type 'K'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(174,5): error TS2322: Type 'L' is not assignable to type 'J'. + Index signature is missing in type 'L'. tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(176,5): error TS2322: Type 'H' is not assignable to type 'K'. Type 'H' is missing the following properties from type '{ a: string; b: string; c: string; }': b, c tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(177,5): error TS2322: Type 'I' is not assignable to type 'H'. @@ -87,7 +88,7 @@ tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5) Type 'J' is missing the following properties from type '{ a: string; b: string; c: string; }': a, b, c -==== tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts (42 errors) ==== +==== tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts (43 errors) ==== interface A { [x: "a" | "b" | "c"]: string; } @@ -352,10 +353,6 @@ tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5) !!! 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; @@ -368,9 +365,15 @@ tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5) ~ !!! 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'. +!!! error TS2322: Type '"a"' is not assignable to type 'never'. j = k; + ~ +!!! error TS2322: Type 'K' is not assignable to type 'J'. +!!! error TS2322: Index signature is missing in type 'K'. j = l; + ~ +!!! error TS2322: Type 'L' is not assignable to type 'J'. +!!! error TS2322: Index signature is missing in type 'L'. k = h; ~ diff --git a/tests/baselines/reference/unusedLocalsStartingWithUnderscore.types b/tests/baselines/reference/unusedLocalsStartingWithUnderscore.types index 88aa923a3e46f..fd277723c542b 100644 --- a/tests/baselines/reference/unusedLocalsStartingWithUnderscore.types +++ b/tests/baselines/reference/unusedLocalsStartingWithUnderscore.types @@ -3,7 +3,7 @@ import * as _ from "./a"; >_ : typeof _ for (const _ of []) { } ->_ : any +>_ : undefined >[] : undefined[] for (const _ in []) { } @@ -17,7 +17,7 @@ namespace _ns { >_ : any for (const _ of []) { } ->_ : any +>_ : undefined >[] : undefined[] for (const _ in []) { } diff --git a/tests/cases/compiler/classWithIndexAllowsNonNumericNames.ts b/tests/cases/compiler/classWithIndexAllowsNonNumericNames.ts new file mode 100644 index 0000000000000..a58c30cb496ed --- /dev/null +++ b/tests/cases/compiler/classWithIndexAllowsNonNumericNames.ts @@ -0,0 +1,4 @@ +class Obs { + [idx: number]: string; + private _field: number; +} diff --git a/tests/cases/fourslash/duplicateIndexers.ts b/tests/cases/fourslash/duplicateIndexers.ts index 5f72625a6ebfd..0b70512ca0f4a 100644 --- a/tests/cases/fourslash/duplicateIndexers.ts +++ b/tests/cases/fourslash/duplicateIndexers.ts @@ -8,4 +8,4 @@ ////var i: I; ////var /**/r = i[1]; -verify.quickInfoAt("", "var r: string"); +verify.quickInfoAt("", "var r: string & number"); From cb0d0755d9b395a11b5a782957a82ff033887a26 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 28 Jan 2019 18:22:01 -0800 Subject: [PATCH 08/11] Reify and check unit types in index signatures identically to mapped types --- src/compiler/checker.ts | 203 ++++++++---- src/compiler/symbolWalker.ts | 2 +- src/compiler/types.ts | 5 +- .../reference/api/tsserverlibrary.d.ts | 2 +- tests/baselines/reference/api/typescript.d.ts | 2 +- .../reference/arraySigChecking.types | 2 +- .../computedPropertyNames11_ES5.types | 4 +- .../computedPropertyNames11_ES6.types | 4 +- .../computedPropertyNames4_ES5.types | 4 +- .../computedPropertyNames4_ES6.types | 4 +- .../computedPropertyNames9_ES5.types | 4 +- .../computedPropertyNames9_ES6.types | 4 +- ...ropertyNamesContextualType8_ES5.errors.txt | 4 +- ...ropertyNamesContextualType8_ES6.errors.txt | 4 +- ...ropertyNamesContextualType9_ES5.errors.txt | 4 +- ...ropertyNamesContextualType9_ES6.errors.txt | 4 +- .../declFileTypeAnnotationTypeLiteral.types | 2 +- .../reference/duplicateNumericIndexers.types | 2 +- .../reference/duplicateStringIndexers.types | 2 +- ...icTypeReferenceWithoutTypeArgument.d.types | 2 +- ...ericTypeReferenceWithoutTypeArgument.types | 2 +- ...ricTypeReferenceWithoutTypeArgument2.types | 2 +- ...ricTypeReferenceWithoutTypeArgument3.types | 2 +- .../reference/indexTypeCheck.errors.txt | 4 +- ...faceWithEnumKeyedIndexSignature.errors.txt | 63 +++- .../interfaceWithEnumKeyedIndexSignature.js | 47 ++- ...terfaceWithEnumKeyedIndexSignature.symbols | 73 ++++- ...interfaceWithEnumKeyedIndexSignature.types | 103 +++++- .../reference/multipleNumericIndexers.types | 4 +- .../reference/multipleStringIndexers.types | 4 +- .../reference/parserIndexSignature8.types | 2 +- .../reference/recursiveTypesWithTypeof.types | 18 +- ...bolIndexerCompatabilityExamples.errors.txt | 16 +- .../symbolIndexerCompatabilityExamples.types | 38 +-- ...arrowsIndexedAccessOfKnownProperty.symbols | 4 +- .../typeOfEnumAndVarRedeclarations.errors.txt | 4 +- ...nionIndexerGeneralAssignability.errors.txt | 302 +++++++----------- .../unionIndexerGeneralAssignability.js | 116 ++++--- .../unionIndexerGeneralAssignability.symbols | 144 ++++----- .../unionIndexerGeneralAssignability.types | 58 ++-- .../interfaceWithEnumKeyedIndexSignature.ts | 28 +- .../unionIndexerGeneralAssignability.ts | 62 ++-- ...ssImplementInterfaceIndexSignaturesBoth.ts | 3 +- 43 files changed, 815 insertions(+), 548 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 676e5defa38bb..fe24f099ee726 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2792,16 +2792,28 @@ namespace ts { return result || emptyArray; } - function setStructuredTypeMembers(type: StructuredType, members: SymbolTable, callSignatures: ReadonlyArray, constructSignatures: ReadonlyArray, indexInfos: IndexInfo[] | undefined): ResolvedType { + function reifyConcreteIndexInfoKeysAsProperties(indexInfos: ReadonlyArray, container: { members: SymbolTable, indexInfos?: IndexInfo[] }) { + // We resolve index infos of concrete props into real properties and combine similar indexes into one + for (const info of indexInfos) { + forEachType(info.indexType, t => { + addMemberForKeyTypeWithModifiers(t, info.type, container, /*modifiersType*/ undefined, info.isReadonly ? MappedTypeModifiers.IncludeReadonly : 0, t === info.indexType ? info : undefined); + }); + } + } + + function setStructuredTypeMembers(type: StructuredType, members: SymbolTable, callSignatures: ReadonlyArray, constructSignatures: ReadonlyArray, indexInfos: ReadonlyArray | undefined): ResolvedType { (type).members = members; + (type).indexInfos = undefined; + if (indexInfos) { + reifyConcreteIndexInfoKeysAsProperties(indexInfos, (type as { members: SymbolTable, indexinfos?: IndexInfo[] })); + } (type).properties = members === emptySymbols ? emptyArray : getNamedMembers(members); (type).callSignatures = callSignatures; (type).constructSignatures = constructSignatures; - (type).indexInfos = indexInfos; return type; } - function createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: ReadonlyArray, constructSignatures: ReadonlyArray, indexInfos: IndexInfo[] | undefined): ResolvedType { + function createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: ReadonlyArray, constructSignatures: ReadonlyArray, indexInfos: ReadonlyArray | undefined): ResolvedType { return setStructuredTypeMembers(createObjectType(ObjectFlags.Anonymous, symbol), members, callSignatures, constructSignatures, indexInfos); } @@ -6647,7 +6659,7 @@ namespace ts { let members: SymbolTable; let callSignatures: ReadonlyArray; let constructSignatures: ReadonlyArray | undefined; - let indexInfos: IndexInfo[] | undefined; + let indexInfos: ReadonlyArray | undefined; if (rangeEquals(typeParameters, typeArguments, 0, typeParameters.length)) { mapper = identityMapper; members = source.symbol ? getMembersOfSymbol(source.symbol) : createSymbolTable(source.declaredProperties); @@ -6680,8 +6692,13 @@ namespace ts { } if (!resolveIndexOnIndexInfos(stringType, indexInfos)) { if (instantiatedBaseType === anyType) { - indexInfos = indexInfos || []; - indexInfos.push(createIndexInfo(stringType, anyType, /*isReadonly*/ false)); + const info = createIndexInfo(stringType, anyType, /*isReadonly*/ false); + if (!indexInfos) { + indexInfos = [info]; + } + else { + indexInfos = concatenate(indexInfos, [info]); + } } } } @@ -6933,8 +6950,8 @@ namespace ts { return result; } - function getUnionIndexInfos(types: ReadonlyArray): IndexInfo[] | undefined { - let finalInfos: IndexInfo[] | undefined; + function getUnionIndexInfos(types: ReadonlyArray): ReadonlyArray | undefined { + let finalInfos: ReadonlyArray | undefined; for (const type of types) { const infos = getIndexInfosOfType(type); if (!infos) { @@ -6963,7 +6980,7 @@ namespace ts { return !type1 ? type2 : !type2 ? type1 : getIntersectionType([type1, type2]); } - function overrideIndexInfos(infos1: IndexInfo[] | undefined, infos2: IndexInfo[] | undefined): IndexInfo[] | undefined { + function overrideIndexInfos(infos1: ReadonlyArray | undefined, infos2: ReadonlyArray | undefined): ReadonlyArray | undefined { if (!infos1) { return infos2; } @@ -6992,7 +7009,7 @@ namespace ts { return concatenate(infos, baseInfos); } - function intersectIndexInfos(infos1: IndexInfo[] | undefined, infos2: IndexInfo[] | undefined): IndexInfo[] | undefined { + function intersectIndexInfos(infos1: ReadonlyArray | undefined, infos2: ReadonlyArray | undefined): ReadonlyArray | undefined { if (!infos1) { return infos2; } @@ -7021,7 +7038,7 @@ namespace ts { return concatenate(infos, baseInfos); } - function unionIndexInfos(infos1: IndexInfo[] | undefined, infos2: IndexInfo[] | undefined): IndexInfo[] | undefined { + function unionIndexInfos(infos1: ReadonlyArray | undefined, infos2: ReadonlyArray | undefined): ReadonlyArray | undefined { if (!infos1 || !infos2) { return; } @@ -7057,7 +7074,7 @@ namespace ts { // intersection type use getPropertiesOfType (only the language service uses this). let callSignatures: ReadonlyArray = emptyArray; let constructSignatures: ReadonlyArray = emptyArray; - let indexInfos: IndexInfo[] | undefined; + let indexInfos: ReadonlyArray | undefined; const types = type.types; const mixinCount = countWhere(types, isMixinConstructorType); for (let i = 0; i < types.length; i++) { @@ -7209,7 +7226,7 @@ namespace ts { /** Resolve the members of a mapped type { [P in K]: T } */ function resolveMappedTypeMembers(type: MappedType) { const members: SymbolTable = createSymbolTable(); - let indexInfos: IndexInfo[] | undefined; + const container: { members: SymbolTable, indexInfos?: IndexInfo[] } = { members, indexInfos: undefined }; // Resolve upfront such that recursive references see an empty object type. setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined); // In { [P in K]: T }, we refer to P as the type parameter type, K as the constraint type, @@ -7238,7 +7255,7 @@ namespace ts { else { forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType); } - setStructuredTypeMembers(type, members, emptyArray, emptyArray, indexInfos); + setStructuredTypeMembers(type, members, emptyArray, emptyArray, container.indexInfos); function addMemberForKeyType(t: Type) { // Create a mapper from T to the current iteration type constituent. Then, if the @@ -7246,38 +7263,62 @@ namespace ts { // instantiation mapper. const templateMapper = combineTypeMappers(type.mapper, createTypeMapper([typeParameter], [t])); const propType = instantiateType(templateType, templateMapper); - // If the current iteration type constituent is a string literal type, create a property. - // Otherwise, for type string create a string index signature. - if (isTypeUsableAsPropertyName(t)) { - const propName = getPropertyNameFromType(t); - const modifiersProp = getPropertyOfType(modifiersType, propName); - const isOptional = !!(templateModifiers & MappedTypeModifiers.IncludeOptional || - !(templateModifiers & MappedTypeModifiers.ExcludeOptional) && modifiersProp && modifiersProp.flags & SymbolFlags.Optional); - const isReadonly = !!(templateModifiers & MappedTypeModifiers.IncludeReadonly || - !(templateModifiers & MappedTypeModifiers.ExcludeReadonly) && modifiersProp && isReadonlySymbol(modifiersProp)); - const prop = createSymbol(SymbolFlags.Property | (isOptional ? SymbolFlags.Optional : 0), propName, isReadonly ? CheckFlags.Readonly : 0); - // When creating an optional property in strictNullChecks mode, if 'undefined' isn't assignable to the - // type, we include 'undefined' in the type. Similarly, when creating a non-optional property in strictNullChecks - // mode, if the underlying property is optional we remove 'undefined' from the type. - prop.type = strictNullChecks && isOptional && !isTypeAssignableTo(undefinedType, propType) ? getOptionalType(propType) : - strictNullChecks && !isOptional && modifiersProp && modifiersProp.flags & SymbolFlags.Optional ? getTypeWithFacts(propType, TypeFacts.NEUndefined) : - propType; - if (modifiersProp) { - prop.syntheticOrigin = modifiersProp; - prop.declarations = modifiersProp.declarations; + addMemberForKeyTypeWithModifiers(t, propType, container, modifiersType, templateModifiers); + } + } + + function addMemberForKeyTypeWithModifiers(t: Type, propType: Type, container: {members: SymbolTable, indexInfos?: IndexInfo[]}, modifiersType: Type | undefined, templateModifiers: MappedTypeModifiers, sourceIndex?: IndexInfo) { + // If the current iteration type constituent is a string literal type, create a property. + // Otherwise, for type string create a string index signature. + if (isTypeUsableAsPropertyName(t)) { + const propName = getPropertyNameFromType(t); + const existing = container.members.get(propName); // If there's an existing symbol, we'll need to union the nameType's, intersect the prop types, and make readonly/optional if either is + const modifiersProp = modifiersType && getPropertyOfType(modifiersType, propName); + const isOptional = !!(existing && existing.flags & SymbolFlags.Optional) || !!(templateModifiers & MappedTypeModifiers.IncludeOptional || + !(templateModifiers & MappedTypeModifiers.ExcludeOptional) && modifiersProp && modifiersProp.flags & SymbolFlags.Optional); + const isReadonly = !!(existing && isReadonlySymbol(existing)) || !!(templateModifiers & MappedTypeModifiers.IncludeReadonly || + !(templateModifiers & MappedTypeModifiers.ExcludeReadonly) && modifiersProp && isReadonlySymbol(modifiersProp)); + const prop = createSymbol(SymbolFlags.Property | (isOptional ? SymbolFlags.Optional : 0), propName, isReadonly ? CheckFlags.Readonly : 0); + // When creating an optional property in strictNullChecks mode, if 'undefined' isn't assignable to the + // type, we include 'undefined' in the type. Similarly, when creating a non-optional property in strictNullChecks + // mode, if the underlying property is optional we remove 'undefined' from the type. + prop.type = strictNullChecks && isOptional && !isTypeAssignableTo(undefinedType, propType) ? getOptionalType(propType) : + strictNullChecks && !isOptional && modifiersProp && modifiersProp.flags & SymbolFlags.Optional ? getTypeWithFacts(propType, TypeFacts.NEUndefined) : + propType; + if (existing) { + prop.type = getIntersectionType([prop.type, getTypeOfSymbol(existing)]); + } + if (modifiersProp) { + prop.syntheticOrigin = modifiersProp; + prop.declarations = modifiersProp.declarations; + } + prop.nameType = existing ? getUnionType([existing.nameType || getLiteralTypeFromProperty(existing, TypeFlags.StringOrNumberLiteralOrUnique, /*retainNonpublic*/ true), t], UnionReduction.Subtype) : t; + container.members.set(propName, prop); + } + // Well-known symbols produce a key type of never when pushed through `getLiteralTypeFromPropertyName` right now, so we need to handle that + // Gracefully by _not_ making a `never` indexer (which would be a huge problem for assignability) + else if (!(t.flags & TypeFlags.Never)) { + container.indexInfos = container.indexInfos || []; + if (isTypeAny(t)) { + // Legacy behavior. TODO: Remove. + t = stringType; + } + const isReadonly = !!(templateModifiers & MappedTypeModifiers.IncludeReadonly); + if (container.indexInfos) { + // if there's already an index info with an identical `propType` (and readonly bit), merge them into one index + for (let i = 0; i < container.indexInfos.length; i++) { + const info = container.indexInfos[i]; + if (info.isReadonly === isReadonly && info.type === propType) { + container.indexInfos.splice(i, 1, createIndexInfo(getUnionType([info.indexType, t]), propType, isReadonly)); + return; + } } - prop.nameType = t; - members.set(propName, prop); } - // Well-known symbols produce a key type of never when pushed through `getLiteralTypeFromPropertyName` right now, so we need to handle that - // Gracefully by _not_ making a `never` indexer (which would be a huge problem for assignability) - else if (!(t.flags & TypeFlags.Never)) { - indexInfos = indexInfos || []; - if (isTypeAny(t)) { - // Legacy behavior. TODO: Remove. - t = stringType; - } - indexInfos.push(createIndexInfo(t, propType, !!(templateModifiers & MappedTypeModifiers.IncludeReadonly))); + if (sourceIndex && sourceIndex.indexType === t && sourceIndex.type === propType && sourceIndex.isReadonly === isReadonly) { + container.indexInfos.push(sourceIndex); + } + else { + container.indexInfos.push(createIndexInfo(t, propType, isReadonly, sourceIndex && sourceIndex.declaration)); } } } @@ -7798,7 +7839,7 @@ namespace ts { } let declarations: Declaration[] | undefined; let firstType: Type | undefined; - let nameType: Type | undefined; + const nameTypes: Type[] = []; const propTypes: Type[] = []; let firstValueDeclaration: Declaration | undefined; let hasNonUniformValueDeclaration = false; @@ -7813,7 +7854,6 @@ namespace ts { const type = getTypeOfSymbol(prop); if (!firstType) { firstType = type; - nameType = prop.nameType; } else if (type !== firstType) { checkFlags |= CheckFlags.HasNonUniformType; @@ -7822,6 +7862,7 @@ namespace ts { checkFlags |= CheckFlags.HasLiteralType; } propTypes.push(type); + nameTypes.push(getLiteralTypeFromProperty(prop, ~0, !(checkFlags & CheckFlags.ContainsPublic))); } addRange(propTypes, indexTypes); const result = createSymbol(SymbolFlags.Property | commonFlags, name, syntheticFlag | checkFlags); @@ -7836,7 +7877,7 @@ namespace ts { } result.declarations = declarations!; - result.nameType = nameType; + result.nameType = isUnion ? getIntersectionType(nameTypes) : getUnionType(nameTypes); result.type = isUnion ? getUnionType(propTypes) : getIntersectionType(propTypes); return result; } @@ -7914,7 +7955,7 @@ namespace ts { return getSignaturesOfStructuredType(getApparentType(type), kind); } - function getIndexInfosOfStructuredType(type: Type): IndexInfo[] | undefined { + function getIndexInfosOfStructuredType(type: Type): ReadonlyArray | undefined { if (type.flags & TypeFlags.StructuredType) { const resolved = resolveStructuredTypeMembers(type); return resolved.indexInfos; @@ -7923,21 +7964,21 @@ namespace ts { // Return the indexing info of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. - function getIndexInfosOfType(type: Type): IndexInfo[] | undefined { + function getIndexInfosOfType(type: Type): ReadonlyArray | undefined { return getIndexInfosOfStructuredType(getApparentType(type)); } // TODO (weswigham): Ensure all callers handle unions of `type` _before_ calling this - function getResultingIndexInfosOfIndexOnType(type: Type, indexType: Type): IndexInfo[] | undefined { + function getResultingIndexInfosOfIndexOnType(type: Type, indexType: Type): ReadonlyArray | undefined { return resolveIndexOnIndexInfos(indexType, getIndexInfosOfType(type)); } - function getApplicableIndexInfosOfIndexOnType(type: Type, indexType: Type, returnPartialSuccess?: boolean): IndexInfo[][] | undefined { + function getApplicableIndexInfosOfIndexOnType(type: Type, indexType: Type, returnPartialSuccess?: boolean): ReadonlyArray[] | undefined { if (!(indexType.flags & TypeFlags.Union)) { const result = getResultingIndexInfosOfIndexOnType(type, indexType); return result && [result]; } - let resultList: IndexInfo[][] | undefined; + let resultList: ReadonlyArray[] | undefined; for (const nameType of (indexType as UnionType).types) { const result = getResultingIndexInfosOfIndexOnType(type, nameType); if (!result && !returnPartialSuccess) { @@ -8512,7 +8553,7 @@ namespace ts { * Given a single type and a list of index infos, if that type is applicable to one or more of them, * returns the index info to which it is the most applicable */ - function resolveIndexOnIndexInfos(indexType: Type, infos: IndexInfo[] | undefined): IndexInfo[] | undefined { + function resolveIndexOnIndexInfos(indexType: Type, infos: ReadonlyArray | undefined): ReadonlyArray | undefined { Debug.assert(!(indexType.flags & TypeFlags.Union)); if (indexType.flags & TypeFlags.StringLiteral) { // Prioritize equivalent numeric representation over the string one, since the "number"s in this case _are_ just a subdomain of the strings @@ -10400,7 +10441,7 @@ namespace ts { const members = createSymbolTable(); const skippedPrivateMembers = createUnderscoreEscapedMap(); - let indexInfos: IndexInfo[] | undefined; + let indexInfos: ReadonlyArray | undefined; if (left === emptyObjectType) { // for the first spread element, left === emptyObjectType, so take the right's string indexer indexInfos = getIndexInfosOfType(right); @@ -11139,7 +11180,7 @@ namespace ts { return createIndexInfo(instantiateType(info.indexType, mapper), instantiateType(info.type, mapper), info.isReadonly, info.declaration); } - function instantiateIndexInfos(infos: IndexInfo[] | undefined, mapper: TypeMapper): IndexInfo[] | undefined { + function instantiateIndexInfos(infos: ReadonlyArray | undefined, mapper: TypeMapper): IndexInfo[] | undefined { return map(infos, i => instantiateIndexInfo(i, mapper)); } @@ -11919,7 +11960,7 @@ namespace ts { if (s & TypeFlags.Undefined && (!strictNullChecks || t & (TypeFlags.Undefined | TypeFlags.Void))) return true; if (s & TypeFlags.Null && (!strictNullChecks || t & TypeFlags.Null)) return true; if (s & TypeFlags.Object && t & TypeFlags.NonPrimitive) return true; - if (relation === assignableRelation || relation === comparableRelation) { + if (relation === assignableRelation || relation === comparableRelation || relation === indexAccessAssignableRelation || relation === indexAssignableRelation) { 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 @@ -11927,15 +11968,15 @@ namespace ts { if (s & (TypeFlags.Number | TypeFlags.NumberLiteral) && !(s & TypeFlags.EnumLiteral) && ( t & TypeFlags.Enum || t & TypeFlags.NumberLiteral && t & TypeFlags.EnumLiteral)) return true; } + if (relation === indexAccessAssignableRelation || relation === indexAssignableRelation) { + if (s & TypeFlags.StringLiteral && t & TypeFlags.NumberLiteral) return +(source as LiteralType).value === (target as LiteralType).value; + if (s & TypeFlags.NumberLiteral && t & TypeFlags.StringLiteral) return (source as LiteralType).value === +(target as LiteralType).value; + } 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; } return false; } @@ -13044,6 +13085,14 @@ namespace ts { } return Ternary.False; } + const targetName = getLiteralTypeFromProperty(targetProp, ~0, /*retainNonpublic*/ true); + const namesRelated = isTypeIndexAssignableTo(targetName, getLiteralTypeFromProperty(sourceProp, ~0, /*retainNonpublic*/ true)); + if (!namesRelated) { + if (reportErrors) { + reportError(Diagnostics.Property_0_does_not_exist_on_type_1, typeToString(targetName), typeToString(source)); + } + return Ternary.False; + } const related = isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); if (!related) { if (reportErrors) { @@ -13265,21 +13314,50 @@ namespace ts { return eachPropertyRelatedToIndexesOf(source, target, reportErrors); } let hasTypedSignature = false; + let hasUnboundedBound = false; for (const info of targetInfo) { if (!(!sourceIsPrimitive && info.type.flags & TypeFlags.AnyOrUnknown)) { hasTypedSignature = true; } + const keyBound = getApparentType(info.indexType); + if (forEachType(keyBound, t => !(t.flags & TypeFlags.StringOrNumberLiteralOrUnique))) { + hasUnboundedBound = true; + } } if (!hasTypedSignature) { return Ternary.True; } + if (!hasUnboundedBound) { + // materialize all index signatures in the target as properties and restart the relationship check + return isRelatedTo(source, getInstantiationWithKeyBounds(target as StructuredType), reportErrors); + } if (reportErrors) { reportError(Diagnostics.Index_signature_is_missing_in_type_0, typeToString(source)); } return Ternary.False; } - function indexInfosIdentical(sourceInfos: IndexInfo[] | undefined, targetInfos: IndexInfo[] | undefined) { + function getInstantiationWithKeyBounds(type: StructuredType): Type { + if ((type as ResolvedType).indexKeysConstrainedInstantiation) { + return (type as ResolvedType).indexKeysConstrainedInstantiation!; + } + if (type.flags & TypeFlags.UnionOrIntersection) { + const types = map((type as UnionOrIntersectionType).types, getInstantiationWithKeyBounds); + return (type as ResolvedType).indexKeysConstrainedInstantiation = type.flags & TypeFlags.Union ? getUnionType(types) : getIntersectionType(types); + } + const resolved = resolveStructuredTypeMembers(type); + if (!length(resolved.indexInfos)) { + return resolved; + } + const clone = createObjectType(ObjectFlags.Anonymous, resolved.symbol); + resolved.indexKeysConstrainedInstantiation = clone; + const members = createSymbolTable(); + copyEntries(resolved.members, members); + setStructuredTypeMembers(clone, members, resolved.callSignatures, resolved.constructSignatures, map(resolved.indexInfos, info => createIndexInfo(getApparentType(info.indexType), info.type, info.isReadonly, info.declaration))); + return clone; + } + + function indexInfosIdentical(sourceInfos: ReadonlyArray | undefined, targetInfos: ReadonlyArray | undefined) { if (length(sourceInfos) !== length(targetInfos)) return Ternary.False; if (!sourceInfos || !targetInfos) return Ternary.True; targetLoop: for (const targetInfo of targetInfos) { @@ -13644,6 +13722,9 @@ namespace ts { if (isReadonlySymbol(sourceProp) !== isReadonlySymbol(targetProp)) { return Ternary.False; } + if (!compareTypes(getLiteralTypeFromProperty(sourceProp, ~0, /*retainNonpublic*/ true), getLiteralTypeFromProperty(targetProp, ~0, /*retainNonpublic*/ true))) { + return Ternary.False; + } return compareTypes(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp)); } diff --git a/src/compiler/symbolWalker.ts b/src/compiler/symbolWalker.ts index 94985e5cdead4..6bc96e15049b4 100644 --- a/src/compiler/symbolWalker.ts +++ b/src/compiler/symbolWalker.ts @@ -8,7 +8,7 @@ namespace ts { resolveStructuredTypeMembers: (type: ObjectType) => ResolvedType, getTypeOfSymbol: (sym: Symbol) => Type, getResolvedSymbol: (node: Node) => Symbol, - getIndexInfosOfType: (type: Type) => IndexInfo[] | undefined, + getIndexInfosOfType: (type: Type) => ReadonlyArray | undefined, getConstraintOfTypeParameter: (typeParameter: TypeParameter) => Type | undefined, getFirstIdentifier: (node: EntityNameOrEntityNameExpression) => Identifier) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 320de44bcb846..9ffbe30d1d238 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3017,7 +3017,7 @@ namespace ts { getPropertiesOfType(type: Type): Symbol[]; getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; /* @internal */ getTypeOfPropertyOfType(type: Type, propertyName: string): Type | undefined; - getIndexInfosOfType(type: Type, indexType?: Type): IndexInfo[] | undefined; + getIndexInfosOfType(type: Type, indexType?: Type): ReadonlyArray | undefined; getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray; getIndexTypeOfType(type: Type, indexType: Type): Type | undefined; getBaseTypes(type: InterfaceType): BaseType[]; @@ -4001,7 +4001,7 @@ namespace ts { /* @internal */ properties?: Symbol[]; // Properties /* @internal */ callSignatures?: ReadonlyArray; // Call signatures of type /* @internal */ constructSignatures?: ReadonlyArray; // Construct signatures of type - /* @internal */ indexInfos?: IndexInfo[]; // Index infos + /* @internal */ indexInfos?: ReadonlyArray; // Index infos } /** Class and interface types (ObjectFlags.Class and ObjectFlags.Interface). */ @@ -4133,6 +4133,7 @@ namespace ts { properties: Symbol[]; // Properties callSignatures: ReadonlyArray; // Call signatures of type constructSignatures: ReadonlyArray; // Construct signatures of type + indexKeysConstrainedInstantiation?: Type; } /* @internal */ diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 84d49f7553e7a..eb4b4cba425e3 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1869,7 +1869,7 @@ declare namespace ts { getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; - getIndexInfosOfType(type: Type, indexType?: Type): IndexInfo[] | undefined; + getIndexInfosOfType(type: Type, indexType?: Type): ReadonlyArray | undefined; getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray; getIndexTypeOfType(type: Type, indexType: Type): Type | undefined; getBaseTypes(type: InterfaceType): BaseType[]; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index ee7995ea6d1e6..7faa63c34e1f2 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1869,7 +1869,7 @@ declare namespace ts { getDeclaredTypeOfSymbol(symbol: Symbol): Type; getPropertiesOfType(type: Type): Symbol[]; getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; - getIndexInfosOfType(type: Type, indexType?: Type): IndexInfo[] | undefined; + getIndexInfosOfType(type: Type, indexType?: Type): ReadonlyArray | undefined; getSignaturesOfType(type: Type, kind: SignatureKind): ReadonlyArray; getIndexTypeOfType(type: Type, indexType: Type): Type | undefined; getBaseTypes(type: InterfaceType): BaseType[]; diff --git a/tests/baselines/reference/arraySigChecking.types b/tests/baselines/reference/arraySigChecking.types index d1367783609b3..23518f12c78d8 100644 --- a/tests/baselines/reference/arraySigChecking.types +++ b/tests/baselines/reference/arraySigChecking.types @@ -18,7 +18,7 @@ declare module M { } var foo: { [index: any]; }; // expect an error here ->foo : { [index: any]: any; } +>foo : { [index: string]: any; } >index : any } diff --git a/tests/baselines/reference/computedPropertyNames11_ES5.types b/tests/baselines/reference/computedPropertyNames11_ES5.types index b5ef2e02b2624..8672a78f00c24 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES5.types +++ b/tests/baselines/reference/computedPropertyNames11_ES5.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [x: string]: any; [x: number]: any; [""]: any; readonly [0]: number; [`hello bye`]: any; } ->{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [x: string]: any; [x: number]: any; [""]: any; readonly [0]: number; [`hello bye`]: any; } +>v : { [x: string | number]: any; [""]: any; readonly [0]: number; [`hello bye`]: any; } +>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [x: string | number]: any; [""]: any; readonly [0]: number; [`hello bye`]: any; } get [s]() { return 0; }, >[s] : number diff --git a/tests/baselines/reference/computedPropertyNames11_ES6.types b/tests/baselines/reference/computedPropertyNames11_ES6.types index 0cec215f33c04..4fc9a719a799c 100644 --- a/tests/baselines/reference/computedPropertyNames11_ES6.types +++ b/tests/baselines/reference/computedPropertyNames11_ES6.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [x: string]: any; [x: number]: any; [""]: any; readonly [0]: number; [`hello bye`]: any; } ->{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [x: string]: any; [x: number]: any; [""]: any; readonly [0]: number; [`hello bye`]: any; } +>v : { [x: string | number]: any; [""]: any; readonly [0]: number; [`hello bye`]: any; } +>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : { [x: string | number]: any; [""]: any; readonly [0]: number; [`hello bye`]: any; } get [s]() { return 0; }, >[s] : number diff --git a/tests/baselines/reference/computedPropertyNames4_ES5.types b/tests/baselines/reference/computedPropertyNames4_ES5.types index e34921dd63a61..cd66d075bb0a7 100644 --- a/tests/baselines/reference/computedPropertyNames4_ES5.types +++ b/tests/baselines/reference/computedPropertyNames4_ES5.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [x: string]: string | number; [x: number]: string | number; [""]: number; [0]: number; [`hello bye`]: number; } ->{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [x: string]: string | number; [x: number]: string | number; [""]: number; [0]: number; [`hello bye`]: number; } +>v : { [x: string | number]: string | number; [""]: number; [0]: number; [`hello bye`]: number; } +>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [x: string | number]: string | number; [""]: number; [0]: number; [`hello bye`]: number; } [s]: 0, >[s] : number diff --git a/tests/baselines/reference/computedPropertyNames4_ES6.types b/tests/baselines/reference/computedPropertyNames4_ES6.types index 85e95a8b1adb8..3a63acdbae645 100644 --- a/tests/baselines/reference/computedPropertyNames4_ES6.types +++ b/tests/baselines/reference/computedPropertyNames4_ES6.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [x: string]: string | number; [x: number]: string | number; [""]: number; [0]: number; [`hello bye`]: number; } ->{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [x: string]: string | number; [x: number]: string | number; [""]: number; [0]: number; [`hello bye`]: number; } +>v : { [x: string | number]: string | number; [""]: number; [0]: number; [`hello bye`]: number; } +>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [x: string | number]: string | number; [""]: number; [0]: number; [`hello bye`]: number; } [s]: 0, >[s] : number diff --git a/tests/baselines/reference/computedPropertyNames9_ES5.types b/tests/baselines/reference/computedPropertyNames9_ES5.types index fd09bc5bec1bd..9cfa05e29a184 100644 --- a/tests/baselines/reference/computedPropertyNames9_ES5.types +++ b/tests/baselines/reference/computedPropertyNames9_ES5.types @@ -16,8 +16,8 @@ function f(x): any { } >x : any var v = { ->v : { [x: string]: number; [x: number]: number; } ->{ [f("")]: 0, [f(0)]: 0, [f(true)]: 0} : { [x: string]: number; [x: number]: number; } +>v : { [x: string | number]: number; } +>{ [f("")]: 0, [f(0)]: 0, [f(true)]: 0} : { [x: string | number]: number; } [f("")]: 0, >[f("")] : number diff --git a/tests/baselines/reference/computedPropertyNames9_ES6.types b/tests/baselines/reference/computedPropertyNames9_ES6.types index 6fa2849fcc68c..2ff7a6d0e4692 100644 --- a/tests/baselines/reference/computedPropertyNames9_ES6.types +++ b/tests/baselines/reference/computedPropertyNames9_ES6.types @@ -16,8 +16,8 @@ function f(x): any { } >x : any var v = { ->v : { [x: string]: number; [x: number]: number; } ->{ [f("")]: 0, [f(0)]: 0, [f(true)]: 0} : { [x: string]: number; [x: number]: number; } +>v : { [x: string | number]: number; } +>{ [f("")]: 0, [f(0)]: 0, [f(true)]: 0} : { [x: string | number]: number; } [f("")]: 0, >[f("")] : number diff --git a/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.errors.txt index eedc4e10ce9b0..e6060b007ccc7 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType8_ES5.ts(6,5): error TS2322: Type '{ [x: string]: string | number; }' is not assignable to type 'I'. - 'string' index signatures are incompatible. + 'string' and 'string | number' index signatures are incompatible. Type 'string | number' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. @@ -13,7 +13,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualTy var o: I = { ~ !!! error TS2322: Type '{ [x: string]: string | number; }' is not assignable to type 'I'. -!!! error TS2322: 'string' index signatures are incompatible. +!!! error TS2322: 'string' and 'string | number' index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. !!! error TS2322: Type 'string' is not assignable to type 'boolean'. [""+"foo"]: "", diff --git a/tests/baselines/reference/computedPropertyNamesContextualType8_ES6.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType8_ES6.errors.txt index 4e5fa2a432db3..0398f75a0a307 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType8_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesContextualType8_ES6.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType8_ES6.ts(6,5): error TS2322: Type '{ [x: string]: string | number; }' is not assignable to type 'I'. - 'string' index signatures are incompatible. + 'string' and 'string | number' index signatures are incompatible. Type 'string | number' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. @@ -13,7 +13,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualTy var o: I = { ~ !!! error TS2322: Type '{ [x: string]: string | number; }' is not assignable to type 'I'. -!!! error TS2322: 'string' index signatures are incompatible. +!!! error TS2322: 'string' and 'string | number' index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. !!! error TS2322: Type 'string' is not assignable to type 'boolean'. [""+"foo"]: "", diff --git a/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.errors.txt index a5f5ece12ebd1..ef0e73a8426e1 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesContextualType9_ES5.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9_ES5.ts(6,5): error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. - 'number' index signatures are incompatible. + 'number' and 'string | number' index signatures are incompatible. Type 'string | number' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. @@ -13,7 +13,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualTy var o: I = { ~ !!! error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. -!!! error TS2322: 'number' index signatures are incompatible. +!!! error TS2322: 'number' and 'string | number' index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. !!! error TS2322: Type 'string' is not assignable to type 'boolean'. [+"foo"]: "", diff --git a/tests/baselines/reference/computedPropertyNamesContextualType9_ES6.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType9_ES6.errors.txt index 1580cba2b7deb..48d25ab1b5892 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType9_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNamesContextualType9_ES6.errors.txt @@ -1,5 +1,5 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualType9_ES6.ts(6,5): error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. - 'number' index signatures are incompatible. + 'number' and 'string | number' index signatures are incompatible. Type 'string | number' is not assignable to type 'boolean'. Type 'string' is not assignable to type 'boolean'. @@ -13,7 +13,7 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNamesContextualTy var o: I = { ~ !!! error TS2322: Type '{ [x: number]: string | number; }' is not assignable to type 'I'. -!!! error TS2322: 'number' index signatures are incompatible. +!!! error TS2322: 'number' and 'string | number' index signatures are incompatible. !!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. !!! error TS2322: Type 'string' is not assignable to type 'boolean'. [+"foo"]: "", diff --git a/tests/baselines/reference/declFileTypeAnnotationTypeLiteral.types b/tests/baselines/reference/declFileTypeAnnotationTypeLiteral.types index 72dbb5251d20f..175df0f25637b 100644 --- a/tests/baselines/reference/declFileTypeAnnotationTypeLiteral.types +++ b/tests/baselines/reference/declFileTypeAnnotationTypeLiteral.types @@ -15,7 +15,7 @@ module m { // Object literal with everything var x: { ->x : { (a: number): c; (a: string): g; new (a: number): c; new (a: string): m.c; [n: number]: c; [n: string]: c; a: c; b: g; m1(): g; m2(a: string, b?: number, ...c: c[]): string; } +>x : { (a: number): c; (a: string): g; new (a: number): c; new (a: string): m.c; [x: string | number]: c; a: c; b: g; m1(): g; m2(a: string, b?: number, ...c: c[]): string; } // Call signatures (a: number): c; diff --git a/tests/baselines/reference/duplicateNumericIndexers.types b/tests/baselines/reference/duplicateNumericIndexers.types index 4e12db0474207..1afadfe1bdae7 100644 --- a/tests/baselines/reference/duplicateNumericIndexers.types +++ b/tests/baselines/reference/duplicateNumericIndexers.types @@ -44,7 +44,7 @@ interface I { } var a: { ->a : { [x: number]: string; [x: number]: string; } +>a : { [x: number]: string; } [x: number]: string; >x : number diff --git a/tests/baselines/reference/duplicateStringIndexers.types b/tests/baselines/reference/duplicateStringIndexers.types index 749e5dd17bfbf..d1381878aad96 100644 --- a/tests/baselines/reference/duplicateStringIndexers.types +++ b/tests/baselines/reference/duplicateStringIndexers.types @@ -47,7 +47,7 @@ module test { } var a: { ->a : { [x: string]: string; [x: string]: string; } +>a : { [x: string]: string; } [x: string]: string; >x : string diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.types b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.types index 171463fcdd96a..f646bcf6bedb2 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.types +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.types @@ -21,7 +21,7 @@ declare var b: { (x: C): C }; >x : any declare var d: { [x: C]: C }; ->d : { [x: any]: any; } +>d : { [x: string]: any; } >x : any declare function f(x: C): C; diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.types b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.types index 8075a2c93e6b0..a24f5504b3cd5 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.types +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.types @@ -21,7 +21,7 @@ var b: { (x: C): C }; >x : any var d: { [x: C]: C }; ->d : { [x: any]: any; } +>d : { [x: string]: any; } >x : any var e = (x: C) => { var y: C; return y; } diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.types b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.types index 634597893ff72..adc3980fdfb11 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.types +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.types @@ -19,7 +19,7 @@ var b: { (x: I): I }; >x : any var d: { [x: I]: I }; ->d : { [x: any]: any; } +>d : { [x: string]: any; } >x : any var e = (x: I) => { var y: I; return y; } diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.types b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.types index 434314906e150..52ed5c46f2f98 100644 --- a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.types +++ b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.types @@ -21,7 +21,7 @@ declare var b: { (x: C): C }; >x : any declare var d: { [x: C]: C }; ->d : { [x: any]: any; } +>d : { [x: string]: any; } >x : any declare function f(x: C): C; diff --git a/tests/baselines/reference/indexTypeCheck.errors.txt b/tests/baselines/reference/indexTypeCheck.errors.txt index 69a57f8b77b11..e7f4164b5e914 100644 --- a/tests/baselines/reference/indexTypeCheck.errors.txt +++ b/tests/baselines/reference/indexTypeCheck.errors.txt @@ -4,7 +4,7 @@ tests/cases/compiler/indexTypeCheck.ts(17,2): error TS2413: 'number' index type Type 'number' is not assignable to type 'string'. tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: 'number' index type 'Orange' is not assignable to 'string' index type 'Yellow'. Type 'Orange' is not assignable to type 'Yellow'. - 'string' index signatures are incompatible. + 'string' and 'string | number' index signatures are incompatible. Type 'string' is not assignable to type 'Red'. 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'. @@ -49,7 +49,7 @@ tests/cases/compiler/indexTypeCheck.ts(51,8): error TS2538: Type 'Blue' cannot b ~~~~~~~~~~~~~~~~~~~ !!! error TS2413: 'number' index type 'Orange' is not assignable to 'string' index type 'Yellow'. !!! error TS2413: Type 'Orange' is not assignable to type 'Yellow'. -!!! error TS2413: 'string' index signatures are incompatible. +!!! error TS2413: 'string' and 'string | number' index signatures are incompatible. !!! error TS2413: Type 'string' is not assignable to type 'Red'. [s:string]: Yellow; // ok } diff --git a/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.errors.txt b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.errors.txt index 15be82de9e3e5..934e5f95cbae3 100644 --- a/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.errors.txt +++ b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.errors.txt @@ -1,13 +1,16 @@ -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(48,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(49,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(50,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(51,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(52,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(53,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(54,15): error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. -==== tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts (7 errors) ==== +==== tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts (10 errors) ==== export interface UserInterfaceColors { [index: UserInterfaceElement]: ColorInfo; } @@ -29,20 +32,12 @@ tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(30 // 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. + + // errors expectColInfo(x[0 as number]); ~~~~~~~~~~~~~~ !!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. @@ -52,4 +47,42 @@ tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(30 expectColInfo(x[12]); ~~~~~ !!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors' has no index signature. + + export interface UserInterfaceColors2 { + [index: UserInterfaceElement2]: ColorInfo; + } + export enum UserInterfaceElement2 { + ActiveTitleBar = "Active", + InactiveTitleBar = "Inactive", + } + + const x2: UserInterfaceColors2 = null as any; + + + // correct uses + expectColInfo(x2[UserInterfaceElement2.ActiveTitleBar]); + expectColInfo(x2[UserInterfaceElement2.InactiveTitleBar]); + + // errors + expectColInfo(x2[0]); + ~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. + expectColInfo(x2[1]); + ~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. + expectColInfo(x2["0"]); + ~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. + expectColInfo(x2["1"]); + ~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. + expectColInfo(x2[0 as number]); + ~~~~~~~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. + expectColInfo(x2["0" as string]); + ~~~~~~~~~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. + expectColInfo(x2[12]); + ~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'UserInterfaceColors2' has no index signature. \ No newline at end of file diff --git a/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.js b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.js index f3da598d3ce9d..d0aed84907df3 100644 --- a/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.js +++ b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.js @@ -20,15 +20,39 @@ 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"]); + +// errors expectColInfo(x[0 as number]); expectColInfo(x["0" as string]); expectColInfo(x[12]); + +export interface UserInterfaceColors2 { + [index: UserInterfaceElement2]: ColorInfo; +} +export enum UserInterfaceElement2 { + ActiveTitleBar = "Active", + InactiveTitleBar = "Inactive", +} + +const x2: UserInterfaceColors2 = null as any; + + +// correct uses +expectColInfo(x2[UserInterfaceElement2.ActiveTitleBar]); +expectColInfo(x2[UserInterfaceElement2.InactiveTitleBar]); + +// errors +expectColInfo(x2[0]); +expectColInfo(x2[1]); +expectColInfo(x2["0"]); +expectColInfo(x2["1"]); +expectColInfo(x2[0 as number]); +expectColInfo(x2["0" as string]); +expectColInfo(x2[12]); //// [interfaceWithEnumKeyedIndexSignature.js] @@ -43,11 +67,28 @@ 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"]); +// errors expectColInfo(x[0]); expectColInfo(x["0"]); expectColInfo(x[12]); +var UserInterfaceElement2; +(function (UserInterfaceElement2) { + UserInterfaceElement2["ActiveTitleBar"] = "Active"; + UserInterfaceElement2["InactiveTitleBar"] = "Inactive"; +})(UserInterfaceElement2 = exports.UserInterfaceElement2 || (exports.UserInterfaceElement2 = {})); +var x2 = null; +// correct uses +expectColInfo(x2[UserInterfaceElement2.ActiveTitleBar]); +expectColInfo(x2[UserInterfaceElement2.InactiveTitleBar]); +// errors +expectColInfo(x2[0]); +expectColInfo(x2[1]); +expectColInfo(x2["0"]); +expectColInfo(x2["1"]); +expectColInfo(x2[0]); +expectColInfo(x2["0"]); +expectColInfo(x2[12]); diff --git a/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.symbols b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.symbols index 04cc6edf589df..dd7778bb233e7 100644 --- a/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.symbols +++ b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.symbols @@ -56,23 +56,27 @@ expectColInfo(x[UserInterfaceElement.InactiveTitleBar]); >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)) +>0 : Symbol(0) expectColInfo(x[1]); >expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) >x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) +>1 : Symbol(1) expectColInfo(x["0"]); >expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) >x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) +>"0" : Symbol(0) expectColInfo(x["1"]); >expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) >x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) +>"1" : Symbol(1) +// errors expectColInfo(x[0 as number]); >expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) >x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) @@ -85,3 +89,70 @@ expectColInfo(x[12]); >expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) >x : Symbol(x, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 5)) +export interface UserInterfaceColors2 { +>UserInterfaceColors2 : Symbol(UserInterfaceColors2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 29, 21)) + + [index: UserInterfaceElement2]: ColorInfo; +>index : Symbol(index, Decl(interfaceWithEnumKeyedIndexSignature.ts, 32, 5)) +>UserInterfaceElement2 : Symbol(UserInterfaceElement2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 33, 1)) +>ColorInfo : Symbol(ColorInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 2, 1)) +} +export enum UserInterfaceElement2 { +>UserInterfaceElement2 : Symbol(UserInterfaceElement2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 33, 1)) + + ActiveTitleBar = "Active", +>ActiveTitleBar : Symbol(UserInterfaceElement2.ActiveTitleBar, Decl(interfaceWithEnumKeyedIndexSignature.ts, 34, 35)) + + InactiveTitleBar = "Inactive", +>InactiveTitleBar : Symbol(UserInterfaceElement2.InactiveTitleBar, Decl(interfaceWithEnumKeyedIndexSignature.ts, 35, 30)) +} + +const x2: UserInterfaceColors2 = null as any; +>x2 : Symbol(x2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 39, 5)) +>UserInterfaceColors2 : Symbol(UserInterfaceColors2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 29, 21)) + + +// correct uses +expectColInfo(x2[UserInterfaceElement2.ActiveTitleBar]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x2 : Symbol(x2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 39, 5)) +>UserInterfaceElement2.ActiveTitleBar : Symbol(UserInterfaceElement2.ActiveTitleBar, Decl(interfaceWithEnumKeyedIndexSignature.ts, 34, 35)) +>UserInterfaceElement2 : Symbol(UserInterfaceElement2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 33, 1)) +>ActiveTitleBar : Symbol(UserInterfaceElement2.ActiveTitleBar, Decl(interfaceWithEnumKeyedIndexSignature.ts, 34, 35)) + +expectColInfo(x2[UserInterfaceElement2.InactiveTitleBar]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x2 : Symbol(x2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 39, 5)) +>UserInterfaceElement2.InactiveTitleBar : Symbol(UserInterfaceElement2.InactiveTitleBar, Decl(interfaceWithEnumKeyedIndexSignature.ts, 35, 30)) +>UserInterfaceElement2 : Symbol(UserInterfaceElement2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 33, 1)) +>InactiveTitleBar : Symbol(UserInterfaceElement2.InactiveTitleBar, Decl(interfaceWithEnumKeyedIndexSignature.ts, 35, 30)) + +// errors +expectColInfo(x2[0]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x2 : Symbol(x2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 39, 5)) + +expectColInfo(x2[1]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x2 : Symbol(x2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 39, 5)) + +expectColInfo(x2["0"]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x2 : Symbol(x2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 39, 5)) + +expectColInfo(x2["1"]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x2 : Symbol(x2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 39, 5)) + +expectColInfo(x2[0 as number]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x2 : Symbol(x2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 39, 5)) + +expectColInfo(x2["0" as string]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x2 : Symbol(x2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 39, 5)) + +expectColInfo(x2[12]); +>expectColInfo : Symbol(expectColInfo, Decl(interfaceWithEnumKeyedIndexSignature.ts, 14, 43)) +>x2 : Symbol(x2, Decl(interfaceWithEnumKeyedIndexSignature.ts, 39, 5)) + diff --git a/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.types b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.types index 2cc0c980cb328..55ec93e361639 100644 --- a/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.types +++ b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.types @@ -56,35 +56,35 @@ expectColInfo(x[UserInterfaceElement.InactiveTitleBar]); >UserInterfaceElement : typeof UserInterfaceElement >InactiveTitleBar : UserInterfaceElement.InactiveTitleBar -// errors expectColInfo(x[0]); >expectColInfo(x[0]) : void >expectColInfo : (x: ColorInfo) => void ->x[0] : any +>x[0] : ColorInfo >x : UserInterfaceColors >0 : 0 expectColInfo(x[1]); >expectColInfo(x[1]) : void >expectColInfo : (x: ColorInfo) => void ->x[1] : any +>x[1] : ColorInfo >x : UserInterfaceColors >1 : 1 expectColInfo(x["0"]); >expectColInfo(x["0"]) : void >expectColInfo : (x: ColorInfo) => void ->x["0"] : any +>x["0"] : ColorInfo >x : UserInterfaceColors >"0" : "0" expectColInfo(x["1"]); >expectColInfo(x["1"]) : void >expectColInfo : (x: ColorInfo) => void ->x["1"] : any +>x["1"] : ColorInfo >x : UserInterfaceColors >"1" : "1" +// errors expectColInfo(x[0 as number]); >expectColInfo(x[0 as number]) : void >expectColInfo : (x: ColorInfo) => void @@ -108,3 +108,96 @@ expectColInfo(x[12]); >x : UserInterfaceColors >12 : 12 +export interface UserInterfaceColors2 { + [index: UserInterfaceElement2]: ColorInfo; +>index : UserInterfaceElement2 +} +export enum UserInterfaceElement2 { +>UserInterfaceElement2 : UserInterfaceElement2 + + ActiveTitleBar = "Active", +>ActiveTitleBar : UserInterfaceElement2.ActiveTitleBar +>"Active" : "Active" + + InactiveTitleBar = "Inactive", +>InactiveTitleBar : UserInterfaceElement2.InactiveTitleBar +>"Inactive" : "Inactive" +} + +const x2: UserInterfaceColors2 = null as any; +>x2 : UserInterfaceColors2 +>null as any : any +>null : null + + +// correct uses +expectColInfo(x2[UserInterfaceElement2.ActiveTitleBar]); +>expectColInfo(x2[UserInterfaceElement2.ActiveTitleBar]) : void +>expectColInfo : (x: ColorInfo) => void +>x2[UserInterfaceElement2.ActiveTitleBar] : ColorInfo +>x2 : UserInterfaceColors2 +>UserInterfaceElement2.ActiveTitleBar : UserInterfaceElement2.ActiveTitleBar +>UserInterfaceElement2 : typeof UserInterfaceElement2 +>ActiveTitleBar : UserInterfaceElement2.ActiveTitleBar + +expectColInfo(x2[UserInterfaceElement2.InactiveTitleBar]); +>expectColInfo(x2[UserInterfaceElement2.InactiveTitleBar]) : void +>expectColInfo : (x: ColorInfo) => void +>x2[UserInterfaceElement2.InactiveTitleBar] : ColorInfo +>x2 : UserInterfaceColors2 +>UserInterfaceElement2.InactiveTitleBar : UserInterfaceElement2.InactiveTitleBar +>UserInterfaceElement2 : typeof UserInterfaceElement2 +>InactiveTitleBar : UserInterfaceElement2.InactiveTitleBar + +// errors +expectColInfo(x2[0]); +>expectColInfo(x2[0]) : void +>expectColInfo : (x: ColorInfo) => void +>x2[0] : any +>x2 : UserInterfaceColors2 +>0 : 0 + +expectColInfo(x2[1]); +>expectColInfo(x2[1]) : void +>expectColInfo : (x: ColorInfo) => void +>x2[1] : any +>x2 : UserInterfaceColors2 +>1 : 1 + +expectColInfo(x2["0"]); +>expectColInfo(x2["0"]) : void +>expectColInfo : (x: ColorInfo) => void +>x2["0"] : any +>x2 : UserInterfaceColors2 +>"0" : "0" + +expectColInfo(x2["1"]); +>expectColInfo(x2["1"]) : void +>expectColInfo : (x: ColorInfo) => void +>x2["1"] : any +>x2 : UserInterfaceColors2 +>"1" : "1" + +expectColInfo(x2[0 as number]); +>expectColInfo(x2[0 as number]) : void +>expectColInfo : (x: ColorInfo) => void +>x2[0 as number] : any +>x2 : UserInterfaceColors2 +>0 as number : number +>0 : 0 + +expectColInfo(x2["0" as string]); +>expectColInfo(x2["0" as string]) : void +>expectColInfo : (x: ColorInfo) => void +>x2["0" as string] : any +>x2 : UserInterfaceColors2 +>"0" as string : string +>"0" : "0" + +expectColInfo(x2[12]); +>expectColInfo(x2[12]) : void +>expectColInfo : (x: ColorInfo) => void +>x2[12] : any +>x2 : UserInterfaceColors2 +>12 : 12 + diff --git a/tests/baselines/reference/multipleNumericIndexers.types b/tests/baselines/reference/multipleNumericIndexers.types index dd22c7e5064d4..1223f5bb0026c 100644 --- a/tests/baselines/reference/multipleNumericIndexers.types +++ b/tests/baselines/reference/multipleNumericIndexers.types @@ -20,7 +20,7 @@ interface I { } var a: { ->a : { [x: number]: string; [x: number]: string; } +>a : { [x: number]: string; } [x: number]: string; >x : number @@ -30,7 +30,7 @@ var a: { } var b: { ->b : { [x: number]: string; [x: number]: string; } +>b : { [x: number]: string; } [x: number]: string; >x : number diff --git a/tests/baselines/reference/multipleStringIndexers.types b/tests/baselines/reference/multipleStringIndexers.types index 1f18f1a9ab196..233d19f030986 100644 --- a/tests/baselines/reference/multipleStringIndexers.types +++ b/tests/baselines/reference/multipleStringIndexers.types @@ -20,7 +20,7 @@ interface I { } var a: { ->a : { [x: string]: string; [x: string]: string; } +>a : { [x: string]: string; } [x: string]: string; >x : string @@ -30,7 +30,7 @@ var a: { } var b: { ->b : { [x: string]: string; [x: string]: string; } +>b : { [x: string]: string; } [x: string]: string; >x : string diff --git a/tests/baselines/reference/parserIndexSignature8.types b/tests/baselines/reference/parserIndexSignature8.types index 4e5f4faa6548c..575bde78113e5 100644 --- a/tests/baselines/reference/parserIndexSignature8.types +++ b/tests/baselines/reference/parserIndexSignature8.types @@ -1,6 +1,6 @@ === tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts === var foo: { [index: any]; }; // expect an error here ->foo : { [index: any]: any; } +>foo : { [index: string]: any; } >index : any var foo2: { [index: RegExp]; }; // expect an error here diff --git a/tests/baselines/reference/recursiveTypesWithTypeof.types b/tests/baselines/reference/recursiveTypesWithTypeof.types index 1d5db5d85e0c1..b6fba955a5045 100644 --- a/tests/baselines/reference/recursiveTypesWithTypeof.types +++ b/tests/baselines/reference/recursiveTypesWithTypeof.types @@ -123,22 +123,22 @@ var j2 = new j2(j2); // Indexers var k: { [n: number]: typeof k;[s: string]: typeof k }; ->k : { [n: number]: any; [s: string]: any; } +>k : { [x: string | number]: any; } >n : number ->k : { [n: number]: any; [s: string]: any; } +>k : { [x: string | number]: any; } >s : string ->k : { [n: number]: any; [s: string]: any; } +>k : { [x: string | number]: any; } var k = k[0]; ->k : { [n: number]: any; [s: string]: any; } ->k[0] : { [n: number]: any; [s: string]: any; } ->k : { [n: number]: any; [s: string]: any; } +>k : { [x: string | number]: any; } +>k[0] : { [x: string | number]: any; } +>k : { [x: string | number]: any; } >0 : 0 var k = k['']; ->k : { [n: number]: any; [s: string]: any; } ->k[''] : { [n: number]: any; [s: string]: any; } ->k : { [n: number]: any; [s: string]: any; } +>k : { [x: string | number]: any; } +>k[''] : { [x: string | number]: any; } +>k : { [x: string | number]: any; } >'' : "" // Hybrid - contains type literals as well as type arguments diff --git a/tests/baselines/reference/symbolIndexerCompatabilityExamples.errors.txt b/tests/baselines/reference/symbolIndexerCompatabilityExamples.errors.txt index 3d2fe2cad2161..60784b1d2111e 100644 --- a/tests/baselines/reference/symbolIndexerCompatabilityExamples.errors.txt +++ b/tests/baselines/reference/symbolIndexerCompatabilityExamples.errors.txt @@ -2,10 +2,10 @@ tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(55,9 tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(59,9): error TS2322: Type 'V' is not assignable to type '{ [k: K]: V; }[K]'. tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(64,13): error TS2322: Type '{ [k: K]: V; }[K]' is not assignable to type 'V'. tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(67,9): error TS2322: Type 'V' is not assignable to type '{ [k: K]: V; }[K]'. -tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(84,9): error TS2322: Type '{ [k: string | number | symbol]: V; }[K]' is not assignable to type 'V'. -tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(88,9): error TS2322: Type 'V' is not assignable to type '{ [k: string | number | symbol]: V; }[K]'. -tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(93,13): error TS2322: Type '{ [k: string | number | symbol]: V; }[K]' is not assignable to type 'V'. -tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(96,9): error TS2322: Type 'V' is not assignable to type '{ [k: string | number | symbol]: V; }[K]'. +tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(84,9): error TS2322: Type '{ [x: string | number | symbol]: V; }[K]' is not assignable to type 'V'. +tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(88,9): error TS2322: Type 'V' is not assignable to type '{ [x: string | number | symbol]: V; }[K]'. +tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(93,13): error TS2322: Type '{ [x: string | number | symbol]: V; }[K]' is not assignable to type 'V'. +tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(96,9): error TS2322: Type 'V' is not assignable to type '{ [x: string | number | symbol]: V; }[K]'. ==== tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts (8 errors) ==== @@ -102,25 +102,25 @@ tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(96,9 public get(k: K): V { return this.o[k]; ~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '{ [k: string | number | symbol]: V; }[K]' is not assignable to type 'V'. +!!! error TS2322: Type '{ [x: string | number | symbol]: V; }[K]' is not assignable to type 'V'. } public set(k: K, v: V) { this.o[k] = v; ~~~~~~~~~ -!!! error TS2322: Type 'V' is not assignable to type '{ [k: string | number | symbol]: V; }[K]'. +!!! error TS2322: Type 'V' is not assignable to type '{ [x: string | number | symbol]: V; }[K]'. } public getMap(k: K): V { if (k in this.o) { return this.o[k]; ~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '{ [k: string | number | symbol]: V; }[K]' is not assignable to type 'V'. +!!! error TS2322: Type '{ [x: string | number | symbol]: V; }[K]' is not assignable to type 'V'. } const res = new SimpleMapMap2(); this.o[k] = res as any as V; ~~~~~~~~~ -!!! error TS2322: Type 'V' is not assignable to type '{ [k: string | number | symbol]: V; }[K]'. +!!! error TS2322: Type 'V' is not assignable to type '{ [x: string | number | symbol]: V; }[K]'. return res as any as V; } diff --git a/tests/baselines/reference/symbolIndexerCompatabilityExamples.types b/tests/baselines/reference/symbolIndexerCompatabilityExamples.types index bc9a81af1964c..a828ff2a85434 100644 --- a/tests/baselines/reference/symbolIndexerCompatabilityExamples.types +++ b/tests/baselines/reference/symbolIndexerCompatabilityExamples.types @@ -198,7 +198,7 @@ class SimpleMapMap2 { >SimpleMapMap2 : SimpleMapMap2 private o: { [k: PropertyKey]: V } = {}; ->o : { [k: string | number | symbol]: V; } +>o : { [x: string | number | symbol]: V; } >k : string | number | symbol >{} : {} @@ -209,9 +209,9 @@ class SimpleMapMap2 { return k in this.o; >k in this.o : boolean >k : K ->this.o : { [k: string | number | symbol]: V; } +>this.o : { [x: string | number | symbol]: V; } >this : this ->o : { [k: string | number | symbol]: V; } +>o : { [x: string | number | symbol]: V; } } public get(k: K): V { @@ -219,10 +219,10 @@ class SimpleMapMap2 { >k : K return this.o[k]; ->this.o[k] : { [k: string | number | symbol]: V; }[K] ->this.o : { [k: string | number | symbol]: V; } +>this.o[k] : { [x: string | number | symbol]: V; }[K] +>this.o : { [x: string | number | symbol]: V; } >this : this ->o : { [k: string | number | symbol]: V; } +>o : { [x: string | number | symbol]: V; } >k : K } @@ -233,10 +233,10 @@ class SimpleMapMap2 { 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.o[k] : { [x: string | number | symbol]: V; }[K] +>this.o : { [x: string | number | symbol]: V; } >this : this ->o : { [k: string | number | symbol]: V; } +>o : { [x: string | number | symbol]: V; } >k : K >v : V } @@ -248,15 +248,15 @@ class SimpleMapMap2 { if (k in this.o) { >k in this.o : boolean >k : K ->this.o : { [k: string | number | symbol]: V; } +>this.o : { [x: string | number | symbol]: V; } >this : this ->o : { [k: string | number | symbol]: V; } +>o : { [x: 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.o[k] : { [x: string | number | symbol]: V; }[K] +>this.o : { [x: string | number | symbol]: V; } >this : this ->o : { [k: string | number | symbol]: V; } +>o : { [x: string | number | symbol]: V; } >k : K } const res = new SimpleMapMap2(); @@ -266,10 +266,10 @@ class 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.o[k] : { [x: string | number | symbol]: V; }[K] +>this.o : { [x: string | number | symbol]: V; } >this : this ->o : { [k: string | number | symbol]: V; } +>o : { [x: string | number | symbol]: V; } >k : K >res as any as V : V >res as any : any @@ -286,9 +286,9 @@ class SimpleMapMap2 { this.o = {}; >this.o = {} : {} ->this.o : { [k: string | number | symbol]: V; } +>this.o : { [x: string | number | symbol]: V; } >this : this ->o : { [k: string | number | symbol]: V; } +>o : { [x: string | number | symbol]: V; } >{} : {} } } diff --git a/tests/baselines/reference/typeGuardNarrowsIndexedAccessOfKnownProperty.symbols b/tests/baselines/reference/typeGuardNarrowsIndexedAccessOfKnownProperty.symbols index 3a8e434aa3c80..bc6bf13eaa3f0 100644 --- a/tests/baselines/reference/typeGuardNarrowsIndexedAccessOfKnownProperty.symbols +++ b/tests/baselines/reference/typeGuardNarrowsIndexedAccessOfKnownProperty.symbols @@ -65,7 +65,7 @@ function area(s: Shape): number { switch(s['dash-ok']) { >s : Symbol(s, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 23, 14)) ->'dash-ok' : Symbol(["dash-ok"], Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 0, 18), Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 4, 22), Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 9, 19)) +>'dash-ok' : Symbol("dash-ok", Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 0, 18), Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 4, 22), Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 9, 19)) case "square": return s['square-size'] * s['square-size']; >s : Symbol(s, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 23, 14)) @@ -103,7 +103,7 @@ function subarea(s: Subshape): number { >"sub" : Symbol(sub, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 15, 10)) >under : Symbol(under, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 16, 14)) >"shape" : Symbol(shape, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 17, 20)) ->"dash-ok" : Symbol(["dash-ok"], Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 0, 18), Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 4, 22), Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 9, 19)) +>"dash-ok" : Symbol("dash-ok", Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 0, 18), Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 4, 22), Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 9, 19)) case "square": return s[0].sub.under.shape["square-size"] * s[0].sub.under.shape["square-size"]; >s[0].sub.under.shape : Symbol(shape, Decl(typeGuardNarrowsIndexedAccessOfKnownProperty.ts, 17, 20)) diff --git a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt index 7ffdc6a976172..89849d3a614a8 100644 --- a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt +++ b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(8,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'typeof E', but here has type '{ readonly [x: number]: string; readonly a: E; readonly b: E; }'. -tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'typeof E', but here has type '{ readonly [x: number]: string; readonly [x: number]: string; readonly a: E; readonly b: E; }'. +tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'typeof E', but here has type '{ readonly [x: number]: string; readonly a: E; readonly b: E; }'. tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,70): error TS2375: Duplicate number index signature. @@ -17,6 +17,6 @@ tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,70): error TS2375: Dup var y = E; var y: { readonly a: E; readonly b: E; readonly [x: number]: string; readonly [x: number]: string } // two errors: the types are not identical and duplicate signatures ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'typeof E', but here has type '{ readonly [x: number]: string; readonly [x: number]: string; readonly a: E; readonly b: E; }'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'typeof E', but here has type '{ readonly [x: number]: string; readonly a: E; readonly b: E; }'. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2375: Duplicate number index signature. \ No newline at end of file diff --git a/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt b/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt index 05a809393bd0c..0ccc4dad3e765 100644 --- a/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt @@ -1,94 +1,67 @@ -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(17,5): error TS2741: Property 'a' is missing in type 'B' but required in type 'A'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(18,5): error TS2741: Property 'a' is missing in type 'AB' but required in type 'A'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(20,5): error TS2741: Property 'd' is missing in type 'A' but required in type 'B'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(21,5): error TS2741: Property 'd' is missing in type 'AB' but required in type 'B'. 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'. + Property 'a' is missing in type 'B' but required in type '{ a: string; b: string; c: string; }'. 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'. + Property 'a' is missing in type 'AB' but required in type '{ a: string; b: string; c: string; }'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(35,5): error TS2739: Type 'SubA' is missing the following properties from type 'A': a, b, c +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(36,5): error TS2739: Type 'SubA' is missing the following properties from type 'B': b, c, d +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(37,5): error TS2739: Type 'SubA' is missing the following properties from type 'AB': b, c 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'. + Property 'a' is missing in type 'B' but required in type '{ a: string; b: string; c: string; }'. 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'. + Property 'a' is missing in type 'AB' but required in type '{ a: string; b: string; c: string; }'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(50,5): error TS2739: Type 'SubB' is missing the following properties from type 'A': a, b, c +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(51,5): error TS2739: Type 'SubB' is missing the following properties from type 'B': b, c, d +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(52,5): error TS2739: Type 'SubB' is missing the following properties from type 'AB': b, c 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(74,5): error TS2739: Type 'C' is missing the following properties from type 'D': d, 4 +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(77,5): error TS2739: Type 'C' is missing the following properties from type 'E': d, 4 +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(105,11): error TS2320: Interface 'IFG' cannot simultaneously extend types 'F' and 'G'. + Named property 'a' of types 'F' and 'G' are not identical. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(105,11): error TS2320: Interface 'IFG' cannot simultaneously extend types 'F' and 'G'. + Named property 'b' of types 'F' and 'G' are not identical. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(105,11): error TS2320: Interface 'IFG' cannot simultaneously extend types 'F' and 'G'. + Named property 'c' of types 'F' and 'G' are not identical. 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'. + Property 'S1.A' does not exist on 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'. + Property 'S2.A' does not exist on type 'F'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(116,5): error TS2322: Type 'IFG' is not assignable to type 'G'. + Property 'S2.A' does not exist on type 'IFG'. 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'. + Property 'S1.A | S2.A' does not exist on 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'. + Property 'S1.A | S2.A' does not exist on type 'G'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(121,5): error TS2322: Type 'IFG' is not assignable to type 'FG'. + Property 'S1.A | S2.A' does not exist on type 'IFG'. 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(126,5): error TS2322: Type 'IFG' is not assignable to type 'F & G'. + Type 'IFG' is not assignable to type 'G'. 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 TS2741: Property '[S3.A]' is missing in type 'I' but required in type 'H'. -tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(162,5): error TS2741: Property '[S3.A]' is missing in type 'J' but required in type 'H'. -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(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. + Property 'S1.A' does not exist on type 'G'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(169,5): error TS2322: Type 'H' is not assignable to type 'J'. + Types of property 'a' are incompatible. + Type '"a"' is not assignable to type 'never'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(170,5): error TS2322: Type 'I' is not assignable to type 'J'. + Types of property 'a' are incompatible. + Type '"a"' is not assignable to type 'never'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(171,5): error TS2322: Type 'K' is not assignable to type 'J'. + Types of property 'a' are incompatible. + Type '"a"' is not assignable to type 'never'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(172,5): error TS2322: Type 'L' is not assignable to type 'J'. + Types of property 'a' are incompatible. Type '"a"' is not assignable to type 'never'. -tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(173,5): error TS2322: Type 'K' is not assignable to type 'J'. - Index signature is missing in type 'K'. -tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(174,5): error TS2322: Type 'L' is not assignable to type 'J'. - Index signature is missing in type 'L'. -tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(176,5): error TS2322: Type 'H' is not assignable to type 'K'. - Type 'H' is missing the following properties from type '{ a: string; b: string; c: string; }': b, c -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 missing the following properties from type '{ a: string; b: string; c: string; }': a, b, c -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 missing the following properties from type '{ a: string; b: string; c: string; }': b, c -tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(182,5): error TS2322: Type 'I' is not assignable to type 'L'. - Type 'I' is missing the following properties from type '{ a: string; b: string; c: string; }': a, b, c -tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5): error TS2322: Type 'J' is not assignable to type 'L'. - Type 'J' is missing the following properties from type '{ a: string; b: string; c: string; }': a, b, c -==== tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts (43 errors) ==== +==== tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts (35 errors) ==== interface A { [x: "a" | "b" | "c"]: string; } @@ -107,21 +80,17 @@ tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5) >(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'. +!!! error TS2741: Property 'a' is missing in type 'B' but required in type 'A'. 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'. +!!! error TS2741: Property 'a' is missing in type 'AB' but required in type 'A'. 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'. +!!! error TS2741: Property 'd' is missing in type 'A' but required in type 'B'. 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'. +!!! error TS2741: Property 'd' is missing in type 'AB' but required in type 'B'. ab = a; ab = b; @@ -132,27 +101,24 @@ tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5) let s: SubA = {}; s[k1]; // valid s = a; - s = b; // error: doesn't provide `"b"` + s = b; // error: doesn't provide `"a"` ~ !!! 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: Property 'a' is missing in type 'B' but required in type '{ a: string; b: string; c: string; }'. + s = ab; // error: doesn't provide `"a"` ~ !!! error TS2322: Type 'AB' is not assignable to type 'SubA'. -!!! error TS2322: Index signature is missing in type 'AB'. +!!! error TS2322: Property 'a' is missing in type 'AB' but required in type '{ a: string; b: string; c: string; }'. 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 TS2739: Type 'SubA' is missing the following properties from type 'A': a, b, c + b = s; // error: might not provide any of `"b"`, `"c"`, or `"d"` ~ -!!! 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 TS2739: Type 'SubA' is missing the following properties from type 'B': b, c, d + ab = s; // error: might not provide any of `"b"`, or `"c"` ~~ -!!! error TS2322: Type 'SubA' is not assignable to type 'AB'. -!!! error TS2322: Index signature is missing in type 'SubA'. +!!! error TS2739: Type 'SubA' is missing the following properties from type 'AB': b, c interface SubB { [x: K2]: string; @@ -166,25 +132,22 @@ tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5) 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'. +!!! error TS2322: Property 'a' is missing in type 'B' but required in type '{ a: string; b: string; c: string; }'. 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'. +!!! error TS2322: Property 'a' is missing in type 'AB' but required in type '{ a: string; b: string; c: string; }'. 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 TS2739: Type 'SubB' is missing the following properties from type 'A': a, b, c + b = s2; // error: might not provide any of `"b"`, `"c"`, or `"d"` ~ -!!! 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 TS2739: Type 'SubB' is missing the following properties from type 'B': b, c, d + ab = s2; // error: might not provide any of b"`, or `"c"` ~~ -!!! error TS2322: Type 'SubB' is not assignable to type 'AB'. -!!! error TS2322: Index signature is missing in type 'SubB'. +!!! error TS2739: Type 'SubB' is missing the following properties from type 'AB': b, c s = s2; // error: might not provide any of the keys of K1 ~ !!! error TS2322: Type 'SubB' is not assignable to type 'SubA'. @@ -211,14 +174,12 @@ tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5) 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'. +!!! error TS2739: Type 'C' is missing the following properties from type 'D': d, 4 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'. +!!! error TS2739: Type 'C' is missing the following properties from type 'E': d, 4 e = d; } @@ -247,12 +208,21 @@ tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5) } interface IFG extends F, G {} + ~~~ +!!! error TS2320: Interface 'IFG' cannot simultaneously extend types 'F' and 'G'. +!!! error TS2320: Named property 'a' of types 'F' and 'G' are not identical. + ~~~ +!!! error TS2320: Interface 'IFG' cannot simultaneously extend types 'F' and 'G'. +!!! error TS2320: Named property 'b' of types 'F' and 'G' are not identical. + ~~~ +!!! error TS2320: Interface 'IFG' cannot simultaneously extend types 'F' and 'G'. +!!! error TS2320: Named property 'c' of types 'F' and 'G' are not identical. 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'. +!!! error TS2322: Property 'S1.A' does not exist on type 'G'. f = fg; // OK f = fg2; // OK f = fg3; // OK @@ -260,21 +230,27 @@ tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5) 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'. +!!! error TS2322: Property 'S2.A' does not exist on type 'F'. g = fg; // OK g = fg2; // OK g = fg3; // OK + ~ +!!! error TS2322: Type 'IFG' is not assignable to type 'G'. +!!! error TS2322: Property 'S2.A' does not exist on type 'IFG'. 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'. +!!! error TS2322: Property 'S1.A | S2.A' does not exist on 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'. +!!! error TS2322: Property 'S1.A | S2.A' does not exist on type 'G'. fg = fg2; // OK fg = fg3; // OK + ~~ +!!! error TS2322: Type 'IFG' is not assignable to type 'FG'. +!!! error TS2322: Property 'S1.A | S2.A' does not exist on type 'IFG'. fg2 = f; // error: doesn't provide S2 ~~~ @@ -286,15 +262,15 @@ tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5) !!! error TS2322: Type 'G' is not assignable to type 'F'. fg2 = fg; // OK fg2 = fg3; // OK + ~~~ +!!! error TS2322: Type 'IFG' is not assignable to type 'F & G'. +!!! error TS2322: Type 'IFG' is not assignable to type 'G'. 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'. +!!! error TS2322: Property 'S1.A' does not exist on type 'G'. fg3 = fg; // OK fg3 = fg2; // OK } @@ -312,99 +288,57 @@ tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(183,5) 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 TS2741: Property '[S3.A]' is missing in type 'I' but required in type 'H'. -!!! related TS2728 tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts:142:5: '[S3.A]' is declared here. - h = j; - ~ -!!! error TS2741: Property '[S3.A]' is missing in type 'J' but required in type 'H'. -!!! related TS2728 tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts:142:5: '[S3.A]' is declared here. - 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"'. + h = i; // ok + h = j; // ok (never is a subtype of "a") + h = k; // ok + h = l; // ok - 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; - i = k; - i = l; - - j = h; + i = h; // ok + i = j; // ok (never is a subtype of "a") + i = k; // ok + i = l; // ok + + j = h; // not ok ~ !!! 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: Types of property 'a' are incompatible. +!!! error TS2322: Type '"a"' is not assignable to type 'never'. + j = i; // not ok ~ !!! error TS2322: Type 'I' is not assignable to type 'J'. -!!! error TS2322: 'S3' and 'S3.A' index signatures are incompatible. +!!! error TS2322: Types of property 'a' are incompatible. !!! error TS2322: Type '"a"' is not assignable to type 'never'. - j = k; + j = k; // not ok ~ !!! error TS2322: Type 'K' is not assignable to type 'J'. -!!! error TS2322: Index signature is missing in type 'K'. - j = l; +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type '"a"' is not assignable to type 'never'. + j = l; // not ok ~ !!! error TS2322: Type 'L' is not assignable to type 'J'. -!!! error TS2322: Index signature is missing in type 'L'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type '"a"' is not assignable to type 'never'. - k = h; - ~ -!!! error TS2322: Type 'H' is not assignable to type 'K'. -!!! error TS2322: Type 'H' is missing the following properties from type '{ a: string; b: string; c: string; }': b, c - 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 missing the following properties from type '{ a: string; b: string; c: string; }': a, b, c - 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"'. + k = h; // ok + k = i; // ok + k = j; // ok (never is a subtype of "a") + k = l; // ok - l = h; - ~ -!!! error TS2322: Type 'H' is not assignable to type 'L'. -!!! error TS2322: Type 'H' is missing the following properties from type '{ a: string; b: string; c: string; }': b, c - l = i; - ~ -!!! error TS2322: Type 'I' is not assignable to type 'L'. -!!! error TS2322: Type 'I' is missing the following properties from type '{ a: string; b: string; c: string; }': a, b, c - l = j; - ~ -!!! error TS2322: Type 'J' is not assignable to type 'L'. -!!! error TS2322: Type 'J' is missing the following properties from type '{ a: string; b: string; c: string; }': a, b, c - l = k; + l = h; // ok + l = i; // ok + l = j; // ok (never is a subtype of "a") + l = k; // ok } \ No newline at end of file diff --git a/tests/baselines/reference/unionIndexerGeneralAssignability.js b/tests/baselines/reference/unionIndexerGeneralAssignability.js index 6a5d01fd4ee76..0a3b043491eca 100644 --- a/tests/baselines/reference/unionIndexerGeneralAssignability.js +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.js @@ -30,12 +30,12 @@ function f1< let s: SubA = {}; s[k1]; // valid s = a; - s = b; // error: doesn't provide `"b"` - s = ab; // error: doesn't provide `"b"` + s = b; // error: doesn't provide `"a"` + s = ab; // error: doesn't provide `"a"` 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"` + b = s; // error: might not provide any of `"b"`, `"c"`, or `"d"` + ab = s; // error: might not provide any of `"b"`, or `"c"` interface SubB { [x: K2]: string; @@ -49,8 +49,8 @@ function f1< 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"` + b = s2; // error: might not provide any of `"b"`, `"c"`, or `"d"` + ab = s2; // error: might not provide any of b"`, or `"c"` s = s2; // error: might not provide any of the keys of K1 } @@ -156,33 +156,31 @@ interface J { 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; + h = i; // ok + h = j; // ok (never is a subtype of "a") + h = k; // ok + h = l; // ok + + i = h; // ok + i = j; // ok (never is a subtype of "a") + i = k; // ok + i = l; // ok + + j = h; // not ok + j = i; // not ok + j = k; // not ok + j = l; // not ok + + k = h; // ok + k = i; // ok + k = j; // ok (never is a subtype of "a") + k = l; // ok + + l = h; // ok + l = i; // ok + l = j; // ok (never is a subtype of "a") + l = k; // ok } @@ -197,11 +195,11 @@ function f1(a, b, ab, k1, k2) { var s = {}; s[k1]; // valid s = a; - s = b; // error: doesn't provide `"b"` - s = ab; // error: doesn't provide `"b"` + s = b; // error: doesn't provide `"a"` + s = ab; // error: doesn't provide `"a"` 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"` + b = s; // error: might not provide any of `"b"`, `"c"`, or `"d"` + ab = s; // error: might not provide any of `"b"`, or `"c"` var s2 = {}; s2[k2]; // valid s2[k1]; // invalid @@ -210,8 +208,8 @@ function f1(a, b, ab, k1, k2) { 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"` + b = s2; // error: might not provide any of `"b"`, `"c"`, or `"d"` + ab = s2; // error: might not provide any of b"`, or `"c"` s = s2; // error: might not provide any of the keys of K1 } function f2(c, d, e) { @@ -262,27 +260,25 @@ var S3; 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; + h = i; // ok + h = j; // ok (never is a subtype of "a") + h = k; // ok + h = l; // ok + i = h; // ok + i = j; // ok (never is a subtype of "a") + i = k; // ok + i = l; // ok + j = h; // not ok + j = i; // not ok + j = k; // not ok + j = l; // not ok + k = h; // ok + k = i; // ok + k = j; // ok (never is a subtype of "a") + k = l; // ok + l = h; // ok + l = i; // ok + l = j; // ok (never is a subtype of "a") + l = k; // ok } diff --git a/tests/baselines/reference/unionIndexerGeneralAssignability.symbols b/tests/baselines/reference/unionIndexerGeneralAssignability.symbols index 7062cec49f388..3040d4c390520 100644 --- a/tests/baselines/reference/unionIndexerGeneralAssignability.symbols +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.symbols @@ -85,11 +85,11 @@ function f1< >s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) >a : Symbol(a, Decl(unionIndexerGeneralAssignability.ts, 15, 2)) - s = b; // error: doesn't provide `"b"` + s = b; // error: doesn't provide `"a"` >s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) >b : Symbol(b, Decl(unionIndexerGeneralAssignability.ts, 15, 7)) - s = ab; // error: doesn't provide `"b"` + s = ab; // error: doesn't provide `"a"` >s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) >ab : Symbol(ab, Decl(unionIndexerGeneralAssignability.ts, 15, 13)) @@ -97,11 +97,11 @@ function f1< >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 = s; // error: might not provide any of `"b"`, `"c"`, or `"d"` >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 = s; // error: might not provide any of `"b"`, or `"c"` >ab : Symbol(ab, Decl(unionIndexerGeneralAssignability.ts, 15, 13)) >s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) @@ -144,11 +144,11 @@ function f1< >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 = s2; // error: might not provide any of `"b"`, `"c"`, or `"d"` >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 = s2; // error: might not provide any of b"`, or `"c"` >ab : Symbol(ab, Decl(unionIndexerGeneralAssignability.ts, 15, 13)) >s2 : Symbol(s2, Decl(unionIndexerGeneralAssignability.ts, 41, 7)) @@ -439,99 +439,97 @@ type L = {[K in S3]: string} & {[x: S3.A]: "a"}; >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, 157, 12)) >H : Symbol(H, Decl(unionIndexerGeneralAssignability.ts, 137, 1)) ->i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) >I : Symbol(I, Decl(unionIndexerGeneralAssignability.ts, 142, 1)) ->j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) >J : Symbol(J, Decl(unionIndexerGeneralAssignability.ts, 147, 1)) ->k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) >K : Symbol(K, Decl(unionIndexerGeneralAssignability.ts, 152, 1)) ->l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 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 = i; // ok +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) - h = j; ->h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) ->j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) + h = j; // ok (never is a subtype of "a") +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) - h = k; ->h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) ->k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) + h = k; // ok +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) - h = l; ->h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) ->l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) + h = l; // ok +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) - i = h; ->i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) ->h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) + i = h; // ok +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) - i = j; ->i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) ->j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) + i = j; // ok (never is a subtype of "a") +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) - i = k; ->i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) ->k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) + i = k; // ok +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) - i = l; ->i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) ->l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) + i = l; // ok +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) - j = h; ->j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) ->h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) + j = h; // not ok +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) - j = i; ->j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) ->i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) + j = i; // not ok +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) - j = k; ->j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) ->k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) + j = k; // not ok +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) - j = l; ->j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) ->l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) + j = l; // not ok +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) - k = h; ->k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) ->h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) + k = h; // ok +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) - h = i; ->h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) ->i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) + k = i; // ok +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) - k = j; ->k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) ->j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) + k = j; // ok (never is a subtype of "a") +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) - k = l; ->k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) ->l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) + k = l; // ok +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) - l = h; ->l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) ->h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 159, 12)) + l = h; // ok +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) - l = i; ->l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) ->i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 159, 17)) + l = i; // ok +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) - l = j; ->l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) ->j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 159, 23)) + l = j; // ok (never is a subtype of "a") +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) - l = k; ->l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 159, 35)) ->k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 159, 29)) + l = k; // ok +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) } diff --git a/tests/baselines/reference/unionIndexerGeneralAssignability.types b/tests/baselines/reference/unionIndexerGeneralAssignability.types index f9c18af227d94..577a8783c2272 100644 --- a/tests/baselines/reference/unionIndexerGeneralAssignability.types +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.types @@ -74,12 +74,12 @@ function f1< >s : SubA >a : A - s = b; // error: doesn't provide `"b"` + s = b; // error: doesn't provide `"a"` >s = b : B >s : SubA >b : B - s = ab; // error: doesn't provide `"b"` + s = ab; // error: doesn't provide `"a"` >s = ab : AB >s : SubA >ab : AB @@ -89,12 +89,12 @@ function f1< >a : A >s : SubA - b = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + b = s; // error: might not provide any of `"b"`, `"c"`, or `"d"` >b = s : SubA >b : B >s : SubA - ab = s; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ab = s; // error: might not provide any of `"b"`, or `"c"` >ab = s : SubA >ab : AB >s : SubA @@ -142,12 +142,12 @@ function f1< >a : A >s2 : SubB - b = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + b = s2; // error: might not provide any of `"b"`, `"c"`, or `"d"` >b = s2 : SubB >b : B >s2 : SubB - ab = s2; // error: might not provide any of `"a"`, `"b"`, or `"c"` + ab = s2; // error: might not provide any of b"`, or `"c"` >ab = s2 : SubB >ab : AB >s2 : SubB @@ -431,8 +431,6 @@ type L = {[K in S3]: string} & {[x: S3.A]: "a"}; >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 @@ -441,102 +439,102 @@ function f4(h: H, i: I, j: J, k: K, l: L) { >k : K >l : L - h = i; + h = i; // ok >h = i : I >h : H >i : I - h = j; + h = j; // ok (never is a subtype of "a") >h = j : J >h : H >j : J - h = k; + h = k; // ok >h = k : K >h : H >k : K - h = l; + h = l; // ok >h = l : L >h : H >l : L - i = h; + i = h; // ok >i = h : H >i : I >h : H - i = j; + i = j; // ok (never is a subtype of "a") >i = j : J >i : I >j : J - i = k; + i = k; // ok >i = k : K >i : I >k : K - i = l; + i = l; // ok >i = l : L >i : I >l : L - j = h; + j = h; // not ok >j = h : H >j : J >h : H - j = i; + j = i; // not ok >j = i : I >j : J >i : I - j = k; + j = k; // not ok >j = k : K >j : J >k : K - j = l; + j = l; // not ok >j = l : L >j : J >l : L - k = h; + k = h; // ok >k = h : H >k : K >h : H - h = i; ->h = i : I ->h : H + k = i; // ok +>k = i : I +>k : K >i : I - k = j; + k = j; // ok (never is a subtype of "a") >k = j : J >k : K >j : J - k = l; + k = l; // ok >k = l : L >k : K >l : L - l = h; + l = h; // ok >l = h : H >l : L >h : H - l = i; + l = i; // ok >l = i : I >l : L >i : I - l = j; + l = j; // ok (never is a subtype of "a") >l = j : J >l : L >j : J - l = k; + l = k; // ok >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 index 70d69a45cb806..fe8974d527734 100644 --- a/tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts +++ b/tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts @@ -20,12 +20,36 @@ 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"]); + +// errors expectColInfo(x[0 as number]); expectColInfo(x["0" as string]); expectColInfo(x[12]); + +export interface UserInterfaceColors2 { + [index: UserInterfaceElement2]: ColorInfo; +} +export enum UserInterfaceElement2 { + ActiveTitleBar = "Active", + InactiveTitleBar = "Inactive", +} + +const x2: UserInterfaceColors2 = null as any; + + +// correct uses +expectColInfo(x2[UserInterfaceElement2.ActiveTitleBar]); +expectColInfo(x2[UserInterfaceElement2.InactiveTitleBar]); + +// errors +expectColInfo(x2[0]); +expectColInfo(x2[1]); +expectColInfo(x2["0"]); +expectColInfo(x2["1"]); +expectColInfo(x2[0 as number]); +expectColInfo(x2["0" as string]); +expectColInfo(x2[12]); diff --git a/tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts b/tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts index 0274f215ee8c1..8cefda91150c0 100644 --- a/tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts +++ b/tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts @@ -29,12 +29,12 @@ function f1< let s: SubA = {}; s[k1]; // valid s = a; - s = b; // error: doesn't provide `"b"` - s = ab; // error: doesn't provide `"b"` + s = b; // error: doesn't provide `"a"` + s = ab; // error: doesn't provide `"a"` 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"` + b = s; // error: might not provide any of `"b"`, `"c"`, or `"d"` + ab = s; // error: might not provide any of `"b"`, or `"c"` interface SubB { [x: K2]: string; @@ -48,8 +48,8 @@ function f1< 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"` + b = s2; // error: might not provide any of `"b"`, `"c"`, or `"d"` + ab = s2; // error: might not provide any of b"`, or `"c"` s = s2; // error: might not provide any of the keys of K1 } @@ -155,31 +155,29 @@ interface J { 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; + h = i; // ok + h = j; // ok (never is a subtype of "a") + h = k; // ok + h = l; // ok + + i = h; // ok + i = j; // ok (never is a subtype of "a") + i = k; // ok + i = l; // ok + + j = h; // not ok + j = i; // not ok + j = k; // not ok + j = l; // not ok + + k = h; // ok + k = i; // ok + k = j; // ok (never is a subtype of "a") + k = l; // ok + + l = h; // ok + l = i; // ok + l = j; // ok (never is a subtype of "a") + l = k; // ok } diff --git a/tests/cases/fourslash/codeFixClassImplementInterfaceIndexSignaturesBoth.ts b/tests/cases/fourslash/codeFixClassImplementInterfaceIndexSignaturesBoth.ts index 15fdcdab91318..d37e56863ba05 100644 --- a/tests/cases/fourslash/codeFixClassImplementInterfaceIndexSignaturesBoth.ts +++ b/tests/cases/fourslash/codeFixClassImplementInterfaceIndexSignaturesBoth.ts @@ -17,7 +17,6 @@ verify.codeFix({ } class C implements I { - [x: number]: I; - [y: string]: I; + [x: string | number]: I; }`, }); From 3fa71c08b25cf26bf9cd981f7968b84b956f6d73 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 7 Dec 2020 13:36:25 -0800 Subject: [PATCH 09/11] Make element accesses by template literals on types with template indexes work like you expect --- src/compiler/checker.ts | 30 ++- ...pesMembersPatternLiteralIndexes.errors.txt | 63 ++++++ .../typesMembersPatternLiteralIndexes.js | 85 ++++++++ .../typesMembersPatternLiteralIndexes.symbols | 147 ++++++++++++++ .../typesMembersPatternLiteralIndexes.types | 186 ++++++++++++++++++ .../typesMembersPatternLiteralIndexes.ts | 49 +++++ 6 files changed, 559 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/typesMembersPatternLiteralIndexes.errors.txt create mode 100644 tests/baselines/reference/typesMembersPatternLiteralIndexes.js create mode 100644 tests/baselines/reference/typesMembersPatternLiteralIndexes.symbols create mode 100644 tests/baselines/reference/typesMembersPatternLiteralIndexes.types create mode 100644 tests/cases/conformance/types/members/typesMembersPatternLiteralIndexes.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3d836f47e4780..22a4a0dbb54df 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21814,6 +21814,7 @@ namespace ts { (parent.parent).operatorToken.kind === SyntaxKind.EqualsToken && (parent.parent).left === parent && !isAssignmentTarget(parent.parent) && + !isTemplateLiteral((parent).argumentExpression) && isTypeAssignableToKind(getTypeOfExpression((parent).argumentExpression), TypeFlags.NumberLike); return isLengthPushOrUnshift || isElementAssignment; } @@ -31094,6 +31095,33 @@ namespace ts { return getUnionType([type1, type2], UnionReduction.Subtype); } + function isOrIsConstrainedToTemplate(type: Type | undefined): boolean { + if (!type) return false; + if (type.flags & TypeFlags.TemplateLiteral) { + return true; + } + if (type.flags & TypeFlags.UnionOrIntersection) { + return some((type as UnionOrIntersectionType).types, isOrIsConstrainedToTemplate); + } + if (type.flags & TypeFlags.InstantiableNonPrimitive) { + const constraint = getBaseConstraintOfType(type); + return constraint ? isOrIsConstrainedToTemplate(constraint) : false; + } + return false; + } + + function isTemplateLiteralContext(node: Node): boolean { + const parent = node.parent; + switch (parent.kind) { + case SyntaxKind.ParenthesizedExpression: + return isTemplateLiteralContext(parent); + case SyntaxKind.ElementAccessExpression: + return (parent as ElementAccessExpression).argumentExpression === node && + isOrIsConstrainedToTemplate(getIndexType(getTypeOfExpression((parent as ElementAccessExpression).expression))); + } + return false; + } + function checkTemplateExpression(node: TemplateExpression): Type { const texts = [node.head.text]; const types = []; @@ -31105,7 +31133,7 @@ namespace ts { texts.push(span.literal.text); types.push(isTypeAssignableTo(type, templateConstraintType) ? type : stringType); } - return isConstContext(node) ? getTemplateLiteralType(texts, types) : stringType; + return isConstContext(node) || isTemplateLiteralContext(node) ? getTemplateLiteralType(texts, types) : stringType; } function getContextNode(node: Expression): Node { diff --git a/tests/baselines/reference/typesMembersPatternLiteralIndexes.errors.txt b/tests/baselines/reference/typesMembersPatternLiteralIndexes.errors.txt new file mode 100644 index 0000000000000..4c057f1ee345a --- /dev/null +++ b/tests/baselines/reference/typesMembersPatternLiteralIndexes.errors.txt @@ -0,0 +1,63 @@ +tests/cases/conformance/types/members/typesMembersPatternLiteralIndexes.ts(8,9): error TS2322: Type 'boolean' is not assignable to type 'string'. +tests/cases/conformance/types/members/typesMembersPatternLiteralIndexes.ts(12,9): error TS2322: Type '{ "my-prop": { whatever: string; }; "aria-disabled": string; }' is not assignable to type 'AriaProps'. + Object literal may only specify known properties, and '"my-prop"' does not exist in type 'AriaProps'. +tests/cases/conformance/types/members/typesMembersPatternLiteralIndexes.ts(23,9): error TS2322: Type 'boolean' is not assignable to type 'string'. + + +==== tests/cases/conformance/types/members/typesMembersPatternLiteralIndexes.ts (3 errors) ==== + function f1() { + interface AriaProps { + [x: `aria-${string}`]: string; + } + + const x: AriaProps = { + "my-prop": {"whatever": "yes"}, + "aria-disabled": false // error + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. +!!! related TS6501 tests/cases/conformance/types/members/typesMembersPatternLiteralIndexes.ts:3:9: The expected type comes from this index signature. + }; + + const y: AriaProps = { + "my-prop": {"whatever": "yes"}, // excess + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ "my-prop": { whatever: string; }; "aria-disabled": string; }' is not assignable to type 'AriaProps'. +!!! error TS2322: Object literal may only specify known properties, and '"my-prop"' does not exist in type 'AriaProps'. + "aria-disabled": "false" // OK + }; + + const z: AriaProps & { [x: string]: unknown } = { + "my-prop": {"whatever": "yes"}, // OK + "aria-disabled": "false" // OK + }; + + const a: AriaProps & { [x: string]: unknown } = { + "my-prop": {"whatever": "yes"}, // OK + "aria-disabled": false // error + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. +!!! related TS6501 tests/cases/conformance/types/members/typesMembersPatternLiteralIndexes.ts:3:9: The expected type comes from this index signature. + }; + } + + function f2() { + interface SlotProxy { + readonly [idx: number]: T; + [idx: `getSlot${number}`]: () => this[number]; + [idx: `setSlot${number}`]: (obj: this[number]) => this; + } + + const obj = makeSlotProxy([{x: 12}, {y: 21}]); + + const obj2 = obj.setSlot2({x: 12}).setSlot0({y: 12}).getSlot1(); + + function makeSlotProxy(x: T[]): SlotProxy { + const result: SlotProxy = {}; + for (let i = 0; i < x.length; i++) { + Object.defineProperty(result, i, { get() { return x[i]; } }); + result[`getSlot${i}`] = () => x[i]; + result[`setSlot${i}`] = (arg) => (x[i] = arg, result); + } + return result; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/typesMembersPatternLiteralIndexes.js b/tests/baselines/reference/typesMembersPatternLiteralIndexes.js new file mode 100644 index 0000000000000..65164b24048e2 --- /dev/null +++ b/tests/baselines/reference/typesMembersPatternLiteralIndexes.js @@ -0,0 +1,85 @@ +//// [typesMembersPatternLiteralIndexes.ts] +function f1() { + interface AriaProps { + [x: `aria-${string}`]: string; + } + + const x: AriaProps = { + "my-prop": {"whatever": "yes"}, + "aria-disabled": false // error + }; + + const y: AriaProps = { + "my-prop": {"whatever": "yes"}, // excess + "aria-disabled": "false" // OK + }; + + const z: AriaProps & { [x: string]: unknown } = { + "my-prop": {"whatever": "yes"}, // OK + "aria-disabled": "false" // OK + }; + + const a: AriaProps & { [x: string]: unknown } = { + "my-prop": {"whatever": "yes"}, // OK + "aria-disabled": false // error + }; +} + +function f2() { + interface SlotProxy { + readonly [idx: number]: T; + [idx: `getSlot${number}`]: () => this[number]; + [idx: `setSlot${number}`]: (obj: this[number]) => this; + } + + const obj = makeSlotProxy([{x: 12}, {y: 21}]); + + const obj2 = obj.setSlot2({x: 12}).setSlot0({y: 12}).getSlot1(); + + function makeSlotProxy(x: T[]): SlotProxy { + const result: SlotProxy = {}; + for (let i = 0; i < x.length; i++) { + Object.defineProperty(result, i, { get() { return x[i]; } }); + result[`getSlot${i}`] = () => x[i]; + result[`setSlot${i}`] = (arg) => (x[i] = arg, result); + } + return result; + } +} + +//// [typesMembersPatternLiteralIndexes.js] +"use strict"; +function f1() { + var x = { + "my-prop": { "whatever": "yes" }, + "aria-disabled": false // error + }; + var y = { + "my-prop": { "whatever": "yes" }, + "aria-disabled": "false" // OK + }; + var z = { + "my-prop": { "whatever": "yes" }, + "aria-disabled": "false" // OK + }; + var a = { + "my-prop": { "whatever": "yes" }, + "aria-disabled": false // error + }; +} +function f2() { + var obj = makeSlotProxy([{ x: 12 }, { y: 21 }]); + var obj2 = obj.setSlot2({ x: 12 }).setSlot0({ y: 12 }).getSlot1(); + function makeSlotProxy(x) { + var result = {}; + var _loop_1 = function (i) { + Object.defineProperty(result, i, { get: function () { return x[i]; } }); + result["getSlot" + i] = function () { return x[i]; }; + result["setSlot" + i] = function (arg) { return (x[i] = arg, result); }; + }; + for (var i = 0; i < x.length; i++) { + _loop_1(i); + } + return result; + } +} diff --git a/tests/baselines/reference/typesMembersPatternLiteralIndexes.symbols b/tests/baselines/reference/typesMembersPatternLiteralIndexes.symbols new file mode 100644 index 0000000000000..9346cb347fc43 --- /dev/null +++ b/tests/baselines/reference/typesMembersPatternLiteralIndexes.symbols @@ -0,0 +1,147 @@ +=== tests/cases/conformance/types/members/typesMembersPatternLiteralIndexes.ts === +function f1() { +>f1 : Symbol(f1, Decl(typesMembersPatternLiteralIndexes.ts, 0, 0)) + + interface AriaProps { +>AriaProps : Symbol(AriaProps, Decl(typesMembersPatternLiteralIndexes.ts, 0, 15)) + + [x: `aria-${string}`]: string; +>x : Symbol(x, Decl(typesMembersPatternLiteralIndexes.ts, 2, 9)) + } + + const x: AriaProps = { +>x : Symbol(x, Decl(typesMembersPatternLiteralIndexes.ts, 5, 9)) +>AriaProps : Symbol(AriaProps, Decl(typesMembersPatternLiteralIndexes.ts, 0, 15)) + + "my-prop": {"whatever": "yes"}, +>"my-prop" : Symbol("my-prop", Decl(typesMembersPatternLiteralIndexes.ts, 5, 26)) +>"whatever" : Symbol("whatever", Decl(typesMembersPatternLiteralIndexes.ts, 6, 20)) + + "aria-disabled": false // error +>"aria-disabled" : Symbol("aria-disabled", Decl(typesMembersPatternLiteralIndexes.ts, 6, 39)) + + }; + + const y: AriaProps = { +>y : Symbol(y, Decl(typesMembersPatternLiteralIndexes.ts, 10, 9)) +>AriaProps : Symbol(AriaProps, Decl(typesMembersPatternLiteralIndexes.ts, 0, 15)) + + "my-prop": {"whatever": "yes"}, // excess +>"my-prop" : Symbol("my-prop", Decl(typesMembersPatternLiteralIndexes.ts, 10, 26)) +>"whatever" : Symbol("whatever", Decl(typesMembersPatternLiteralIndexes.ts, 11, 20)) + + "aria-disabled": "false" // OK +>"aria-disabled" : Symbol("aria-disabled", Decl(typesMembersPatternLiteralIndexes.ts, 11, 39)) + + }; + + const z: AriaProps & { [x: string]: unknown } = { +>z : Symbol(z, Decl(typesMembersPatternLiteralIndexes.ts, 15, 9)) +>AriaProps : Symbol(AriaProps, Decl(typesMembersPatternLiteralIndexes.ts, 0, 15)) +>x : Symbol(x, Decl(typesMembersPatternLiteralIndexes.ts, 15, 28)) + + "my-prop": {"whatever": "yes"}, // OK +>"my-prop" : Symbol("my-prop", Decl(typesMembersPatternLiteralIndexes.ts, 15, 53)) +>"whatever" : Symbol("whatever", Decl(typesMembersPatternLiteralIndexes.ts, 16, 20)) + + "aria-disabled": "false" // OK +>"aria-disabled" : Symbol("aria-disabled", Decl(typesMembersPatternLiteralIndexes.ts, 16, 39)) + + }; + + const a: AriaProps & { [x: string]: unknown } = { +>a : Symbol(a, Decl(typesMembersPatternLiteralIndexes.ts, 20, 9)) +>AriaProps : Symbol(AriaProps, Decl(typesMembersPatternLiteralIndexes.ts, 0, 15)) +>x : Symbol(x, Decl(typesMembersPatternLiteralIndexes.ts, 20, 28)) + + "my-prop": {"whatever": "yes"}, // OK +>"my-prop" : Symbol("my-prop", Decl(typesMembersPatternLiteralIndexes.ts, 20, 53)) +>"whatever" : Symbol("whatever", Decl(typesMembersPatternLiteralIndexes.ts, 21, 20)) + + "aria-disabled": false // error +>"aria-disabled" : Symbol("aria-disabled", Decl(typesMembersPatternLiteralIndexes.ts, 21, 39)) + + }; +} + +function f2() { +>f2 : Symbol(f2, Decl(typesMembersPatternLiteralIndexes.ts, 24, 1)) + + interface SlotProxy { +>SlotProxy : Symbol(SlotProxy, Decl(typesMembersPatternLiteralIndexes.ts, 26, 15)) +>T : Symbol(T, Decl(typesMembersPatternLiteralIndexes.ts, 27, 24)) + + readonly [idx: number]: T; +>idx : Symbol(idx, Decl(typesMembersPatternLiteralIndexes.ts, 28, 18)) +>T : Symbol(T, Decl(typesMembersPatternLiteralIndexes.ts, 27, 24)) + + [idx: `getSlot${number}`]: () => this[number]; +>idx : Symbol(idx, Decl(typesMembersPatternLiteralIndexes.ts, 29, 9)) + + [idx: `setSlot${number}`]: (obj: this[number]) => this; +>idx : Symbol(idx, Decl(typesMembersPatternLiteralIndexes.ts, 30, 9)) +>obj : Symbol(obj, Decl(typesMembersPatternLiteralIndexes.ts, 30, 36)) + } + + const obj = makeSlotProxy([{x: 12}, {y: 21}]); +>obj : Symbol(obj, Decl(typesMembersPatternLiteralIndexes.ts, 33, 9)) +>makeSlotProxy : Symbol(makeSlotProxy, Decl(typesMembersPatternLiteralIndexes.ts, 35, 68)) +>x : Symbol(x, Decl(typesMembersPatternLiteralIndexes.ts, 33, 32)) +>y : Symbol(y, Decl(typesMembersPatternLiteralIndexes.ts, 33, 41)) + + const obj2 = obj.setSlot2({x: 12}).setSlot0({y: 12}).getSlot1(); +>obj2 : Symbol(obj2, Decl(typesMembersPatternLiteralIndexes.ts, 35, 9)) +>obj : Symbol(obj, Decl(typesMembersPatternLiteralIndexes.ts, 33, 9)) +>x : Symbol(x, Decl(typesMembersPatternLiteralIndexes.ts, 35, 31)) +>y : Symbol(y, Decl(typesMembersPatternLiteralIndexes.ts, 35, 49)) + + function makeSlotProxy(x: T[]): SlotProxy { +>makeSlotProxy : Symbol(makeSlotProxy, Decl(typesMembersPatternLiteralIndexes.ts, 35, 68)) +>T : Symbol(T, Decl(typesMembersPatternLiteralIndexes.ts, 37, 27)) +>x : Symbol(x, Decl(typesMembersPatternLiteralIndexes.ts, 37, 30)) +>T : Symbol(T, Decl(typesMembersPatternLiteralIndexes.ts, 37, 27)) +>SlotProxy : Symbol(SlotProxy, Decl(typesMembersPatternLiteralIndexes.ts, 26, 15)) +>T : Symbol(T, Decl(typesMembersPatternLiteralIndexes.ts, 37, 27)) + + const result: SlotProxy = {}; +>result : Symbol(result, Decl(typesMembersPatternLiteralIndexes.ts, 38, 13)) +>SlotProxy : Symbol(SlotProxy, Decl(typesMembersPatternLiteralIndexes.ts, 26, 15)) +>T : Symbol(T, Decl(typesMembersPatternLiteralIndexes.ts, 37, 27)) + + for (let i = 0; i < x.length; i++) { +>i : Symbol(i, Decl(typesMembersPatternLiteralIndexes.ts, 39, 16)) +>i : Symbol(i, Decl(typesMembersPatternLiteralIndexes.ts, 39, 16)) +>x.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(typesMembersPatternLiteralIndexes.ts, 37, 30)) +>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>i : Symbol(i, Decl(typesMembersPatternLiteralIndexes.ts, 39, 16)) + + Object.defineProperty(result, i, { get() { return x[i]; } }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>result : Symbol(result, Decl(typesMembersPatternLiteralIndexes.ts, 38, 13)) +>i : Symbol(i, Decl(typesMembersPatternLiteralIndexes.ts, 39, 16)) +>get : Symbol(get, Decl(typesMembersPatternLiteralIndexes.ts, 40, 46)) +>x : Symbol(x, Decl(typesMembersPatternLiteralIndexes.ts, 37, 30)) +>i : Symbol(i, Decl(typesMembersPatternLiteralIndexes.ts, 39, 16)) + + result[`getSlot${i}`] = () => x[i]; +>result : Symbol(result, Decl(typesMembersPatternLiteralIndexes.ts, 38, 13)) +>i : Symbol(i, Decl(typesMembersPatternLiteralIndexes.ts, 39, 16)) +>x : Symbol(x, Decl(typesMembersPatternLiteralIndexes.ts, 37, 30)) +>i : Symbol(i, Decl(typesMembersPatternLiteralIndexes.ts, 39, 16)) + + result[`setSlot${i}`] = (arg) => (x[i] = arg, result); +>result : Symbol(result, Decl(typesMembersPatternLiteralIndexes.ts, 38, 13)) +>i : Symbol(i, Decl(typesMembersPatternLiteralIndexes.ts, 39, 16)) +>arg : Symbol(arg, Decl(typesMembersPatternLiteralIndexes.ts, 42, 37)) +>x : Symbol(x, Decl(typesMembersPatternLiteralIndexes.ts, 37, 30)) +>i : Symbol(i, Decl(typesMembersPatternLiteralIndexes.ts, 39, 16)) +>arg : Symbol(arg, Decl(typesMembersPatternLiteralIndexes.ts, 42, 37)) +>result : Symbol(result, Decl(typesMembersPatternLiteralIndexes.ts, 38, 13)) + } + return result; +>result : Symbol(result, Decl(typesMembersPatternLiteralIndexes.ts, 38, 13)) + } +} diff --git a/tests/baselines/reference/typesMembersPatternLiteralIndexes.types b/tests/baselines/reference/typesMembersPatternLiteralIndexes.types new file mode 100644 index 0000000000000..ca1479402ab9b --- /dev/null +++ b/tests/baselines/reference/typesMembersPatternLiteralIndexes.types @@ -0,0 +1,186 @@ +=== tests/cases/conformance/types/members/typesMembersPatternLiteralIndexes.ts === +function f1() { +>f1 : () => void + + interface AriaProps { + [x: `aria-${string}`]: string; +>x : `aria-${string}` + } + + const x: AriaProps = { +>x : AriaProps +>{ "my-prop": {"whatever": "yes"}, "aria-disabled": false // error } : { "my-prop": { whatever: string; }; "aria-disabled": boolean; } + + "my-prop": {"whatever": "yes"}, +>"my-prop" : { whatever: string; } +>{"whatever": "yes"} : { whatever: string; } +>"whatever" : string +>"yes" : "yes" + + "aria-disabled": false // error +>"aria-disabled" : boolean +>false : false + + }; + + const y: AriaProps = { +>y : AriaProps +>{ "my-prop": {"whatever": "yes"}, // excess "aria-disabled": "false" // OK } : { "my-prop": { whatever: string; }; "aria-disabled": string; } + + "my-prop": {"whatever": "yes"}, // excess +>"my-prop" : { whatever: string; } +>{"whatever": "yes"} : { whatever: string; } +>"whatever" : string +>"yes" : "yes" + + "aria-disabled": "false" // OK +>"aria-disabled" : string +>"false" : "false" + + }; + + const z: AriaProps & { [x: string]: unknown } = { +>z : AriaProps & { [x: string]: unknown; } +>x : string +>{ "my-prop": {"whatever": "yes"}, // OK "aria-disabled": "false" // OK } : { "my-prop": { whatever: string; }; "aria-disabled": string; } + + "my-prop": {"whatever": "yes"}, // OK +>"my-prop" : { whatever: string; } +>{"whatever": "yes"} : { whatever: string; } +>"whatever" : string +>"yes" : "yes" + + "aria-disabled": "false" // OK +>"aria-disabled" : string +>"false" : "false" + + }; + + const a: AriaProps & { [x: string]: unknown } = { +>a : AriaProps & { [x: string]: unknown; } +>x : string +>{ "my-prop": {"whatever": "yes"}, // OK "aria-disabled": false // error } : { "my-prop": { whatever: string; }; "aria-disabled": boolean; } + + "my-prop": {"whatever": "yes"}, // OK +>"my-prop" : { whatever: string; } +>{"whatever": "yes"} : { whatever: string; } +>"whatever" : string +>"yes" : "yes" + + "aria-disabled": false // error +>"aria-disabled" : boolean +>false : false + + }; +} + +function f2() { +>f2 : () => void + + interface SlotProxy { + readonly [idx: number]: T; +>idx : number + + [idx: `getSlot${number}`]: () => this[number]; +>idx : `getSlot${number}` + + [idx: `setSlot${number}`]: (obj: this[number]) => this; +>idx : `setSlot${number}` +>obj : this[number] + } + + const obj = makeSlotProxy([{x: 12}, {y: 21}]); +>obj : SlotProxy<{ x: number; y?: undefined; } | { y: number; x?: undefined; }> +>makeSlotProxy([{x: 12}, {y: 21}]) : SlotProxy<{ x: number; y?: undefined; } | { y: number; x?: undefined; }> +>makeSlotProxy : (x: T[]) => SlotProxy +>[{x: 12}, {y: 21}] : ({ x: number; } | { y: number; })[] +>{x: 12} : { x: number; } +>x : number +>12 : 12 +>{y: 21} : { y: number; } +>y : number +>21 : 21 + + const obj2 = obj.setSlot2({x: 12}).setSlot0({y: 12}).getSlot1(); +>obj2 : { x: number; y?: undefined; } | { y: number; x?: undefined; } +>obj.setSlot2({x: 12}).setSlot0({y: 12}).getSlot1() : { x: number; y?: undefined; } | { y: number; x?: undefined; } +>obj.setSlot2({x: 12}).setSlot0({y: 12}).getSlot1 : () => { x: number; y?: undefined; } | { y: number; x?: undefined; } +>obj.setSlot2({x: 12}).setSlot0({y: 12}) : SlotProxy<{ x: number; y?: undefined; } | { y: number; x?: undefined; }> +>obj.setSlot2({x: 12}).setSlot0 : (obj: { x: number; y?: undefined; } | { y: number; x?: undefined; }) => SlotProxy<{ x: number; y?: undefined; } | { y: number; x?: undefined; }> +>obj.setSlot2({x: 12}) : SlotProxy<{ x: number; y?: undefined; } | { y: number; x?: undefined; }> +>obj.setSlot2 : (obj: { x: number; y?: undefined; } | { y: number; x?: undefined; }) => SlotProxy<{ x: number; y?: undefined; } | { y: number; x?: undefined; }> +>obj : SlotProxy<{ x: number; y?: undefined; } | { y: number; x?: undefined; }> +>setSlot2 : (obj: { x: number; y?: undefined; } | { y: number; x?: undefined; }) => SlotProxy<{ x: number; y?: undefined; } | { y: number; x?: undefined; }> +>{x: 12} : { x: number; } +>x : number +>12 : 12 +>setSlot0 : (obj: { x: number; y?: undefined; } | { y: number; x?: undefined; }) => SlotProxy<{ x: number; y?: undefined; } | { y: number; x?: undefined; }> +>{y: 12} : { y: number; } +>y : number +>12 : 12 +>getSlot1 : () => { x: number; y?: undefined; } | { y: number; x?: undefined; } + + function makeSlotProxy(x: T[]): SlotProxy { +>makeSlotProxy : (x: T[]) => SlotProxy +>x : T[] + + const result: SlotProxy = {}; +>result : SlotProxy +>{} : {} + + for (let i = 0; i < x.length; i++) { +>i : number +>0 : 0 +>i < x.length : boolean +>i : number +>x.length : number +>x : T[] +>length : number +>i++ : number +>i : number + + Object.defineProperty(result, i, { get() { return x[i]; } }); +>Object.defineProperty(result, i, { get() { return x[i]; } }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>result : SlotProxy +>i : number +>{ get() { return x[i]; } } : { get(): T; } +>get : () => T +>x[i] : T +>x : T[] +>i : number + + result[`getSlot${i}`] = () => x[i]; +>result[`getSlot${i}`] = () => x[i] : () => T +>result[`getSlot${i}`] : () => T +>result : SlotProxy +>`getSlot${i}` : `getSlot${number}` +>i : number +>() => x[i] : () => T +>x[i] : T +>x : T[] +>i : number + + result[`setSlot${i}`] = (arg) => (x[i] = arg, result); +>result[`setSlot${i}`] = (arg) => (x[i] = arg, result) : (arg: T) => SlotProxy +>result[`setSlot${i}`] : (obj: T) => SlotProxy +>result : SlotProxy +>`setSlot${i}` : `setSlot${number}` +>i : number +>(arg) => (x[i] = arg, result) : (arg: T) => SlotProxy +>arg : T +>(x[i] = arg, result) : SlotProxy +>x[i] = arg, result : SlotProxy +>x[i] = arg : T +>x[i] : T +>x : T[] +>i : number +>arg : T +>result : SlotProxy + } + return result; +>result : SlotProxy + } +} diff --git a/tests/cases/conformance/types/members/typesMembersPatternLiteralIndexes.ts b/tests/cases/conformance/types/members/typesMembersPatternLiteralIndexes.ts new file mode 100644 index 0000000000000..264b284d5953d --- /dev/null +++ b/tests/cases/conformance/types/members/typesMembersPatternLiteralIndexes.ts @@ -0,0 +1,49 @@ +// @strict: true + +function f1() { + interface AriaProps { + [x: `aria-${string}`]: string; + } + + const x: AriaProps = { + "my-prop": {"whatever": "yes"}, + "aria-disabled": false // error + }; + + const y: AriaProps = { + "my-prop": {"whatever": "yes"}, // excess + "aria-disabled": "false" // OK + }; + + const z: AriaProps & { [x: string]: unknown } = { + "my-prop": {"whatever": "yes"}, // OK + "aria-disabled": "false" // OK + }; + + const a: AriaProps & { [x: string]: unknown } = { + "my-prop": {"whatever": "yes"}, // OK + "aria-disabled": false // error + }; +} + +function f2() { + interface SlotProxy { + readonly [idx: number]: T; + [idx: `getSlot${number}`]: () => this[number]; + [idx: `setSlot${number}`]: (obj: this[number]) => this; + } + + const obj = makeSlotProxy([{x: 12}, {y: 21}]); + + const obj2 = obj.setSlot2({x: 12}).setSlot0({y: 12}).getSlot1(); + + function makeSlotProxy(x: T[]): SlotProxy { + const result: SlotProxy = {}; + for (let i = 0; i < x.length; i++) { + Object.defineProperty(result, i, { get() { return x[i]; } }); + result[`getSlot${i}`] = () => x[i]; + result[`setSlot${i}`] = (arg) => (x[i] = arg, result); + } + return result; + } +} \ No newline at end of file From 05f63f65057f374ed19b6c6db57afd20b623f329 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 3 Mar 2021 13:36:20 -0800 Subject: [PATCH 10/11] Excise well-known symbol ignoring code in index signature handling --- src/compiler/checker.ts | 9 +-------- .../computedPropertyNames45_ES5.errors.txt | 6 +++--- .../computedPropertyNames45_ES6.errors.txt | 6 +++--- .../reference/symbolProperty17.errors.txt | 14 ++++++++++++++ .../reference/symbolProperty30.errors.txt | 12 ++++++++++++ .../reference/symbolProperty32.errors.txt | 14 ++++++++++++++ .../reference/symbolProperty34.errors.txt | 5 ++++- 7 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 tests/baselines/reference/symbolProperty17.errors.txt create mode 100644 tests/baselines/reference/symbolProperty30.errors.txt create mode 100644 tests/baselines/reference/symbolProperty32.errors.txt diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 06c4261304a3e..778a28edc37d1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -36442,13 +36442,6 @@ namespace ts { if (indexInfos) { forEach(getPropertiesOfObjectType(type), prop => { const propType = getTypeOfSymbol(prop); - // TODO: Well known symbols should _probably_ be subject to a symbol indexer, but unfortunately they have no associated literal - // type right now, so they're very difficult to check/flow. They're on the chopping block for removal thanks to advancements, - // and other issues though, so it's probably OK to just let their removal and simultaneous replacement with `unique symbol`s - // fix this. - if (isKnownSymbol(prop)) { - return; - } checkIndexConstraintForProperty(prop, getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique, /*retainNonpublicNames*/ true), propType, type, declaredIndexers); }); @@ -36533,7 +36526,7 @@ namespace ts { let errorNode: Node | undefined; if (propDeclaration && name && (propDeclaration.kind === SyntaxKind.BinaryExpression || - name.kind === SyntaxKind.ComputedPropertyName || + (name.kind === SyntaxKind.ComputedPropertyName && name.parent.parent === containingType.symbol.valueDeclaration) || prop.parent === containingType.symbol)) { errorNode = propDeclaration; } diff --git a/tests/baselines/reference/computedPropertyNames45_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames45_ES5.errors.txt index dca0d5f5a16ba..7db9feb85e2f2 100644 --- a/tests/baselines/reference/computedPropertyNames45_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames45_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(5,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(10,5): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(11,9): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. @@ -8,13 +8,13 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts(11 class C { get ["get1"]() { return new Foo } - ~~~~~~~~ -!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. } class D extends C { // No error when the indexer is in a class more derived than the computed property [s: string]: Foo2; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. set ["set1"](p: Foo) { } ~~~~~~~~ !!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. diff --git a/tests/baselines/reference/computedPropertyNames45_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames45_ES6.errors.txt index 5bd2d5caa4a44..935f34bf7c769 100644 --- a/tests/baselines/reference/computedPropertyNames45_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames45_ES6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(5,9): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(10,5): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(11,9): error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. @@ -8,13 +8,13 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts(11 class C { get ["get1"]() { return new Foo } - ~~~~~~~~ -!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. } class D extends C { // No error when the indexer is in a class more derived than the computed property [s: string]: Foo2; + ~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. set ["set1"](p: Foo) { } ~~~~~~~~ !!! error TS2411: Property '["set1"]' of type 'Foo' is not assignable to 'string' index type 'Foo2'. diff --git a/tests/baselines/reference/symbolProperty17.errors.txt b/tests/baselines/reference/symbolProperty17.errors.txt new file mode 100644 index 0000000000000..4b6ee88ffd214 --- /dev/null +++ b/tests/baselines/reference/symbolProperty17.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/es6/Symbols/symbolProperty17.ts(2,5): error TS2411: Property '[Symbol.iterator]' of type 'number' is not assignable to 'symbol' index type 'string'. + + +==== tests/cases/conformance/es6/Symbols/symbolProperty17.ts (1 errors) ==== + interface I { + [Symbol.iterator]: number; + ~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '[Symbol.iterator]' of type 'number' is not assignable to 'symbol' index type 'string'. + [s: symbol]: string; + "__@iterator": string; + } + + var i: I; + var it = i[Symbol.iterator]; \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty30.errors.txt b/tests/baselines/reference/symbolProperty30.errors.txt new file mode 100644 index 0000000000000..97ae1d8f60076 --- /dev/null +++ b/tests/baselines/reference/symbolProperty30.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/es6/Symbols/symbolProperty30.ts(2,5): error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'. + + +==== tests/cases/conformance/es6/Symbols/symbolProperty30.ts (1 errors) ==== + class C1 { + [Symbol.toStringTag]() { + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'. + return { x: "" }; + } + [s: symbol]: () => { x: number }; + } \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty32.errors.txt b/tests/baselines/reference/symbolProperty32.errors.txt new file mode 100644 index 0000000000000..c8b4845d51902 --- /dev/null +++ b/tests/baselines/reference/symbolProperty32.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/es6/Symbols/symbolProperty32.ts(7,5): error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: 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 TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'. + } \ No newline at end of file diff --git a/tests/baselines/reference/symbolProperty34.errors.txt b/tests/baselines/reference/symbolProperty34.errors.txt index 6adbeb6fa7afb..e1fe289ce70a0 100644 --- a/tests/baselines/reference/symbolProperty34.errors.txt +++ b/tests/baselines/reference/symbolProperty34.errors.txt @@ -1,12 +1,15 @@ tests/cases/conformance/es6/Symbols/symbolProperty34.ts(1,18): error TS2449: Class 'C2' used before its declaration. +tests/cases/conformance/es6/Symbols/symbolProperty34.ts(2,5): error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'. -==== tests/cases/conformance/es6/Symbols/symbolProperty34.ts (1 errors) ==== +==== tests/cases/conformance/es6/Symbols/symbolProperty34.ts (2 errors) ==== class C1 extends C2 { ~~ !!! error TS2449: Class 'C2' used before its declaration. !!! related TS2728 tests/cases/conformance/es6/Symbols/symbolProperty34.ts:6:7: 'C2' is declared here. [Symbol.toStringTag]() { + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2411: Property '[Symbol.toStringTag]' of type '() => { x: string; }' is not assignable to 'symbol' index type '() => { x: number; }'. return { x: "" }; } } From 4844c46a72887d4276564b44021bd0a94e72840a Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 3 Mar 2021 15:03:36 -0800 Subject: [PATCH 11/11] Add Anders test case, with small explaination for why it be like it is when a type literal --- ...nionIndexerGenericAssignability.errors.txt | 80 ++++++++ .../unionIndexerGenericAssignability.js | 79 ++++++++ .../unionIndexerGenericAssignability.symbols | 172 ++++++++++++++++++ .../unionIndexerGenericAssignability.types | 145 +++++++++++++++ .../unionIndexerGenericAssignability.ts | 54 ++++++ 5 files changed, 530 insertions(+) create mode 100644 tests/baselines/reference/unionIndexerGenericAssignability.errors.txt create mode 100644 tests/baselines/reference/unionIndexerGenericAssignability.js create mode 100644 tests/baselines/reference/unionIndexerGenericAssignability.symbols create mode 100644 tests/baselines/reference/unionIndexerGenericAssignability.types create mode 100644 tests/cases/conformance/types/members/unionIndexerGenericAssignability.ts diff --git a/tests/baselines/reference/unionIndexerGenericAssignability.errors.txt b/tests/baselines/reference/unionIndexerGenericAssignability.errors.txt new file mode 100644 index 0000000000000..a58994394388c --- /dev/null +++ b/tests/baselines/reference/unionIndexerGenericAssignability.errors.txt @@ -0,0 +1,80 @@ +tests/cases/conformance/types/members/unionIndexerGenericAssignability.ts(7,4): error TS2741: Property '"data-hello"' is missing in type 'Foo3' but required in type 'Foo3'. +tests/cases/conformance/types/members/unionIndexerGenericAssignability.ts(41,5): error TS2322: Type '`data-${T}`' is not assignable to type '`data-${U}`'. + Type '`data-${string}`' is not assignable to type '`data-${U}`'. +tests/cases/conformance/types/members/unionIndexerGenericAssignability.ts(43,5): error TS2322: Type '{ [_ in `data-${U}`]: any; }' is not assignable to type '{ [_ in `data-${T}`]: any; }'. + Type '`data-${T}`' is not assignable to type '`data-${U}`'. +tests/cases/conformance/types/members/unionIndexerGenericAssignability.ts(46,5): error TS2322: Type '{ [_ in `data-${U}`]?: any; }' is not assignable to type '{ [_ in `data-${T}`]?: any; }'. + Type '`data-${T}`' is not assignable to type '`data-${U}`'. +tests/cases/conformance/types/members/unionIndexerGenericAssignability.ts(52,5): error TS2322: Type 'I1' is not assignable to type 'I1'. + Index signature is missing in type 'I1'. + + +==== tests/cases/conformance/types/members/unionIndexerGenericAssignability.ts (5 errors) ==== + interface Foo3 { + [x: `data-${T}`]: number; + a: string; + } + + function goo(obj1: Foo3, obj2: Foo3) { + obj1 = obj2; // Error expected + ~~~~ +!!! error TS2741: Property '"data-hello"' is missing in type 'Foo3' but required in type 'Foo3'. + obj2 = obj1; + } + + type Foo4 = { + [x: `data-${T}`]: number; + a: string; + } + + function loo(obj1: Foo4, obj2: Foo4) { + obj1 = obj2; // Error expected, doesn't occur because object types have "inferrable indexes" + obj2 = obj1; + } + + interface I1 { + [x: `data-${T}`]: number; + } + + function f1< + T extends string, + U extends T + >( + a: `data-${T}`, + b: `data-${U}`, + aObj: {[_ in `data-${T}`]: any}, + bObj: {[_ in `data-${U}`]: any}, + aObj2: {[_ in `data-${T}`]?: any}, + bObj2: {[_ in `data-${U}`]?: any}, + aObj3: {[x: `data-${T}`]: number}, // type literals can have a "inferrable index" + bObj3: {[x: `data-${U}`]: number}, // type literals can have a "inferrable index" + aObj4: I1, + bObj4: I1, + ) { + a = b; + b = a; + ~ +!!! error TS2322: Type '`data-${T}`' is not assignable to type '`data-${U}`'. +!!! error TS2322: Type '`data-${string}`' is not assignable to type '`data-${U}`'. + + aObj = bObj; + ~~~~ +!!! error TS2322: Type '{ [_ in `data-${U}`]: any; }' is not assignable to type '{ [_ in `data-${T}`]: any; }'. +!!! error TS2322: Type '`data-${T}`' is not assignable to type '`data-${U}`'. + bObj = aObj; + + aObj2 = bObj2; + ~~~~~ +!!! error TS2322: Type '{ [_ in `data-${U}`]?: any; }' is not assignable to type '{ [_ in `data-${T}`]?: any; }'. +!!! error TS2322: Type '`data-${T}`' is not assignable to type '`data-${U}`'. + bObj2 = aObj2; + + aObj3 = bObj3; // not an error because the type-literaly-ness of the source is allowing us to pretend it's closed and simply providing no members of the target at present - an "inferred index" + bObj3 = aObj3; + + aObj4 = bObj4; + ~~~~~ +!!! error TS2322: Type 'I1' is not assignable to type 'I1'. +!!! error TS2322: Index signature is missing in type 'I1'. + bObj4 = aObj4; + } \ No newline at end of file diff --git a/tests/baselines/reference/unionIndexerGenericAssignability.js b/tests/baselines/reference/unionIndexerGenericAssignability.js new file mode 100644 index 0000000000000..eb7f56aea4828 --- /dev/null +++ b/tests/baselines/reference/unionIndexerGenericAssignability.js @@ -0,0 +1,79 @@ +//// [unionIndexerGenericAssignability.ts] +interface Foo3 { + [x: `data-${T}`]: number; + a: string; +} + +function goo(obj1: Foo3, obj2: Foo3) { + obj1 = obj2; // Error expected + obj2 = obj1; +} + +type Foo4 = { + [x: `data-${T}`]: number; + a: string; + } + + function loo(obj1: Foo4, obj2: Foo4) { + obj1 = obj2; // Error expected, doesn't occur because object types have "inferrable indexes" + obj2 = obj1; + } + +interface I1 { + [x: `data-${T}`]: number; +} + +function f1< + T extends string, + U extends T +>( + a: `data-${T}`, + b: `data-${U}`, + aObj: {[_ in `data-${T}`]: any}, + bObj: {[_ in `data-${U}`]: any}, + aObj2: {[_ in `data-${T}`]?: any}, + bObj2: {[_ in `data-${U}`]?: any}, + aObj3: {[x: `data-${T}`]: number}, // type literals can have a "inferrable index" + bObj3: {[x: `data-${U}`]: number}, // type literals can have a "inferrable index" + aObj4: I1, + bObj4: I1, +) { + a = b; + b = a; + + aObj = bObj; + bObj = aObj; + + aObj2 = bObj2; + bObj2 = aObj2; + + aObj3 = bObj3; // not an error because the type-literaly-ness of the source is allowing us to pretend it's closed and simply providing no members of the target at present - an "inferred index" + bObj3 = aObj3; + + aObj4 = bObj4; + bObj4 = aObj4; +} + +//// [unionIndexerGenericAssignability.js] +function goo(obj1, obj2) { + obj1 = obj2; // Error expected + obj2 = obj1; +} +function loo(obj1, obj2) { + obj1 = obj2; // Error expected, doesn't occur because object types have "inferrable indexes" + obj2 = obj1; +} +function f1(a, b, aObj, bObj, aObj2, bObj2, aObj3, // type literals can have a "inferrable index" +bObj3, // type literals can have a "inferrable index" +aObj4, bObj4) { + a = b; + b = a; + aObj = bObj; + bObj = aObj; + aObj2 = bObj2; + bObj2 = aObj2; + aObj3 = bObj3; // not an error because the type-literaly-ness of the source is allowing us to pretend it's closed and simply providing no members of the target at present - an "inferred index" + bObj3 = aObj3; + aObj4 = bObj4; + bObj4 = aObj4; +} diff --git a/tests/baselines/reference/unionIndexerGenericAssignability.symbols b/tests/baselines/reference/unionIndexerGenericAssignability.symbols new file mode 100644 index 0000000000000..5f27a5ce578e9 --- /dev/null +++ b/tests/baselines/reference/unionIndexerGenericAssignability.symbols @@ -0,0 +1,172 @@ +=== tests/cases/conformance/types/members/unionIndexerGenericAssignability.ts === +interface Foo3 { +>Foo3 : Symbol(Foo3, Decl(unionIndexerGenericAssignability.ts, 0, 0)) +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 0, 15)) + + [x: `data-${T}`]: number; +>x : Symbol(x, Decl(unionIndexerGenericAssignability.ts, 1, 4)) +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 0, 15)) + + a: string; +>a : Symbol(Foo3.a, Decl(unionIndexerGenericAssignability.ts, 1, 28)) +} + +function goo(obj1: Foo3, obj2: Foo3) { +>goo : Symbol(goo, Decl(unionIndexerGenericAssignability.ts, 3, 1)) +>U : Symbol(U, Decl(unionIndexerGenericAssignability.ts, 5, 13)) +>obj1 : Symbol(obj1, Decl(unionIndexerGenericAssignability.ts, 5, 31)) +>Foo3 : Symbol(Foo3, Decl(unionIndexerGenericAssignability.ts, 0, 0)) +>U : Symbol(U, Decl(unionIndexerGenericAssignability.ts, 5, 13)) +>obj2 : Symbol(obj2, Decl(unionIndexerGenericAssignability.ts, 5, 55)) +>Foo3 : Symbol(Foo3, Decl(unionIndexerGenericAssignability.ts, 0, 0)) +>U : Symbol(U, Decl(unionIndexerGenericAssignability.ts, 5, 13)) + + obj1 = obj2; // Error expected +>obj1 : Symbol(obj1, Decl(unionIndexerGenericAssignability.ts, 5, 31)) +>obj2 : Symbol(obj2, Decl(unionIndexerGenericAssignability.ts, 5, 55)) + + obj2 = obj1; +>obj2 : Symbol(obj2, Decl(unionIndexerGenericAssignability.ts, 5, 55)) +>obj1 : Symbol(obj1, Decl(unionIndexerGenericAssignability.ts, 5, 31)) +} + +type Foo4 = { +>Foo4 : Symbol(Foo4, Decl(unionIndexerGenericAssignability.ts, 8, 1)) +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 10, 10)) + + [x: `data-${T}`]: number; +>x : Symbol(x, Decl(unionIndexerGenericAssignability.ts, 11, 5)) +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 10, 10)) + + a: string; +>a : Symbol(a, Decl(unionIndexerGenericAssignability.ts, 11, 29)) + } + + function loo(obj1: Foo4, obj2: Foo4) { +>loo : Symbol(loo, Decl(unionIndexerGenericAssignability.ts, 13, 2)) +>U : Symbol(U, Decl(unionIndexerGenericAssignability.ts, 15, 14)) +>obj1 : Symbol(obj1, Decl(unionIndexerGenericAssignability.ts, 15, 32)) +>Foo4 : Symbol(Foo4, Decl(unionIndexerGenericAssignability.ts, 8, 1)) +>U : Symbol(U, Decl(unionIndexerGenericAssignability.ts, 15, 14)) +>obj2 : Symbol(obj2, Decl(unionIndexerGenericAssignability.ts, 15, 56)) +>Foo4 : Symbol(Foo4, Decl(unionIndexerGenericAssignability.ts, 8, 1)) +>U : Symbol(U, Decl(unionIndexerGenericAssignability.ts, 15, 14)) + + obj1 = obj2; // Error expected, doesn't occur because object types have "inferrable indexes" +>obj1 : Symbol(obj1, Decl(unionIndexerGenericAssignability.ts, 15, 32)) +>obj2 : Symbol(obj2, Decl(unionIndexerGenericAssignability.ts, 15, 56)) + + obj2 = obj1; +>obj2 : Symbol(obj2, Decl(unionIndexerGenericAssignability.ts, 15, 56)) +>obj1 : Symbol(obj1, Decl(unionIndexerGenericAssignability.ts, 15, 32)) + } + +interface I1 { +>I1 : Symbol(I1, Decl(unionIndexerGenericAssignability.ts, 18, 2)) +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 20, 13)) + + [x: `data-${T}`]: number; +>x : Symbol(x, Decl(unionIndexerGenericAssignability.ts, 21, 5)) +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 20, 13)) +} + +function f1< +>f1 : Symbol(f1, Decl(unionIndexerGenericAssignability.ts, 22, 1)) + + T extends string, +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 24, 12)) + + U extends T +>U : Symbol(U, Decl(unionIndexerGenericAssignability.ts, 25, 21)) +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 24, 12)) + +>( + a: `data-${T}`, +>a : Symbol(a, Decl(unionIndexerGenericAssignability.ts, 27, 2)) +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 24, 12)) + + b: `data-${U}`, +>b : Symbol(b, Decl(unionIndexerGenericAssignability.ts, 28, 19)) +>U : Symbol(U, Decl(unionIndexerGenericAssignability.ts, 25, 21)) + + aObj: {[_ in `data-${T}`]: any}, +>aObj : Symbol(aObj, Decl(unionIndexerGenericAssignability.ts, 29, 19)) +>_ : Symbol(_, Decl(unionIndexerGenericAssignability.ts, 30, 12)) +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 24, 12)) + + bObj: {[_ in `data-${U}`]: any}, +>bObj : Symbol(bObj, Decl(unionIndexerGenericAssignability.ts, 30, 36)) +>_ : Symbol(_, Decl(unionIndexerGenericAssignability.ts, 31, 12)) +>U : Symbol(U, Decl(unionIndexerGenericAssignability.ts, 25, 21)) + + aObj2: {[_ in `data-${T}`]?: any}, +>aObj2 : Symbol(aObj2, Decl(unionIndexerGenericAssignability.ts, 31, 36)) +>_ : Symbol(_, Decl(unionIndexerGenericAssignability.ts, 32, 13)) +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 24, 12)) + + bObj2: {[_ in `data-${U}`]?: any}, +>bObj2 : Symbol(bObj2, Decl(unionIndexerGenericAssignability.ts, 32, 38)) +>_ : Symbol(_, Decl(unionIndexerGenericAssignability.ts, 33, 13)) +>U : Symbol(U, Decl(unionIndexerGenericAssignability.ts, 25, 21)) + + aObj3: {[x: `data-${T}`]: number}, // type literals can have a "inferrable index" +>aObj3 : Symbol(aObj3, Decl(unionIndexerGenericAssignability.ts, 33, 38)) +>x : Symbol(x, Decl(unionIndexerGenericAssignability.ts, 34, 13)) +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 24, 12)) + + bObj3: {[x: `data-${U}`]: number}, // type literals can have a "inferrable index" +>bObj3 : Symbol(bObj3, Decl(unionIndexerGenericAssignability.ts, 34, 38)) +>x : Symbol(x, Decl(unionIndexerGenericAssignability.ts, 35, 13)) +>U : Symbol(U, Decl(unionIndexerGenericAssignability.ts, 25, 21)) + + aObj4: I1, +>aObj4 : Symbol(aObj4, Decl(unionIndexerGenericAssignability.ts, 35, 38)) +>I1 : Symbol(I1, Decl(unionIndexerGenericAssignability.ts, 18, 2)) +>T : Symbol(T, Decl(unionIndexerGenericAssignability.ts, 24, 12)) + + bObj4: I1, +>bObj4 : Symbol(bObj4, Decl(unionIndexerGenericAssignability.ts, 36, 17)) +>I1 : Symbol(I1, Decl(unionIndexerGenericAssignability.ts, 18, 2)) +>U : Symbol(U, Decl(unionIndexerGenericAssignability.ts, 25, 21)) + +) { + a = b; +>a : Symbol(a, Decl(unionIndexerGenericAssignability.ts, 27, 2)) +>b : Symbol(b, Decl(unionIndexerGenericAssignability.ts, 28, 19)) + + b = a; +>b : Symbol(b, Decl(unionIndexerGenericAssignability.ts, 28, 19)) +>a : Symbol(a, Decl(unionIndexerGenericAssignability.ts, 27, 2)) + + aObj = bObj; +>aObj : Symbol(aObj, Decl(unionIndexerGenericAssignability.ts, 29, 19)) +>bObj : Symbol(bObj, Decl(unionIndexerGenericAssignability.ts, 30, 36)) + + bObj = aObj; +>bObj : Symbol(bObj, Decl(unionIndexerGenericAssignability.ts, 30, 36)) +>aObj : Symbol(aObj, Decl(unionIndexerGenericAssignability.ts, 29, 19)) + + aObj2 = bObj2; +>aObj2 : Symbol(aObj2, Decl(unionIndexerGenericAssignability.ts, 31, 36)) +>bObj2 : Symbol(bObj2, Decl(unionIndexerGenericAssignability.ts, 32, 38)) + + bObj2 = aObj2; +>bObj2 : Symbol(bObj2, Decl(unionIndexerGenericAssignability.ts, 32, 38)) +>aObj2 : Symbol(aObj2, Decl(unionIndexerGenericAssignability.ts, 31, 36)) + + aObj3 = bObj3; // not an error because the type-literaly-ness of the source is allowing us to pretend it's closed and simply providing no members of the target at present - an "inferred index" +>aObj3 : Symbol(aObj3, Decl(unionIndexerGenericAssignability.ts, 33, 38)) +>bObj3 : Symbol(bObj3, Decl(unionIndexerGenericAssignability.ts, 34, 38)) + + bObj3 = aObj3; +>bObj3 : Symbol(bObj3, Decl(unionIndexerGenericAssignability.ts, 34, 38)) +>aObj3 : Symbol(aObj3, Decl(unionIndexerGenericAssignability.ts, 33, 38)) + + aObj4 = bObj4; +>aObj4 : Symbol(aObj4, Decl(unionIndexerGenericAssignability.ts, 35, 38)) +>bObj4 : Symbol(bObj4, Decl(unionIndexerGenericAssignability.ts, 36, 17)) + + bObj4 = aObj4; +>bObj4 : Symbol(bObj4, Decl(unionIndexerGenericAssignability.ts, 36, 17)) +>aObj4 : Symbol(aObj4, Decl(unionIndexerGenericAssignability.ts, 35, 38)) +} diff --git a/tests/baselines/reference/unionIndexerGenericAssignability.types b/tests/baselines/reference/unionIndexerGenericAssignability.types new file mode 100644 index 0000000000000..d75787800f225 --- /dev/null +++ b/tests/baselines/reference/unionIndexerGenericAssignability.types @@ -0,0 +1,145 @@ +=== tests/cases/conformance/types/members/unionIndexerGenericAssignability.ts === +interface Foo3 { + [x: `data-${T}`]: number; +>x : `data-${T}` + + a: string; +>a : string +} + +function goo(obj1: Foo3, obj2: Foo3) { +>goo : (obj1: Foo3, obj2: Foo3) => void +>obj1 : Foo3 +>obj2 : Foo3 + + obj1 = obj2; // Error expected +>obj1 = obj2 : Foo3 +>obj1 : Foo3 +>obj2 : Foo3 + + obj2 = obj1; +>obj2 = obj1 : Foo3 +>obj2 : Foo3 +>obj1 : Foo3 +} + +type Foo4 = { +>Foo4 : Foo4 + + [x: `data-${T}`]: number; +>x : `data-${T}` + + a: string; +>a : string + } + + function loo(obj1: Foo4, obj2: Foo4) { +>loo : (obj1: Foo4, obj2: Foo4) => void +>obj1 : Foo4<"hello" | U> +>obj2 : Foo4 + + obj1 = obj2; // Error expected, doesn't occur because object types have "inferrable indexes" +>obj1 = obj2 : Foo4 +>obj1 : Foo4<"hello" | U> +>obj2 : Foo4 + + obj2 = obj1; +>obj2 = obj1 : Foo4<"hello" | U> +>obj2 : Foo4 +>obj1 : Foo4<"hello" | U> + } + +interface I1 { + [x: `data-${T}`]: number; +>x : `data-${T}` +} + +function f1< +>f1 : (a: `data-${T}`, b: `data-${U}`, aObj: { [_ in `data-${T}`]: any; }, bObj: { [_ in `data-${U}`]: any; }, aObj2: { [_ in `data-${T}`]?: any; }, bObj2: { [_ in `data-${U}`]?: any; }, aObj3: { [x: `data-${T}`]: number; }, bObj3: { [x: `data-${U}`]: number; }, aObj4: I1, bObj4: I1) => void + + T extends string, + U extends T +>( + a: `data-${T}`, +>a : `data-${T}` + + b: `data-${U}`, +>b : `data-${U}` + + aObj: {[_ in `data-${T}`]: any}, +>aObj : { [_ in `data-${T}`]: any; } + + bObj: {[_ in `data-${U}`]: any}, +>bObj : { [_ in `data-${U}`]: any; } + + aObj2: {[_ in `data-${T}`]?: any}, +>aObj2 : { [_ in `data-${T}`]?: any; } + + bObj2: {[_ in `data-${U}`]?: any}, +>bObj2 : { [_ in `data-${U}`]?: any; } + + aObj3: {[x: `data-${T}`]: number}, // type literals can have a "inferrable index" +>aObj3 : { [x: `data-${T}`]: number; } +>x : `data-${T}` + + bObj3: {[x: `data-${U}`]: number}, // type literals can have a "inferrable index" +>bObj3 : { [x: `data-${U}`]: number; } +>x : `data-${U}` + + aObj4: I1, +>aObj4 : I1 + + bObj4: I1, +>bObj4 : I1 + +) { + a = b; +>a = b : `data-${U}` +>a : `data-${T}` +>b : `data-${U}` + + b = a; +>b = a : `data-${T}` +>b : `data-${U}` +>a : `data-${T}` + + aObj = bObj; +>aObj = bObj : { [_ in `data-${U}`]: any; } +>aObj : { [_ in `data-${T}`]: any; } +>bObj : { [_ in `data-${U}`]: any; } + + bObj = aObj; +>bObj = aObj : { [_ in `data-${T}`]: any; } +>bObj : { [_ in `data-${U}`]: any; } +>aObj : { [_ in `data-${T}`]: any; } + + aObj2 = bObj2; +>aObj2 = bObj2 : { [_ in `data-${U}`]?: any; } +>aObj2 : { [_ in `data-${T}`]?: any; } +>bObj2 : { [_ in `data-${U}`]?: any; } + + bObj2 = aObj2; +>bObj2 = aObj2 : { [_ in `data-${T}`]?: any; } +>bObj2 : { [_ in `data-${U}`]?: any; } +>aObj2 : { [_ in `data-${T}`]?: any; } + + aObj3 = bObj3; // not an error because the type-literaly-ness of the source is allowing us to pretend it's closed and simply providing no members of the target at present - an "inferred index" +>aObj3 = bObj3 : { [x: `data-${U}`]: number; } +>aObj3 : { [x: `data-${T}`]: number; } +>bObj3 : { [x: `data-${U}`]: number; } + + bObj3 = aObj3; +>bObj3 = aObj3 : { [x: `data-${T}`]: number; } +>bObj3 : { [x: `data-${U}`]: number; } +>aObj3 : { [x: `data-${T}`]: number; } + + aObj4 = bObj4; +>aObj4 = bObj4 : I1 +>aObj4 : I1 +>bObj4 : I1 + + bObj4 = aObj4; +>bObj4 = aObj4 : I1 +>bObj4 : I1 +>aObj4 : I1 +} diff --git a/tests/cases/conformance/types/members/unionIndexerGenericAssignability.ts b/tests/cases/conformance/types/members/unionIndexerGenericAssignability.ts new file mode 100644 index 0000000000000..94b4811faa62c --- /dev/null +++ b/tests/cases/conformance/types/members/unionIndexerGenericAssignability.ts @@ -0,0 +1,54 @@ +interface Foo3 { + [x: `data-${T}`]: number; + a: string; +} + +function goo(obj1: Foo3, obj2: Foo3) { + obj1 = obj2; // Error expected + obj2 = obj1; +} + +type Foo4 = { + [x: `data-${T}`]: number; + a: string; + } + + function loo(obj1: Foo4, obj2: Foo4) { + obj1 = obj2; // Error expected, doesn't occur because object types have "inferrable indexes" + obj2 = obj1; + } + +interface I1 { + [x: `data-${T}`]: number; +} + +function f1< + T extends string, + U extends T +>( + a: `data-${T}`, + b: `data-${U}`, + aObj: {[_ in `data-${T}`]: any}, + bObj: {[_ in `data-${U}`]: any}, + aObj2: {[_ in `data-${T}`]?: any}, + bObj2: {[_ in `data-${U}`]?: any}, + aObj3: {[x: `data-${T}`]: number}, // type literals can have a "inferrable index" + bObj3: {[x: `data-${U}`]: number}, // type literals can have a "inferrable index" + aObj4: I1, + bObj4: I1, +) { + a = b; + b = a; + + aObj = bObj; + bObj = aObj; + + aObj2 = bObj2; + bObj2 = aObj2; + + aObj3 = bObj3; // not an error because the type-literaly-ness of the source is allowing us to pretend it's closed and simply providing no members of the target at present - an "inferred index" + bObj3 = aObj3; + + aObj4 = bObj4; + bObj4 = aObj4; +} \ No newline at end of file