diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 4e850f4eea9ea..9e34342f04188 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -173,6 +173,10 @@ namespace ts { const binder = createBinder(); + function createSymbolTable() { + return Debug.flagCheckerImmutableObject(ts.createSymbolTable()); + }; + export function bindSourceFile(file: SourceFile, options: CompilerOptions) { tracing?.push(tracing.Phase.Bind, "bindSourceFile", { path: file.path }, /*separateBeginAndEnd*/ true); performance.mark("beforeBind"); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b2036d24a3138..b9c1d9434e10a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -302,6 +302,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 = memoize(() => { const set = new Set(); @@ -422,9 +429,9 @@ namespace ts { return lexicallyScopedIdentifier ? getPrivateIdentifierPropertyOfType(leftType, lexicallyScopedIdentifier) : undefined; }, getTypeOfPropertyOfType: (type, name) => getTypeOfPropertyOfType(type, escapeLeadingUnderscores(name)), - getIndexInfoOfType, + getIndexInfosOfType: (type, indexType?) => indexType ? flatten(getApplicableIndexInfosOfIndexOnType(type, indexType) || emptyArray) : getIndexInfosOfType(type), getSignaturesOfType, - getIndexTypeOfType, + getIndexTypeOfType: (type, indexType) => getResultingTypeOfIndexOnType(type, indexType), getBaseTypes, getBaseTypeOfLiteralType, getWidenedType, @@ -588,7 +595,7 @@ namespace ts { resolveStructuredTypeMembers, getTypeOfSymbol, getResolvedSymbol, - getIndexTypeOfStructuredType, + getIndexInfosOfType, getConstraintOfTypeParameter, getFirstIdentifier, getTypeArguments, @@ -609,8 +616,14 @@ namespace ts { }, getApparentType, getUnionType, + createAnonymousType: (symbol: Symbol | undefined, members: SymbolTable, call: Signature[], construct: Signature[], stringInfoOrInfos?: IndexInfo[] | IndexInfo | undefined, numberInfo?: IndexInfo | undefined) => + createAnonymousType( + symbol, + members, + call, + construct, + stringInfoOrInfos instanceof Array ? stringInfoOrInfos : stringInfoOrInfos && numberInfo ? [stringInfoOrInfos, numberInfo] : stringInfoOrInfos ? [stringInfoOrInfos] : numberInfo ? [numberInfo] : undefined), isTypeAssignableTo, - createAnonymousType, createSignature, createSymbol, createIndexInfo, @@ -784,25 +797,25 @@ namespace ts { const restrictiveMapper: TypeMapper = makeFunctionTypeMapper(t => t.flags & TypeFlags.TypeParameter ? getRestrictiveTypeParameter(t) : t); const permissiveMapper: TypeMapper = makeFunctionTypeMapper(t => t.flags & TypeFlags.TypeParameter ? wildcardType : t); - const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); - const emptyJsxObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined); + const emptyJsxObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined); emptyJsxObjectType.objectFlags |= ObjectFlags.JsxAttributes; 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 = new Map(); - 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.objectFlags |= ObjectFlags.NonInferrableType; - 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 = createTypeParameter(); const markerSubType = createTypeParameter(); @@ -816,7 +829,7 @@ namespace ts { const resolvingSignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*resolvedTypePredicate*/ undefined, 0, SignatureFlags.None); const silentNeverSignature = createSignature(undefined, undefined, undefined, emptyArray, silentNeverType, /*resolvedTypePredicate*/ undefined, 0, SignatureFlags.None); - const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true); + const enumNumberIndexInfo = createIndexInfo(numberType, stringType, /*isReadonly*/ true); const iterationTypesCache = new Map(); // cache for common IterationTypes instances const noIterationTypes: IterationTypes = { @@ -981,6 +994,8 @@ namespace ts { const subtypeRelation = new Map(); const strictSubtypeRelation = new Map(); const assignableRelation = new Map(); + const indexAccessAssignableRelation = new Map(); + const indexAssignableRelation = new Map(); const comparableRelation = new Map(); const identityRelation = new Map(); const enumRelation = new Map(); @@ -3480,7 +3495,7 @@ namespace ts { if (symbol.members) result.members = new Map(symbol.members); if (symbol.exports) result.exports = new Map(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; } } @@ -3857,8 +3872,7 @@ namespace ts { type.properties = undefined; type.callSignatures = undefined; type.constructSignatures = undefined; - type.stringIndexInfo = undefined; - type.numberIndexInfo = undefined; + type.indexInfos = undefined; return type; } @@ -3894,28 +3908,42 @@ namespace ts { return result || emptyArray; } + function reifyConcreteIndexInfoKeysAsProperties(indexInfos: readonly IndexInfo[], container: { members: SymbolTable, indexInfos?: IndexInfo[] }) { + Debug.assertMutable(container.members); + // 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 => { + addMemberForKeyTypeWorker(/*mappedType*/ undefined, t, t, () => info.type, container, /*modifiersType*/ undefined, info.isReadonly ? MappedTypeModifiers.IncludeReadonly : 0, t === info.indexType ? info : undefined); + }); + } + } + function getNamedOrIndexSignatureMembers(members: SymbolTable): Symbol[] { const result = getNamedMembers(members); const index = getIndexSymbolFromSymbolTable(members); return index ? concatenate(result, [index]) : result; } - function setStructuredTypeMembers(type: StructuredType, members: SymbolTable, callSignatures: readonly Signature[], constructSignatures: readonly Signature[], stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): ResolvedType { + function setStructuredTypeMembers(type: StructuredType, members: SymbolTable, callSignatures: readonly Signature[], constructSignatures: readonly Signature[], indexInfos: readonly IndexInfo[] | undefined): ResolvedType { + // `members` needs to be mutable for `reifyConcreteIndexInfoKeysAsProperties` to function, so in a scenario where we plan to call it, + // we use the `emptySymbols` singleton as a signal to make a new symbol table. const resolved = type; - resolved.members = members; + resolved.members = members === emptySymbols && indexInfos ? createSymbolTable() : members; resolved.properties = emptyArray; + resolved.indexInfos = undefined; + if (indexInfos) { + reifyConcreteIndexInfoKeysAsProperties(indexInfos, resolved as {indexInfos?: IndexInfo[]} & typeof resolved); + } resolved.callSignatures = callSignatures; resolved.constructSignatures = constructSignatures; - resolved.stringIndexInfo = stringIndexInfo; - resolved.numberIndexInfo = numberIndexInfo; // This can loop back to getPropertyOfType() which would crash if `callSignatures` & `constructSignatures` are not initialized. if (members !== emptySymbols) resolved.properties = getNamedMembers(members); return resolved; } - function createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: readonly Signature[], constructSignatures: readonly Signature[], stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): ResolvedType { + function createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: readonly Signature[], constructSignatures: readonly Signature[], indexInfos: readonly IndexInfo[] | undefined): ResolvedType { return setStructuredTypeMembers(createObjectType(ObjectFlags.Anonymous, symbol), - members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); + members, callSignatures, constructSignatures, indexInfos); } function getResolvedTypeWithoutAbstractConstructSignatures(type: ResolvedType) { @@ -3928,8 +3956,7 @@ namespace ts { type.members, type.callSignatures, some(constructSignatures) ? constructSignatures : emptyArray, - type.stringIndexInfo, - type.numberIndexInfo); + type.indexInfos); type.objectTypeWithoutAbstractConstructSignatures = typeCopy; typeCopy.objectTypeWithoutAbstractConstructSignatures = typeCopy; return typeCopy; @@ -4465,8 +4492,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, /*typeNode*/ undefined)), + indexInfoToIndexSignatureDeclaration: (indexInfo: IndexInfo, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => + withContext(enclosingDeclaration, flags, tracker, context => indexInfoToIndexSignatureDeclarationHelper(indexInfo, context, /*typeNode*/ undefined))!, // TODO: GH#18217 signatureToSignatureDeclaration: (signature: Signature, kind: SignatureDeclaration["kind"], 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) => @@ -4940,7 +4967,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(factory.createTypeLiteralNode(/*members*/ undefined), EmitFlags.SingleLine); @@ -4967,8 +4994,7 @@ namespace ts { const typeElementCount = resolved.callSignatures.length + (resolved.constructSignatures.length - abstractSignatures.length) + - (resolved.stringIndexInfo ? 1 : 0) + - (resolved.numberIndexInfo ? 1 : 0) + + length(resolved.indexInfos) + // exclude `prototype` when writing a class expression as a type literal, as per // the logic in `createTypeNodesFromResolvedType`. (context.flags & NodeBuilderFlags.WriteClassExpressionAsTypeLiteral ? @@ -5164,22 +5190,13 @@ namespace ts { if (signature.flags & SignatureFlags.Abstract) continue; typeElements.push(signatureToSignatureDeclarationHelper(signature, SyntaxKind.ConstructSignature, context)); } - if (resolvedType.stringIndexInfo) { - let indexSignature: IndexSignatureDeclaration; - if (resolvedType.objectFlags & ObjectFlags.ReverseMapped) { - indexSignature = indexInfoToIndexSignatureDeclarationHelper( - createIndexInfo(anyType, resolvedType.stringIndexInfo.isReadonly, resolvedType.stringIndexInfo.declaration), - IndexKind.String, - context, - createElidedInformationPlaceholder(context)); - } - else { - indexSignature = indexInfoToIndexSignatureDeclarationHelper(resolvedType.stringIndexInfo, IndexKind.String, context, /*typeNode*/ undefined); + if (resolvedType.indexInfos) { + for (let info of resolvedType.indexInfos) { + if (resolvedType.objectFlags & ObjectFlags.ReverseMapped) { + info = createIndexInfo(info.indexType, anyType, info.isReadonly, info.declaration); + } + typeElements.push(indexInfoToIndexSignatureDeclarationHelper(info, context, resolvedType.objectFlags & ObjectFlags.ReverseMapped ? createElidedInformationPlaceholder(context) : undefined)); } - typeElements.push(indexSignature); - } - if (resolvedType.numberIndexInfo) { - typeElements.push(indexInfoToIndexSignatureDeclarationHelper(resolvedType.numberIndexInfo, IndexKind.Number, context, /*typeNode*/ undefined)); } const properties = resolvedType.properties; @@ -5375,15 +5392,16 @@ namespace ts { } } + function typesAreSameReference(a: Type, b: Type): boolean { return a === b || !!a.symbol && a.symbol === b.symbol || !!a.aliasSymbol && a.aliasSymbol === b.aliasSymbol; } - function indexInfoToIndexSignatureDeclarationHelper(indexInfo: IndexInfo, kind: IndexKind, context: NodeBuilderContext, typeNode: TypeNode | undefined): IndexSignatureDeclaration { + function indexInfoToIndexSignatureDeclarationHelper(indexInfo: IndexInfo, context: NodeBuilderContext, typeNode: TypeNode | undefined): IndexSignatureDeclaration { const name = getNameFromIndexInfo(indexInfo) || "x"; - const indexerTypeNode = factory.createKeywordTypeNode(kind === IndexKind.String ? SyntaxKind.StringKeyword : SyntaxKind.NumberKeyword); + const indexerTypeNode = typeToTypeNodeHelper(indexInfo.indexType, context); const indexingParameter = factory.createParameterDeclaration( /*decorators*/ undefined, @@ -7433,8 +7451,7 @@ namespace ts { // whose input is not type annotated (if the input symbol has an annotation we can reuse, we should prefer it) const ctxSrc = getSourceFileOfNode(context.enclosingDeclaration); return getObjectFlags(typeToSerialize) & (ObjectFlags.Anonymous | ObjectFlags.Mapped) && - !getIndexInfoOfType(typeToSerialize, IndexKind.String) && - !getIndexInfoOfType(typeToSerialize, IndexKind.Number) && + !getIndexInfosOfType(typeToSerialize) && !isClassInstanceSide(typeToSerialize) && // While a class instance is potentially representable as a NS, prefer printing a reference to the instance type and serializing the class !!(length(filter(getPropertiesOfType(typeToSerialize), isNamespaceMember)) || length(getSignaturesOfType(typeToSerialize, SignatureKind.Call))) && !length(getSignaturesOfType(typeToSerialize, SignatureKind.Construct)) && // TODO: could probably serialize as function + ns + class, now that that's OK @@ -7625,18 +7642,20 @@ namespace ts { function serializeIndexSignatures(input: Type, baseType: Type | undefined) { const results: IndexSignatureDeclaration[] = []; - for (const type of [IndexKind.String, IndexKind.Number]) { - const info = getIndexInfoOfType(input, type); - if (info) { - if (baseType) { - const baseInfo = getIndexInfoOfType(baseType, type); - if (baseInfo) { - if (isTypeIdenticalTo(info.type, baseInfo.type)) { - continue; // elide identical index signatures + const infos = getIndexInfosOfType(input); + if (infos) { + for (const info of infos) { + if (info) { + if (baseType) { + const baseInfos = flatten(getApplicableIndexInfosOfIndexOnType(baseType, info.indexType) || emptyArray); + if (baseInfos && baseInfos.length) { + if (some(baseInfos, i => info.isReadonly === i.isReadonly && info.indexType === i.indexType && info.type === i.type)) { + continue; // elide identical index signatures + } } } + results.push(indexInfoToIndexSignatureDeclarationHelper(info, context, /*typeNode*/ undefined)); } - results.push(indexInfoToIndexSignatureDeclarationHelper(info, type, context, /*typeNode*/ undefined)); } } return results; @@ -8158,7 +8177,7 @@ namespace ts { } function getTypeOfPropertyOrIndexSignature(type: Type, name: __String): Type { - return getTypeOfPropertyOfType(type, name) || isNumericLiteralName(name) && getIndexTypeOfType(type, IndexKind.Number) || getIndexTypeOfType(type, IndexKind.String) || unknownType; + return getTypeOfPropertyOfType(type, name) || getResultingTypeOfIndexOnType(type, getLiteralType(isNumericLiteralName(name) ? Number(name) : unescapeLeadingUnderscores(name))) || unknownType; } function isTypeAny(type: Type | undefined) { @@ -8200,9 +8219,8 @@ namespace ts { members.set(prop.escapedName, getSpreadSymbol(prop, /*readonly*/ false)); } } - const stringIndexInfo = getIndexInfoOfType(source, IndexKind.String); - const numberIndexInfo = getIndexInfoOfType(source, IndexKind.Number); - const result = createAnonymousType(symbol, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); + const indexInfos = getIndexInfosOfType(source); + const result = createAnonymousType(symbol, members, emptyArray, emptyArray, indexInfos); result.objectFlags |= ObjectFlags.ObjectRestType; return result; } @@ -8669,7 +8687,7 @@ namespace ts { if (s?.exports?.size) { 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; } @@ -8779,8 +8797,7 @@ namespace ts { members, exportedType.callSignatures, exportedType.constructSignatures, - exportedType.stringIndexInfo, - exportedType.numberIndexInfo); + exportedType.indexInfos); result.objectFlags |= (getObjectFlags(type) & ObjectFlags.JSLiteral); // Propagate JSLiteral flag if (result.symbol && result.symbol.flags & SymbolFlags.Class && type === getDeclaredTypeOfClassOrInterface(result.symbol)) { result.objectFlags |= ObjectFlags.IsClassInstanceClone; // Propagate the knowledge that this type is equivalent to the symbol's class instance type @@ -8851,7 +8868,7 @@ namespace ts { forEach(pattern.elements, e => { const name = e.propertyName || e.name; if (e.dotDotDotToken) { - stringIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false); + stringIndexInfo = createIndexInfo(stringType, anyType, /*isReadonly*/ false); return; } @@ -8868,7 +8885,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.objectFlags |= objectFlags; if (includePatternInType) { result.pattern = pattern; @@ -9006,7 +9023,7 @@ namespace ts { if (fileSymbol.exports) result.exports = new Map(fileSymbol.exports); const members = createSymbolTable(); members.set("exports" as __String, result); - return createAnonymousType(symbol, members, emptyArray, emptyArray, undefined, undefined); + return createAnonymousType(symbol, members, emptyArray, emptyArray, undefined); } // Handle catch clause variables Debug.assertIsDefined(symbol.valueDeclaration); @@ -10157,8 +10174,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; } @@ -10424,44 +10440,53 @@ namespace ts { let members: SymbolTable; let callSignatures: readonly Signature[]; let constructSignatures: readonly Signature[] | undefined; - let stringIndexInfo: IndexInfo | undefined; - let numberIndexInfo: IndexInfo | undefined; + let indexInfos: readonly IndexInfo[] | undefined; if (rangeEquals(typeParameters, typeArguments, 0, typeParameters.length)) { 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); + if (baseInfos) { + indexInfos = overrideIndexInfos(baseInfos, indexInfos); + } + if (!resolveIndexOnIndexInfos(stringType, indexInfos)) { + if (instantiatedBaseType === anyType) { + const info = createIndexInfo(stringType, anyType, /*isReadonly*/ false); + if (!indexInfos) { + indexInfos = [info]; + } + else { + indexInfos = concatenate(indexInfos, [info]); + } + } } - numberIndexInfo = numberIndexInfo || getIndexInfoOfType(instantiatedBaseType, IndexKind.Number); } } - setStructuredTypeMembers(type, members, callSignatures, constructSignatures, stringIndexInfo, numberIndexInfo); + if (source.symbol && members === getMembersOfSymbol(source.symbol) && indexInfos) { + members = createSymbolTable(source.declaredProperties); + } + setStructuredTypeMembers(type, members, callSignatures, constructSignatures, indexInfos); } function resolveClassOrInterfaceMembers(type: InterfaceType): void { @@ -10800,18 +10825,19 @@ namespace ts { return result; } - function getUnionIndexInfo(types: readonly Type[], kind: IndexKind): IndexInfo | undefined { - const indexTypes: Type[] = []; - let isAnyReadonly = false; + function getUnionIndexInfos(types: readonly Type[]): readonly IndexInfo[] | undefined { + let finalInfos: readonly IndexInfo[] | undefined; for (const type of types) { - const indexInfo = getIndexInfoOfType(getApparentType(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) { @@ -10819,9 +10845,8 @@ namespace ts { // type use getPropertiesOfType (only the language service uses this). const callSignatures = getUnionSignatures(map(type.types, t => t === globalFunctionType ? [unknownSignature] : getSignaturesOfType(t, SignatureKind.Call))); const constructSignatures = getUnionSignatures(map(type.types, t => getSignaturesOfType(t, 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; @@ -10830,14 +10855,80 @@ 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 overrideIndexInfos(infos1: readonly IndexInfo[] | undefined, infos2: readonly IndexInfo[] | undefined): readonly 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: readonly IndexInfo[] | undefined, infos2: readonly IndexInfo[] | undefined): IndexInfo[] | undefined { + if (!infos1) { + return infos2 && [...infos2]; + } + if (!infos2) { + return infos1 && [...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.flags & TypeFlags.Never) && !(intersectedKeys.flags & TypeFlags.Intersection)) { + infos = append(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 = append(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: readonly IndexInfo[] | undefined, infos2: readonly IndexInfo[] | undefined): readonly 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.flags & TypeFlags.Never) && !(intersectedKeys.flags & TypeFlags.Intersection)) { + infos = append(infos, createIndexInfo(intersectedKeys, getUnionType([info1.type, info2.type]), info1.isReadonly || info2.isReadonly)); + } + } + } + // And drop the rest + return infos; } function findMixins(types: readonly Type[]): readonly boolean[] { @@ -10868,8 +10959,7 @@ namespace ts { // intersection type use getPropertiesOfType (only the language service uses this). let callSignatures: Signature[] | undefined; let constructSignatures: Signature[] | undefined; - let stringIndexInfo: IndexInfo | undefined; - let numberIndexInfo: IndexInfo | undefined; + let indexInfos: IndexInfo[] | undefined; const types = type.types; const mixinFlags = findMixins(types); const mixinCount = countWhere(mixinFlags, (b) => b); @@ -10892,10 +10982,9 @@ namespace ts { constructSignatures = appendSignatures(constructSignatures, signatures); } callSignatures = appendSignatures(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 || emptyArray, constructSignatures || emptyArray, stringIndexInfo, numberIndexInfo); + setStructuredTypeMembers(type, emptySymbols, callSignatures || emptyArray, constructSignatures || emptyArray, indexInfos); } function appendSignatures(signatures: Signature[] | undefined, newSignatures: readonly Signature[]) { @@ -10913,28 +11002,25 @@ namespace ts { function resolveAnonymousTypeMembers(type: AnonymousType) { const symbol = getMergedSymbol(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, indexInfos ? createSymbolTable(arrayFrom(members.values())) : members, callSignatures, constructSignatures, indexInfos); } else { // Combinations of function, class, enum and module let members = emptySymbols; - let stringIndexInfo: IndexInfo | undefined; - let numberIndexInfo: IndexInfo | undefined; + let indexInfos: IndexInfo[] | undefined; if (symbol.exports) { members = getExportsOfSymbol(symbol); if (symbol === globalThisSymbol) { @@ -10947,8 +11033,7 @@ namespace ts { members = varsOnly; } } - let baseConstructorIndexInfo: IndexInfo | undefined; - 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); @@ -10957,23 +11042,19 @@ namespace ts { addInheritedMembers(members, getPropertiesOfType(baseConstructorType)); } else if (baseConstructorType === anyType) { - baseConstructorIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false); + indexInfos = [createIndexInfo(stringType, anyType, /*isReadonly*/ false)]; } } - + if (symbol.flags & SymbolFlags.Enum && (getDeclaredTypeOfSymbol(symbol).flags & TypeFlags.Enum || + some(type.properties, prop => !!(getTypeOfSymbol(prop).flags & TypeFlags.NumberLike)))) { + indexInfos = indexInfos || []; + indexInfos.push(enumNumberIndexInfo); + } const indexSymbol = getIndexSymbolFromSymbolTable(members); if (indexSymbol) { - stringIndexInfo = getIndexInfoOfIndexSymbol(indexSymbol, IndexKind.String); - numberIndexInfo = getIndexInfoOfIndexSymbol(indexSymbol, IndexKind.Number); - } - else { - stringIndexInfo = baseConstructorIndexInfo; - if (symbol.flags & SymbolFlags.Enum && (getDeclaredTypeOfSymbol(symbol).flags & TypeFlags.Enum || - some(type.properties, prop => !!(getTypeOfSymbol(prop).flags & TypeFlags.NumberLike)))) { - numberIndexInfo = enumNumberIndexInfo; - } + indexInfos = getIndexInfosOfIndexSymbol(indexSymbol); } - setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); + setStructuredTypeMembers(type, members = indexInfos ? createSymbolTable(arrayFrom(members.values())) : 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 @@ -11008,19 +11089,16 @@ namespace ts { return instantiateType(instantiable, createTypeMapper([type.indexType, type.objectType], [getLiteralType(0), createTupleType([replacement])])); } - function getIndexInfoOfIndexSymbol(indexSymbol: Symbol, indexKind: IndexKind) { - const declaration = getIndexDeclarationOfIndexSymbol(indexSymbol, indexKind); - if (!declaration) return undefined; - return createIndexInfo(declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, - hasEffectiveModifier(declaration, ModifierFlags.Readonly), declaration); - } - 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, type.constraintType), 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, type.constraintType), readonlyMask && i.isReadonly)); const members = createSymbolTable(); for (const prop of getPropertiesOfType(type.source)) { const checkFlags = CheckFlags.ReverseMapped | (readonlyMask && isReadonlySymbol(prop) ? CheckFlags.Readonly : 0); @@ -11045,7 +11123,7 @@ namespace ts { } members.set(prop.escapedName, inferredProp); } - setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, undefined); + setStructuredTypeMembers(type, members, emptyArray, emptyArray, mappedIndexInfos); } // Return the lower bound of the key type in a mapped type. Intuitively, the lower @@ -11082,10 +11160,9 @@ namespace ts { /** 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; + 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, 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); @@ -11100,67 +11177,120 @@ namespace ts { for (const prop of getPropertiesOfType(modifiersType)) { addMemberForKeyType(getLiteralTypeFromProperty(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 { forEachType(getLowerBoundOfKeyType(constraintType), addMemberForKeyType); } - setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); + setStructuredTypeMembers(type, members, emptyArray, emptyArray, container.indexInfos); function addMemberForKeyType(keyType: Type) { const propNameType = nameType ? instantiateType(nameType, appendTypeMapping(type.mapper, typeParameter, keyType)) : keyType; - forEachType(propNameType, t => addMemberForKeyTypeWorker(keyType, t)); - } - - function addMemberForKeyTypeWorker(keyType: Type, propNameType: Type) { - // 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(propNameType)) { - const propName = getPropertyNameFromType(propNameType); - // String enum members from separate enums with identical values - // are distinct types with the same property name. Make the resulting - // property symbol's name type be the union of those enum member types. - const existingProp = members.get(propName) as MappedSymbol | undefined; - if (existingProp) { - existingProp.nameType = getUnionType([existingProp.nameType!, propNameType]); - existingProp.keyType = getUnionType([existingProp.keyType, keyType]); + forEachType(propNameType, t => addMemberForKeyTypeWorker(type, keyType, t, () => instantiateType(templateType, appendTypeMapping(type.mapper, typeParameter, keyType)), container, modifiersType, templateModifiers)); + } + } + + function addMemberForKeyTypeWorker(mappedType: MappedType | undefined, keyType: Type, propNameType: Type, getPropType: () => 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(propNameType)) { + const propName = getPropertyNameFromType(propNameType); + // String enum members from separate enums with identical values + // are distinct types with the same property name. Make the resulting + // property symbol's name type be the union of those enum member types. + const existingProp = container.members.get(propName) as MappedSymbol | undefined; + if (existingProp) { + // This helper is used to reify properties for index signatures, in addition to mapped types + // In such cases, the existing properties will potentially not have a `.nameType` cached (yet) + // or a `.keyType` (at all). In such cases, using the name derived from the symbol name should be sufficient. + const nameTypeFallback = getSymbolLinks(existingProp).nameType || getLiteralTypeFromProperty(existingProp, TypeFlags.StringOrNumberLiteralOrUnique); + const combinedNameType = getUnionType([existingProp.nameType || nameTypeFallback, propNameType]); + const combinedKeyType = getUnionType([existingProp.keyType || nameTypeFallback, keyType]); + + if (isTransientSymbol(existingProp)) { + // We may have non-transient symbols in the members table due to preexisting interface symbols, so only assign + // directly to the symbol if we're working on building a transient symbol (otherwise the symbol will leak types + // across checkers!) + existingProp.nameType = combinedNameType; + existingProp.keyType = combinedKeyType; } else { - const modifiersProp = isTypeUsableAsPropertyName(keyType) ? getPropertyOfType(modifiersType, getPropertyNameFromType(keyType)) : undefined; - 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 stripOptional = strictNullChecks && !isOptional && modifiersProp && modifiersProp.flags & SymbolFlags.Optional; - const lateFlag: CheckFlags = modifiersProp ? getIsLateCheckFlag(modifiersProp) : 0; - const prop = createSymbol(SymbolFlags.Property | (isOptional ? SymbolFlags.Optional : 0), propName, - lateFlag | CheckFlags.Mapped | (isReadonly ? CheckFlags.Readonly : 0) | (stripOptional ? CheckFlags.StripOptional : 0)); - prop.mappedType = type; - prop.nameType = propNameType; - prop.keyType = keyType; - if (modifiersProp) { - prop.syntheticOrigin = modifiersProp; - prop.declarations = modifiersProp.declarations; - } - members.set(propName, prop); - } - } - else if (propNameType.flags & (TypeFlags.Any | TypeFlags.String | TypeFlags.Number | TypeFlags.Enum)) { - const propType = instantiateType(templateType, appendTypeMapping(type.mapper, typeParameter, keyType)); - if (propNameType.flags & (TypeFlags.Any | TypeFlags.String)) { - stringIndexInfo = createIndexInfo(stringIndexInfo ? getUnionType([stringIndexInfo.type, propType]) : propType, - !!(templateModifiers & MappedTypeModifiers.IncludeReadonly)); + getSymbolLinks(existingProp).nameType = combinedNameType; + } + + // When multiple keys overlap in the same slot, we choose the last type, provided it is the most derived type. + // This way if you have a type such as `{[x: "a" | "b"]: string; [x: "a"]: "a"}`, for prop `a`, we return type `"a"`. + // Index signature checking will issue an error if the signatures are inconsistent, however if they aren't, + // doing an intersection here should at worst case produce `never`. + // Conversely, for mapped types, suppose you have something akin to + // `{[K in "a" | "b" as "a"]: K extends "a" ? number : string}` - the "a" slot is overloaded, and has incompatible + // types, however unlike for index signatures, where we want to prefer the most specific declaration, + // a mapped type is defined to return the union of all possible values for the slots (being very permissive for + // writing, but incredibly pessimistic for reading). _That_ logic is handled by the deferred property type + // instantiation done for mapped symbols (which the below does not affect). + const existingType = getSymbolLinks(existingProp).type; + if (existingType) { + const newType = getPropType(); + getSymbolLinks(existingProp).type = intersectTypes(existingType, newType); + } + } + else { + const modifiersProp = isTypeUsableAsPropertyName(keyType) && modifiersType ? getPropertyOfType(modifiersType, getPropertyNameFromType(keyType)) : undefined; + 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 stripOptional = strictNullChecks && !isOptional && modifiersProp && modifiersProp.flags & SymbolFlags.Optional; + const lateFlag: CheckFlags = modifiersProp ? getIsLateCheckFlag(modifiersProp) : 0; + const prop = createSymbol(SymbolFlags.Property | (isOptional ? SymbolFlags.Optional : 0), propName, + lateFlag | CheckFlags.Mapped | (isReadonly ? CheckFlags.Readonly : 0) | (stripOptional ? CheckFlags.StripOptional : 0)); + if (mappedType) { + prop.mappedType = mappedType; } else { - numberIndexInfo = createIndexInfo(numberIndexInfo ? getUnionType([numberIndexInfo.type, propType]) : propType, - !!(templateModifiers & MappedTypeModifiers.IncludeReadonly)); + prop.type = getPropType(); + } + prop.nameType = propNameType; + prop.keyType = keyType; + if (modifiersProp) { + prop.syntheticOrigin = modifiersProp; + prop.declarations = modifiersProp.declarations; + } + container.members.set(propName, prop); + } + } + else if (!(propNameType.flags & TypeFlags.Never)) { + const propType = getPropType(); + container.indexInfos = container.indexInfos || []; + if (isTypeAny(propNameType)) { + // Legacy behavior. TODO: Remove. + propNameType = 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, propNameType]), propType, isReadonly)); + return; + } } } + if (sourceIndex && sourceIndex.indexType === propNameType && sourceIndex.type === propType && sourceIndex.isReadonly === isReadonly) { + container.indexInfos.push(sourceIndex); + } + else { + container.indexInfos.push(createIndexInfo(propNameType, propType, isReadonly, sourceIndex && sourceIndex.declaration)); + } } } @@ -11332,7 +11462,7 @@ namespace ts { } // The properties of a union type are those that are present in all constituent types, so // we only need to check the properties of the first type without index signature - if (type.flags & TypeFlags.Union && !getIndexInfoOfType(current, IndexKind.String) && !getIndexInfoOfType(current, IndexKind.Number)) { + if (type.flags & TypeFlags.Union && !getIndexInfosOfType(current)) { break; } } @@ -11778,10 +11908,12 @@ namespace ts { } } else if (isUnion) { - const indexInfo = !isLateBoundName(name) && (isNumericLiteralName(name) && getIndexInfoOfType(type, IndexKind.Number) || getIndexInfoOfType(type, IndexKind.String)); - if (indexInfo) { - checkFlags |= CheckFlags.WritePartial | (indexInfo.isReadonly ? CheckFlags.Readonly : 0); - indexTypes = append(indexTypes, isTupleType(type) ? getRestTypeOfTupleType(type) || undefinedType : indexInfo.type); + const index = !isLateBoundName(name) && ( + getResultingIndexInfosOfIndexOnType(type, getLiteralType(isNumericLiteralName(name) ? +name : "" + name)) + ); + if (index) { + checkFlags |= CheckFlags.WritePartial | (some(index, i => i.isReadonly) ? CheckFlags.Readonly : 0); + indexTypes = append(indexTypes, isTupleType(type) ? getRestTypeOfTupleType(type) || undefinedType : getIntersectionType(map(index, i => i.type))); } else if (isObjectLiteralType(type) && !(getObjectFlags(type) & ObjectFlags.ContainsSpread)) { checkFlags |= CheckFlags.WritePartial; @@ -11816,7 +11948,7 @@ namespace ts { const props = propSet ? arrayFrom(propSet.values()) : [singleProp]; 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; @@ -11831,7 +11963,6 @@ namespace ts { const type = getTypeOfSymbol(prop); if (!firstType) { firstType = type; - nameType = getSymbolLinks(prop).nameType; } else if (type !== firstType) { checkFlags |= CheckFlags.HasNonUniformType; @@ -11843,6 +11974,7 @@ namespace ts { checkFlags |= CheckFlags.HasNeverType; } propTypes.push(type); + nameTypes.push(getSymbolLinks(prop).nameType || getLiteralTypeFromProperty(prop, ~0, !(checkFlags & CheckFlags.ContainsPublic))); } addRange(propTypes, indexTypes); const result = createSymbol(SymbolFlags.Property | optionalFlag, name, syntheticFlag | checkFlags); @@ -11857,7 +11989,7 @@ namespace ts { } result.declarations = declarations; - result.nameType = nameType; + result.nameType = isUnion ? getIntersectionType(nameTypes) : getUnionType(nameTypes); if (propTypes.length > 2) { // When `propTypes` has the potential to explode in size when normalized, defer normalization until absolutely needed result.checkFlags |= CheckFlags.DeferredType; @@ -12012,41 +12144,61 @@ namespace ts { return getSignaturesOfStructuredType(getReducedApparentType(type), kind); } - function getIndexInfoOfStructuredType(type: Type, kind: IndexKind): IndexInfo | undefined { + function getIndexInfosOfStructuredType(type: Type): readonly 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(getReducedApparentType(type), kind); + function getIndexInfosOfType(type: Type): readonly IndexInfo[] | undefined { + return getIndexInfosOfStructuredType(getReducedApparentType(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(getReducedApparentType(type), kind); + // TODO (weswigham): Ensure all callers handle unions of `type` _before_ calling this + function getResultingIndexInfosOfIndexOnType(type: Type, indexType: Type): readonly IndexInfo[] | undefined { + return resolveIndexOnIndexInfos(indexType, getIndexInfosOfType(type)); + } + + function getApplicableIndexInfosOfIndexOnType(type: Type, indexType: Type, returnPartialSuccess?: boolean): (readonly IndexInfo[])[] | undefined { + if (!(indexType.flags & TypeFlags.Union)) { + const result = getResultingIndexInfosOfIndexOnType(type, indexType); + return result && [result]; + } + let resultList: (readonly IndexInfo[])[] | undefined; + for (const nameType of (indexType as UnionType).types) { + const result = getResultingIndexInfosOfIndexOnType(type, nameType); + if (!result && !returnPartialSuccess) { + return; + } + if (result) { + resultList = appendIfUnique(resultList, result); + } + } + return resultList; + } + + function getResultingTypeOfIndexOnType(type: Type, indexType: Type, returnPartialSuccess?: boolean): Type | undefined { + const resultInfos = getApplicableIndexInfosOfIndexOnType(type, indexType, returnPartialSuccess); + return resultInfos && getUnionType(map(resultInfos, applicableInfos => getIntersectionType(map(applicableInfos, 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 = getSymbolLinks(prop).nameType || getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique); + if (isTypeIndexAccessAssignableTo(nameType, targetIndexType)) { const propType = getTypeOfSymbol(prop); propTypes.push(prop.flags & SymbolFlags.Optional ? getTypeWithFacts(propType, TypeFacts.NEUndefined) : propType); } } - if (kind === IndexKind.String) { - append(propTypes, getIndexTypeOfType(type, IndexKind.Number)); + for (const info of getIndexInfosOfType(type) || emptyArray) { + if (isTypeIndexAccessAssignableTo(info.indexType, targetIndexType)) { + propTypes.push(info.type); + } } if (propTypes.length) { return getUnionType(propTypes); @@ -12493,7 +12645,7 @@ namespace ts { if (signatureHasRestParameter(signature)) { const sigRestType = getTypeOfSymbol(signature.parameters[signature.parameters.length - 1]); const restType = isTupleType(sigRestType) ? getRestTypeOfTupleType(sigRestType) : sigRestType; - return restType && getIndexTypeOfType(restType, IndexKind.Number); + return restType && getResultingTypeOfIndexOnType(restType, numberType); } return undefined; } @@ -12609,37 +12761,63 @@ namespace ts { return symbolTable.get(InternalSymbolName.Index); } - function getIndexDeclarationOfSymbol(symbol: Symbol | undefined, kind: IndexKind): IndexSignatureDeclaration | undefined { - const indexSymbol = symbol && getIndexSymbol(symbol); - return indexSymbol && getIndexDeclarationOfIndexSymbol(indexSymbol, kind); + function getIndexDeclarationsOfSymbol(symbol: Symbol) { + const indexSymbol = getIndexSymbol(symbol); + return indexSymbol && getIndexDeclarationsOfIndexSymbol(indexSymbol); } - function getIndexDeclarationOfIndexSymbol(indexSymbol: Symbol, kind: IndexKind): IndexSignatureDeclaration | undefined { - const syntaxKind = kind === IndexKind.Number ? SyntaxKind.NumberKeyword : SyntaxKind.StringKeyword; + function getIndexDeclarationsOfIndexSymbol(indexSymbol: Symbol): IndexSignatureDeclaration[] | undefined { + let result: IndexSignatureDeclaration[] | undefined; if (indexSymbol?.declarations) { 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; + return result; + } + + /** + * 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: readonly IndexInfo[] | undefined): readonly 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 => isTypeIndexAccessAssignableTo(indexType, info.indexType)); + if (!length(applicable)) return; + return applicable; + } + + function createIndexInfo(indexType: Type, type: Type, isReadonly: boolean, declaration?: IndexSignatureDeclaration): IndexInfo { + return { indexType, type, isReadonly, declaration }; } - function createIndexInfo(type: Type, isReadonly: boolean, declaration?: IndexSignatureDeclaration): IndexInfo { - return { type, isReadonly, declaration }; + function getIndexInfosOfSymbol(symbol: Symbol): IndexInfo[] | undefined { + const indexSymbol = getIndexSymbol(symbol); + return indexSymbol && getIndexInfosOfIndexSymbol(indexSymbol); } - function getIndexInfoOfSymbol(symbol: Symbol, kind: IndexKind): IndexInfo | undefined { - const declaration = getIndexDeclarationOfSymbol(symbol, kind); - if (declaration) { - return createIndexInfo(declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, - hasEffectiveModifier(declaration, ModifierFlags.Readonly), declaration); + function getIndexInfosOfIndexSymbol(indexSymbol: Symbol) { + const declarations = getIndexDeclarationsOfIndexSymbol(indexSymbol); + if (declarations) { + return map(declarations, declaration => createIndexInfo( + declaration.parameters?.[0]?.type ? getTypeFromTypeNode(declaration.parameters[0].type) : anyType, + declaration.type ? getTypeFromTypeNode(declaration.type) : anyType, + hasEffectiveModifier(declaration, ModifierFlags.Readonly), + declaration) + ); } return undefined; } @@ -13124,8 +13302,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; } @@ -13551,8 +13729,7 @@ namespace ts { type.declaredProperties = properties; type.declaredCallSignatures = emptyArray; type.declaredConstructSignatures = emptyArray; - type.declaredStringIndexInfo = undefined; - type.declaredNumberIndexInfo = undefined; + type.declaredIndexInfos = emptyArray; type.elementFlags = elementFlags; type.minLength = minLength; type.fixedLength = fixedLength; @@ -13613,7 +13790,7 @@ namespace ts { } else { // Treat everything else as an array type and create a rest element. - addElement(isArrayLikeType(type) && getIndexTypeOfType(type, IndexKind.Number) || errorType, ElementFlags.Rest, target.labeledElementDeclarations?.[i]); + addElement(isArrayLikeType(type) && getResultingTypeOfIndexOnType(type, numberType) || errorType, ElementFlags.Rest, target.labeledElementDeclarations?.[i]); } } else { @@ -14170,6 +14347,9 @@ namespace ts { // Also, unlike union types, the order of the constituent types is preserved in order that overload resolution // for intersections of types with signatures can be deterministic. function getIntersectionType(types: readonly Type[], aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[]): Type { + if (types.length === 1 && !aliasSymbol) { + return types[0]; + } const typeMembershipMap: ESMap = new Map(); const includes = addTypesToIntersection(typeMembershipMap, 0, types); const typeSet: Type[] = arrayFrom(typeMembershipMap.values()); @@ -14360,8 +14540,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 = getSymbolLinks(getLateBoundSymbol(prop)).nameType; if (!type) { if (prop.escapedName === InternalSymbolName.Default) { @@ -14385,9 +14565,24 @@ namespace ts { /*aliasSymbol*/ undefined, /*aliasTypeArguments*/ undefined, origin); } - function getNonEnumNumberIndexInfo(type: Type) { - const numberIndexInfo = getIndexInfoOfType(type, IndexKind.Number); - return numberIndexInfo !== enumNumberIndexInfo ? numberIndexInfo : undefined; + function calculateIndexTypeForObjectType(type: Type, stringsOnly: boolean, includeOrigin: boolean, noIndexSignatures?: boolean) { + const base = getUnionType([ + filterType(getUnionType(map(filter(getIndexInfosOfType(type) || emptyArray, info => info !== enumNumberIndexInfo), t => t.indexType)), t => !stringsOnly || isTypeAssignableTo(t, stringType)), + getLiteralTypeFromProperties(type, stringsOnly ? TypeFlags.StringLiteral : TypeFlags.StringOrNumberLiteralOrUnique, /*includeOrigin*/ false), + ]); + let result = base; + if (!stringsOnly && maybeTypeOfKind(base, TypeFlags.String)) { + result = getUnionType([base, numberType]); + } + if (noIndexSignatures) { + // symbol, number, string, and pattern template literals all make index signatures + result = filterType(result, t => isLiteralType(t)); + } + if (!(result.flags & TypeFlags.Union)) { + return result; + } + const origin = includeOrigin && (getObjectFlags(type) & (ObjectFlags.ClassOrInterface | ObjectFlags.Reference) || type.aliasSymbol) ? createOriginIndexType(type) : undefined; + return getUnionType((result as UnionType).types, UnionReduction.Literal, /*aliasSymbol*/ undefined, /*aliasTypeArguments*/ undefined, origin); } function getIndexType(type: Type, stringsOnly = keyofStringsOnly, noIndexSignatures?: boolean): Type { @@ -14400,10 +14595,7 @@ namespace ts { type === wildcardType ? wildcardType : type.flags & TypeFlags.Unknown ? neverType : type.flags & (TypeFlags.Any | TypeFlags.Never) ? keyofConstraintType : - stringsOnly ? !noIndexSignatures && getIndexInfoOfType(type, IndexKind.String) ? stringType : getLiteralTypeFromProperties(type, TypeFlags.StringLiteral, includeOrigin) : - !noIndexSignatures && getIndexInfoOfType(type, IndexKind.String) ? getUnionType([stringType, numberType, getLiteralTypeFromProperties(type, TypeFlags.UniqueESSymbol, includeOrigin)]) : - getNonEnumNumberIndexInfo(type) ? getUnionType([numberType, getLiteralTypeFromProperties(type, TypeFlags.StringLiteral | TypeFlags.UniqueESSymbol, includeOrigin)]) : - getLiteralTypeFromProperties(type, TypeFlags.StringOrNumberLiteralOrUnique, includeOrigin); + calculateIndexTypeForObjectType(type, stringsOnly, includeOrigin, noIndexSignatures); } function getExtractStringType(type: Type) { @@ -14653,7 +14845,7 @@ namespace ts { error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, unescapeLeadingUnderscores(propName), typeToString(objectType)); } } - errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, IndexKind.Number)); + errorIfWritingToReadonlyIndex(getResultingIndexInfosOfIndexOnType(objectType, numberType)); return mapType(objectType, t => { const restType = getRestTypeOfTupleType(t) || undefinedType; return noUncheckedIndexedAccessCandidate ? getUnionType([restType, undefinedType]) : restType; @@ -14664,22 +14856,24 @@ namespace ts { if (objectType.flags & (TypeFlags.Any | TypeFlags.Never)) { return objectType; } - const stringIndexInfo = getIndexInfoOfType(objectType, IndexKind.String); - const indexInfo = isTypeAssignableToKind(indexType, TypeFlags.NumberLike) && getIndexInfoOfType(objectType, IndexKind.Number) || stringIndexInfo; + const indexInfo = getResultingIndexInfosOfIndexOnType(objectType, indexType); if (indexInfo) { - if (accessFlags & AccessFlags.NoIndexSignatures && indexInfo === stringIndexInfo) { + if (accessFlags & AccessFlags.NoIndexSignatures && some(getResultingIndexInfosOfIndexOnType(objectType, stringType), i => some(indexInfo, i2 => i2 === i))) { if (accessExpression) { error(accessExpression, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(originalObjectType)); } return undefined; } - if (accessNode && !isTypeAssignableToKind(indexType, TypeFlags.String | TypeFlags.Number)) { + 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)); - return noUncheckedIndexedAccessCandidate ? getUnionType([indexInfo.type, undefinedType]) : indexInfo.type; + const resultType = getIntersectionType(map(indexInfo, i => i.type)); + return noUncheckedIndexedAccessCandidate ? getUnionType([resultType, undefinedType]) : resultType; } + errorIfWritingToReadonlyIndex(indexInfo); - return noUncheckedIndexedAccessCandidate ? getUnionType([indexInfo.type, undefinedType]) : indexInfo.type; + const resultType = getIntersectionType(map(indexInfo, i => i.type)); + return noUncheckedIndexedAccessCandidate ? getUnionType([resultType, undefinedType]) : resultType; } if (indexType.flags & TypeFlags.Never) { return neverType; @@ -14709,7 +14903,7 @@ namespace ts { const typeName = typeToString(objectType); error(accessExpression, Diagnostics.Property_0_does_not_exist_on_type_1_Did_you_mean_to_access_the_static_member_2_instead, propName as string, typeName, typeName + "[" + getTextOfNode(accessExpression.argumentExpression) + "]"); } - else if (getIndexTypeOfType(objectType, IndexKind.Number)) { + else if (getResultingIndexInfosOfIndexOnType(objectType, numberType)) { error(accessExpression.argumentExpression, Diagnostics.Element_implicitly_has_an_any_type_because_index_expression_is_not_of_type_number); } else { @@ -14775,8 +14969,9 @@ namespace ts { } return undefined; - function errorIfWritingToReadonlyIndex(indexInfo: IndexInfo | undefined): void { - if (indexInfo && indexInfo.isReadonly && accessExpression && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) { + function errorIfWritingToReadonlyIndex(indexInfos: readonly IndexInfo[] | undefined): void { + const indexInfo = find(indexInfos || emptyArray, i => i.isReadonly); + if (indexInfo && accessExpression && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) { error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType)); } } @@ -14941,6 +15136,11 @@ namespace ts { return getSimplifiedType(falseType, writing); } } + // TODO: Is the below necessary? + // const indexedType = getResultingTypeOfIndexOnType(objectType, indexType); + // if (indexedType) { + // return getSimplifiedType(indexedType); + // } return type; } @@ -15398,8 +15598,7 @@ namespace ts { members, emptyArray, emptyArray, - getIndexInfoOfType(type, IndexKind.String), - getIndexInfoOfType(type, IndexKind.Number)); + getIndexInfosOfType(type)); spread.objectFlags |= ObjectFlags.ObjectLiteral | ObjectFlags.ContainsObjectOrArrayLiteral; return spread; } @@ -15464,16 +15663,13 @@ namespace ts { const members = createSymbolTable(); const skippedPrivateMembers = new Set<__String>(); - let stringIndexInfo: IndexInfo | undefined; - let numberIndexInfo: IndexInfo | undefined; + let indexInfos: readonly 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)) { @@ -15514,10 +15710,16 @@ namespace ts { members, emptyArray, emptyArray, - getIndexInfoWithReadonly(stringIndexInfo, readonly), - getIndexInfoWithReadonly(numberIndexInfo, readonly)); + map(indexInfos, getReadonlyModifiedIndexSignature)); spread.objectFlags |= ObjectFlags.ObjectLiteral | ObjectFlags.ContainsObjectOrArrayLiteral | ObjectFlags.ContainsSpread | objectFlags; return spread; + + function getReadonlyModifiedIndexSignature(index: IndexInfo) { + if (index.isReadonly !== readonly) { + return createIndexInfo(index.indexType, index.type, readonly, index.declaration); + } + return index; + } } /** We approximate own properties as non-methods plus methods that are inside the object literal */ @@ -15541,10 +15743,6 @@ namespace ts { return result; } - function getIndexInfoWithReadonly(info: IndexInfo | undefined, readonly: boolean) { - return info && info.isReadonly !== readonly ? createIndexInfo(info.type, readonly, info.declaration) : info; - } - function createLiteralType(flags: TypeFlags, value: string | number | PseudoBigInt, symbol: Symbol | undefined) { const type = createType(flags); type.symbol = symbol!; @@ -16338,8 +16536,12 @@ namespace ts { return type.restrictiveInstantiation; } - 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(instantiateType(info.indexType, mapper), instantiateType(info.type, mapper), info.isReadonly, info.declaration); + } + + function instantiateIndexInfos(infos: readonly 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 @@ -16461,6 +16663,16 @@ namespace ts { return isTypeRelatedTo(source, target, assignableRelation); } + // Assignability, except number is assignable to string (and literal numbers are assignable to equivalent literal strings) + function isTypeIndexAccessAssignableTo(source: Type, target: Type): boolean { + return isTypeRelatedTo(source, target, indexAccessAssignableRelation); + } + + // Assignability, except string is assignable to number (and literal strings are assignable to equivalent literal numbers) + 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 @@ -16719,12 +16931,11 @@ namespace ts { let issuedElaboration = false; if (!targetProp) { - const indexInfo = isTypeAssignableToKind(nameType, TypeFlags.NumberLike) && getIndexInfoOfType(target, IndexKind.Number) || - getIndexInfoOfType(target, IndexKind.String) || - undefined; - if (indexInfo && indexInfo.declaration && !getSourceFileOfNode(indexInfo.declaration).hasNoDefaultLib) { + const indexInfo = flatten(getApplicableIndexInfosOfIndexOnType(target, nameType) || emptyArray); + const elaboratableInfo = indexInfo && indexInfo.length && 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)); } } @@ -16926,7 +17137,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; } @@ -17185,8 +17396,7 @@ namespace ts { t.properties.length === 0 && t.callSignatures.length === 0 && t.constructSignatures.length === 0 && - !t.stringIndexInfo && - !t.numberIndexInfo; + !length(t.indexInfos); } function isEmptyObjectType(type: Type): boolean { @@ -17204,7 +17414,7 @@ namespace ts { } function isStringIndexSignatureOnlyType(type: Type): boolean { - return type.flags & TypeFlags.Object && !isGenericMappedType(type) && getPropertiesOfType(type).length === 0 && getIndexInfoOfType(type, IndexKind.String) && !getIndexInfoOfType(type, IndexKind.Number) || + return type.flags & TypeFlags.Object && !isGenericMappedType(type) && getPropertiesOfType(type).length === 0 && length(getIndexInfosOfType(type)) === 1 && getIndexInfosOfType(type)![0].indexType === stringType || type.flags & TypeFlags.UnionOrIntersection && every((type).types, isStringIndexSignatureOnlyType) || false; } @@ -17269,7 +17479,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 @@ -17277,6 +17487,16 @@ namespace ts { if (s & (TypeFlags.Number | TypeFlags.NumberLiteral) && !(s & TypeFlags.EnumLiteral) && ( t & TypeFlags.Enum || relation === assignableRelation && 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.NumberLike && t & TypeFlags.String) return true; + } + if (relation === indexAssignableRelation) { + if (s & TypeFlags.String && t & TypeFlags.Number) return true; + } return false; } @@ -17918,7 +18138,7 @@ namespace ts { const appendPropType = (propTypes: Type[] | undefined, type: Type) => { type = getApparentType(type); const prop = type.flags & TypeFlags.UnionOrIntersection ? getPropertyOfUnionOrIntersectionType(type, name) : getPropertyOfObjectType(type, name); - const propType = prop && getTypeOfSymbol(prop) || isNumericLiteralName(name) && getIndexTypeOfType(type, IndexKind.Number) || getIndexTypeOfType(type, IndexKind.String) || undefinedType; + const propType = prop && getTypeOfSymbol(prop) || getResultingTypeOfIndexOnType(type, getLiteralType(unescapeLeadingUnderscores(name))) || undefinedType; return append(propTypes, propType); }; return getUnionType(reduceLeft(types, appendPropType, /*initial*/ undefined) || emptyArray); @@ -17929,7 +18149,7 @@ namespace ts { return false; // Disable excess property checks on JS literals to simulate having an implicit "index signature" - but only outside of noImplicitAny } const isComparingJsxAttributes = !!(getObjectFlags(source) & ObjectFlags.JsxAttributes); - if ((relation === assignableRelation || relation === comparableRelation) && + if ((relation === assignableRelation || relation === comparableRelation || relation === indexAssignableRelation || relation === indexAccessAssignableRelation) && (isTypeSubsetOf(globalObjectType, target) || (!isComparingJsxAttributes && isEmptyObjectType(target)))) { return false; } @@ -17941,7 +18161,7 @@ namespace ts { } for (const prop of getPropertiesOfType(source)) { if (shouldCheckAsExcessProperty(prop, source.symbol) && !isIgnoredJsxProperty(source, prop)) { - if (!isKnownProperty(reducedTarget, prop.escapedName, isComparingJsxAttributes)) { + if (!isKnownProperty(reducedTarget, getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique), prop.escapedName, isComparingJsxAttributes)) { if (reportErrors) { // Report error in terms of object types in the target as those are the only ones // we check in isKnownProperty. @@ -18712,7 +18932,7 @@ namespace ts { } else if (isReadonlyArrayType(target) ? isArrayType(source) || isTupleType(source) : isArrayType(target) && isTupleType(source) && !source.target.readonly) { if (relation !== identityRelation) { - return isRelatedTo(getIndexTypeOfType(source, IndexKind.Number) || anyType, getIndexTypeOfType(target, IndexKind.Number) || anyType, reportErrors); + return isRelatedTo(getResultingTypeOfIndexOnType(source, numberType) || anyType, getResultingTypeOfIndexOnType(target, numberType) || anyType, reportErrors); } else { // By flags alone, we know that the `target` is a readonly array while the source is a normal array or tuple @@ -18739,10 +18959,7 @@ namespace ts { if (result) { result &= signaturesRelatedTo(source, target, SignatureKind.Construct, reportStructuralErrors); if (result) { - result &= indexTypesRelatedTo(source, target, IndexKind.String, sourceIsPrimitive, reportStructuralErrors, intersectionState); - if (result) { - result &= indexTypesRelatedTo(source, target, IndexKind.Number, sourceIsPrimitive, reportStructuralErrors, intersectionState); - } + result &= indexTypesRelatedTo(source, target, sourceIsPrimitive, reportStructuralErrors, intersectionState); } } } @@ -18930,15 +19147,12 @@ namespace ts { result &= signaturesRelatedTo(source, type, SignatureKind.Call, /*reportStructuralErrors*/ false); if (result) { result &= signaturesRelatedTo(source, type, SignatureKind.Construct, /*reportStructuralErrors*/ false); - if (result) { - result &= indexTypesRelatedTo(source, type, IndexKind.String, /*sourceIsPrimitive*/ false, /*reportStructuralErrors*/ false, IntersectionState.None); - // Comparing numeric index types when both `source` and `type` are tuples is unnecessary as the + if (result && !(isTupleType(source) && isTupleType(type))) { + // Comparing index types when both `source` and `type` are tuples is unnecessary as the // element types should be sufficiently covered by `propertiesRelatedTo`. It also causes problems // with index type assignability as the types for the excluded discriminants are still included // in the index type. - if (result && !(isTupleType(source) && isTupleType(type))) { - result &= indexTypesRelatedTo(source, type, IndexKind.Number, /*sourceIsPrimitive*/ false, /*reportStructuralErrors*/ false, IntersectionState.None); - } + result &= indexTypesRelatedTo(source, type, /*sourceIsPrimitive*/ false, /*reportStructuralErrors*/ false, IntersectionState.None); } } } @@ -19009,6 +19223,14 @@ namespace ts { } function propertyRelatedTo(source: Type, target: Type, sourceProp: Symbol, targetProp: Symbol, getTypeOfSourceProperty: (sym: Symbol) => Type, reportErrors: boolean, intersectionState: IntersectionState, skipOptional: boolean): Ternary { + 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 sourcePropFlags = getDeclarationModifierFlagsFromSymbol(sourceProp); const targetPropFlags = getDeclarationModifierFlagsFromSymbol(targetProp); if (sourcePropFlags & ModifierFlags.Private || targetPropFlags & ModifierFlags.Private) { @@ -19418,7 +19640,7 @@ namespace ts { return result; } - function eachPropertyRelatedTo(source: Type, target: Type, kind: IndexKind, reportErrors: boolean): Ternary { + function eachPropertyRelatedToIndexesOf(source: Type, target: Type, reportErrors: boolean): Ternary { let result = Ternary.True; const props = source.flags & TypeFlags.Intersection ? getPropertiesOfUnionOrIntersectionType(source) : getPropertiesOfObjectType(source); for (const prop of props) { @@ -19426,16 +19648,16 @@ namespace ts { if (isIgnoredJsxProperty(source, prop)) { continue; } - const nameType = getSymbolLinks(prop).nameType; - if (nameType && nameType.flags & TypeFlags.UniqueESSymbol) { - continue; - } - if (kind === IndexKind.String || isNumericLiteralName(prop.escapedName)) { + const nameType = getSymbolLinks(prop).nameType || getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique, /*retainNonPublicNames*/ true); + if (nameType.flags & TypeFlags.Never) continue; + const targetType = getResultingTypeOfIndexOnType(target, nameType); + if (targetType) { const propType = getTypeOfSymbol(prop); - const type = propType.flags & TypeFlags.Undefined || !(kind === IndexKind.String && prop.flags & SymbolFlags.Optional) + // An index with an unbounded key component that is assignable to `string` allows `undefined` to be stripped from the source type (thus allowing optional property assignments) + const type = propType.flags & TypeFlags.Undefined || !(every(flatten(getApplicableIndexInfosOfIndexOnType(target, nameType) || emptyArray), i => !!forEachType(i.indexType, t => !(t.flags & TypeFlags.StringOrNumberLiteralOrUnique) && isTypeAssignableTo(t, stringType))) && prop.flags & SymbolFlags.Optional) ? propType : getTypeWithFacts(propType, TypeFacts.NEUndefined); - const related = isRelatedTo(type, target, reportErrors); + const related = isRelatedTo(type, targetType, reportErrors); if (!related) { if (reportErrors) { reportError(Diagnostics.Property_0_is_incompatible_with_index_signature, symbolToString(prop)); @@ -19448,51 +19670,60 @@ namespace ts { return result; } - function indexTypeRelatedTo(sourceType: Type, targetType: Type, reportErrors: boolean) { - const related = isRelatedTo(sourceType, targetType, reportErrors); - if (!related && reportErrors) { - reportError(Diagnostics.Index_signatures_are_incompatible); - } - return related; - } - - function indexTypesRelatedTo(source: Type, target: Type, kind: IndexKind, sourceIsPrimitive: boolean, reportErrors: boolean, intersectionState: IntersectionState): Ternary { + function indexTypesRelatedTo(source: Type, target: Type, sourceIsPrimitive: boolean, reportErrors: boolean, intersectionState: IntersectionState): Ternary { if (relation === identityRelation) { - return indexTypesIdenticalTo(source, target, kind); + return indexInfosIdentical(getIndexInfosOfType(source), getIndexInfosOfType(target)); } - const targetType = getIndexTypeOfType(target, kind); - if (!targetType) { + const targetInfo = getIndexInfosOfType(target); + if (!targetInfo) { return Ternary.True; } - if (targetType.flags & TypeFlags.Any && !sourceIsPrimitive) { - // An index signature of type `any` permits assignment from everything but primitives, - // provided that there is also a `string` index signature of type `any`. - const stringIndexType = kind === IndexKind.String ? targetType : getIndexTypeOfType(target, IndexKind.String); - if (stringIndexType && stringIndexType.flags & TypeFlags.Any) { - return Ternary.True; - } - - } if (isGenericMappedType(source)) { - // A generic mapped type { [P in K]: T } is related to a type with an index signature - // { [x: string]: U }, and optionally with an index signature { [x: number]: V }, - // if T is related to U and V. - return getIndexTypeOfType(target, IndexKind.String) ? isRelatedTo(getTemplateTypeFromMappedType(source), targetType, reportErrors) : Ternary.False; + // A generic mapped type { [P in K]: T } is related to an index signature { [x: string]: U } + // if T is related to U. + 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 (!isRelatedTo(getTemplateTypeFromMappedType(source), result, reportErrors)) { + return true; + } + }); + if (failed) { + return Ternary.False; + } + return hadSomeMatch ? Ternary.True : Ternary.False; } - const indexType = getIndexTypeOfType(source, kind) || kind === IndexKind.Number && getIndexTypeOfType(source, IndexKind.String); - if (indexType) { - return indexTypeRelatedTo(indexType, targetType, reportErrors); + const sourceInfo = getIndexInfosOfType(source); + if (sourceInfo) { + return indexInfosRelated(source, target, sourceIsPrimitive, reportErrors); } if (!(intersectionState & IntersectionState.Source) && isObjectTypeWithInferableIndex(source)) { - // Intersection constituents are never considered to have an inferred index signature - let related = eachPropertyRelatedTo(source, targetType, kind, reportErrors); - if (related && kind === IndexKind.String) { - const numberIndexType = getIndexTypeOfType(source, IndexKind.Number); - if (numberIndexType) { - related &= indexTypeRelatedTo(numberIndexType, targetType, reportErrors); - } + return eachPropertyRelatedToIndexesOf(source, target, reportErrors); + } + let hasTypedSignature = false; + let hasUnboundedBound = false; + for (const info of targetInfo) { + if (!(!sourceIsPrimitive && info.type.flags & TypeFlags.Any && info.indexType === stringType)) { + hasTypedSignature = true; } - return related; + 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)); @@ -19500,16 +19731,94 @@ 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) { - return Ternary.True; + function getInstantiationWithKeyBounds(type: StructuredType): Type { + if ((type as ResolvedType).indexKeysConstrainedInstantiation) { + return (type as ResolvedType).indexKeysConstrainedInstantiation!; } - if (sourceInfo && targetInfo && sourceInfo.isReadonly === targetInfo.isReadonly) { - return isRelatedTo(sourceInfo.type, targetInfo.type); + 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); } - return Ternary.False; + 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: readonly IndexInfo[] | undefined, targetInfos: readonly 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(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.Any) { + continue; + } + const indexingResult = getResultingTypeOfIndexOnType(source, targetInfo.indexType, sourceHasInferableIndex); + if (!indexingResult) { + if (sourceHasInferableIndex) { + continue; + } + 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 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; + } + } + } + return result; + } + } + 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) { @@ -19619,7 +19928,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)); } @@ -19631,7 +19940,7 @@ namespace ts { function hasCommonProperties(source: Type, target: Type, isComparingJsxAttributes: boolean) { for (const prop of getPropertiesOfType(source)) { - if (isKnownProperty(target, prop.escapedName, isComparingJsxAttributes)) { + if (isKnownProperty(target, getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique), prop.escapedName, isComparingJsxAttributes)) { return true; } } @@ -19926,6 +20235,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)); } @@ -20438,8 +20750,7 @@ namespace ts { members, resolved.callSignatures, resolved.constructSignatures, - resolved.stringIndexInfo, - resolved.numberIndexInfo); + resolved.indexInfos); regularNew.flags = resolved.flags; regularNew.objectFlags |= resolved.objectFlags & ~ObjectFlags.FreshLiteral; (type).regularType = regularNew; @@ -20518,12 +20829,10 @@ 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)); - result.objectFlags |= (getObjectFlags(type) & (ObjectFlags.JSLiteral | ObjectFlags.NonInferrableType)); // Retain js literal flag through widening + map(indexInfos, indexInfo => createIndexInfo(indexInfo.indexType, getWidenedType(indexInfo.type), indexInfo.isReadonly))); + result.objectFlags |= (getObjectFlags(type) & (ObjectFlags.JSLiteral | ObjectFlags.NonInferrableType)); // Retain js literal flag through widening return result; } @@ -20854,8 +21163,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); } /** @@ -20892,7 +21201,7 @@ namespace ts { function createReverseMappedType(source: Type, target: MappedType, constraint: IndexType) { // We consider a source type reverse mappable if it has a string index signature or if // it has one or more properties and is of a partially inferable type. - if (!(getIndexInfoOfType(source, IndexKind.String) || getPropertiesOfType(source).length !== 0 && isPartiallyInferableType(source))) { + if (!(getIndexInfosOfType(source) || getPropertiesOfType(source).length !== 0 && isPartiallyInferableType(source))) { return undefined; } // For arrays and tuples we infer new arrays and tuples where the reverse mapping has been @@ -21540,9 +21849,10 @@ namespace ts { return true; } if (constraintType.flags & TypeFlags.TypeParameter) { - // We're inferring from some source type S to a mapped type { [P in K]: X }, where K is a type - // parameter. First infer from 'keyof S' to K. + // We're inferring from some source type S to a mapped type { [P in T]: X }, where T is a type + // parameter. Infer from 'keyof S' to T and infer from a union of each property type in S to X. inferWithPriority(getIndexType(source), constraintType, InferencePriority.MappedTypeConstraint); + // If K is constrained to a type C, also infer to C. Thus, for a mapped type { [P in K]: X }, // where K extends keyof T, we make the same inferences as for a homomorphic mapped type // { [P in keyof T]: X }. This enables us to make meaningful inferences when the target is a @@ -21553,11 +21863,11 @@ namespace ts { } // If no inferences can be made to K's constraint, infer from a union of the property types // in the source to the template type X. - const propTypes = map(getPropertiesOfType(source), getTypeOfSymbol); - const stringIndexType = getIndexTypeOfType(source, IndexKind.String); - const numberIndexInfo = getNonEnumNumberIndexInfo(source); - const numberIndexType = numberIndexInfo && numberIndexInfo.type; - inferFromTypes(getUnionType(append(append(propTypes, stringIndexType), numberIndexType)), getTemplateTypeFromMappedType(target)); + const valueTypes = [ + ...mapDefined(getIndexInfosOfType(source), i => i.type), + ...map(getPropertiesOfType(source), getTypeOfSymbol) + ]; + inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(target)); return true; } return false; @@ -21718,21 +22028,29 @@ 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; + } + // Infer implicit indexes before any non-implicit ones + for (const targetInfo of targetInfos) { + const implicitIndexType = getImplicitIndexTypeOfType(source, targetInfo.indexType); + if (implicitIndexType) { + inferFromTypes(implicitIndexType, targetInfo.type); } } - 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); + const sourceInfos = getIndexInfosOfType(source); + if (!sourceInfos) { + return; + } + 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); + } } } } @@ -22305,10 +22623,9 @@ namespace ts { const nameType = getLiteralTypeFromPropertyName(name); if (!isTypeUsableAsPropertyName(nameType)) return errorType; const text = getPropertyNameFromType(nameType); - return getTypeOfPropertyOfType(type, text) || - isNumericLiteralName(text) && includeUndefinedInIndexSignature(getIndexTypeOfType(type, IndexKind.Number)) || - includeUndefinedInIndexSignature(getIndexTypeOfType(type, IndexKind.String)) || - errorType; + return getNarrowableTypeForReference(getTypeOfPropertyOfType(type, text) || + includeUndefinedInIndexSignature(getResultingTypeOfIndexOnType(type, getLiteralType(isNumericLiteralName(text) ? +text : unescapeLeadingUnderscores(text)))) || + errorType, name); } function getTypeOfDestructuredArrayElement(type: Type, index: number) { @@ -22512,22 +22829,6 @@ namespace ts { return containsType(target.types, source); } - function forEachType(type: Type, f: (t: Type) => T | undefined): T | undefined { - return type.flags & TypeFlags.Union ? forEach((type).types, f) : f(type); - } - - function someType(type: Type, f: (t: Type) => boolean): boolean { - return type.flags & TypeFlags.Union ? some((type).types, f) : f(type); - } - - function everyType(type: Type, f: (t: Type) => boolean): boolean { - return type.flags & TypeFlags.Union ? every((type).types, f) : f(type); - } - - function everyContainedType(type: Type, f: (t: Type) => boolean): boolean { - return type.flags & TypeFlags.UnionOrIntersection ? every((type as UnionOrIntersectionType).types, f) : f(type); - } - function filterType(type: Type, f: (t: Type) => boolean): Type { if (type.flags & TypeFlags.Union) { const types = (type).types; @@ -22705,6 +23006,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; } @@ -23488,7 +23790,7 @@ namespace ts { } function isTypePresencePossible(type: Type, propName: __String, assumeTrue: boolean) { - if (getIndexInfoOfType(type, IndexKind.String)) { + if (getResultingIndexInfosOfIndexOnType(type, stringType)) { return true; } const prop = getPropertyOfType(type, propName); @@ -25344,15 +25646,15 @@ namespace ts { return restType; } } - return isNumericLiteralName(name) && getIndexTypeOfContextualType(t, IndexKind.Number) || - getIndexTypeOfContextualType(t, IndexKind.String); + return isNumericLiteralName(name) && getResultingTypeOfIndexOnType(t, getLiteralType(+name)) || + getResultingTypeOfIndexOnType(t, getLiteralType(unescapeLeadingUnderscores(name))); } return undefined; }, /*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); } // In an object literal contextually typed by a type T, the contextual type of a property assignment is the type of @@ -25385,8 +25687,8 @@ namespace ts { return propertyType; } } - return isNumericName(element.name!) && getIndexTypeOfContextualType(type, IndexKind.Number) || - getIndexTypeOfContextualType(type, IndexKind.String); + return isNumericName(element.name!) && getIndexTypeOfContextualType(type, numberType) || + getIndexTypeOfContextualType(type, stringType); } return undefined; } @@ -26025,7 +26327,7 @@ namespace ts { // get the contextual element type from it. So we do something similar to // getContextualTypeForElementExpression, which will crucially not error // if there is no index type / iterated type. - const restElementType = getIndexTypeOfType(spreadType, IndexKind.Number) || + const restElementType = getResultingTypeOfIndexOnType(spreadType, numberType) || getIteratedTypeOrElementType(IterationUse.Destructuring, spreadType, undefinedType, /*errorNode*/ undefined, /*checkAssignability*/ false) || unknownType; elementTypes.push(restElementType); @@ -26158,7 +26460,7 @@ namespace ts { } } const unionType = propTypes.length ? getUnionType(propTypes, UnionReduction.Subtype) : undefinedType; - return createIndexInfo(unionType, isConstContext(node)); + return createIndexInfo(kind === IndexKind.Number ? numberType : stringType, unionType, isConstContext(node)); } function getImmediateAliasedSymbol(symbol: Symbol): Symbol | undefined { @@ -26256,7 +26558,7 @@ namespace ts { prop.flags |= impliedProp.flags & SymbolFlags.Optional; } - else if (!compilerOptions.suppressExcessPropertyErrors && !getIndexInfoOfType(contextualType!, IndexKind.String)) { + else if (!compilerOptions.suppressExcessPropertyErrors && !length(flatten(getApplicableIndexInfosOfIndexOnType(contextualType!, nameType || stringType) || emptyArray))) { error(memberDecl.name, Diagnostics.Object_literal_may_only_specify_known_properties_and_0_does_not_exist_in_type_1, symbolToString(member), typeToString(contextualType!)); } @@ -26366,9 +26668,14 @@ namespace ts { return createObjectLiteralType(); function createObjectLiteralType() { - const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo(node, offset, propertiesArray, IndexKind.String) : undefined; - const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node, 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, offset, propertiesArray, IndexKind.String)); + } + if (hasComputedNumberProperty) { + indexInfos = append(indexInfos, getObjectLiteralIndexInfo(node, offset, propertiesArray, IndexKind.Number)); + } + const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, indexInfos); result.objectFlags |= objectFlags | ObjectFlags.ObjectLiteral | ObjectFlags.ContainsObjectOrArrayLiteral; if (isJSObjectLiteral) { result.objectFlags |= ObjectFlags.JSLiteral; @@ -26554,7 +26861,7 @@ namespace ts { childrenPropSymbol.valueDeclaration.symbol = childrenPropSymbol; 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, objectFlags, /*readonly*/ false); } @@ -26575,7 +26882,7 @@ namespace ts { */ function createJsxAttributesType() { objectFlags |= freshObjectLiteralFlag; - const result = createAnonymousType(attributes.symbol, attributesTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined); + const result = createAnonymousType(attributes.symbol, attributesTable, emptyArray, emptyArray, /*indexInfos*/ undefined); result.objectFlags |= objectFlags | ObjectFlags.ObjectLiteral | ObjectFlags.ContainsObjectOrArrayLiteral; return result; } @@ -26648,7 +26955,7 @@ namespace ts { } // Intrinsic string indexer case - const indexSignatureType = getIndexTypeOfType(intrinsicElementsType, IndexKind.String); + const indexSignatureType = getResultingIndexInfosOfIndexOnType(intrinsicElementsType, stringType); if (indexSignatureType) { links.jsxFlags |= JsxFlags.IntrinsicIndexedElement; return links.resolvedSymbol = intrinsicElementsType.symbol; @@ -26818,7 +27125,7 @@ namespace ts { if (intrinsicProp) { return getTypeOfSymbol(intrinsicProp); } - const indexSignatureType = getIndexTypeOfType(intrinsicElementsType, IndexKind.String); + const indexSignatureType = getResultingTypeOfIndexOnType(intrinsicElementsType, stringType); if (indexSignatureType) { return indexSignatureType; } @@ -26873,7 +27180,7 @@ namespace ts { } else if (links.jsxFlags & JsxFlags.IntrinsicIndexedElement) { return links.resolvedJsxElementAttributesType = - getIndexTypeOfType(getJsxType(JsxNames.IntrinsicElements, node), IndexKind.String) || errorType; + getResultingTypeOfIndexOnType(getJsxType(JsxNames.IntrinsicElements, node), stringType) || errorType; } else { return links.resolvedJsxElementAttributesType = errorType; @@ -26972,14 +27279,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 (length(flatten(getApplicableIndexInfosOfIndexOnType(resolved, nameType) || emptyArray)) || getPropertyOfObjectType(targetType, name) || isComparingJsxAttributes && !isUnhyphenatedJsxName(name)) { // For JSXAttributes, if the attribute has a hyphenated name, consider that the attribute to be known. @@ -26988,7 +27295,7 @@ namespace ts { } else if (targetType.flags & TypeFlags.UnionOrIntersection && isExcessPropertyCheckTarget(targetType)) { for (const t of (targetType as UnionOrIntersectionType).types) { - if (isKnownProperty(t, name, isComparingJsxAttributes)) { + if (isKnownProperty(t, nameType, name, isComparingJsxAttributes)) { return true; } } @@ -27412,8 +27719,9 @@ namespace ts { let propType: Type; if (!prop) { - const indexInfo = !isPrivateIdentifier(right) && (assignmentKind === AssignmentKind.None || !isGenericObjectType(leftType) || isThisTypeParameter(leftType)) ? getIndexInfoOfType(apparentType, IndexKind.String) : undefined; - if (!(indexInfo && indexInfo.type)) { + const propNameType = getLiteralType(unescapeLeadingUnderscores(right.escapedText)); + const indexType = !isPrivateIdentifier(right) && (assignmentKind === AssignmentKind.None || !isGenericObjectType(leftType) || isThisTypeParameter(leftType)) ? getResultingTypeOfIndexOnType(apparentType, propNameType) : undefined; + if (!indexType) { if (isJSLiteralType(leftType)) { return anyType; } @@ -27431,11 +27739,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 = (compilerOptions.noUncheckedIndexedAccess && !isAssignmentTarget(node)) ? getUnionType([indexInfo.type, undefinedType]) : indexInfo.type; + propType = (compilerOptions.noUncheckedIndexedAccess && !isAssignmentTarget(node)) ? getUnionType([indexType, undefinedType]) : indexType; if (compilerOptions.noPropertyAccessFromIndexSignature && isPropertyAccessExpression(node)) { error(right, Diagnostics.Property_0_comes_from_an_index_signature_so_it_must_be_accessed_with_0, unescapeLeadingUnderscores(right.escapedText)); } @@ -27594,7 +27901,7 @@ namespace ts { let relatedInfo: Diagnostic | undefined; if (!isPrivateIdentifier(propNode) && containingType.flags & TypeFlags.Union && !(containingType.flags & TypeFlags.Primitive)) { for (const subtype of (containingType as UnionType).types) { - if (!getPropertyOfType(subtype, propNode.escapedText) && !getIndexInfoOfType(subtype, IndexKind.String)) { + if (!getPropertyOfType(subtype, propNode.escapedText) && !getResultingTypeOfIndexOnType(subtype, getLiteralTypeFromPropertyName(propNode))) { errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(propNode), typeToString(subtype)); break; } @@ -27886,7 +28193,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 getResultingIndexInfosOfIndexOnType(type, numberType) && !getResultingIndexInfosOfIndexOnType(type, stringType); } /** @@ -28142,7 +28449,7 @@ namespace ts { function getSingleSignature(type: Type, kind: SignatureKind, allowMembers: boolean): Signature | undefined { if (type.flags & TypeFlags.Object) { const resolved = resolveStructuredTypeMembers(type); - if (allowMembers || resolved.properties.length === 0 && !resolved.stringIndexInfo && !resolved.numberIndexInfo) { + if (allowMembers || resolved.properties.length === 0 && !length(resolved.indexInfos)) { if (kind === SignatureKind.Call && resolved.callSignatures.length === 1 && resolved.constructSignatures.length === 0) { return resolved.callSignatures[0]; } @@ -30001,7 +30308,7 @@ namespace ts { if (isInJSFile(node)) { const jsSymbol = getSymbolOfExpando(node, /*allowDeclaration*/ false); if (jsSymbol?.exports?.size) { - const jsAssignmentType = createAnonymousType(jsSymbol, jsSymbol.exports, emptyArray, emptyArray, undefined, undefined); + const jsAssignmentType = createAnonymousType(jsSymbol, jsSymbol.exports, emptyArray, emptyArray, undefined); jsAssignmentType.objectFlags |= ObjectFlags.JSLiteral; return getIntersectionType([returnType, jsAssignmentType]); } @@ -30104,7 +30411,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, /*objectFlags*/ 0, /*readonly*/ false) : defaultContainingObject; } @@ -30952,7 +31259,7 @@ namespace ts { } const returnType = getReturnTypeFromBody(node, checkMode); const returnOnlySignature = createSignature(undefined, undefined, undefined, emptyArray, returnType, /*resolvedTypePredicate*/ undefined, 0, SignatureFlags.None); - const returnOnlyType = createAnonymousType(node.symbol, emptySymbols, [returnOnlySignature], emptyArray, undefined, undefined); + const returnOnlyType = createAnonymousType(node.symbol, emptySymbols, [returnOnlySignature], emptyArray, undefined); returnOnlyType.objectFlags |= ObjectFlags.NonInferrableType; return links.contextFreeType = returnOnlyType; } @@ -32338,6 +32645,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 = []; @@ -32349,7 +32683,7 @@ namespace ts { texts.push(span.literal.text); types.push(isTypeAssignableTo(type, templateConstraintType) ? type : stringType); } - return isConstContext(node) || someType(getContextualType(node) || unknownType, isTemplateLiteralContextualType) ? getTemplateLiteralType(texts, types) : stringType; + return isConstContext(node) || someType(getContextualType(node) || unknownType, isTemplateLiteralContextualType) || isTemplateLiteralContext(node) ? getTemplateLiteralType(texts, types) : stringType; } function isTemplateLiteralContextualType(type: Type): boolean { @@ -33695,7 +34029,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. const apparentObjectType = getApparentType(objectType); - if (getIndexInfoOfType(apparentObjectType, IndexKind.Number) && isTypeAssignableToKind(indexType, TypeFlags.NumberLike)) { + if (getApplicableIndexInfosOfIndexOnType(apparentObjectType, getBaseConstraintOrType(indexType))) { return type; } if (isGenericObjectType(objectType)) { @@ -36020,7 +36354,7 @@ namespace ts { return hasStringConstituent ? possibleOutOfBounds ? includeUndefinedInIndexSignature(stringType) : 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 && !compilerOptions.noUncheckedIndexedAccess) { @@ -36861,17 +37195,13 @@ namespace ts { } function checkIndexConstraints(type: Type) { - const declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, IndexKind.Number); - const declaredStringIndexer = getIndexDeclarationOfSymbol(type.symbol, IndexKind.String); + const declaredIndexers = getIndexDeclarationsOfSymbol(type.symbol); + const indexInfos = getIndexInfosOfType(type); - const stringIndexType = getIndexTypeOfType(type, IndexKind.String); - const numberIndexType = getIndexTypeOfType(type, IndexKind.Number); - - if (stringIndexType || numberIndexType) { + 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, getLiteralTypeFromProperty(prop, TypeFlags.StringOrNumberLiteralOrUnique, /*retainNonpublicNames*/ true), propType, type, declaredIndexers); }); const classDeclaration = type.symbol.valueDeclaration; @@ -36883,40 +37213,65 @@ namespace ts { if (!hasSyntacticModifier(member, ModifierFlags.Static) && !hasBindableName(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, checkExpressionCached((member as DynamicNamedDeclaration).name.expression), 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 || !type.symbol.declarations ? 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 (isTypeIndexAccessAssignableTo(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, /*diagnosticMessage*/ undefined, rootChain); + } + } + }); + } } function checkIndexConstraintForProperty( prop: Symbol, + propName: Type, 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)) { - return; + indexDeclarations: Declaration[] | undefined + ): void { + 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; const name = propDeclaration && getNameOfDeclaration(propDeclaration); @@ -36925,17 +37280,12 @@ namespace ts { return; } - // index is numeric and property name is not valid numeric literal - if (indexKind === IndexKind.Number && !(name ? isNumericName(name) : isNumericLiteralName(prop.escapedName))) { - return; - } - // 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 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; } @@ -36946,16 +37296,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 || !containingType.symbol.declarations ? 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(resolvedType) + ); } } } @@ -40585,7 +40938,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) || globalArrayType; @@ -41181,23 +41534,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(node.type ? getTypeFromTypeNode(node.type) : anyType)); - } - - if (type.flags & TypeFlags.Union && allTypesAssignableToKind(type, TypeFlags.StringOrNumberLiteral, /*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_either_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/core.ts b/src/compiler/core.ts index dafda8263ad89..a462813bb845f 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -92,6 +92,22 @@ namespace ts { return undefined; } + export function forEachType(type: Type, f: (t: Type) => T | undefined): T | undefined { + return type.flags & TypeFlags.Union ? forEach((type).types, f) : f(type); + } + + export function someType(type: Type, f: (t: Type) => boolean): boolean { + return type.flags & TypeFlags.Union ? some((type).types, f) : f(type); + } + + export function everyType(type: Type, f: (t: Type) => boolean): boolean { + return type.flags & TypeFlags.Union ? every((type).types, f) : f(type); + } + + export function everyContainedType(type: Type, f: (t: Type) => boolean): boolean { + return type.flags & TypeFlags.UnionOrIntersection ? every((type as UnionOrIntersectionType).types, f) : f(type); + } + /** * Like `forEach`, but iterates in reverse order. */ diff --git a/src/compiler/debug.ts b/src/compiler/debug.ts index adf968fe2c7bd..1a4a20aa4dea7 100644 --- a/src/compiler/debug.ts +++ b/src/compiler/debug.ts @@ -171,6 +171,22 @@ namespace ts { return value; } + export function flagCheckerImmutableObject(object: T): T { + if (isDebugging) { + Object.defineProperties(object, { + __debugImmutable: { + value: true + } + }); + } + return object; + } + + export function assertMutable(object: T): T { + assert(!(object as any).__debugImmutable, "Object is flagged as checker-immutable, but is used in a position requiring mutation"); + return object; + } + /** * @deprecated Use `checkDefined` to check whether a value is defined inline. Use `assertIsDefined` to check whether * a value is defined at the statement level. diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 5c8810f5ea8ca..50b26c15d8e71 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -75,7 +75,7 @@ "category": "Error", "code": 1022 }, - "An index signature parameter type must be either 'string' or 'number'.": { + "An index signature parameter type must be assignable to 'string | number | symbol'.": { "category": "Error", "code": 1023 }, @@ -992,14 +992,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 @@ -1522,7 +1514,7 @@ "category": "Error", "code": 2329 }, - "Index signatures are incompatible.": { + "'{0}' and '{1}' index signatures are incompatible.": { "category": "Error", "code": 2330 }, @@ -1842,15 +1834,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 }, @@ -2682,6 +2670,10 @@ "category": "Error", "code": 2633 }, + "'{0}' index signatures are incompatible.": { + "category": "Error", + "code": 2634 + }, "Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": { "category": "Error", diff --git a/src/compiler/symbolWalker.ts b/src/compiler/symbolWalker.ts index b03ef31db6e11..7fff5008a5af0 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) => readonly IndexInfo[] | undefined, getConstraintOfTypeParameter: (typeParameter: TypeParameter) => Type | undefined, getFirstIdentifier: (node: EntityNameOrEntityNameExpression) => Identifier, getTypeArguments: (type: TypeReference) => readonly Type[]) { @@ -140,10 +140,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 430a2f2b20176..ef4b52d1cc418 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4056,9 +4056,9 @@ namespace ts { getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; getPrivateIdentifierPropertyOfType(leftType: Type, name: string, location: Node): Symbol | undefined; /* @internal */ getTypeOfPropertyOfType(type: Type, propertyName: string): Type | undefined; - getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined; + getIndexInfosOfType(type: Type, indexType?: Type): readonly IndexInfo[] | undefined; getSignaturesOfType(type: Type, kind: SignatureKind): readonly Signature[]; - 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; @@ -4086,8 +4086,8 @@ namespace ts { signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined): SignatureDeclaration & {typeArguments?: NodeArray} | undefined; /* @internal */ signatureToSignatureDeclaration(signature: Signature, kind: SyntaxKind, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined, tracker?: SymbolTracker): SignatureDeclaration & {typeArguments?: NodeArray} | undefined; // eslint-disable-line @typescript-eslint/unified-signatures /** Note that the resulting nodes cannot be checked. */ - indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined): IndexSignatureDeclaration | undefined; - /* @internal */ indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined, tracker?: SymbolTracker): IndexSignatureDeclaration | undefined; // eslint-disable-line @typescript-eslint/unified-signatures + indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, enclosingDeclaration: Node | undefined, flags?: NodeBuilderFlags): IndexSignatureDeclaration | undefined; + /* @internal */ indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, enclosingDeclaration: Node | undefined, flags?: NodeBuilderFlags, tracker?: SymbolTracker): IndexSignatureDeclaration | undefined; // eslint-disable-line @typescript-eslint/unified-signatures /** Note that the resulting nodes cannot be checked. */ symbolToEntityName(symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined): EntityName | undefined; /** Note that the resulting nodes cannot be checked. */ @@ -4210,9 +4210,10 @@ namespace ts { /* @internal */ createArrayType(elementType: Type): Type; /* @internal */ getElementTypeOfArrayType(arrayType: Type): Type | undefined; /* @internal */ createPromiseType(type: Type): Type; + /* @internal */ createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], indexInfos: IndexInfo[] | undefined): Type; // tslint:disable-line unified-signatures + /* @internal */ createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): Type; /* @internal */ isTypeAssignableTo(source: Type, target: Type): boolean; - /* @internal */ createAnonymousType(symbol: Symbol | undefined, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo | undefined, numberIndexInfo: IndexInfo | undefined): Type; /* @internal */ createSignature( declaration: SignatureDeclaration, typeParameters: readonly TypeParameter[] | undefined, @@ -4224,7 +4225,7 @@ namespace ts { flags: SignatureFlags ): 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 */ tryFindAmbientModule(moduleName: string): Symbol | undefined; /* @internal */ tryFindAmbientModuleWithoutAugmentations(moduleName: string): Symbol | undefined; @@ -5239,8 +5240,7 @@ namespace ts { /* @internal */ properties?: Symbol[]; // Properties /* @internal */ callSignatures?: readonly Signature[]; // Call signatures of type /* @internal */ constructSignatures?: readonly Signature[]; // Construct signatures of type - /* @internal */ stringIndexInfo?: IndexInfo; // String indexing info - /* @internal */ numberIndexInfo?: IndexInfo; // Numeric indexing info + /* @internal */ indexInfos?: readonly IndexInfo[]; // Index infos /* @internal */ objectTypeWithoutAbstractConstructSignatures?: ObjectType; } @@ -5265,8 +5265,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 } /** @@ -5424,6 +5423,7 @@ namespace ts { properties: Symbol[]; // Properties callSignatures: readonly Signature[]; // Call signatures of type constructSignatures: readonly Signature[]; // Construct signatures of type + indexKeysConstrainedInstantiation?: Type; } /* @internal */ @@ -5649,6 +5649,7 @@ namespace ts { } export interface IndexInfo { + indexType: Type; type: Type; isReadonly: boolean; declaration?: IndexSignatureDeclaration; diff --git a/src/harness/fourslashImpl.ts b/src/harness/fourslashImpl.ts index 742dc6bced721..5d29d1686442a 100644 --- a/src/harness/fourslashImpl.ts +++ b/src/harness/fourslashImpl.ts @@ -843,7 +843,7 @@ namespace FourSlash { else { for (const marker of toArray(options.marker)) { this.goToMarker(marker); - this.verifyCompletionsWorker(options); + this.verifyCompletionsWorker({ ...options, marker }); } } } diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index bfa5241a84d94..2d06f8f68e928 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -94,7 +94,7 @@ interface PropertyDescriptor { } interface PropertyDescriptorMap { - [s: string]: PropertyDescriptor; + [s: string | number | symbol]: PropertyDescriptor; } interface Object { diff --git a/src/server/session.ts b/src/server/session.ts index 93013251e1ef4..aa3e3babe9f70 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -2574,26 +2574,26 @@ namespace ts.server { } private handlers = new Map(getEntries<(request: protocol.Request) => HandlerResponse>({ - [CommandNames.Status]: () => { + [protocol.CommandTypes.Status]: () => { const response: protocol.StatusResponseBody = { version: ts.version }; // eslint-disable-line @typescript-eslint/no-unnecessary-qualifier 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, request.arguments.includeProjectReferenceRedirectInfo); if (!result.some(p => p.projectErrors && p.projectErrors.length !== 0)) { return this.requiredResponse(result); @@ -2611,7 +2611,7 @@ namespace ts.server { }); return this.requiredResponse(converted); }, - [CommandNames.UpdateOpen]: (request: protocol.UpdateOpenRequest) => { + [protocol.CommandTypes.UpdateOpen]: (request: protocol.UpdateOpenRequest) => { this.changeSeq++; this.projectService.applyChangesInOpenFiles( request.arguments.openFiles && mapIterator(arrayIterator(request.arguments.openFiles), file => ({ @@ -2633,7 +2633,7 @@ namespace ts.server { ); return this.requiredResponse(/*response*/ true); }, - [CommandNames.ApplyChangedToOpenFiles]: (request: protocol.ApplyChangedToOpenFilesRequest) => { + [protocol.CommandTypes.ApplyChangedToOpenFiles]: (request: protocol.ApplyChangedToOpenFilesRequest) => { this.changeSeq++; this.projectService.applyChangesInOpenFiles( request.arguments.openFiles && arrayIterator(request.arguments.openFiles), @@ -2647,50 +2647,50 @@ namespace ts.server { // 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, @@ -2698,224 +2698,224 @@ 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.FileReferences]: (request: protocol.FileReferencesRequest) => { + [protocol.CommandTypes.FileReferences]: (request: protocol.FileReferencesRequest) => { return this.requiredResponse(this.getFileReferences(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.FileReferencesFull]: (request: protocol.FileReferencesRequest) => { + [protocol.CommandTypes.FileReferencesFull]: (request: protocol.FileReferencesRequest) => { return this.requiredResponse(this.getFileReferences(request.arguments, /*simplifiedResult*/ false)); }, - [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, /*fullResult*/ false)); }, - [CommandNames.CompletionDetailsFull]: (request: protocol.CompletionDetailsRequest) => { + [protocol.CommandTypes.CompletionDetailsFull]: (request: protocol.CompletionDetailsRequest) => { return this.requiredResponse(this.getCompletionEntryDetails(request.arguments, /*fullResult*/ true)); }, - [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.EncodedSyntacticClassificationsFull]: (request: protocol.EncodedSyntacticClassificationsRequest) => { + [protocol.CommandTypes.EncodedSyntacticClassificationsFull]: (request: protocol.EncodedSyntacticClassificationsRequest) => { return this.requiredResponse(this.getEncodedSyntacticClassifications(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)); }, [CommandNames.ConfigurePlugin]: (request: protocol.ConfigurePluginRequest) => { diff --git a/src/services/codefixes/convertToMappedObjectType.ts b/src/services/codefixes/convertToMappedObjectType.ts deleted file mode 100644 index 687b7318bbe94..0000000000000 --- a/src/services/codefixes/convertToMappedObjectType.ts +++ /dev/null @@ -1,57 +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 factory.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 = factory.createTypeParameterDeclaration(cast(parameter.name, isIdentifier), parameter.type); - const mappedIntersectionType = factory.createMappedTypeNode( - hasEffectiveReadonlyModifier(indexSignature) ? factory.createModifier(SyntaxKind.ReadonlyKeyword) : undefined, - mappedTypeParameter, - /*nameType*/ undefined, - indexSignature.questionToken, - indexSignature.type); - const intersectionType = factory.createIntersectionTypeNode([ - ...getAllSuperTypeNodes(container), - mappedIntersectionType, - ...(otherMembers.length ? [factory.createTypeLiteralNode(otherMembers)] : emptyArray), - ]); - changes.replaceNode(sourceFile, container, createTypeAliasFromInterface(container, intersectionType)); - } -} diff --git a/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts b/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts index 01410672b3f28..32eba38a13141 100644 --- a/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts +++ b/src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts @@ -56,21 +56,20 @@ namespace ts.codefix { const classType = checker.getTypeAtLocation(classDeclaration); const constructor = find(classDeclaration.members, m => isConstructorDeclaration(m)); - if (!classType.getNumberIndexType()) { - createMissingIndexSignatureDeclaration(implementedType, IndexKind.Number); - } - if (!classType.getStringIndexType()) { - createMissingIndexSignatureDeclaration(implementedType, IndexKind.String); - } + createMissingIndexSignatureDeclarations(implementedType, classType); const importAdder = createImportAdder(sourceFile, context.program, preferences, context.host); createMissingMemberNodes(classDeclaration, nonPrivateAndNotExistedInHeritageClauseMembers, sourceFile, context, preferences, importAdder, member => insertInterfaceMemberNode(sourceFile, classDeclaration, member)); importAdder.writeFixes(changeTracker); - function createMissingIndexSignatureDeclaration(type: InterfaceType, kind: IndexKind): void { - const indexInfoOfKind = checker.getIndexInfoOfType(type, kind); - if (indexInfoOfKind) { - insertInterfaceMemberNode(sourceFile, classDeclaration, checker.indexInfoToIndexSignatureDeclaration(indexInfoOfKind, kind, classDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context))!); + 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, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context))!); + } + } } } diff --git a/src/services/codefixes/fixInvalidImportSyntax.ts b/src/services/codefixes/fixInvalidImportSyntax.ts index 9728cc032f250..c25d6efd62f48 100644 --- a/src/services/codefixes/fixInvalidImportSyntax.ts +++ b/src/services/codefixes/fixInvalidImportSyntax.ts @@ -57,9 +57,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 303e86884f9e3..5cc7ea5eb9b3c 100644 --- a/src/services/codefixes/inferFromUsage.ts +++ b/src/services/codefixes/inferFromUsage.ts @@ -943,10 +943,7 @@ namespace ts.codefix { } const calls = []; const constructs = []; - const stringIndices = []; - const numberIndices = []; - let stringIndexReadonly = false; - let numberIndexReadonly = false; + const indicies = []; const props = createMultiMap(); for (const anon of anons) { for (const p of checker.getPropertiesOfType(anon)) { @@ -954,13 +951,8 @@ namespace ts.codefix { } calls.push(...checker.getSignaturesOfType(anon, SignatureKind.Call)); constructs.push(...checker.getSignaturesOfType(anon, SignatureKind.Construct)); - if (anon.stringIndexInfo) { - stringIndices.push(anon.stringIndexInfo.type); - stringIndexReadonly = stringIndexReadonly || anon.stringIndexInfo.isReadonly; - } - if (anon.numberIndexInfo) { - numberIndices.push(anon.numberIndexInfo.type); - numberIndexReadonly = numberIndexReadonly || anon.numberIndexInfo.isReadonly; + if (anon.indexInfos) { + indicies.push(...anon.indexInfos); } } const members = mapEntries(props, (name, types) => { @@ -974,8 +966,7 @@ namespace ts.codefix { members as UnderscoreEscapedMap, calls, constructs, - stringIndices.length ? checker.createIndexInfo(checker.getUnionType(stringIndices), stringIndexReadonly) : undefined, - numberIndices.length ? checker.createIndexInfo(checker.getUnionType(numberIndices), numberIndexReadonly) : undefined); + indicies); } function inferTypes(usage: Usage): Type[] { @@ -1014,7 +1005,7 @@ namespace ts.codefix { } const callSignatures: Signature[] = usage.calls ? [getSignatureFromCalls(usage.calls)] : []; const constructSignatures: Signature[] = usage.constructs ? [getSignatureFromCalls(usage.constructs)] : []; - const stringIndexInfo = usage.stringIndex && checker.createIndexInfo(combineFromUsage(usage.stringIndex), /*isReadonly*/ false); + const stringIndexInfo = usage.stringIndex && checker.createIndexInfo(checker.getStringType(), combineFromUsage(usage.stringIndex), /*isReadonly*/ false); return checker.createAnonymousType(/*symbol*/ undefined, members, callSignatures, constructSignatures, stringIndexInfo, /*numberIndexInfo*/ undefined); } diff --git a/src/services/completions.ts b/src/services/completions.ts index 98d5add6fe0a4..07c3e99ff5d4b 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1407,7 +1407,7 @@ namespace ts.Completions { } function addTypeProperties(type: Type, insertAwait: boolean, insertQuestionDot: boolean): void { - isNewIdentifierLocation = !!type.getStringIndexType(); + isNewIdentifierLocation = !!type.getTypeIndexedByType(typeChecker.getStringType()); if (isRightOfQuestionDot && some(type.getCallSignatures())) { isNewIdentifierLocation = true; } @@ -1968,15 +1968,15 @@ namespace ts.Completions { return GlobalsSearch.Continue; } const completionsType = typeChecker.getContextualType(objectLikeContainer, ContextFlags.Completions); - const hasStringIndexType = (completionsType || instantiatedType).getStringIndexType(); - const hasNumberIndextype = (completionsType || instantiatedType).getNumberIndexType(); - isNewIdentifierLocation = !!hasStringIndexType || !!hasNumberIndextype; + const hasOpenStringIndexType = some(typeChecker.getIndexInfosOfType(completionsType || instantiatedType), i => !!forEachType(i.indexType, t => !!(t.flags & TypeFlags.String) || !!(t.flags & TypeFlags.TemplateLiteral))); + const hasOtherOpenIndexType = some(typeChecker.getIndexInfosOfType(completionsType || instantiatedType), i => !!forEachType(i.indexType, t => !!(t.flags & TypeFlags.Number) || !!(t.flags & TypeFlags.ESSymbol))); + isNewIdentifierLocation = !!hasOpenStringIndexType || !!hasOtherOpenIndexType; typeMembers = getPropertiesForObjectExpression(instantiatedType, completionsType, objectLikeContainer, typeChecker); existingMembers = objectLikeContainer.properties; if (typeMembers.length === 0) { - // Edge case: If NumberIndexType exists - if (!hasNumberIndextype) { + // If there is only a non-string indexer, we are OK to return empty completions, otherwise we should return the global completions + if (!hasOtherOpenIndexType || hasOpenStringIndexType) { isNonContextualObjectLiteral = true; return GlobalsSearch.Continue; } diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index d4f317d754314..d7b087e8e7c6e 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -214,10 +214,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 08f6c8897a29d..b4e6ae28c2651 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -440,11 +440,8 @@ namespace ts { getConstructSignatures(): readonly Signature[] { 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/tsconfig.json b/src/services/tsconfig.json index 1e846b9214d16..f420d08d6d004 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -103,7 +103,6 @@ "codefixes/useBigintLiteral.ts", "codefixes/fixAddModuleReferTypeMissingTypeof.ts", "codefixes/wrapJsxInFragment.ts", - "codefixes/convertToMappedObjectType.ts", "codefixes/removeAccidentalCallParentheses.ts", "codefixes/removeUnnecessaryAwait.ts", "codefixes/splitTypeOnlyImport.ts", diff --git a/src/services/types.ts b/src/services/types.ts index be1d09ff69c57..c0eca881082ef 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -54,8 +54,7 @@ namespace ts { getApparentProperties(): Symbol[]; getCallSignatures(): readonly Signature[]; getConstructSignatures(): readonly Signature[]; - getStringIndexType(): Type | undefined; - getNumberIndexType(): Type | undefined; + getTypeIndexedByType(indexType: Type): Type | undefined; getBaseTypes(): BaseType[] | undefined; getNonNullableType(): Type; /*@internal*/ getNonOptionalType(): Type; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index e91f962e80eef..02bf218c3b716 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -2603,7 +2603,7 @@ namespace ts { } export function hasIndexSignature(type: Type): boolean { - return !!type.getStringIndexType() || !!type.getNumberIndexType(); + return !!type.getTypeIndexedByType(type.checker.getNumberType()) || !!type.getTypeIndexedByType(type.checker.getStringType()); } export function getSwitchedType(caseClause: CaseClause, checker: TypeChecker): Type | undefined { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index edd094bb4d964..3bde1c9d7708b 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2169,9 +2169,9 @@ declare namespace ts { getPropertiesOfType(type: Type): Symbol[]; getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; getPrivateIdentifierPropertyOfType(leftType: Type, name: string, location: Node): Symbol | undefined; - getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined; + getIndexInfosOfType(type: Type, indexType?: Type): readonly IndexInfo[] | undefined; getSignaturesOfType(type: Type, kind: SignatureKind): readonly Signature[]; - 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; @@ -2186,7 +2186,7 @@ declare namespace ts { typeArguments?: NodeArray; } | undefined; /** Note that the resulting nodes cannot be checked. */ - indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined): IndexSignatureDeclaration | undefined; + indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, enclosingDeclaration: Node | undefined, flags?: NodeBuilderFlags): IndexSignatureDeclaration | undefined; /** Note that the resulting nodes cannot be checked. */ symbolToEntityName(symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined): EntityName | undefined; /** Note that the resulting nodes cannot be checked. */ @@ -2584,8 +2584,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 @@ -2699,6 +2698,7 @@ declare namespace ts { Number = 1 } export interface IndexInfo { + indexType: Type; type: Type; isReadonly: boolean; declaration?: IndexSignatureDeclaration; @@ -5389,8 +5389,7 @@ declare namespace ts { getApparentProperties(): Symbol[]; getCallSignatures(): readonly Signature[]; getConstructSignatures(): readonly Signature[]; - 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 de5f04cd820df..93311b0652116 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2169,9 +2169,9 @@ declare namespace ts { getPropertiesOfType(type: Type): Symbol[]; getPropertyOfType(type: Type, propertyName: string): Symbol | undefined; getPrivateIdentifierPropertyOfType(leftType: Type, name: string, location: Node): Symbol | undefined; - getIndexInfoOfType(type: Type, kind: IndexKind): IndexInfo | undefined; + getIndexInfosOfType(type: Type, indexType?: Type): readonly IndexInfo[] | undefined; getSignaturesOfType(type: Type, kind: SignatureKind): readonly Signature[]; - 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; @@ -2186,7 +2186,7 @@ declare namespace ts { typeArguments?: NodeArray; } | undefined; /** Note that the resulting nodes cannot be checked. */ - indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, kind: IndexKind, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined): IndexSignatureDeclaration | undefined; + indexInfoToIndexSignatureDeclaration(indexInfo: IndexInfo, enclosingDeclaration: Node | undefined, flags?: NodeBuilderFlags): IndexSignatureDeclaration | undefined; /** Note that the resulting nodes cannot be checked. */ symbolToEntityName(symbol: Symbol, meaning: SymbolFlags, enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined): EntityName | undefined; /** Note that the resulting nodes cannot be checked. */ @@ -2584,8 +2584,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 @@ -2699,6 +2698,7 @@ declare namespace ts { Number = 1 } export interface IndexInfo { + indexType: Type; type: Type; isReadonly: boolean; declaration?: IndexSignatureDeclaration; @@ -5389,8 +5389,7 @@ declare namespace ts { getApparentProperties(): Symbol[]; getCallSignatures(): readonly Signature[]; getConstructSignatures(): readonly Signature[]; - 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/arraySigChecking.errors.txt b/tests/baselines/reference/arraySigChecking.errors.txt index 5bf4cfdd58e07..b1c8d6055252f 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 either '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,27): error TS2322: Type 'void' is not assignable to type 'string'. tests/cases/compiler/arraySigChecking.ts(22,13): error TS2322: Type 'number' is not assignable to type 'number[]'. tests/cases/compiler/arraySigChecking.ts(22,16): error TS2322: Type 'number' is not assignable to type 'number[]'. @@ -16,8 +16,8 @@ tests/cases/compiler/arraySigChecking.ts(22,16): error TS2322: Type 'number' is } var foo: { [index: any]; }; // expect an error here - ~~~~~ -!!! error TS1023: An index signature parameter type must be either 'string' or 'number'. + ~~~~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. } interface myInt { diff --git a/tests/baselines/reference/arraySigChecking.types b/tests/baselines/reference/arraySigChecking.types index bbde4920731a6..def541ed3e999 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: string]: any; } >index : any } diff --git a/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt b/tests/baselines/reference/assignmentCompatWithNumericIndexer.errors.txt index 7358455430c80..2a2a3f3abcef5 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. Property 'bar' is missing in type 'Base' but required in type 'Derived'. 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 missing the following properties from type 'Derived2': baz, bar 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'. 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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'. 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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: Property 'bar' is missing in type 'Base' but required in type 'Derived'. !!! related TS2728 tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer.ts:4:34: 'bar' is declared here. @@ -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 missing the following properties from type 'Derived2': baz, bar module Generics { @@ -66,13 +66,13 @@ 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'. !!! error TS2322: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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,13 +80,13 @@ 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'. !!! error TS2322: 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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 f4b2e46f44f96..e294347084798 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. Property 'bar' is missing in type 'Base' but required in type 'Derived'. 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 missing the following properties from type 'Derived2': baz, bar 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'. 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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'. 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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: Property 'bar' is missing in type 'Base' but required in type 'Derived'. !!! related TS2728 tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer2.ts:4:34: 'bar' is declared here. @@ -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 missing the following properties from type 'Derived2': baz, bar module Generics { @@ -66,13 +66,13 @@ 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'. !!! error TS2322: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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,13 +80,13 @@ 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'. !!! error TS2322: 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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 1f279ba2858f7..5b72d9f1ec2de 100644 --- a/tests/baselines/reference/assignmentCompatWithNumericIndexer3.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithNumericIndexer3.errors.txt @@ -1,11 +1,11 @@ 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. Property 'bar' is missing in type 'Base' but required in type 'Derived'. 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. Property 'baz' is missing in type 'Derived' but required in type 'Derived2'. 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'. 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'. @@ -27,7 +27,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: Property 'bar' is missing in type 'Base' but required in type 'Derived'. !!! related TS2728 tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3.ts:4:34: 'bar' is declared here. b = a; // ok @@ -41,7 +41,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: Property 'baz' is missing in type 'Derived' but required in type 'Derived2'. !!! related TS2728 tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithNumericIndexer3.ts:5:38: 'baz' is declared here. @@ -56,7 +56,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'. !!! error TS2322: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'. b = a; // ok diff --git a/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt b/tests/baselines/reference/assignmentCompatWithStringIndexer.errors.txt index b3970325dc298..9c5b1e1c11fbc 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. Property 'bar' is missing in type 'Base' but required in type 'Derived'. 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 missing the following properties from type 'Derived2': baz, bar 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'. 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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'. 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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: Property 'bar' is missing in type 'Base' but required in type 'Derived'. !!! related TS2728 tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer.ts:4:34: 'bar' is declared here. @@ -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 missing the following properties from type 'Derived2': baz, bar module Generics { @@ -73,7 +73,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 { @@ -85,7 +85,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() { @@ -94,13 +94,13 @@ 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'. !!! error TS2322: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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,13 +108,13 @@ 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'. !!! error TS2322: 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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 f90f8a41feb05..6247b5f1c48bc 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. Property 'bar' is missing in type 'Base' but required in type 'Derived'. 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 missing the following properties from type 'Derived2': baz, bar 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'. 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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'. 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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: Property 'bar' is missing in type 'Base' but required in type 'Derived'. !!! related TS2728 tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithStringIndexer2.ts:4:34: 'bar' is declared here. @@ -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 missing the following properties from type 'Derived2': baz, bar module Generics { @@ -73,7 +73,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 { @@ -85,7 +85,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() { @@ -94,13 +94,13 @@ 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'. !!! error TS2322: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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,13 +108,13 @@ 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'. !!! error TS2322: 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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 dc1acb8de071a..d3735e6f19901 100644 --- a/tests/baselines/reference/assignmentCompatWithStringIndexer3.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithStringIndexer3.errors.txt @@ -1,10 +1,10 @@ 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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'string'. 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'. @@ -34,13 +34,13 @@ 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'. !!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'string'. 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/bigintIndex.errors.txt b/tests/baselines/reference/bigintIndex.errors.txt index 216e2d4857f07..0afa93365e400 100644 --- a/tests/baselines/reference/bigintIndex.errors.txt +++ b/tests/baselines/reference/bigintIndex.errors.txt @@ -1,4 +1,5 @@ -tests/cases/compiler/a.ts(2,6): error TS1023: An index signature parameter type must be either 'string' or 'number'. +tests/cases/compiler/a.ts(2,6): error TS1023: An index signature parameter type must be assignable to 'string | number | symbol'. + Type 'bigint' is not assignable to type 'string | number | symbol'. tests/cases/compiler/a.ts(8,11): error TS2538: Type '1n' cannot be used as an index type. tests/cases/compiler/a.ts(14,1): error TS2322: Type 'bigint' is not assignable to type 'string | number | symbol'. tests/cases/compiler/a.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type. @@ -13,7 +14,8 @@ tests/cases/compiler/b.ts(4,12): error TS2464: A computed property name must be interface BigIntIndex { [index: bigint]: E; // should error ~~~~~ -!!! error TS1023: An index signature parameter type must be either 'string' or 'number'. +!!! error TS1023: An index signature parameter type must be assignable to 'string | number | symbol'. +!!! error TS1023: Type 'bigint' is not assignable to type 'string | number | symbol'. } const arr: number[] = [1, 2, 3]; diff --git a/tests/baselines/reference/bigintIndex.types b/tests/baselines/reference/bigintIndex.types index a70c1f9aec573..1d80ce04fe707 100644 --- a/tests/baselines/reference/bigintIndex.types +++ b/tests/baselines/reference/bigintIndex.types @@ -18,9 +18,9 @@ let num: number = arr[1]; >1 : 1 num = arr["1"]; ->num = arr["1"] : any +>num = arr["1"] : number >num : number ->arr["1"] : any +>arr["1"] : number >arr : number[] >"1" : "1" @@ -84,7 +84,7 @@ typedArray[String(bigNum)] = 0xAA; typedArray["1"] = 0xBB; >typedArray["1"] = 0xBB : 187 ->typedArray["1"] : any +>typedArray["1"] : number >typedArray : Uint8Array >"1" : "1" >0xBB : 187 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/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 97169b771d382..67ced5db340ba 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/computedPropertyNames11_ES5.types b/tests/baselines/reference/computedPropertyNames11_ES5.types index 944f4a4cfcc3b..a2a3a023aea65 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 1d9551ea082be..c330cd7ba3f90 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/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..7db9feb85e2f2 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(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'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES5.ts (2 errors) ==== @@ -8,14 +8,14 @@ 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'. +!!! 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..935f34bf7c769 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(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'. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames45_ES6.ts (2 errors) ==== @@ -8,14 +8,14 @@ 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'. +!!! 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/computedPropertyNames4_ES5.types b/tests/baselines/reference/computedPropertyNames4_ES5.types index b9181140ed56c..9d83dd42df0b5 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 669af26ebdf12..ff58b2dd5a6a8 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/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/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/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/computedPropertyNamesContextualType8_ES5.errors.txt b/tests/baselines/reference/computedPropertyNamesContextualType8_ES5.errors.txt index ee36609095a04..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'. - 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: 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 1048fd2e119e7..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'. - 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: 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 e76b3a704dc6e..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'. - 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: 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 468ad400c26cc..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'. - 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: 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/controlFlowOptionalChain.types b/tests/baselines/reference/controlFlowOptionalChain.types index 4e335fca6d287..1bcdf65de093e 100644 --- a/tests/baselines/reference/controlFlowOptionalChain.types +++ b/tests/baselines/reference/controlFlowOptionalChain.types @@ -1,7 +1,7 @@ === tests/cases/conformance/controlFlow/controlFlowOptionalChain.ts === // assignments in shortcutting chain declare const o: undefined | { ->o : { (...args: any[]): any; [key: string]: any; [key: number]: any; } | undefined +>o : { (...args: any[]): any; [x: string | number]: any; } | undefined [key: string]: any; >key : string @@ -19,7 +19,7 @@ let a: number; o?.[a = 1]; >o?.[a = 1] : any ->o : { (...args: any[]): any; [key: string]: any; [key: number]: any; } | undefined +>o : { (...args: any[]): any; [x: string | number]: any; } | undefined >a = 1 : 1 >a : number >1 : 1 @@ -36,7 +36,7 @@ let b: number; o?.x[b = 1]; >o?.x[b = 1] : any >o?.x : any ->o : { (...args: any[]): any; [key: string]: any; [key: number]: any; } | undefined +>o : { (...args: any[]): any; [x: string | number]: any; } | undefined >x : any >b = 1 : 1 >b : number @@ -53,7 +53,7 @@ let c: number; o?.(c = 1) >o?.(c = 1) : any ->o : { (...args: any[]): any; [key: string]: any; [key: number]: any; } | undefined +>o : { (...args: any[]): any; [x: string | number]: any; } | undefined >c = 1 : 1 >c : number >1 : 1 @@ -70,7 +70,7 @@ let d: number; o?.x(d = 1); >o?.x(d = 1) : any >o?.x : any ->o : { (...args: any[]): any; [key: string]: any; [key: number]: any; } | undefined +>o : { (...args: any[]): any; [x: string | number]: any; } | undefined >x : any >d = 1 : 1 >d : number diff --git a/tests/baselines/reference/declFileTypeAnnotationTypeLiteral.types b/tests/baselines/reference/declFileTypeAnnotationTypeLiteral.types index 30d386b6c17d2..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: 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; [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/declFileTypeAnnotationVisibilityErrorTypeLiteral.js b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js index b3ba6a4ee5222..f7b2e37de6c40 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js @@ -86,8 +86,8 @@ declare module m { }; export 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/declarationEmitIndexTypeNotFound.errors.txt b/tests/baselines/reference/declarationEmitIndexTypeNotFound.errors.txt index 2e116a25861e2..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 either '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 either 'string' or 'number'. ~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'TypeNotFound'. ~~~~~~~~~~~~ diff --git a/tests/baselines/reference/deepKeysIndexing.types b/tests/baselines/reference/deepKeysIndexing.types index 73189b504da10..fed261833cdd8 100644 --- a/tests/baselines/reference/deepKeysIndexing.types +++ b/tests/baselines/reference/deepKeysIndexing.types @@ -92,27 +92,27 @@ const bar = new Bar(); // all 3 of the below should error on passing `true` for `"1"` bar.broken("a", "1", true); // was broken in the past - with 2nd argument incorrectly of type "1" | "2" | "3". >bar.broken("a", "1", true) : void ->bar.broken : , V extends Foo[K1][K2]>(k1: K1, k2: K2, value: V) => void +>bar.broken : , V extends Foo[K1][K2]>(k1: K1, k2: K2, value: V) => void >bar : Bar ->broken : , V extends Foo[K1][K2]>(k1: K1, k2: K2, value: V) => void +>broken : , V extends Foo[K1][K2]>(k1: K1, k2: K2, value: V) => void >"a" : "a" >"1" : "1" >true : true bar.working("a", "1", true); // ok - true is not allowed >bar.working("a", "1", true) : void ->bar.working : , V extends Foo[K1][K2]>(k1: K1, k2: K2, value: V) => void +>bar.working : , V extends Foo[K1][K2]>(k1: K1, k2: K2, value: V) => void >bar : Bar ->working : , V extends Foo[K1][K2]>(k1: K1, k2: K2, value: V) => void +>working : , V extends Foo[K1][K2]>(k1: K1, k2: K2, value: V) => void >"a" : "a" >"1" : "1" >true : true bar.workaround("a", "1", true); // ok - true is not allowed >bar.workaround("a", "1", true) : void ->bar.workaround : , V extends Foo[K1][K2]>(k1: K1, k2: K2, value: V) => void +>bar.workaround : , V extends Foo[K1][K2]>(k1: K1, k2: K2, value: V) => void >bar : Bar ->workaround : , V extends Foo[K1][K2]>(k1: K1, k2: K2, value: V) => void +>workaround : , V extends Foo[K1][K2]>(k1: K1, k2: K2, value: V) => void >"a" : "a" >"1" : "1" >true : true diff --git a/tests/baselines/reference/deeplyNestedConstraints.js b/tests/baselines/reference/deeplyNestedConstraints.js index 99fcbf4391c65..b6a7fdb870fbe 100644 --- a/tests/baselines/reference/deeplyNestedConstraints.js +++ b/tests/baselines/reference/deeplyNestedConstraints.js @@ -1,7 +1,7 @@ //// [deeplyNestedConstraints.ts] // Repro from #41931 -type Enum = Record; +type Enum = Record; type TypeMap = { [key in E[keyof E]]: number | boolean | string | number[] }; @@ -26,7 +26,7 @@ var BufferPool = /** @class */ (function () { //// [deeplyNestedConstraints.d.ts] -declare type Enum = Record; +declare type Enum = Record; declare type TypeMap = { [key in E[keyof E]]: number | boolean | string | number[]; }; diff --git a/tests/baselines/reference/deeplyNestedConstraints.symbols b/tests/baselines/reference/deeplyNestedConstraints.symbols index 15a0919f36bdd..f8ee3414fa897 100644 --- a/tests/baselines/reference/deeplyNestedConstraints.symbols +++ b/tests/baselines/reference/deeplyNestedConstraints.symbols @@ -1,12 +1,12 @@ === tests/cases/compiler/deeplyNestedConstraints.ts === // Repro from #41931 -type Enum = Record; +type Enum = Record; >Enum : Symbol(Enum, Decl(deeplyNestedConstraints.ts, 0, 0)) >Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) type TypeMap = { [key in E[keyof E]]: number | boolean | string | number[] }; ->TypeMap : Symbol(TypeMap, Decl(deeplyNestedConstraints.ts, 2, 44)) +>TypeMap : Symbol(TypeMap, Decl(deeplyNestedConstraints.ts, 2, 53)) >E : Symbol(E, Decl(deeplyNestedConstraints.ts, 4, 13)) >Enum : Symbol(Enum, Decl(deeplyNestedConstraints.ts, 0, 0)) >key : Symbol(key, Decl(deeplyNestedConstraints.ts, 4, 34)) @@ -18,7 +18,7 @@ class BufferPool> { >E : Symbol(E, Decl(deeplyNestedConstraints.ts, 6, 17)) >Enum : Symbol(Enum, Decl(deeplyNestedConstraints.ts, 0, 0)) >M : Symbol(M, Decl(deeplyNestedConstraints.ts, 6, 32)) ->TypeMap : Symbol(TypeMap, Decl(deeplyNestedConstraints.ts, 2, 44)) +>TypeMap : Symbol(TypeMap, Decl(deeplyNestedConstraints.ts, 2, 53)) >E : Symbol(E, Decl(deeplyNestedConstraints.ts, 6, 17)) setArray2(_: K, array: Extract>) { diff --git a/tests/baselines/reference/deeplyNestedConstraints.types b/tests/baselines/reference/deeplyNestedConstraints.types index 2d8d34729068e..cc17262430126 100644 --- a/tests/baselines/reference/deeplyNestedConstraints.types +++ b/tests/baselines/reference/deeplyNestedConstraints.types @@ -1,7 +1,7 @@ === tests/cases/compiler/deeplyNestedConstraints.ts === // Repro from #41931 -type Enum = Record; +type Enum = Record; >Enum : Enum type TypeMap = { [key in E[keyof E]]: number | boolean | string | number[] }; 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 9f3ed172fe11e..23b3a57e88e45 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 255487908657f..d2066ba5ff40b 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 904a6f5fe34f2..aac97717a71fc 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; } & { 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; } & { x: 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; } & { x: 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; } & { x: 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; } & { x: 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/emptyObjectNotSubtypeOfIndexSignatureContainingObject1.errors.txt b/tests/baselines/reference/emptyObjectNotSubtypeOfIndexSignatureContainingObject1.errors.txt index 56135cf8b0d14..cbb0fba87f162 100644 --- a/tests/baselines/reference/emptyObjectNotSubtypeOfIndexSignatureContainingObject1.errors.txt +++ b/tests/baselines/reference/emptyObjectNotSubtypeOfIndexSignatureContainingObject1.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts(41,3): error TS2322: Type 'Dictionary' is not assignable to type 'Record'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'string' is not assignable to type 'Bar'. @@ -47,7 +47,7 @@ tests/cases/compiler/emptyObjectNotSubtypeOfIndexSignatureContainingObject1.ts(4 return result; ~~~~~~~~~~~~~~ !!! error TS2322: Type 'Dictionary' is not assignable to type 'Record'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'string' is not assignable to type 'Bar'. } \ No newline at end of file diff --git a/tests/baselines/reference/emptyObjectNotSubtypeOfIndexSignatureContainingObject2.errors.txt b/tests/baselines/reference/emptyObjectNotSubtypeOfIndexSignatureContainingObject2.errors.txt index 58de463148308..cef5fb902c6a4 100644 --- a/tests/baselines/reference/emptyObjectNotSubtypeOfIndexSignatureContainingObject2.errors.txt +++ b/tests/baselines/reference/emptyObjectNotSubtypeOfIndexSignatureContainingObject2.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/emptyObjectNotSubtypeOfIndexSignatureContainingObject2.ts(42,3): error TS2322: Type 'Dictionary' is not assignable to type 'Record'. - Index signatures are incompatible. + 'string' index signatures are incompatible. Type 'string' is not assignable to type 'Bar'. @@ -48,7 +48,7 @@ tests/cases/compiler/emptyObjectNotSubtypeOfIndexSignatureContainingObject2.ts(4 return result; ~~~~~~~~~~~~~~ !!! error TS2322: Type 'Dictionary' is not assignable to type 'Record'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string' index signatures are incompatible. !!! error TS2322: Type 'string' is not assignable to type 'Bar'. } \ No newline at end of file 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 a22bdef219965..8d9a60b0c869c 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: This overload signature is not compatible with its implementation signature. -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) ==== @@ -13,5 +13,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..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 : Object ->r2['1'] : Object +>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 1e9b5d82c634e..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 : Object ->r2['1'] : Object +>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/genericIndexTypeHasSensibleErrorMessage.errors.txt b/tests/baselines/reference/genericIndexTypeHasSensibleErrorMessage.errors.txt deleted file mode 100644 index 36f2bf9fbdaf7..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 either 'string' or 'number'. - - -==== tests/cases/compiler/genericIndexTypeHasSensibleErrorMessage.ts (1 errors) ==== - type Wat = { [x: T]: string }; - ~ -!!! error TS1023: An index signature parameter type must be either '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 14107cde7e176..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 either '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 either 'string' or 'number'. ~ !!! error TS2314: Generic type 'C' requires 1 type argument(s). ~ diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.types b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.types index 8763804f1b06c..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 : {} +>d : { [x: string]: any; } >x : any declare function f(x: C): C; diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.errors.txt b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.errors.txt index 68d91622a310f..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 either '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 either 'string' or 'number'. ~ !!! error TS2314: Generic type 'C' requires 1 type argument(s). ~ diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.types b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.types index 3c32c79b5aabe..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 : {} +>d : { [x: string]: any; } >x : any var e = (x: C) => { var y: C; return y; } diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt index 7a63caeaf670c..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 either '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 either 'string' or 'number'. ~ !!! error TS2314: Generic type 'I' requires 1 type argument(s). ~ diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.types b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.types index 8aaf6e9585cac..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 : {} +>d : { [x: string]: any; } >x : any var e = (x: I) => { var y: I; return y; } diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.errors.txt b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.errors.txt index bb6ee2494add0..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 either '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 either 'string' or 'number'. ~ !!! error TS2314: Generic type 'C' requires 1 type argument(s). ~ diff --git a/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.types b/tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.types index fd5c4c348cc8e..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 : {} +>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 c5c16f5ecd914..e7f4164b5e914 100644 --- a/tests/baselines/reference/indexTypeCheck.errors.txt +++ b/tests/baselines/reference/indexTypeCheck.errors.txt @@ -1,14 +1,22 @@ 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'. + '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'. 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 either '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 ~~~~~~~~~~~ @@ -31,21 +39,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: 'string' and 'string | number' index signatures are incompatible. +!!! error TS2413: Type 'string' 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 } @@ -57,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 either '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/indexerConstraints.errors.txt b/tests/baselines/reference/indexerConstraints.errors.txt index cb7785535d18a..80678920f9639 100644 --- a/tests/baselines/reference/indexerConstraints.errors.txt +++ b/tests/baselines/reference/indexerConstraints.errors.txt @@ -1,7 +1,11 @@ -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'. + Property 'b' is missing in type 'A' but required in type 'B'. +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 +27,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: Property 'b' is missing in type 'A' but required in type 'B'. +!!! related TS2728 tests/cases/compiler/indexerConstraints.ts:2:25: 'b' is declared here. } // Inheritance @@ -33,7 +39,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 +50,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 +61,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 b3bd692122efd..9fcb054eb9fda 100644 --- a/tests/baselines/reference/indexerConstraints2.errors.txt +++ b/tests/baselines/reference/indexerConstraints2.errors.txt @@ -1,18 +1,18 @@ -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(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 either '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 either 'string' or 'number'. -tests/cases/compiler/indexerConstraints2.ts(64,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(70,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(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(79,6): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[key: string]: any' instead. +tests/cases/compiler/indexerConstraints2.ts(9,5): error TS2413: 'number' index type 'A' is not assignable to 'string' index type 'B'. + Property 'b' is missing in type 'A' but required in type 'B'. +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(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 'boolean' is not assignable to type 'string | number | symbol'. +tests/cases/compiler/indexerConstraints2.ts(79,5): error TS1021: An index signature must have a type annotation. -==== tests/cases/compiler/indexerConstraints2.ts (12 errors) ==== +==== tests/cases/compiler/indexerConstraints2.ts (6 errors) ==== class A { a: number; } class B extends A { b: number; } @@ -23,7 +23,9 @@ tests/cases/compiler/indexerConstraints2.ts(79,6): error TS1336: 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: Property 'b' is missing in type 'A' but required in type 'B'. +!!! related TS2728 tests/cases/compiler/indexerConstraints2.ts:2:21: 'b' is declared here. } // Other way @@ -33,7 +35,8 @@ tests/cases/compiler/indexerConstraints2.ts(79,6): error TS1336: 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 @@ -44,7 +47,8 @@ tests/cases/compiler/indexerConstraints2.ts(79,6): error TS1336: 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; } @@ -53,16 +57,12 @@ tests/cases/compiler/indexerConstraints2.ts(79,6): error TS1336: 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; @@ -70,15 +70,14 @@ tests/cases/compiler/indexerConstraints2.ts(79,6): error TS1336: An index signat interface N { [b: AliasedBoolean]: A; ~ -!!! error TS1023: An index signature parameter type must be either '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 | {}; @@ -86,35 +85,31 @@ tests/cases/compiler/indexerConstraints2.ts(79,6): error TS1336: An index signat interface P { [u: NonIndexableUnion]: A; ~ -!!! error TS1023: An index signature parameter type must be either '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 'boolean' is not assignable to type 'string | number | symbol'. } type NonIndexableUnion2 = string | number; interface Q { [u: NonIndexableUnion2]: A; - ~ -!!! error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead. } type NonIndexableUnion3 = "foo" | 42; interface R { [u: NonIndexableUnion3]: A; - ~ -!!! error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead. } 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. } type Key = string; interface T { [key: Key] - ~~~ -!!! error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[key: string]: any' instead. + ~~~~~~~~~~ +!!! error TS1021: An index signature must have a type annotation. } \ No newline at end of file diff --git a/tests/baselines/reference/inheritedMembersAndIndexSignaturesFromDifferentBases.errors.txt b/tests/baselines/reference/inheritedMembersAndIndexSignaturesFromDifferentBases.errors.txt index d2ad69730dad7..47fe9cba4f16b 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; } & { 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; }'. -==== 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; } & { a: 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; } & { a: 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..0708567239c29 100644 --- a/tests/baselines/reference/inheritedStringIndexersFromDifferentBaseTypes2.errors.txt +++ b/tests/baselines/reference/inheritedStringIndexersFromDifferentBaseTypes2.errors.txt @@ -1,4 +1,5 @@ -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; }'. + Property 'a' is missing in type '{}' but required in type '{ a: any; }'. ==== tests/cases/compiler/inheritedStringIndexersFromDifferentBaseTypes2.ts (1 errors) ==== @@ -21,7 +22,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: Property 'a' is missing in type '{}' but required in type '{ a: any; }'. +!!! related TS2728 tests/cases/compiler/inheritedStringIndexersFromDifferentBaseTypes2.ts:4:9: 'a' is declared here. 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 17cb5585cf87e..84282ef3b5141 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/interfaceWithEnumKeyedIndexSignature.errors.txt b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.errors.txt new file mode 100644 index 0000000000000..7d7320416926b --- /dev/null +++ b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.errors.txt @@ -0,0 +1,108 @@ +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(28,15): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'UserInterfaceColors'. + No index signature with a parameter of type 'number' was found on type 'UserInterfaceColors'. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(29,15): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'UserInterfaceColors'. + No index signature with a parameter of type 'string' was found on type 'UserInterfaceColors'. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(30,15): error TS7053: Element implicitly has an 'any' type because expression of type '12' can't be used to index type 'UserInterfaceColors'. + Property '12' does not exist on type 'UserInterfaceColors'. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(48,15): error TS7053: Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'UserInterfaceColors2'. + Property '0' does not exist on type 'UserInterfaceColors2'. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(49,15): error TS7053: Element implicitly has an 'any' type because expression of type '1' can't be used to index type 'UserInterfaceColors2'. + Property '1' does not exist on type 'UserInterfaceColors2'. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(50,15): error TS7053: Element implicitly has an 'any' type because expression of type '"0"' can't be used to index type 'UserInterfaceColors2'. + Property '0' does not exist on type 'UserInterfaceColors2'. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(51,15): error TS7053: Element implicitly has an 'any' type because expression of type '"1"' can't be used to index type 'UserInterfaceColors2'. + Property '1' does not exist on type 'UserInterfaceColors2'. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(52,15): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'UserInterfaceColors2'. + No index signature with a parameter of type 'number' was found on type 'UserInterfaceColors2'. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(53,15): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'UserInterfaceColors2'. + No index signature with a parameter of type 'string' was found on type 'UserInterfaceColors2'. +tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts(54,15): error TS7053: Element implicitly has an 'any' type because expression of type '12' can't be used to index type 'UserInterfaceColors2'. + Property '12' does not exist on type 'UserInterfaceColors2'. + + +==== tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts (10 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]); + expectColInfo(x[0]); + expectColInfo(x[1]); + expectColInfo(x["0"]); + expectColInfo(x["1"]); + + // errors + expectColInfo(x[0 as number]); + ~~~~~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'UserInterfaceColors'. +!!! error TS7053: No index signature with a parameter of type 'number' was found on type 'UserInterfaceColors'. + expectColInfo(x["0" as string]); + ~~~~~~~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'UserInterfaceColors'. +!!! error TS7053: No index signature with a parameter of type 'string' was found on type 'UserInterfaceColors'. + expectColInfo(x[12]); + ~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '12' can't be used to index type 'UserInterfaceColors'. +!!! error TS7053: Property '12' does not exist on type 'UserInterfaceColors'. + + 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 TS7053: Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'UserInterfaceColors2'. +!!! error TS7053: Property '0' does not exist on type 'UserInterfaceColors2'. + expectColInfo(x2[1]); + ~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '1' can't be used to index type 'UserInterfaceColors2'. +!!! error TS7053: Property '1' does not exist on type 'UserInterfaceColors2'. + expectColInfo(x2["0"]); + ~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"0"' can't be used to index type 'UserInterfaceColors2'. +!!! error TS7053: Property '0' does not exist on type 'UserInterfaceColors2'. + expectColInfo(x2["1"]); + ~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"1"' can't be used to index type 'UserInterfaceColors2'. +!!! error TS7053: Property '1' does not exist on type 'UserInterfaceColors2'. + expectColInfo(x2[0 as number]); + ~~~~~~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'UserInterfaceColors2'. +!!! error TS7053: No index signature with a parameter of type 'number' was found on type 'UserInterfaceColors2'. + expectColInfo(x2["0" as string]); + ~~~~~~~~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'UserInterfaceColors2'. +!!! error TS7053: No index signature with a parameter of type 'string' was found on type 'UserInterfaceColors2'. + expectColInfo(x2[12]); + ~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '12' can't be used to index type 'UserInterfaceColors2'. +!!! error TS7053: Property '12' does not exist on type 'UserInterfaceColors2'. + \ 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..45910306d7c03 --- /dev/null +++ b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.js @@ -0,0 +1,95 @@ +//// [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]); +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] +"use strict"; +exports.__esModule = true; +exports.UserInterfaceElement2 = exports.UserInterfaceElement = void 0; +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]); +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 new file mode 100644 index 0000000000000..dd7778bb233e7 --- /dev/null +++ b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.symbols @@ -0,0 +1,158 @@ +=== 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)) + +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)) + +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)) + +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 new file mode 100644 index 0000000000000..55ec93e361639 --- /dev/null +++ b/tests/baselines/reference/interfaceWithEnumKeyedIndexSignature.types @@ -0,0 +1,203 @@ +=== 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 + +expectColInfo(x[0]); +>expectColInfo(x[0]) : void +>expectColInfo : (x: ColorInfo) => void +>x[0] : ColorInfo +>x : UserInterfaceColors +>0 : 0 + +expectColInfo(x[1]); +>expectColInfo(x[1]) : void +>expectColInfo : (x: ColorInfo) => void +>x[1] : ColorInfo +>x : UserInterfaceColors +>1 : 1 + +expectColInfo(x["0"]); +>expectColInfo(x["0"]) : void +>expectColInfo : (x: ColorInfo) => void +>x["0"] : ColorInfo +>x : UserInterfaceColors +>"0" : "0" + +expectColInfo(x["1"]); +>expectColInfo(x["1"]) : void +>expectColInfo : (x: ColorInfo) => void +>x["1"] : ColorInfo +>x : UserInterfaceColors +>"1" : "1" + +// errors +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 + +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/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..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 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; } & { a: 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; }'. 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/intersectionWithIndexSignatures.errors.txt b/tests/baselines/reference/intersectionWithIndexSignatures.errors.txt index 0837890bbe365..b77b5f630a757 100644 --- a/tests/baselines/reference/intersectionWithIndexSignatures.errors.txt +++ b/tests/baselines/reference/intersectionWithIndexSignatures.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/types/intersection/intersectionWithIndexSignatures.ts(17 Property 'a' is missing in type 'B' but required in type 'A'. tests/cases/conformance/types/intersection/intersectionWithIndexSignatures.ts(27,10): error TS2339: Property 'b' does not exist on type '{ a: string; }'. tests/cases/conformance/types/intersection/intersectionWithIndexSignatures.ts(29,7): error TS2322: Type 's' is not assignable to type '{ [key: string]: { a: string; b: string; }; }'. - Index signatures are incompatible. + 'string | number' and 'string' index signatures are incompatible. Property 'b' is missing in type '{ a: string; }' but required in type '{ a: string; b: string; }'. tests/cases/conformance/types/intersection/intersectionWithIndexSignatures.ts(35,1): error TS2322: Type '{ a: string; } & { b: number; }' is not assignable to type '{ [key: string]: string; }'. Property 'b' is incompatible with index signature. @@ -49,7 +49,7 @@ tests/cases/conformance/types/intersection/intersectionWithIndexSignatures.ts(35 const d: { [key: string]: {a: string, b: string} } = q; // Error ~ !!! error TS2322: Type 's' is not assignable to type '{ [key: string]: { a: string; b: string; }; }'. -!!! error TS2322: Index signatures are incompatible. +!!! error TS2322: 'string | number' and 'string' index signatures are incompatible. !!! error TS2322: Property 'b' is missing in type '{ a: string; }' but required in type '{ a: string; b: string; }'. !!! related TS2728 tests/cases/conformance/types/intersection/intersectionWithIndexSignatures.ts:29:39: 'b' is declared here. diff --git a/tests/baselines/reference/invariantGenericErrorElaboration.errors.txt b/tests/baselines/reference/invariantGenericErrorElaboration.errors.txt index 7ab83c61bcdd5..8a5641869a264 100644 --- a/tests/baselines/reference/invariantGenericErrorElaboration.errors.txt +++ b/tests/baselines/reference/invariantGenericErrorElaboration.errors.txt @@ -29,7 +29,7 @@ tests/cases/compiler/invariantGenericErrorElaboration.ts(4,19): error TS2322: Ty } 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 67f336786f976..1b1b5649f6d6d 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/jsDeclarationsClassesErr.js b/tests/baselines/reference/jsDeclarationsClassesErr.js index 50f6099701dc4..63c00d65df3e8 100644 --- a/tests/baselines/reference/jsDeclarationsClassesErr.js +++ b/tests/baselines/reference/jsDeclarationsClassesErr.js @@ -249,14 +249,14 @@ export class T { export class U extends T { } export class V extends T { - [idx: string]: string; + [x: string | number]: string; } export class W extends T { [idx: number]: "ok"; } export class X extends T { - [idx: string]: string; [idx: number]: "ok"; + [idx: string]: string; } export class Y { [idx: string]: { diff --git a/tests/baselines/reference/jsDeclarationsInterfaces.js b/tests/baselines/reference/jsDeclarationsInterfaces.js index 00e78c8286a88..3f49a5d7fe7ed 100644 --- a/tests/baselines/reference/jsDeclarationsInterfaces.js +++ b/tests/baselines/reference/jsDeclarationsInterfaces.js @@ -186,14 +186,14 @@ export interface T { export interface U extends T { } export interface V extends T { - [idx: string]: string; + [x: string | number]: string; } export interface W extends T { [idx: number]: "ok"; } export interface X extends T { - [idx: string]: string; [idx: number]: "ok"; + [idx: string]: string; } export interface Y { [idx: string]: { diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index 769d0368cbe91..32aa78c4ccc1b 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']; } @@ -498,7 +498,7 @@ function updateIds, K extends string>( // Repro from #13285 -function updateIds2( +function updateIds2( obj: T, key: K, stringMap: { [oldId: string]: string } @@ -1221,7 +1221,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; @@ -1324,7 +1324,7 @@ declare function onChangeGenericFunction(handler: Handler, K extends string>(obj: T, idFields: K[], idMapping: Partial>): 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 c3bebb6c7d042..60e966deae789 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -1028,21 +1028,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)) @@ -1810,7 +1810,7 @@ function updateIds, K extends string>( // Repro from #13285 -function updateIds2( +function updateIds2( >updateIds2 : Symbol(updateIds2, Decl(keyofAndIndexedAccess.ts, 495, 1)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 499, 20)) >x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 499, 33)) @@ -1818,7 +1818,7 @@ function updateIds2( >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 499, 20)) obj: T, ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 499, 74)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 499, 83)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 499, 20)) key: K, @@ -1832,7 +1832,7 @@ function updateIds2( ) { var x = obj[key]; >x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 504, 7)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 499, 74)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 499, 83)) >key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 500, 11)) stringMap[x]; // Should be OK. diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index c90e635247a7b..5ad0a61a00b10 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" | "valueOf" | "charAt" | "charCodeAt" | "localeCompare" | "match" | "replace" | "search" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" +>K01 : number | "length" | "toString" | "concat" | "slice" | "indexOf" | "lastIndexOf" | "charAt" | "charCodeAt" | "localeCompare" | "match" | "replace" | "search" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" | "valueOf" type K02 = keyof number; // "toString" | "toFixed" | "toExponential" | ... >K02 : "toString" | "toLocaleString" | "valueOf" | "toFixed" | "toExponential" | "toPrecision" @@ -86,10 +86,10 @@ type K10 = keyof Shape; // "name" | "width" | "height" | "visible" >K10 : keyof Shape type K11 = keyof Shape[]; // "length" | "toString" | ... ->K11 : number | keyof Shape[] +>K11 : keyof Shape[] type K12 = keyof Dictionary; // string ->K12 : string | number +>K12 : keyof Dictionary type K13 = keyof {}; // never >K13 : never @@ -101,7 +101,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 | keyof [string, number] +>K16 : keyof [string, number] type K17 = keyof (Shape | Item); // "name" >K17 : "name" @@ -119,7 +119,7 @@ type K20 = KeyOf; // "name" | "width" | "height" | "visible" >K20 : keyof Shape type K21 = KeyOf>; // string ->K21 : string | number +>K21 : keyof Dictionary type NAME = "name"; >NAME : "name" @@ -1065,8 +1065,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 @@ -1087,7 +1087,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; } @@ -1098,7 +1098,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; } @@ -1775,8 +1775,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/keyofAndIndexedAccess2.errors.txt b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt index 510f6fc6359b0..a17763dd12045 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt @@ -230,9 +230,9 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(108,5): error TS23 // Repro from #31385 - type Foo = { [key: string]: { [K in keyof T]: K }[keyof T] }; + type Foo = { [key: PropertyKey]: { [K in keyof T]: K }[keyof T] }; - type Bar = { [key: string]: { [K in keyof T]: [K] }[keyof T] }; + type Bar = { [key: PropertyKey]: { [K in keyof T]: [K] }[keyof T] }; type Baz> = { [K in keyof Q]: T[Q[K]] }; diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.js b/tests/baselines/reference/keyofAndIndexedAccess2.js index a2d7f9b2fdde9..8997426181877 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.js +++ b/tests/baselines/reference/keyofAndIndexedAccess2.js @@ -149,9 +149,9 @@ export class c { // Repro from #31385 -type Foo = { [key: string]: { [K in keyof T]: K }[keyof T] }; +type Foo = { [key: PropertyKey]: { [K in keyof T]: K }[keyof T] }; -type Bar = { [key: string]: { [K in keyof T]: [K] }[keyof T] }; +type Bar = { [key: PropertyKey]: { [K in keyof T]: [K] }[keyof T] }; type Baz> = { [K in keyof Q]: T[Q[K]] }; diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.symbols b/tests/baselines/reference/keyofAndIndexedAccess2.symbols index 58b5f470c030b..fb6b072ded916 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess2.symbols @@ -522,26 +522,28 @@ export class c { // Repro from #31385 -type Foo = { [key: string]: { [K in keyof T]: K }[keyof T] }; +type Foo = { [key: PropertyKey]: { [K in keyof T]: K }[keyof T] }; >Foo : Symbol(Foo, Decl(keyofAndIndexedAccess2.ts, 146, 1)) >T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 150, 9)) >key : Symbol(key, Decl(keyofAndIndexedAccess2.ts, 150, 17)) ->K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 150, 34)) +>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 150, 39)) >T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 150, 9)) ->K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 150, 34)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 150, 39)) >T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 150, 9)) -type Bar = { [key: string]: { [K in keyof T]: [K] }[keyof T] }; ->Bar : Symbol(Bar, Decl(keyofAndIndexedAccess2.ts, 150, 64)) +type Bar = { [key: PropertyKey]: { [K in keyof T]: [K] }[keyof T] }; +>Bar : Symbol(Bar, Decl(keyofAndIndexedAccess2.ts, 150, 69)) >T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 152, 9)) >key : Symbol(key, Decl(keyofAndIndexedAccess2.ts, 152, 17)) ->K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 152, 34)) +>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 152, 39)) >T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 152, 9)) ->K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 152, 34)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 152, 39)) >T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 152, 9)) type Baz> = { [K in keyof Q]: T[Q[K]] }; ->Baz : Symbol(Baz, Decl(keyofAndIndexedAccess2.ts, 152, 66)) +>Baz : Symbol(Baz, Decl(keyofAndIndexedAccess2.ts, 152, 71)) >T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 154, 9)) >Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 154, 11)) >Foo : Symbol(Foo, Decl(keyofAndIndexedAccess2.ts, 146, 1)) @@ -556,7 +558,7 @@ type Qux> = { [K in keyof Q]: T[Q[K]["0"]] }; >Qux : Symbol(Qux, Decl(keyofAndIndexedAccess2.ts, 154, 60)) >T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 156, 9)) >Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 156, 11)) ->Bar : Symbol(Bar, Decl(keyofAndIndexedAccess2.ts, 150, 64)) +>Bar : Symbol(Bar, Decl(keyofAndIndexedAccess2.ts, 150, 69)) >T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 156, 9)) >K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 156, 35)) >Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 156, 11)) diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.types b/tests/baselines/reference/keyofAndIndexedAccess2.types index 048e11cad674d..775397f1f484c 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.types +++ b/tests/baselines/reference/keyofAndIndexedAccess2.types @@ -351,7 +351,7 @@ export interface EntityState { >ids : IdOf[] entities: { [key: string]: E, [key: number]: E }; ->entities : { [key: string]: E; [key: number]: E; } +>entities : { [x: string | number]: E; } >key : string >key : number } @@ -363,18 +363,18 @@ export function getAllEntities(state: EntityState): E[] { const { ids, entities } = state; >ids : IdOf[] ->entities : { [key: string]: E; [key: number]: E; } +>entities : { [x: string | number]: E; } >state : EntityState return ids.map(id => entities[id]); ->ids.map(id => entities[id]) : { [key: string]: E; [key: number]: E; }[IdOf][] +>ids.map(id => entities[id]) : { [x: string | number]: E; }[IdOf][] >ids.map : (callbackfn: (value: IdOf, index: number, array: IdOf[]) => U, thisArg?: any) => U[] >ids : IdOf[] >map : (callbackfn: (value: IdOf, index: number, array: IdOf[]) => U, thisArg?: any) => U[] ->id => entities[id] : (id: IdOf) => { [key: string]: E; [key: number]: E; }[IdOf] +>id => entities[id] : (id: IdOf) => { [x: string | number]: E; }[IdOf] >id : IdOf ->entities[id] : { [key: string]: E; [key: number]: E; }[IdOf] ->entities : { [key: string]: E; [key: number]: E; } +>entities[id] : { [x: string | number]: E; }[IdOf] +>entities : { [x: string | number]: E; } >id : IdOf } @@ -385,7 +385,7 @@ export function getEntity(id: IdOf, state: EntityState): const { ids, entities } = state; >ids : IdOf[] ->entities : { [key: string]: E; [key: number]: E; } +>entities : { [x: string | number]: E; } >state : EntityState if (!ids.includes(id)) { @@ -401,8 +401,8 @@ export function getEntity(id: IdOf, state: EntityState): } return entities[id]; ->entities[id] : { [key: string]: E; [key: number]: E; }[IdOf] ->entities : { [key: string]: E; [key: number]: E; } +>entities[id] : { [x: string | number]: E; }[IdOf] +>entities : { [x: string | number]: E; } >id : IdOf } @@ -526,13 +526,13 @@ export class c { // Repro from #31385 -type Foo = { [key: string]: { [K in keyof T]: K }[keyof T] }; +type Foo = { [key: PropertyKey]: { [K in keyof T]: K }[keyof T] }; >Foo : Foo ->key : string +>key : PropertyKey -type Bar = { [key: string]: { [K in keyof T]: [K] }[keyof T] }; +type Bar = { [key: PropertyKey]: { [K in keyof T]: [K] }[keyof T] }; >Bar : Bar ->key : string +>key : PropertyKey type Baz> = { [K in keyof Q]: T[Q[K]] }; >Baz : Baz diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.types b/tests/baselines/reference/keyofAndIndexedAccessErrors.types index 27f0642094e45..6fb2b69bfad91 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.types +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.types @@ -26,19 +26,19 @@ type T01 = keyof Object; >T01 : keyof Object 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 42a2d373be64e..0ade7f748e4bc 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 'string' 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 00ccad59caa36..ef4afad91a69a 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; 0: 0; [sym]: symbol; } // "str" | "num" diff --git a/tests/baselines/reference/lateBoundDestructuringImplicitAnyError.types b/tests/baselines/reference/lateBoundDestructuringImplicitAnyError.types index 60c220095adb3..92d2c4c662c4b 100644 --- a/tests/baselines/reference/lateBoundDestructuringImplicitAnyError.types +++ b/tests/baselines/reference/lateBoundDestructuringImplicitAnyError.types @@ -87,12 +87,12 @@ void prop6; let {[symed]: prop7} = strIndexed; >symed : unique symbol ->prop7 : string +>prop7 : any >strIndexed : { [idx: string]: string; } void prop7; >void prop7 : undefined ->prop7 : string +>prop7 : any let {[symed2]: prop8} = numIndexed; >symed2 : symbol @@ -105,10 +105,10 @@ void prop8; let {[symed2]: prop9} = strIndexed; >symed2 : symbol ->prop9 : string +>prop9 : any >strIndexed : { [idx: string]: string; } void prop9; >void prop9 : undefined ->prop9 : string +>prop9 : any diff --git a/tests/baselines/reference/mappedTypeErrors.errors.txt b/tests/baselines/reference/mappedTypeErrors.errors.txt index b2c59fce02c00..8c30ada92355c 100644 --- a/tests/baselines/reference/mappedTypeErrors.errors.txt +++ b/tests/baselines/reference/mappedTypeErrors.errors.txt @@ -39,11 +39,13 @@ 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: false; }' 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(148,17): error TS2339: Property 'foo' does not exist on type 'Pick'. tests/cases/conformance/types/mapped/mappedTypeErrors.ts(152,17): error TS2339: Property 'foo' does not exist on type 'Record'. -==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (27 errors) ==== +==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (28 errors) ==== interface Shape { name: string; width: number; @@ -262,6 +264,10 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(152,17): error TS2339: let f: Foo2 = { pf: {x: 7}, pt: {x: 7, y: false}, + ~~~~ +!!! error TS2322: Type '{ x: number; y: false; }' 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' }; // Repro from #28170 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..6d34f30b4316a --- /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; } & { directive?: TDir; }) => [TArg, TRet, TDir] +>options : { [x: symbol]: (arg: TArg) => TRet; } & { directive?: 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; } & { directive?: TDir; }) => [TArg, TRet, TDir] +>{ [strdirective]: (x: string) => 'str', [s1]: (x: number) => x + 1, [s2]: (x: number) => x + x,} : { directive: (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; } & { directive?: 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; directive: (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; } & { directive?: TDir; }) => [TArg, TRet, TDir] +>{ [strdirective]: 'str', [s1]: (x: number) => x + 1, [s2]: (x: number) => x + x,} : { directive: 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 b37c9b83cfc15..8718ce726c466 100644 --- a/tests/baselines/reference/mappedTypeRelationships.errors.txt +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -244,12 +244,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 deb240454c395..2048e8b002113 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; } @@ -357,8 +357,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 f50d49cde3a03..6553476938209 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 f138f86e521f7..c028caf362fe6 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/mappedTypeWithAny.types b/tests/baselines/reference/mappedTypeWithAny.types index 6aa71ef174070..378a319f7ecbe 100644 --- a/tests/baselines/reference/mappedTypeWithAny.types +++ b/tests/baselines/reference/mappedTypeWithAny.types @@ -10,7 +10,7 @@ declare let x0: keyof any; >x0 : string | number | symbol declare let x1: { [P in any]: Item }; ->x1 : { [x: string]: Item; [x: number]: Item; } +>x1 : { [x: string | number | symbol]: Item; } declare let x2: { [P in string]: Item }; >x2 : { [x: string]: Item; } diff --git a/tests/baselines/reference/mergedInterfacesWithIndexers.types b/tests/baselines/reference/mergedInterfacesWithIndexers.types index 73e0ee72c941b..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 : { length: number; } ->a['1'] : { length: number; } +>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 f649b5469937d..82e8a67825785 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 & { length: number; }'. ==== 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 & { length: 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/objectLiteralErrors.errors.txt b/tests/baselines/reference/objectLiteralErrors.errors.txt index 2a6114ed0957e..52cb54e103a0e 100644 --- a/tests/baselines/reference/objectLiteralErrors.errors.txt +++ b/tests/baselines/reference/objectLiteralErrors.errors.txt @@ -60,6 +60,7 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(35,13) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(35,23): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(35,23): error TS2300: Duplicate identifier '0x0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(36,13): error TS2300: Duplicate identifier '0'. +tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(36,23): error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o0'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(36,23): error TS1119: An object literal cannot have property and accessor with the same name. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(36,23): error TS2300: Duplicate identifier '000'. tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(37,13): error TS2300: Duplicate identifier '"100"'. @@ -76,7 +77,11 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(43,22) tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16): error TS2380: The return type of a 'get' accessor must be assignable to its 'set' accessor type +<<<<<<< HEAD +==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (79 errors) ==== +======= ==== tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts (76 errors) ==== +>>>>>>> master // Multiple properties with the same name var e1 = { a: 0, a: 0 }; ~ @@ -238,6 +243,8 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralErrors.ts(44,16) ~ !!! error TS2300: Duplicate identifier '0'. ~~~ +!!! error TS1085: Octal literals are not available when targeting ECMAScript 5 and higher. Use the syntax '0o0'. + ~~~ !!! error TS1119: An object literal cannot have property and accessor with the same name. ~~~ !!! error TS2300: Duplicate identifier '000'. 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/objectRest.errors.txt b/tests/baselines/reference/objectRest.errors.txt index f6fd179d28d3a..50561ae18cab4 100644 --- a/tests/baselines/reference/objectRest.errors.txt +++ b/tests/baselines/reference/objectRest.errors.txt @@ -1,5 +1,3 @@ -tests/cases/conformance/types/rest/objectRest.ts(7,12): error TS2339: Property '0' does not exist on type 'String'. -tests/cases/conformance/types/rest/objectRest.ts(7,20): error TS2339: Property '1' does not exist on type 'String'. tests/cases/conformance/types/rest/objectRest.ts(43,8): error TS2537: Type '{ a: number; b: string; }' has no matching index signature for type 'string'. tests/cases/conformance/types/rest/objectRest.ts(43,35): error TS2537: Type '{ a: number; b: string; }' has no matching index signature for type 'string'. tests/cases/conformance/types/rest/objectRest.ts(43,57): error TS2403: Subsequent variable declarations must have the same type. Variable 'o' must be of type '{ a: number; b: string; }', but here has type '{}'. @@ -8,7 +6,7 @@ tests/cases/conformance/types/rest/objectRest.ts(44,32): error TS2537: Type '{ a tests/cases/conformance/types/rest/objectRest.ts(44,53): error TS2739: Type '{}' is missing the following properties from type '{ a: number; b: string; }': a, b -==== tests/cases/conformance/types/rest/objectRest.ts (8 errors) ==== +==== tests/cases/conformance/types/rest/objectRest.ts (6 errors) ==== var o = { a: 1, b: 'no' } var { ...clone } = o; var { a, ...justB } = o; @@ -16,10 +14,6 @@ tests/cases/conformance/types/rest/objectRest.ts(44,53): error TS2739: Type '{}' var { ['b']: renamed, ...justA } = o; var { 'b': renamed, ...justA } = o; var { b: { '0': n, '1': oooo }, ...justA } = o; - ~~~ -!!! error TS2339: Property '0' does not exist on type 'String'. - ~~~ -!!! error TS2339: Property '1' does not exist on type 'String'. let o2 = { c: 'terrible idea?', d: 'yes' }; var { d: renamed, ...d } = o2; diff --git a/tests/baselines/reference/objectRest.types b/tests/baselines/reference/objectRest.types index b0d34beae7dac..821bb809972dd 100644 --- a/tests/baselines/reference/objectRest.types +++ b/tests/baselines/reference/objectRest.types @@ -36,8 +36,8 @@ var { 'b': renamed, ...justA } = o; var { b: { '0': n, '1': oooo }, ...justA } = o; >b : any ->n : any ->oooo : any +>n : string +>oooo : string >justA : { a: number; } >o : { a: number; b: string; } diff --git a/tests/baselines/reference/objectTypeHidingMembersOfExtendedObject.errors.txt b/tests/baselines/reference/objectTypeHidingMembersOfExtendedObject.errors.txt index 94810f6d0028f..3d9b65ae4c15c 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: PropertyKey) => 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: PropertyKey) => 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: PropertyKey) => 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: PropertyKey) => 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: PropertyKey) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'hasOwnProperty' of type '(v: PropertyKey) => 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: PropertyKey) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'propertyIsEnumerable' of type '(v: PropertyKey) => 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 d85cc3ddfdb11..00dc1a7ea46f8 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: PropertyKey) => 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: PropertyKey) => 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: PropertyKey) => 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: PropertyKey) => 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: PropertyKey) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'hasOwnProperty' of type '(v: PropertyKey) => 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: PropertyKey) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'propertyIsEnumerable' of type '(v: PropertyKey) => 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/parserES5SymbolIndexer1.errors.txt b/tests/baselines/reference/parserES5SymbolIndexer1.errors.txt deleted file mode 100644 index a0010dc0a27a4..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 either '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 either '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 acc43ed9b74e2..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 either '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 either '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 12d8819c60130..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 either '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 either 'string' or 'number'. - } \ No newline at end of file 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/parserIndexSignature6.errors.txt b/tests/baselines/reference/parserIndexSignature6.errors.txt index 9df13e05b6c87..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 either '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 either '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 5ca6f11573fee..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 either 'string' or 'number'. -tests/cases/conformance/parser/ecmascript5/IndexSignatures/parserIndexSignature8.ts(2,14): error TS1023: An index signature parameter type must be either '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 either '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 either '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/parserIndexSignature8.types b/tests/baselines/reference/parserIndexSignature8.types index f8d18d540a181..575bde78113e5 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: string]: any; } >index : any var foo2: { [index: RegExp]; }; // expect an error here ->foo2 : {} +>foo2 : { [index: RegExp]: any; } >index : RegExp diff --git a/tests/baselines/reference/parserSymbolIndexer1.errors.txt b/tests/baselines/reference/parserSymbolIndexer1.errors.txt deleted file mode 100644 index b9a34890151d7..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 either '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 either '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 3b8735feef9ac..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 either '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 either '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 4da102891a0fd..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 either '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 either 'string' or 'number'. - } \ No newline at end of file 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..0f0998cf2c454 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 'string' index type 'never'. +tests/cases/compiler/propertiesAndIndexers.ts(35,5): error TS2411: Property 'Infinity' of type 'number' is not assignable to 'string' index type 'never'. +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 'string' index type 'never'. 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 'string' index type 'never'. 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..e9bca8f46b026 100644 --- a/tests/baselines/reference/propertiesAndIndexers2.errors.txt +++ b/tests/baselines/reference/propertiesAndIndexers2.errors.txt @@ -1,19 +1,20 @@ -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(9,5): error TS2411: Property '3' of type 'string' is not assignable to 'number' index type 'never'. +tests/cases/compiler/propertiesAndIndexers2.ts(10,5): error TS2411: Property 'Infinity' of type 'string' is not assignable to 'number' index type 'never'. +tests/cases/compiler/propertiesAndIndexers2.ts(11,5): error TS2411: Property '"-Infinity"' of type 'string' is not assignable to 'number' index type 'never'. +tests/cases/compiler/propertiesAndIndexers2.ts(12,5): error TS2411: Property 'NaN' of type 'string' is not assignable to 'number' index type 'never'. +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 'never'. -==== tests/cases/compiler/propertiesAndIndexers2.ts (9 errors) ==== +==== tests/cases/compiler/propertiesAndIndexers2.ts (8 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 +22,24 @@ 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'. +!!! error TS2411: Property '3' of type 'string' is not assignable to 'number' index type 'never'. Infinity: string; ~~~~~~~~ -!!! error TS2411: Property 'Infinity' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property 'Infinity' of type 'string' is not assignable to 'number' index type 'never'. "-Infinity": string; ~~~~~~~~~~~ -!!! error TS2411: Property '"-Infinity"' of type 'string' is not assignable to string index type 'number'. +!!! error TS2411: Property '"-Infinity"' of type 'string' is not assignable to 'number' index type 'never'. 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 'number' index type 'never'. "-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 'never'. } \ 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/propertyAccess.errors.txt b/tests/baselines/reference/propertyAccess.errors.txt index 26c0aaaeceadf..b5521d01ddf5c 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,16 @@ 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'. +!!! related TS6203 tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts:124:5: 'ww' was also declared here. // 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'. +!!! related TS6203 tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts:128:5: 'xx' was also declared here. // Bracket notation property access using string value on type with numeric index signature and string index signature var yy = bothIndex['foo']; @@ -169,6 +177,6 @@ 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'. !!! related TS6203 tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts:148:5: 'x3' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/propertyAccess.types b/tests/baselines/reference/propertyAccess.types index b81767eb8c066..882f3c26fe279 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 bea7932ed4cd7..70f7384318486 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 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 '{ [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 ff80ad048b199..6f7c4659d3725 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 : { [x: string | number]: any; } >n : number ->k : { [s: string]: any; [n: number]: any; } +>k : { [x: string | number]: any; } >s : string ->k : { [s: string]: any; [n: number]: any; } +>k : { [x: string | number]: 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 : { [x: string | number]: any; } +>k[0] : { [x: string | number]: any; } +>k : { [x: string | number]: 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 : { [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/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 8923b04d51fc7..2d6cbf094badb 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,8): error TS2741: Property 'foo' is missing in type 'typeof A' but required in type 'A'. tests/cases/conformance/types/objectTypeLiteral/indexSignatures/stringIndexerConstrainsPropertyDeclarations2.ts(38,8): error TS2741: Property 'foo' is missing in type 'typeof B' but required in type 'A'. @@ -25,10 +25,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 { @@ -37,10 +37,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: { @@ -49,10 +49,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 8c8a65f9f7c34..b1cdb85104c3a 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints.errors.txt @@ -1,23 +1,48 @@ -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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'U'. -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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'U'. +<<<<<<< HEAD + Type 'V' is not assignable to type 'T'. + 'T' could be instantiated with an arbitrary type which could be unrelated to 'V'. +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'. +>>>>>>> master 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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'V'. -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'. 'U' could be instantiated with an arbitrary type which could be unrelated to 'V'. -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'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. +<<<<<<< HEAD + Type 'V' is not assignable to type 'T'. + 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. + Type 'Date' is not assignable to type 'T'. + 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. +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'. + 'V' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. + Type 'Date' is not assignable to type 'T'. + 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. +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'. + 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. + Type 'Date' is not assignable to type 'U'. + 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. +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(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'. @@ -27,14 +52,15 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf Type 'V' is not assignable to type 'U'. 'V' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. 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'. +>>>>>>> master 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'. 'Date' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Date'. -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'. 'Date' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Date'. -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'. 'Date' is assignable to the constraint of type 'V', but 'V' could be instantiated with a different subtype of constraint 'Date'. @@ -61,7 +87,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'. @@ -98,7 +124,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'. @@ -121,7 +147,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'. @@ -132,7 +158,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'. @@ -178,7 +204,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'. @@ -206,7 +232,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'. @@ -217,7 +243,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'. @@ -240,7 +266,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'. @@ -251,7 +277,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'. @@ -262,7 +288,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 0f63d2741304a..a85a27262ac76 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints4.errors.txt @@ -1,19 +1,31 @@ -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'. 'U' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Foo'. +<<<<<<< HEAD + Type 'Foo' is not assignable to type 'T'. + 'T' could be instantiated with an arbitrary type which could be unrelated to 'Foo'. +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'. +>>>>>>> master 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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'V'. -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'. 'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'Foo'. +<<<<<<< HEAD + Type 'Foo' is not assignable to type 'U'. + 'U' could be instantiated with an arbitrary type which could be unrelated to 'Foo'. +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'. +>>>>>>> master 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'. 'U' could be instantiated with an arbitrary type which could be unrelated to 'V'. @@ -68,7 +80,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'. @@ -83,7 +95,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'. @@ -94,7 +106,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'. @@ -105,7 +117,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'. @@ -121,7 +133,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 f7b626f3ae73f..702dd3ba2e437 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt +++ b/tests/baselines/reference/subtypesOfTypeParameterWithRecursiveConstraints.errors.txt @@ -1,7 +1,36 @@ -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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'U'. +<<<<<<< HEAD + Type 'Foo' is not assignable to type 'T'. + 'T' could be instantiated with an arbitrary type which could be unrelated to 'Foo'. +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'. + 'T' could be instantiated with an arbitrary type which could be unrelated to 'V'. + Type 'Foo' is not assignable to type 'T'. + 'T' could be instantiated with an arbitrary type which could be unrelated to 'Foo'. +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'. + 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. + Type 'Foo' is not assignable to type 'U'. + 'U' could be instantiated with an arbitrary type which could be unrelated to 'Foo'. +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'. + 'U' could be instantiated with an arbitrary type which could be unrelated to 'V'. + Type 'Foo' is not assignable to type 'U'. + 'U' could be instantiated with an arbitrary type which could be unrelated to 'Foo'. +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'. + 'V' could be instantiated with an arbitrary type which could be unrelated to 'T'. + Type 'Foo' is not assignable to type 'V'. + 'V' could be instantiated with an arbitrary type which could be unrelated to 'Foo'. +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(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'. @@ -19,6 +48,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf Type 'T' is not assignable to type 'V'. 'V' could be instantiated with an arbitrary type which could be unrelated to 'T'. 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'. +>>>>>>> master 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'. 'V' could be instantiated with an arbitrary type which could be unrelated to 'U'. @@ -27,32 +57,63 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf Type 'Foo' is not assignable to type 'Foo'. Type 'U' is not assignable to type 'T'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'U'. +<<<<<<< HEAD + Type 'Foo' is not assignable to type 'T'. + 'T' could be instantiated with an arbitrary type which could be unrelated to 'Foo'. +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'. +>>>>>>> master 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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'V'. +<<<<<<< HEAD + Type 'Foo' is not assignable to type 'T'. + 'T' could be instantiated with an arbitrary type which could be unrelated to 'Foo'. +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'. +>>>>>>> master 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'. 'U' could be instantiated with an arbitrary type which could be unrelated to 'T'. +<<<<<<< HEAD + Type 'Foo' is not assignable to type 'U'. + 'U' could be instantiated with an arbitrary type which could be unrelated to 'Foo'. +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'. +>>>>>>> master 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'. 'U' could be instantiated with an arbitrary type which could be unrelated to 'V'. +<<<<<<< HEAD + Type 'Foo' is not assignable to type 'U'. + 'U' could be instantiated with an arbitrary type which could be unrelated to 'Foo'. +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'. +>>>>>>> master 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'. 'V' could be instantiated with an arbitrary type which could be unrelated to 'U'. +<<<<<<< HEAD + Type 'Foo' is not assignable to type 'V'. + 'V' could be instantiated with an arbitrary type which could be unrelated to 'Foo'. +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'. +>>>>>>> master 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 +191,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 +202,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 +213,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 +229,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 +240,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 +251,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 +285,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 +305,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 +323,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 +336,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 +349,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 0c79c352a4c85..5bc973332a950 100644 --- a/tests/baselines/reference/subtypingWithNumericIndexer.errors.txt +++ b/tests/baselines/reference/subtypingWithNumericIndexer.errors.txt @@ -1,9 +1,9 @@ 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'. 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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'. 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. @@ -43,7 +43,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'. !!! error TS2415: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. [x: number]: Derived; // error, BUG? @@ -52,7 +52,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'. !!! error TS2415: 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. [x: number]: Derived2; // error, BUG? diff --git a/tests/baselines/reference/subtypingWithNumericIndexer2.errors.txt b/tests/baselines/reference/subtypingWithNumericIndexer2.errors.txt index ed48870168e18..619e25ce094e3 100644 --- a/tests/baselines/reference/subtypingWithNumericIndexer2.errors.txt +++ b/tests/baselines/reference/subtypingWithNumericIndexer2.errors.txt @@ -1,17 +1,17 @@ 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. Property 'bar' is missing in type 'Base' but required in type 'Derived'. 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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'Base'. 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'. 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'. 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'. 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived2'. @@ -30,7 +30,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: Property 'bar' is missing in type 'Base' but required in type 'Derived'. !!! related TS2728 tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2.ts:4:34: 'bar' is declared here. [x: number]: Base; // error @@ -58,7 +58,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'. !!! error TS2430: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Base'. [x: number]: Base; // error @@ -67,7 +67,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'. !!! error TS2430: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'. [x: number]: Derived; // error @@ -76,7 +76,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'. !!! error TS2430: 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived2'. [x: number]: Derived2; // error diff --git a/tests/baselines/reference/subtypingWithNumericIndexer3.errors.txt b/tests/baselines/reference/subtypingWithNumericIndexer3.errors.txt index 08020cd5652d5..d3c67979ba5e1 100644 --- a/tests/baselines/reference/subtypingWithNumericIndexer3.errors.txt +++ b/tests/baselines/reference/subtypingWithNumericIndexer3.errors.txt @@ -1,17 +1,17 @@ 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. Property 'bar' is missing in type 'Base' but required in type 'Derived'. 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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'Base'. 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'. 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'. 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'. 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived2'. @@ -30,7 +30,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: Property 'bar' is missing in type 'Base' but required in type 'Derived'. !!! related TS2728 tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer3.ts:4:34: 'bar' is declared here. [x: number]: Base; // error @@ -58,7 +58,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'. !!! error TS2415: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Base'. [x: number]: Base; // error @@ -67,7 +67,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'. !!! error TS2415: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'. [x: number]: Derived; // error @@ -76,7 +76,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'. !!! error TS2415: 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived2'. [x: number]: Derived2; // error diff --git a/tests/baselines/reference/subtypingWithNumericIndexer4.errors.txt b/tests/baselines/reference/subtypingWithNumericIndexer4.errors.txt index 21a6f22c4da4b..263f66d50e0e6 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' but required in type 'Derived'. 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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'string'. @@ -26,7 +26,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 } @@ -39,7 +39,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'. @@ -51,7 +51,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'. !!! error TS2415: 'T' could be instantiated with an arbitrary type which could be unrelated to 'string'. [x: number]: string; // error diff --git a/tests/baselines/reference/subtypingWithNumericIndexer5.errors.txt b/tests/baselines/reference/subtypingWithNumericIndexer5.errors.txt index 897e76300e9e3..a35684b943f33 100644 --- a/tests/baselines/reference/subtypingWithNumericIndexer5.errors.txt +++ b/tests/baselines/reference/subtypingWithNumericIndexer5.errors.txt @@ -1,17 +1,17 @@ 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' but required in type 'Derived'. 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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'Base'. 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'. 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'. 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'. 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived2'. @@ -30,7 +30,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' but required in type 'Derived'. !!! related TS2728 tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer5.ts:4:34: 'bar' is declared here. @@ -57,7 +57,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'. !!! error TS2420: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Base'. [x: string]: Base; // error @@ -66,7 +66,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'. !!! error TS2420: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'. [x: string]: Derived; // error @@ -75,7 +75,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'. !!! error TS2420: 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived2'. [x: string]: Derived2; // error diff --git a/tests/baselines/reference/subtypingWithStringIndexer.errors.txt b/tests/baselines/reference/subtypingWithStringIndexer.errors.txt index 80a1a6acfc043..89d152e4da109 100644 --- a/tests/baselines/reference/subtypingWithStringIndexer.errors.txt +++ b/tests/baselines/reference/subtypingWithStringIndexer.errors.txt @@ -1,9 +1,9 @@ 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'. 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. 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'. 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. @@ -43,7 +43,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'. !!! error TS2415: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. [x: string]: Derived; // error @@ -52,7 +52,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'. !!! error TS2415: 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Base'. [x: string]: Derived2; // error diff --git a/tests/baselines/reference/subtypingWithStringIndexer2.errors.txt b/tests/baselines/reference/subtypingWithStringIndexer2.errors.txt index 5dfd4904ec31d..1025474d0b7a4 100644 --- a/tests/baselines/reference/subtypingWithStringIndexer2.errors.txt +++ b/tests/baselines/reference/subtypingWithStringIndexer2.errors.txt @@ -1,17 +1,17 @@ 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. Property 'bar' is missing in type 'Base' but required in type 'Derived'. 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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'Base'. 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'. 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'. 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'. 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived2'. @@ -30,7 +30,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: Property 'bar' is missing in type 'Base' but required in type 'Derived'. !!! related TS2728 tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2.ts:4:34: 'bar' is declared here. [x: string]: Base; // error @@ -58,7 +58,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'. !!! error TS2430: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Base'. [x: string]: Base; // error @@ -67,7 +67,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'. !!! error TS2430: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'. [x: string]: Derived; // error @@ -76,7 +76,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'. !!! error TS2430: 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived2'. [x: string]: Derived2; // error diff --git a/tests/baselines/reference/subtypingWithStringIndexer3.errors.txt b/tests/baselines/reference/subtypingWithStringIndexer3.errors.txt index 936be924c0157..d5f6facc71ad6 100644 --- a/tests/baselines/reference/subtypingWithStringIndexer3.errors.txt +++ b/tests/baselines/reference/subtypingWithStringIndexer3.errors.txt @@ -1,17 +1,17 @@ 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. Property 'bar' is missing in type 'Base' but required in type 'Derived'. 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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'Base'. 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'. 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'. 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'. 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived2'. @@ -30,7 +30,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: Property 'bar' is missing in type 'Base' but required in type 'Derived'. !!! related TS2728 tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer3.ts:4:34: 'bar' is declared here. [x: string]: Base; // error @@ -58,7 +58,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'. !!! error TS2415: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Base'. [x: string]: Base; // error @@ -67,7 +67,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'. !!! error TS2415: 'Derived' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived'. [x: string]: Derived; // error @@ -76,7 +76,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'. !!! error TS2415: 'Derived2' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Derived2'. [x: string]: Derived2; // error diff --git a/tests/baselines/reference/subtypingWithStringIndexer4.errors.txt b/tests/baselines/reference/subtypingWithStringIndexer4.errors.txt index 824200e9f0d2f..66aa8858ce891 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' but required in type 'Derived'. 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'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'string'. @@ -26,7 +26,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 } @@ -39,7 +39,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'. @@ -51,7 +51,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'. !!! error TS2415: 'T' could be instantiated with an arbitrary type which could be unrelated to 'string'. [x: string]: string; // error diff --git a/tests/baselines/reference/symbolIndexerCompatabilityExamples.errors.txt b/tests/baselines/reference/symbolIndexerCompatabilityExamples.errors.txt new file mode 100644 index 0000000000000..8a35b1c068069 --- /dev/null +++ b/tests/baselines/reference/symbolIndexerCompatabilityExamples.errors.txt @@ -0,0 +1,123 @@ +tests/cases/conformance/types/members/symbolIndexerCompatabilityExamples.ts(55,9): error TS2322: Type '{ [k: K]: V; }[K]' is not assignable to type 'V'. + 'V' could be instantiated with an arbitrary type which could be unrelated to '{ [k: K]: V; }[K]'. +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'. + 'V' could be instantiated with an arbitrary type which could be unrelated to '{ [k: K]: V; }[K]'. +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 (4 errors) ==== + 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]; + ~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ [k: K]: V; }[K]' is not assignable to type 'V'. +!!! error TS2322: 'V' could be instantiated with an arbitrary type which could be unrelated to '{ [k: K]: V; }[K]'. + } + + public set(k: K, v: V) { + this.o[k] = v; + ~~~~~~~~~ +!!! error TS2322: Type 'V' is not assignable to type '{ [k: K]: V; }[K]'. + } + + public getMap(k: K): V { + if (k in this.o) { + return this.o[k]; + ~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ [k: K]: V; }[K]' is not assignable to type 'V'. +!!! error TS2322: 'V' could be instantiated with an arbitrary type which could be unrelated to '{ [k: K]: V; }[K]'. + } + const res = new SimpleMapMap(); + this.o[k] = res as any as V; + ~~~~~~~~~ +!!! error TS2322: Type 'V' is not assignable to type '{ [k: K]: V; }[K]'. + 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 = {}; + } + } + \ 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..31b3fc2caccef --- /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 : { [x: string | number | symbol]: V; } +>k : PropertyKey +>{} : {} + + 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 : { [x: string | number | symbol]: V; } +>this : this +>o : { [x: string | number | symbol]: V; } + } + + public get(k: K): V { +>get : (k: K) => V +>k : K + + return this.o[k]; +>this.o[k] : { [x: string | number | symbol]: V; }[K] +>this.o : { [x: string | number | symbol]: V; } +>this : this +>o : { [x: 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] : { [x: string | number | symbol]: V; }[K] +>this.o : { [x: string | number | symbol]: V; } +>this : this +>o : { [x: 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 : { [x: string | number | symbol]: V; } +>this : this +>o : { [x: string | number | symbol]: V; } + + return this.o[k]; +>this.o[k] : { [x: string | number | symbol]: V; }[K] +>this.o : { [x: string | number | symbol]: V; } +>this : this +>o : { [x: 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] : { [x: string | number | symbol]: V; }[K] +>this.o : { [x: string | number | symbol]: V; } +>this : this +>o : { [x: 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 : { [x: string | number | symbol]: V; } +>this : this +>o : { [x: string | number | symbol]: V; } +>{} : {} + } +} + diff --git a/tests/baselines/reference/symbolProperty17.errors.txt b/tests/baselines/reference/symbolProperty17.errors.txt index a28a1d0981041..4b6ee88ffd214 100644 --- a/tests/baselines/reference/symbolProperty17.errors.txt +++ b/tests/baselines/reference/symbolProperty17.errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/es6/Symbols/symbolProperty17.ts(3,6): error TS1023: An index signature parameter type must be either 'string' or 'number'. +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; - ~ -!!! error TS1023: An index signature parameter type must be either 'string' or 'number'. "__@iterator": string; } diff --git a/tests/baselines/reference/symbolProperty29.errors.txt b/tests/baselines/reference/symbolProperty29.errors.txt deleted file mode 100644 index b0f6bb3bc3169..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 either '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 either '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 index c986fd28641be..97ae1d8f60076 100644 --- a/tests/baselines/reference/symbolProperty30.errors.txt +++ b/tests/baselines/reference/symbolProperty30.errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/es6/Symbols/symbolProperty30.ts(5,6): error TS1023: An index signature parameter type must be either 'string' or 'number'. +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 }; - ~ -!!! error TS1023: An index signature parameter type must be either '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 46a6177809016..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 either '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 either '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 index 3318459b29404..c8b4845d51902 100644 --- a/tests/baselines/reference/symbolProperty32.errors.txt +++ b/tests/baselines/reference/symbolProperty32.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/Symbols/symbolProperty32.ts(7,6): error TS1023: An index signature parameter type must be either 'string' or 'number'. +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) ==== @@ -9,6 +9,6 @@ tests/cases/conformance/es6/Symbols/symbolProperty32.ts(7,6): error TS1023: An i } class C2 extends C1 { [s: symbol]: () => { x: number }; - ~ -!!! error TS1023: An index signature parameter type must be either 'string' or '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/symbolProperty33.errors.txt b/tests/baselines/reference/symbolProperty33.errors.txt index 09b32a501ce93..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 either '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 either '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 390ead2177f04..e1fe289ce70a0 100644 --- a/tests/baselines/reference/symbolProperty34.errors.txt +++ b/tests/baselines/reference/symbolProperty34.errors.txt @@ -1,5 +1,5 @@ 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 either 'string' or 'number'. +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 (2 errors) ==== @@ -8,11 +8,11 @@ tests/cases/conformance/es6/Symbols/symbolProperty34.ts(7,6): error TS1023: An i !!! 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: "" }; } } class C2 { [s: symbol]: () => { x: number }; - ~ -!!! error TS1023: An index signature parameter type must be either 'string' or 'number'. } \ No newline at end of file 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/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/typeName1.errors.txt b/tests/baselines/reference/typeName1.errors.txt index 28c88a45ca0d6..71a804d67ba8d 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 'number' is not assi tests/cases/compiler/typeName1.ts(14,5): error TS2322: Type 'number' is not assignable to type '{ z: number; f: { (n: number): string; (s: string): number; }; }'. tests/cases/compiler/typeName1.ts(15,5): error TS2322: Type 'number' is not assignable to type '(s: string) => boolean'. tests/cases/compiler/typeName1.ts(16,5): error TS2322: Type 'number' 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 'number' is not assignable to type 'I'. tests/cases/compiler/typeName1.ts(18,5): error TS2322: Type 'number' is not assignable to type 'I[][][][]'. tests/cases/compiler/typeName1.ts(19,5): error TS2322: Type 'number' is not assignable to type '{ z: I; x: boolean; }[][]'. tests/cases/compiler/typeName1.ts(20,5): error TS2322: Type 'number' 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 'number' 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 'number' 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 'number' 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 'number' 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 'number' 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 'number' is not assignable to type '{ (): {}; new (): number; new (n: number): number; x: string; w: { y: number; }; }'. 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..5b7a41ed8b20e --- /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: PropertyKey, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: PropertyKey, 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/baselines/reference/unionIndexerGeneralAssignability.errors.txt b/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt new file mode 100644 index 0000000000000..61c265492a54e --- /dev/null +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.errors.txt @@ -0,0 +1,350 @@ +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'. + 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'. + 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'. + 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'. + 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 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'. + 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'. + 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'. + 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'. + 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'. + Property 'S2.A' does not exist on type 'F'. +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'. + Property 'S1.A' does not exist on type 'G'. +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'. + Property 'S2.A' does not exist on type 'IFG'. +tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts(129,5): error TS2322: Type 'G' is not assignable to type 'IFG'. + 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 'string' 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 'string' 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 'string' 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 'string' is not assignable to type 'never'. + + +==== tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts (35 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 TS2741: Property 'a' is missing in type 'B' but required in type 'A'. + a = ab; // error: AB is missing `"a"` + ~ +!!! error TS2741: Property 'a' is missing in type 'AB' but required in type 'A'. + + b = a; // error: A is missing `"d"` + ~ +!!! error TS2741: Property 'd' is missing in type 'A' but required in type 'B'. + b = ab; // error: AB is missing `"d"` + ~ +!!! error TS2741: Property 'd' is missing in type 'AB' but required in type 'B'. + + ab = a; + ab = b; + + interface SubA { + [x: K1]: string; + } + let s: SubA = {}; + s[k1]; // valid + s = a; + s = b; // error: doesn't provide `"a"` + ~ +!!! error TS2322: Type 'B' is not assignable to type 'SubA'. +!!! 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: 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 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 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 TS2739: Type 'SubA' is missing the following properties from type 'AB': b, c + + 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: 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: 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 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 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 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'. +!!! 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 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 TS2739: Type 'C' is missing the following properties from type 'E': d, 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 {} + ~~~ +!!! 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: Property 'S1.A' does not exist on 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: 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: 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: 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 + ~~~ +!!! error TS2322: Type 'F' is not assignable to type 'F & G'. +!!! error TS2322: Type 'F' is not assignable to type 'G'. +!!! error TS2322: Property 'S2.A' does not exist on type 'F'. + 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'. +!!! error TS2322: Property 'S1.A' does not exist on type 'G'. + 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'. +!!! error TS2322: Property 'S2.A' does not exist on type 'IFG'. + + fg3 = f; // error: doesn't provide S2 + fg3 = g; // error: doesn't provide S1 + ~~~ +!!! error TS2322: Type 'G' is not assignable to type 'IFG'. +!!! error TS2322: Property 'S1.A' does not exist on 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; + [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"}; + + function f4(h: H, i: I, j: J, k: K, l: L) { + 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 + ~ +!!! error TS2322: Type 'H' is not assignable to type 'J'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'never'. + j = i; // not ok + ~ +!!! error TS2322: Type 'I' is not assignable to type 'J'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'never'. + j = k; // not ok + ~ +!!! error TS2322: Type 'K' is not assignable to type 'J'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'never'. + j = l; // not ok + ~ +!!! error TS2322: Type 'L' is not assignable to type 'J'. +!!! error TS2322: Types of property 'a' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'never'. + + 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 + } + \ 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..0a3b043491eca --- /dev/null +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.js @@ -0,0 +1,284 @@ +//// [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 `"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 `"b"`, `"c"`, or `"d"` + ab = s; // error: might not provide any of `"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 `"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 +} + +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"}; + +function f4(h: H, i: I, j: J, k: K, l: L) { + 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 +} + + +//// [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 `"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 `"b"`, `"c"`, or `"d"` + ab = s; // error: might not provide any of `"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 `"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) { + 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 = {})); +function f4(h, i, j, k, l) { + 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 new file mode 100644 index 0000000000000..3040d4c390520 --- /dev/null +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.symbols @@ -0,0 +1,535 @@ +=== 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 `"a"` +>s : Symbol(s, Decl(unionIndexerGeneralAssignability.ts, 28, 7)) +>b : Symbol(b, Decl(unionIndexerGeneralAssignability.ts, 15, 7)) + + s = ab; // error: doesn't provide `"a"` +>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 `"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 `"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 `"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 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)) + +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, 157, 12)) +>H : Symbol(H, Decl(unionIndexerGeneralAssignability.ts, 137, 1)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) +>I : Symbol(I, Decl(unionIndexerGeneralAssignability.ts, 142, 1)) +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) +>J : Symbol(J, Decl(unionIndexerGeneralAssignability.ts, 147, 1)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) +>K : Symbol(K, Decl(unionIndexerGeneralAssignability.ts, 152, 1)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) +>L : Symbol(L, Decl(unionIndexerGeneralAssignability.ts, 154, 45)) + + h = i; // ok +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) + + 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; // ok +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) + + h = l; // ok +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) + + i = h; // ok +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) + + 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; // ok +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) + + i = l; // ok +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) + + j = h; // not ok +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) + + j = i; // not ok +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) + + j = k; // not ok +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) + + j = l; // not ok +>j : Symbol(j, Decl(unionIndexerGeneralAssignability.ts, 157, 23)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) + + k = h; // ok +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) + + k = i; // ok +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) + + 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; // ok +>k : Symbol(k, Decl(unionIndexerGeneralAssignability.ts, 157, 29)) +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) + + l = h; // ok +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) +>h : Symbol(h, Decl(unionIndexerGeneralAssignability.ts, 157, 12)) + + l = i; // ok +>l : Symbol(l, Decl(unionIndexerGeneralAssignability.ts, 157, 35)) +>i : Symbol(i, Decl(unionIndexerGeneralAssignability.ts, 157, 17)) + + 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; // 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 new file mode 100644 index 0000000000000..31eaecfde50ca --- /dev/null +++ b/tests/baselines/reference/unionIndexerGeneralAssignability.types @@ -0,0 +1,542 @@ +=== 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 `"a"` +>s = b : B +>s : SubA +>b : B + + s = ab; // error: doesn't provide `"a"` +>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 `"b"`, `"c"`, or `"d"` +>b = s : SubA +>b : B +>s : SubA + + ab = s; // error: might not provide any of `"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] : any +>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 `"b"`, `"c"`, or `"d"` +>b = s2 : SubB +>b : B +>s2 : SubB + + ab = s2; // error: might not provide any of 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 + +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; // ok +>h = i : I +>h : H +>i : I + + h = j; // ok (never is a subtype of "a") +>h = j : J +>h : H +>j : J + + h = k; // ok +>h = k : K +>h : H +>k : K + + h = l; // ok +>h = l : L +>h : H +>l : L + + i = h; // ok +>i = h : H +>i : I +>h : H + + i = j; // ok (never is a subtype of "a") +>i = j : J +>i : I +>j : J + + i = k; // ok +>i = k : K +>i : I +>k : K + + i = l; // ok +>i = l : L +>i : I +>l : L + + j = h; // not ok +>j = h : H +>j : J +>h : H + + j = i; // not ok +>j = i : I +>j : J +>i : I + + j = k; // not ok +>j = k : K +>j : J +>k : K + + j = l; // not ok +>j = l : L +>j : J +>l : L + + k = h; // ok +>k = h : H +>k : K +>h : H + + k = i; // ok +>k = i : I +>k : K +>i : I + + k = j; // ok (never is a subtype of "a") +>k = j : J +>k : K +>j : J + + k = l; // ok +>k = l : L +>k : K +>l : L + + l = h; // ok +>l = h : H +>l : L +>h : H + + l = i; // ok +>l = i : I +>l : L +>i : I + + l = j; // ok (never is a subtype of "a") +>l = j : J +>l : L +>j : J + + l = k; // ok +>l = k : K +>l : L +>k : K +} + 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/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/baselines/reference/variadicTuples1.errors.txt b/tests/baselines/reference/variadicTuples1.errors.txt index 956bd6a922be2..b917aa585d2a3 100644 --- a/tests/baselines/reference/variadicTuples1.errors.txt +++ b/tests/baselines/reference/variadicTuples1.errors.txt @@ -33,7 +33,7 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(191,5): error TS2322: Typ Type 'T' is not assignable to type 'U'. 'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'readonly string[]'. tests/cases/conformance/types/tuple/variadicTuples1.ts(203,5): error TS2322: Type 'string' is not assignable to type 'keyof [1, 2, ...T]'. - Type '"2"' is not assignable to type 'number | "0" | keyof T[] | "1"'. + Type '"2"' is not assignable to type '"0" | keyof T[] | "1"'. tests/cases/conformance/types/tuple/variadicTuples1.ts(357,26): error TS2322: Type 'string' is not assignable to type 'number | undefined'. tests/cases/conformance/types/tuple/variadicTuples1.ts(397,7): error TS2322: Type '[false, false]' is not assignable to type '[...number[], boolean]'. Type at position 0 in source is not compatible with type at position 0 in target. @@ -298,7 +298,7 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(397,7): error TS2322: Typ k3 = '2'; // Error ~~ !!! error TS2322: Type 'string' is not assignable to type 'keyof [1, 2, ...T]'. -!!! error TS2322: Type '"2"' is not assignable to type 'number | "0" | keyof T[] | "1"'. +!!! error TS2322: Type '"2"' is not assignable to type '"0" | keyof T[] | "1"'. } // Inference between variadic tuple types 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/compiler/deeplyNestedConstraints.ts b/tests/cases/compiler/deeplyNestedConstraints.ts index 906962b6dbd6f..82ca2aed9aa1d 100644 --- a/tests/cases/compiler/deeplyNestedConstraints.ts +++ b/tests/cases/compiler/deeplyNestedConstraints.ts @@ -3,7 +3,7 @@ // Repro from #41931 -type Enum = Record; +type Enum = Record; type TypeMap = { [key in E[keyof E]]: number | boolean | string | number[] }; 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 new file mode 100644 index 0000000000000..fa42fe28abf10 --- /dev/null +++ b/tests/cases/compiler/mappedTypeInferenceOnlySymbolsIfSymbolsSpecified.ts @@ -0,0 +1,51 @@ +// @target: es6 +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] diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index 56ff157a67fd0..829adb06196e0 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']; } @@ -500,7 +500,7 @@ function updateIds, K extends string>( // Repro from #13285 -function updateIds2( +function updateIds2( obj: T, key: K, stringMap: { [oldId: string]: string } diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts index a86f4718e35c7..42b1f7c70c855 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts @@ -151,9 +151,9 @@ export class c { // Repro from #31385 -type Foo = { [key: string]: { [K in keyof T]: K }[keyof T] }; +type Foo = { [key: PropertyKey]: { [K in keyof T]: K }[keyof T] }; -type Bar = { [key: string]: { [K in keyof T]: [K] }[keyof T] }; +type Bar = { [key: PropertyKey]: { [K in keyof T]: [K] }[keyof T] }; type Baz> = { [K in keyof Q]: T[Q[K]] }; diff --git a/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts b/tests/cases/conformance/types/mapped/mappedTypeRelationships.ts index 9bec21145b28e..01053fd1a1914 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/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts b/tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts new file mode 100644 index 0000000000000..fe8974d527734 --- /dev/null +++ b/tests/cases/conformance/types/members/interfaceWithEnumKeyedIndexSignature.ts @@ -0,0 +1,55 @@ +// @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]); +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/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/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 diff --git a/tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts b/tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts new file mode 100644 index 0000000000000..8cefda91150c0 --- /dev/null +++ b/tests/cases/conformance/types/members/unionIndexerGeneralAssignability.ts @@ -0,0 +1,183 @@ +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 `"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 `"b"`, `"c"`, or `"d"` + ab = s; // error: might not provide any of `"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 `"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 +} + +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"}; + +function f4(h: H, i: I, j: J, k: K, l: L) { + 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/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 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; }`, }); 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/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; -};` -}) diff --git a/tests/cases/fourslash/completionListObjectMembers.ts b/tests/cases/fourslash/completionListObjectMembers.ts index ebf50ae18db59..1f477ac1b587b 100644 --- a/tests/cases/fourslash/completionListObjectMembers.ts +++ b/tests/cases/fourslash/completionListObjectMembers.ts @@ -11,5 +11,6 @@ verify.completions({ marker: "", + isNewIdentifierLocation: true, includes: [{ name: "bar", text: "(property) bar: any" }, { name: "foo", text: "(method) foo(bar: any): any" }], }); diff --git a/tests/cases/fourslash/completionPropertyShorthandForObjectLiteral.ts b/tests/cases/fourslash/completionPropertyShorthandForObjectLiteral.ts index 8eae3df67a698..3141f4d3288dc 100644 --- a/tests/cases/fourslash/completionPropertyShorthandForObjectLiteral.ts +++ b/tests/cases/fourslash/completionPropertyShorthandForObjectLiteral.ts @@ -24,6 +24,19 @@ //// declare function f15(obj: Record): void; //// declare function f16(obj: { [key: number]: number }): void; +//// declare function f17(obj: Record): void; +//// declare function f18(obj: { [key: symbol]: number }): void; + +//// declare function f19(obj: Record<`data-${string}`, any>): void; +//// declare function f20(obj: { [key: `data-${string}`]: number }): void; + +//// declare function f21(obj: Record): void; +//// declare function f22(obj: { [key: string | number | symbol]: number }): void; + +//// declare function f23(obj: Record & Record): void; +//// declare function f24(obj: { [key: string]: number; [key: number]: number; }): void; + + //// f1({f/*1*/}); //// f2({f/*2*/}); //// f3({f/*3*/}); @@ -44,12 +57,24 @@ //// f15({f/*15*/}); //// f16({f/*16*/}); -//// f1({ f1, /*17*/ }); +//// f17({f/*17*/}); +//// f18({f/*18*/}); + +//// f19({f/*19*/}); +//// f20({f/*20*/}); + +//// f21({f/*21*/}); +//// f22({f/*22*/}); + +//// f23({f/*23*/}); +//// f24({f/*24*/}); + +//// f1({ f1, /*f1*/ }); const locals = [ ...(() => { const symbols = []; - for (let i = 1; i <= 16; i ++) { + for (let i = 1; i <= 24; i ++) { symbols.push(`f${i}`); } return symbols; @@ -58,13 +83,13 @@ const locals = [ ]; verify.completions( // Non-contextual, any, unknown, object, Record, [key: string]: .., Type parameter, etc.. - { marker: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"], exact: completion.globalsPlus(locals), isNewIdentifierLocation: true }, + { marker: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "19", "20", "21", "22", "23", "24"], exact: completion.globalsPlus(locals), isNewIdentifierLocation: true }, // Has named property { marker: ["12", "13"], exact: "typed", isNewIdentifierLocation: false }, // Has both StringIndexType and named property { marker: ["14"], exact: "prop", isNewIdentifierLocation: true }, // NumberIndexType - { marker: ["15", "16"], exact: [], isNewIdentifierLocation: true }, + { marker: ["15", "16", "17", "18"], exact: [], isNewIdentifierLocation: true }, // After comma - { marker: ["17"], exact: completion.globalsPlus(locals), isNewIdentifierLocation: true }, + { marker: ["f1"], exact: completion.globalsPlus(locals), isNewIdentifierLocation: true }, ); diff --git a/tests/cases/fourslash/duplicateIndexers.ts b/tests/cases/fourslash/duplicateIndexers.ts index 5f72625a6ebfd..3c358f95b9042 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: never"); 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" });