diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e6e3364840d..2557e3b7078 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -516,8 +516,9 @@ namespace ts { const saveReturnTarget = currentReturnTarget; const saveActiveLabels = activeLabels; const saveHasExplicitReturn = hasExplicitReturn; - const isIIFE = containerFlags & ContainerFlags.IsFunctionExpression && !hasModifier(node, ModifierFlags.Async) && !!getImmediatelyInvokedFunctionExpression(node); - // A non-async IIFE is considered part of the containing control flow. Return statements behave + const isIIFE = containerFlags & ContainerFlags.IsFunctionExpression && !hasModifier(node, ModifierFlags.Async) && + !(node).asteriskToken && !!getImmediatelyInvokedFunctionExpression(node); + // A non-async, non-generator IIFE is considered part of the containing control flow. Return statements behave // similarly to break statements that exit to a label just past the statement body. if (!isIIFE) { currentFlow = { flags: FlowFlags.Start }; @@ -2219,14 +2220,14 @@ namespace ts { bindAnonymousDeclaration(file, SymbolFlags.ValueModule, `"${removeFileExtension(file.fileName)}"` as __String); } - function bindExportAssignment(node: ExportAssignment | BinaryExpression) { + function bindExportAssignment(node: ExportAssignment) { if (!container.symbol || !container.symbol.exports) { // Export assignment in some sort of block construct bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node)); } else { const flags = node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(node) - // An export default clause with an EntityNameExpression exports all meanings of that identifier + // An export default clause with an EntityNameExpression or a class expression exports all meanings of that identifier or expression; ? SymbolFlags.Alias // An export default clause with any other expression exports a value : SymbolFlags.Property; @@ -2321,7 +2322,10 @@ namespace ts { // 'module.exports = expr' assignment setCommonJsModuleIndicator(node); - declareSymbol(file.symbol.exports, file.symbol, node, SymbolFlags.Property | SymbolFlags.ExportValue | SymbolFlags.ValueModule, SymbolFlags.None); + const flags = exportAssignmentIsAlias(node) + ? SymbolFlags.Alias // An export= with an EntityNameExpression or a ClassExpression exports all meanings of that identifier or class + : SymbolFlags.Property | SymbolFlags.ExportValue | SymbolFlags.ValueModule; + declareSymbol(file.symbol.exports, file.symbol, node, flags, SymbolFlags.None); } function bindThisPropertyAssignment(node: BinaryExpression | PropertyAccessExpression) { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bfc9c1fd550..75f8715fca7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -67,6 +67,7 @@ namespace ts { const strictPropertyInitialization = getStrictOptionValue(compilerOptions, "strictPropertyInitialization"); const noImplicitAny = getStrictOptionValue(compilerOptions, "noImplicitAny"); const noImplicitThis = getStrictOptionValue(compilerOptions, "noImplicitThis"); + const keyofStringsOnly = !!compilerOptions.keyofStringsOnly; const emitResolver = createResolver(); const nodeBuilder = createNodeBuilder(); @@ -356,6 +357,8 @@ namespace ts { const silentNeverType = createIntrinsicType(TypeFlags.Never, "never"); const implicitNeverType = createIntrinsicType(TypeFlags.Never, "never"); const nonPrimitiveType = createIntrinsicType(TypeFlags.NonPrimitive, "object"); + const stringNumberSymbolType = getUnionType([stringType, numberType, esSymbolType]); + const keyofConstraintType = keyofStringsOnly ? stringType : stringNumberSymbolType; const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -430,6 +433,7 @@ namespace ts { let deferredGlobalAsyncIteratorType: GenericType; let deferredGlobalAsyncIterableIteratorType: GenericType; let deferredGlobalTemplateStringsArrayType: ObjectType; + let deferredGlobalExtractSymbol: Symbol; let deferredNodes: Node[]; const allPotentiallyUnusedIdentifiers = createMap>(); // key is file name @@ -1568,7 +1572,7 @@ namespace ts { return false; } - const container = getThisContainer(errorLocation, /*includeArrowFunctions*/ true); + const container = getThisContainer(errorLocation, /*includeArrowFunctions*/ false); let location = container; while (location) { if (isClassLike(location.parent)) { @@ -1841,7 +1845,7 @@ namespace ts { return valueSymbol; } const result = createSymbol(valueSymbol.flags | typeSymbol.flags, valueSymbol.escapedName); - result.declarations = concatenate(valueSymbol.declarations, typeSymbol.declarations); + result.declarations = deduplicate(concatenate(valueSymbol.declarations, typeSymbol.declarations), equateValues); result.parent = valueSymbol.parent || typeSymbol.parent; if (valueSymbol.valueDeclaration) result.valueDeclaration = valueSymbol.valueDeclaration; if (typeSymbol.members) result.members = typeSymbol.members; @@ -1876,7 +1880,7 @@ namespace ts { let symbolFromVariable: Symbol; // First check if module was specified with "export=". If so, get the member from the resolved type - if (moduleSymbol && moduleSymbol.exports && moduleSymbol.exports.get("export=" as __String)) { + if (moduleSymbol && moduleSymbol.exports && moduleSymbol.exports.get(InternalSymbolName.ExportEquals)) { symbolFromVariable = getPropertyOfType(getTypeOfSymbol(targetSymbol), name.escapedText); } else { @@ -1889,7 +1893,7 @@ namespace ts { if (!symbolFromModule && allowSyntheticDefaultImports && name.escapedText === InternalSymbolName.Default) { symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); } - const symbol = symbolFromModule && symbolFromVariable ? + const symbol = symbolFromModule && symbolFromVariable && symbolFromModule !== symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { @@ -1922,13 +1926,17 @@ namespace ts { resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); } - function getTargetOfExportAssignment(node: ExportAssignment, dontResolveAlias: boolean): Symbol | undefined { - const aliasLike = resolveEntityName(node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/ true, dontResolveAlias); + function getTargetOfExportAssignment(node: ExportAssignment | BinaryExpression, dontResolveAlias: boolean): Symbol | undefined { + const expression = (isExportAssignment(node) ? node.expression : node.right) as EntityNameExpression | ClassExpression; + if (isClassExpression(expression)) { + return checkExpression(expression).symbol; + } + const aliasLike = resolveEntityName(expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/ true, dontResolveAlias); if (aliasLike) { return aliasLike; } - checkExpression(node.expression); - return getNodeLinks(node.expression).resolvedSymbol; + checkExpression(expression); + return getNodeLinks(expression).resolvedSymbol; } function getTargetOfAliasDeclaration(node: Declaration, dontRecursivelyResolve?: boolean): Symbol | undefined { @@ -1944,7 +1952,8 @@ namespace ts { case SyntaxKind.ExportSpecifier: return getTargetOfExportSpecifier(node, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, dontRecursivelyResolve); case SyntaxKind.ExportAssignment: - return getTargetOfExportAssignment(node, dontRecursivelyResolve); + case SyntaxKind.BinaryExpression: + return getTargetOfExportAssignment((node), dontRecursivelyResolve); case SyntaxKind.NamespaceExportDeclaration: return getTargetOfNamespaceExportDeclaration(node, dontRecursivelyResolve); } @@ -2061,7 +2070,7 @@ namespace ts { let symbol: Symbol; if (name.kind === SyntaxKind.Identifier) { const message = meaning === namespaceMeaning ? Diagnostics.Cannot_find_namespace_0 : Diagnostics.Cannot_find_name_0; - const symbolFromJSPrototype = isInJavaScriptFile(name) && resolveEntityNameFromJSPrototype(name, meaning); + const symbolFromJSPrototype = isInJavaScriptFile(name) ? resolveEntityNameFromJSPrototype(name, meaning) : undefined; symbol = resolveName(location || name, name.escapedText, meaning, ignoreErrors || symbolFromJSPrototype ? undefined : message, name, /*isUse*/ true); if (!symbol) { return symbolFromJSPrototype; @@ -2225,20 +2234,28 @@ namespace ts { // An external module with an 'export =' declaration resolves to the target of the 'export =' declaration, // and an external module with no 'export =' declaration resolves to the module itself. function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol { - return moduleSymbol && getMergedSymbol(resolveSymbol(getCommonJsExportEquals(moduleSymbol), dontResolveAlias)) || moduleSymbol; + return moduleSymbol && getMergedSymbol(getCommonJsExportEquals(resolveSymbol(moduleSymbol.exports.get(InternalSymbolName.ExportEquals), dontResolveAlias), moduleSymbol)) || moduleSymbol; } - function getCommonJsExportEquals(moduleSymbol: Symbol): Symbol { - const exported = moduleSymbol.exports.get(InternalSymbolName.ExportEquals); - if (!exported || !exported.exports || moduleSymbol.exports.size === 1) { + function getCommonJsExportEquals(exported: Symbol, moduleSymbol: Symbol): Symbol { + if (!exported || moduleSymbol.exports.size === 1) { return exported; } const merged = cloneSymbol(exported); + if (merged.exports === undefined) { + merged.flags = merged.flags | SymbolFlags.ValueModule; + merged.exports = createSymbolTable(); + } moduleSymbol.exports.forEach((s, name) => { if (name === InternalSymbolName.ExportEquals) return; if (!merged.exports.has(name)) { merged.exports.set(name, s); } + else { + const ms = cloneSymbol(merged.exports.get(name)); + mergeSymbol(ms, s); + merged.exports.set(name, ms); + } }); return merged; } @@ -3859,10 +3876,13 @@ namespace ts { return "(Anonymous function)"; } } - if ((symbol as TransientSymbol).nameType && (symbol as TransientSymbol).nameType.flags & TypeFlags.StringLiteral) { - const stringValue = ((symbol as TransientSymbol).nameType as StringLiteralType).value; - if (!isIdentifierText(stringValue, compilerOptions.target)) { - return `"${escapeString(stringValue, CharacterCodes.doubleQuote)}"`; + const nameType = symbol.nameType; + if (nameType) { + if (nameType.flags & TypeFlags.StringLiteral && !isIdentifierText((nameType).value, compilerOptions.target)) { + return `"${escapeString((nameType).value, CharacterCodes.doubleQuote)}"`; + } + if (nameType && nameType.flags & TypeFlags.UniqueESSymbol) { + return `[${getNameOfSymbolAsWritten((nameType).symbol, context)}]`; } } return symbolName(symbol); @@ -4273,7 +4293,7 @@ namespace ts { // right hand expression is of a type parameter type. if (isVariableDeclaration(declaration) && declaration.parent.parent.kind === SyntaxKind.ForInStatement) { const indexType = getIndexType(checkNonNullExpression(declaration.parent.parent.expression)); - return indexType.flags & (TypeFlags.TypeParameter | TypeFlags.Index) ? indexType : stringType; + return indexType.flags & (TypeFlags.TypeParameter | TypeFlags.Index) ? getExtractStringType(indexType) : stringType; } if (isVariableDeclaration(declaration) && declaration.parent.parent.kind === SyntaxKind.ForOfStatement) { @@ -5290,6 +5310,16 @@ namespace ts { return links.declaredType; } + function isStringConcatExpression(expr: Node): boolean { + if (expr.kind === SyntaxKind.StringLiteral) { + return true; + } + else if (expr.kind === SyntaxKind.BinaryExpression) { + return isStringConcatExpression((expr).left) && isStringConcatExpression((expr).right); + } + return false; + } + function isLiteralEnumMember(member: EnumMember) { const expr = member.initializer; if (!expr) { @@ -5304,6 +5334,8 @@ namespace ts { (expr).operand.kind === SyntaxKind.NumericLiteral; case SyntaxKind.Identifier: return nodeIsMissing(expr) || !!getSymbolOfNode(member.parent).exports.get((expr).escapedText); + case SyntaxKind.BinaryExpression: + return isStringConcatExpression(expr); default: return false; } @@ -5665,13 +5697,7 @@ namespace ts { error(decl.name || decl, Diagnostics.Duplicate_declaration_0, name); lateSymbol = createSymbol(SymbolFlags.None, memberName, CheckFlags.Late); } - - const symbolLinks = getSymbolLinks(lateSymbol); - if (!symbolLinks.nameType) { - // Retain link to name type so that it can be reused later - symbolLinks.nameType = type; - } - + lateSymbol.nameType = type; addDeclarationToLateBoundSymbol(lateSymbol, decl, symbolFlags); if (lateSymbol.parent) { Debug.assert(lateSymbol.parent === parent, "Existing symbol parent should match new one"); @@ -6103,6 +6129,7 @@ namespace ts { const checkFlags = CheckFlags.ReverseMapped | (readonlyMask && isReadonlySymbol(prop) ? CheckFlags.Readonly : 0); const inferredProp = createSymbol(SymbolFlags.Property | prop.flags & optionalMask, prop.escapedName, checkFlags) as ReverseMappedSymbol; inferredProp.declarations = prop.declarations; + inferredProp.nameType = prop.nameType; inferredProp.propertyType = getTypeOfSymbol(prop); inferredProp.mappedType = type.mappedType; members.set(prop.escapedName, inferredProp); @@ -6114,6 +6141,7 @@ namespace ts { function resolveMappedTypeMembers(type: MappedType) { const members: SymbolTable = createSymbolTable(); let stringIndexInfo: IndexInfo; + let numberIndexInfo: IndexInfo; // Resolve upfront such that recursive references see an empty object type. setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined, undefined); // In { [P in K]: T }, we refer to P as the type parameter type, K as the constraint type, @@ -6124,15 +6152,19 @@ namespace ts { const modifiersType = getApparentType(getModifiersTypeFromMappedType(type)); // The 'T' in 'keyof T' const templateModifiers = getMappedTypeModifiers(type); const constraintDeclaration = type.declaration.typeParameter.constraint; + const include = keyofStringsOnly ? TypeFlags.StringLiteral : TypeFlags.StringOrNumberLiteralOrUnique; if (constraintDeclaration.kind === SyntaxKind.TypeOperator && (constraintDeclaration).operator === SyntaxKind.KeyOfKeyword) { // We have a { [P in keyof T]: X } - for (const propertySymbol of getPropertiesOfType(modifiersType)) { - addMemberForKeyType(getLiteralTypeFromPropertyName(propertySymbol), propertySymbol); + for (const prop of getPropertiesOfType(modifiersType)) { + addMemberForKeyType(getLiteralTypeFromPropertyName(prop, include), /*_index*/ undefined, prop); } if (modifiersType.flags & TypeFlags.Any || getIndexInfoOfType(modifiersType, IndexKind.String)) { addMemberForKeyType(stringType); } + if (!keyofStringsOnly && getIndexInfoOfType(modifiersType, IndexKind.Number)) { + addMemberForKeyType(numberType); + } } else { // First, if the constraint type is a type parameter, obtain the base constraint. Then, @@ -6142,16 +6174,9 @@ namespace ts { const iterationType = keyType.flags & TypeFlags.Index ? getIndexType(getApparentType((keyType).type)) : keyType; forEachType(iterationType, addMemberForKeyType); } - setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, undefined); + setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); - function addMemberForKeyType(t: Type, propertySymbolOrIndex?: Symbol | number) { - let propertySymbol: Symbol; - // forEachType delegates to forEach, which calls with a numeric second argument - // the type system currently doesn't catch this incompatibility, so we annotate - // the function ourselves to indicate the runtime behavior and deal with it here - if (typeof propertySymbolOrIndex === "object") { - propertySymbol = propertySymbolOrIndex; - } + function addMemberForKeyType(t: Type, _index?: number, origin?: Symbol) { // Create a mapper from T to the current iteration type constituent. Then, if the // mapped type is itself an instantiated type, combine the iteration mapper with the // instantiation mapper. @@ -6159,8 +6184,8 @@ namespace ts { const propType = instantiateType(templateType, templateMapper); // If the current iteration type constituent is a string literal type, create a property. // Otherwise, for type string create a string index signature. - if (t.flags & TypeFlags.StringLiteral) { - const propName = getLateBoundNameFromType(t as LiteralType | UniqueESSymbolType); + if (t.flags & TypeFlags.StringOrNumberLiteralOrUnique) { + const propName = getLateBoundNameFromType(t as LiteralType); const modifiersProp = getPropertyOfType(modifiersType, propName); const isOptional = !!(templateModifiers & MappedTypeModifiers.IncludeOptional || !(templateModifiers & MappedTypeModifiers.ExcludeOptional) && modifiersProp && modifiersProp.flags & SymbolFlags.Optional); @@ -6173,9 +6198,9 @@ namespace ts { prop.type = strictNullChecks && isOptional && !isTypeAssignableTo(undefinedType, propType) ? getOptionalType(propType) : strictNullChecks && !isOptional && modifiersProp && modifiersProp.flags & SymbolFlags.Optional ? getTypeWithFacts(propType, TypeFacts.NEUndefined) : propType; - if (propertySymbol) { - prop.syntheticOrigin = propertySymbol; - prop.declarations = propertySymbol.declarations; + if (origin) { + prop.syntheticOrigin = origin; + prop.declarations = origin.declarations; } prop.nameType = t; members.set(propName, prop); @@ -6183,6 +6208,9 @@ namespace ts { else if (t.flags & (TypeFlags.Any | TypeFlags.String)) { stringIndexInfo = createIndexInfo(propType, !!(templateModifiers & MappedTypeModifiers.IncludeReadonly)); } + else if (t.flags & TypeFlags.Number) { + numberIndexInfo = createIndexInfo(propType, !!(templateModifiers & MappedTypeModifiers.IncludeReadonly)); + } } } @@ -6362,18 +6390,10 @@ namespace ts { } function getConstraintOfIndexedAccess(type: IndexedAccessType) { - const transformed = getSimplifiedIndexedAccessType(type); - if (transformed) { - return transformed; - } - const baseObjectType = getBaseConstraintOfType(type.objectType); - const baseIndexType = getBaseConstraintOfType(type.indexType); - if (baseIndexType === stringType && !getIndexInfoOfType(baseObjectType || type.objectType, IndexKind.String)) { - // getIndexedAccessType returns `any` for X[string] where X doesn't have an index signature. - // to avoid this, return `undefined`. - return undefined; - } - return baseObjectType || baseIndexType ? getIndexedAccessType(baseObjectType || type.objectType, baseIndexType || type.indexType) : undefined; + const objectType = getBaseConstraintOfType(type.objectType) || type.objectType; + const indexType = getBaseConstraintOfType(type.indexType) || type.indexType; + const constraint = !isGenericObjectType(objectType) && !isGenericIndexType(indexType) ? getIndexedAccessType(objectType, indexType) : undefined; + return constraint && constraint !== unknownType ? constraint : undefined; } function getDefaultConstraintOfConditionalType(type: ConditionalType) { @@ -6420,7 +6440,7 @@ namespace ts { function getBaseConstraintOfType(type: Type): Type { const constraint = getBaseConstraintOfInstantiableNonPrimitiveUnionOrIntersection(type); if (!constraint && type.flags & TypeFlags.Index) { - return stringType; + return keyofConstraintType; } return constraint; } @@ -6455,7 +6475,7 @@ namespace ts { circular = true; return undefined; } - const result = computeBaseConstraint(t); + const result = computeBaseConstraint(getSimplifiedType(t)); if (!popTypeResolution()) { circular = true; return undefined; @@ -6484,13 +6504,9 @@ namespace ts { undefined; } if (t.flags & TypeFlags.Index) { - return stringType; + return keyofConstraintType; } if (t.flags & TypeFlags.IndexedAccess) { - const transformed = getSimplifiedIndexedAccessType(t); - if (transformed) { - return getBaseConstraint(transformed); - } const baseObjectType = getBaseConstraint((t).objectType); const baseIndexType = getBaseConstraint((t).indexType); const baseIndexedAccess = baseObjectType && baseIndexType ? getIndexedAccessType(baseObjectType, baseIndexType) : undefined; @@ -6574,6 +6590,7 @@ namespace ts { t.flags & TypeFlags.BooleanLike ? globalBooleanType : t.flags & TypeFlags.ESSymbolLike ? getGlobalESSymbolType(/*reportErrors*/ languageVersion >= ScriptTarget.ES2015) : t.flags & TypeFlags.NonPrimitive ? emptyObjectType : + t.flags & TypeFlags.Index ? keyofConstraintType : t; } @@ -6613,25 +6630,30 @@ namespace ts { if (props.length === 1 && !(checkFlags & CheckFlags.Partial)) { return props[0]; } - const propTypes: Type[] = []; - const declarations: Declaration[] = []; + let declarations: Declaration[]; let commonType: Type; + let nameType: Type; + const propTypes: Type[] = []; + let first = true; for (const prop of props) { - if (prop.declarations) { - addRange(declarations, prop.declarations); - } + declarations = addRange(declarations, prop.declarations); const type = getTypeOfSymbol(prop); - if (!commonType) { + if (first) { commonType = type; + nameType = prop.nameType; + first = false; } - else if (type !== commonType) { - checkFlags |= CheckFlags.HasNonUniformType; + else { + if (type !== commonType) { + checkFlags |= CheckFlags.HasNonUniformType; + } } propTypes.push(type); } const result = createSymbol(SymbolFlags.Property | commonFlags, name, syntheticFlag | checkFlags); result.containingType = containingType; result.declarations = declarations; + result.nameType = nameType; result.type = isUnion ? getUnionType(propTypes) : getIntersectionType(propTypes); return result; } @@ -7769,6 +7791,10 @@ namespace ts { return symbol && getTypeOfGlobalSymbol(symbol, arity); } + function getGlobalExtractSymbol(): Symbol { + return deferredGlobalExtractSymbol || (deferredGlobalExtractSymbol = getGlobalSymbol("Extract" as __String, SymbolFlags.TypeAlias, Diagnostics.Cannot_find_global_type_0)); + } + /** * Instantiates a global type that is generic with some element type, and returns that instantiation. */ @@ -8203,53 +8229,66 @@ namespace ts { return links.resolvedType; } - function getIndexTypeForGenericType(type: InstantiableType | UnionOrIntersectionType, includeDeclaredTypes?: boolean) { - const cacheLocation = includeDeclaredTypes ? "resolvedDeclaredIndexType" : "resolvedIndexType"; - if (!type[cacheLocation]) { - type[cacheLocation] = createType(TypeFlags.Index); - type[cacheLocation].type = type; - if (includeDeclaredTypes) { - type[cacheLocation].isDeclaredType = true; - } - } - return type[cacheLocation]; + function createIndexType(type: InstantiableType | UnionOrIntersectionType, stringsOnly: boolean) { + const result = createType(TypeFlags.Index); + result.type = type; + result.stringsOnly = stringsOnly; + return result; } - function getLiteralTypeFromPropertyName(prop: Symbol) { - const links = getSymbolLinks(getLateBoundSymbol(prop)); - if (!links.nameType) { - if (links.target && links.target !== unknownSymbol && links.target !== resolvingSymbol && links.target.escapedName === prop.escapedName) { - links.nameType = getLiteralTypeFromPropertyName(links.target); - } - else { - links.nameType = getDeclarationModifierFlagsFromSymbol(prop) & ModifierFlags.NonPublicAccessibilityModifier || isKnownSymbol(prop) ? - neverType : + function getIndexTypeForGenericType(type: InstantiableType | UnionOrIntersectionType, stringsOnly: boolean) { + return stringsOnly ? + type.resolvedStringIndexType || (type.resolvedStringIndexType = createIndexType(type, /*stringsOnly*/ true)) : + type.resolvedIndexType || (type.resolvedIndexType = createIndexType(type, /*stringsOnly*/ false)); + } + + function getLiteralTypeFromPropertyName(prop: Symbol, include: TypeFlags) { + if (!(getDeclarationModifierFlagsFromSymbol(prop) & ModifierFlags.NonPublicAccessibilityModifier)) { + let type = getLateBoundSymbol(prop).nameType; + if (!type && !isKnownSymbol(prop)) { + const name = getNameOfDeclaration(prop.valueDeclaration); + type = name && isNumericLiteral(name) ? getLiteralType(+name.text) : + name && name.kind === SyntaxKind.ComputedPropertyName && isNumericLiteral(name.expression) ? getLiteralType(+name.expression.text) : getLiteralType(symbolName(prop)); } + if (type && type.flags & include) { + return type; + } } - return links.nameType; + return neverType; } - function isTypeString(type: Type) { - return isTypeAssignableToKind(type, TypeFlags.StringLike); + function getLiteralTypeFromPropertyNames(type: Type, include: TypeFlags) { + return getUnionType(map(getPropertiesOfType(type), t => getLiteralTypeFromPropertyName(t, include))); } - function getLiteralTypeFromPropertyNames(type: Type, includeDeclaredTypes?: boolean) { - const originalKeys = map(getPropertiesOfType(type), getLiteralTypeFromPropertyName); - return getUnionType(includeDeclaredTypes ? originalKeys : filter(originalKeys, isTypeString)); + function getNonEnumNumberIndexInfo(type: Type) { + const numberIndexInfo = getIndexInfoOfType(type, IndexKind.Number); + return numberIndexInfo !== enumNumberIndexInfo ? numberIndexInfo : undefined; } - function getIndexType(type: Type, includeDeclaredTypes?: boolean): Type { - return type.flags & TypeFlags.Intersection ? getUnionType(map((type).types, t => getIndexType(t, includeDeclaredTypes))) : - maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive) ? getIndexTypeForGenericType(type, includeDeclaredTypes) : + function getIndexType(type: Type, stringsOnly = keyofStringsOnly): Type { + return type.flags & TypeFlags.Intersection ? getUnionType(map((type).types, t => getIndexType(t, stringsOnly))) : + maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive) ? getIndexTypeForGenericType(type, stringsOnly) : getObjectFlags(type) & ObjectFlags.Mapped ? getConstraintTypeFromMappedType(type) : type === wildcardType ? wildcardType : - type.flags & TypeFlags.Any || getIndexInfoOfType(type, IndexKind.String) ? stringType : - getLiteralTypeFromPropertyNames(type, includeDeclaredTypes); + type.flags & TypeFlags.Any ? keyofConstraintType : + stringsOnly ? getIndexInfoOfType(type, IndexKind.String) ? stringType : getLiteralTypeFromPropertyNames(type, TypeFlags.StringLiteral) : + getIndexInfoOfType(type, IndexKind.String) ? getUnionType([stringType, numberType, getLiteralTypeFromPropertyNames(type, TypeFlags.UniqueESSymbol)]) : + getNonEnumNumberIndexInfo(type) ? getUnionType([numberType, getLiteralTypeFromPropertyNames(type, TypeFlags.StringLiteral | TypeFlags.UniqueESSymbol)]) : + getLiteralTypeFromPropertyNames(type, TypeFlags.StringOrNumberLiteralOrUnique); + } + + function getExtractStringType(type: Type) { + if (keyofStringsOnly) { + return type; + } + const extractTypeAlias = getGlobalExtractSymbol(); + return extractTypeAlias ? getTypeAliasInstantiation(extractTypeAlias, [type, stringType]) : stringType; } function getIndexTypeOrString(type: Type): Type { - const indexType = getIndexType(type); + const indexType = getExtractStringType(getIndexType(type)); return indexType.flags & TypeFlags.Never ? stringType : indexType; } @@ -8307,7 +8346,11 @@ namespace ts { getIndexInfoOfType(objectType, IndexKind.String) || undefined; if (indexInfo) { - if (accessExpression && indexInfo.isReadonly && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) { + if (accessNode && !isTypeAssignableToKind(indexType, TypeFlags.String | TypeFlags.Number)) { + const indexNode = accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode.argumentExpression : accessNode.indexType; + error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType)); + } + else if (accessExpression && indexInfo.isReadonly && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) { error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType)); } return indexInfo.type; @@ -8338,9 +8381,8 @@ namespace ts { else { error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType)); } - return unknownType; } - return anyType; + return unknownType; } function isGenericObjectType(type: Type): boolean { @@ -8367,8 +8409,12 @@ namespace ts { return getObjectFlags(type) & ObjectFlags.Mapped && getTemplateTypeFromMappedType(type as MappedType) === neverType; } + function getSimplifiedType(type: Type): Type { + return type.flags & TypeFlags.IndexedAccess ? getSimplifiedIndexedAccessType(type) : type; + } + // Transform an indexed access to a simpler form, if possible. Return the simpler form, or return - // undefined if no transformation is possible. + // the type itself if no transformation is possible. function getSimplifiedIndexedAccessType(type: IndexedAccessType): Type { const objectType = type.objectType; if (objectType.flags & TypeFlags.Intersection && isGenericObjectType(objectType)) { @@ -8388,7 +8434,7 @@ namespace ts { } } return getUnionType([ - getIndexedAccessType(getIntersectionType(regularTypes), type.indexType), + getSimplifiedType(getIndexedAccessType(getIntersectionType(regularTypes), type.indexType)), getIntersectionType(stringIndexTypes) ]); } @@ -8398,13 +8444,13 @@ namespace ts { // eventually anyway, but it easier to reason about. if (some((objectType).types, isMappedTypeToNever)) { const nonNeverTypes = filter((objectType).types, t => !isMappedTypeToNever(t)); - return getIndexedAccessType(getIntersectionType(nonNeverTypes), type.indexType); + return getSimplifiedType(getIndexedAccessType(getIntersectionType(nonNeverTypes), type.indexType)); } } - // If the object type is a mapped type { [P in K]: E }, where K is generic, instantiate E using a mapper // that substitutes the index type for P. For example, for an index access { [P in K]: Box }[X], we - // construct the type Box. + // construct the type Box. We do not further simplify the result because mapped types can be recursive + // and we might never terminate. if (isGenericMappedType(objectType)) { return substituteIndexedMappedType(objectType, type); } @@ -8414,7 +8460,7 @@ namespace ts { return substituteIndexedMappedType(constraint, type); } } - return undefined; + return type; } function substituteIndexedMappedType(objectType: MappedType, type: IndexedAccessType) { @@ -8747,7 +8793,7 @@ namespace ts { if (right.flags & TypeFlags.Union) { return mapType(right, t => getSpreadType(left, t, symbol, typeFlags, objectFlags)); } - if (right.flags & (TypeFlags.BooleanLike | TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.EnumLike | TypeFlags.NonPrimitive)) { + if (right.flags & (TypeFlags.BooleanLike | TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.EnumLike | TypeFlags.NonPrimitive | TypeFlags.Index)) { return left; } @@ -8793,6 +8839,7 @@ namespace ts { result.leftSpread = leftProp; result.rightSpread = rightProp; result.declarations = declarations; + result.nameType = leftProp.nameType; members.set(leftProp.escapedName, result); } } @@ -8821,6 +8868,7 @@ namespace ts { const result = createSymbol(flags, prop.escapedName); result.type = getTypeOfSymbol(prop); result.declarations = prop.declarations; + result.nameType = prop.nameType; result.syntheticOrigin = prop; return result; } @@ -9166,8 +9214,13 @@ namespace ts { if (symbol.valueDeclaration) { result.valueDeclaration = symbol.valueDeclaration; } - if ((symbol as TransientSymbol).isRestParameter) { - result.isRestParameter = (symbol as TransientSymbol).isRestParameter; + if (symbol.nameType) { + result.nameType = symbol.nameType; + } + if (isTransientSymbol(symbol)) { + if (symbol.isRestParameter) { + result.isRestParameter = symbol.isRestParameter; + } } return result; } @@ -9973,6 +10026,12 @@ namespace ts { if (target.flags & TypeFlags.Substitution) { target = (target).typeVariable; } + if (source.flags & TypeFlags.IndexedAccess) { + source = getSimplifiedType(source); + } + if (target.flags & TypeFlags.IndexedAccess) { + target = getSimplifiedType(target); + } // both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases if (source === target) return Ternary.True; @@ -10426,15 +10485,15 @@ namespace ts { // constraint of T. const constraint = getConstraintForRelation((target).type); if (constraint) { - if (result = isRelatedTo(source, getIndexType(constraint, (target as IndexType).isDeclaredType), reportErrors)) { + if (result = isRelatedTo(source, getIndexType(constraint, (target as IndexType).stringsOnly), reportErrors)) { return result; } } } else if (target.flags & TypeFlags.IndexedAccess) { - // A type S is related to a type T[K] if S is related to A[K], where K is string-like and - // A is the apparent type of T. - const constraint = getConstraintForRelation(target); + // A type S is related to a type T[K] if S is related to C, where C is the + // constraint of T[K] + const constraint = getConstraintForRelation(target); if (constraint) { if (result = isRelatedTo(source, constraint, reportErrors)) { errorInfo = saveErrorInfo; @@ -10447,21 +10506,21 @@ namespace ts { const template = getTemplateTypeFromMappedType(target); const modifiers = getMappedTypeModifiers(target); if (!(modifiers & MappedTypeModifiers.ExcludeOptional)) { - if (template.flags & TypeFlags.IndexedAccess && (template).objectType === source && - (template).indexType === getTypeParameterFromMappedType(target)) { - return Ternary.True; - } - // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X. - if (!isGenericMappedType(source) && getConstraintTypeFromMappedType(target) === getIndexType(source)) { - const indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target)); - const templateType = getTemplateTypeFromMappedType(target); - if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { - errorInfo = saveErrorInfo; - return result; + if (template.flags & TypeFlags.IndexedAccess && (template).objectType === source && + (template).indexType === getTypeParameterFromMappedType(target)) { + return Ternary.True; + } + // A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X. + if (!isGenericMappedType(source) && getConstraintTypeFromMappedType(target) === getIndexType(source)) { + const indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(target)); + const templateType = getTemplateTypeFromMappedType(target); + if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) { + errorInfo = saveErrorInfo; + return result; + } } } } - } if (source.flags & TypeFlags.TypeParameter) { let constraint = getConstraintForRelation(source); @@ -10479,16 +10538,8 @@ namespace ts { } } else if (source.flags & TypeFlags.IndexedAccess) { - // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and - // A is the apparent type of S. - const constraint = getConstraintForRelation(source); - if (constraint) { - if (result = isRelatedTo(constraint, target, reportErrors)) { - errorInfo = saveErrorInfo; - return result; - } - } - else if (target.flags & TypeFlags.IndexedAccess) { + if (target.flags & TypeFlags.IndexedAccess) { + // A type S[K] is related to a type T[J] if S is related to T and K is related to J. if (result = isRelatedTo((source).objectType, (target).objectType, reportErrors)) { result &= isRelatedTo((source).indexType, (target).indexType, reportErrors); } @@ -10497,6 +10548,21 @@ namespace ts { return result; } } + // A type S[K] is related to a type T if C is related to T, where C is the + // constraint of S[K]. + const constraint = getConstraintForRelation(source); + if (constraint) { + if (result = isRelatedTo(constraint, target, reportErrors)) { + errorInfo = saveErrorInfo; + return result; + } + } + } + else if (source.flags & TypeFlags.Index) { + if (result = isRelatedTo(keyofConstraintType, target, reportErrors)) { + errorInfo = saveErrorInfo; + return result; + } } else if (source.flags & TypeFlags.Conditional) { if (target.flags & TypeFlags.Conditional) { @@ -10889,8 +10955,7 @@ namespace ts { continue; } // Skip over symbol-named members - const nameType = getLiteralTypeFromPropertyName(prop); - if (nameType !== undefined && !(isRelatedTo(nameType, stringType) || isRelatedTo(nameType, numberType))) { + if (prop.nameType && prop.nameType.flags & TypeFlags.UniqueESSymbol) { continue; } if (kind === IndexKind.String || isNumericLiteralName(prop.escapedName)) { @@ -11493,6 +11558,9 @@ namespace ts { if (source.valueDeclaration) { symbol.valueDeclaration = source.valueDeclaration; } + if (source.nameType) { + symbol.nameType = source.nameType; + } return symbol; } @@ -11535,7 +11603,7 @@ namespace ts { } function createWideningContext(parent: WideningContext, propertyName: __String, siblings: Type[]): WideningContext { - return { parent, propertyName, siblings, resolvedPropertyNames: undefined }; + return { parent, propertyName, siblings, resolvedProperties: undefined }; } function getSiblingsOfContext(context: WideningContext): Type[] { @@ -11556,19 +11624,19 @@ namespace ts { return context.siblings; } - function getPropertyNamesOfContext(context: WideningContext): __String[] { - if (!context.resolvedPropertyNames) { - const names = createMap() as UnderscoreEscapedMap; + function getPropertiesOfContext(context: WideningContext): Symbol[] { + if (!context.resolvedProperties) { + const names = createMap() as UnderscoreEscapedMap; for (const t of getSiblingsOfContext(context)) { if (isObjectLiteralType(t) && !(getObjectFlags(t) & ObjectFlags.ContainsSpread)) { for (const prop of getPropertiesOfType(t)) { - names.set(prop.escapedName, true); + names.set(prop.escapedName, prop); } } } - context.resolvedPropertyNames = arrayFrom(names.keys()); + context.resolvedProperties = arrayFrom(names.values()); } - return context.resolvedPropertyNames; + return context.resolvedProperties; } function getWidenedProperty(prop: Symbol, context: WideningContext): Symbol { @@ -11578,18 +11646,14 @@ namespace ts { return widened === original ? prop : createSymbolWithType(prop, widened); } - function getUndefinedProperty(name: __String) { - const cached = undefinedProperties.get(name); + function getUndefinedProperty(prop: Symbol) { + const cached = undefinedProperties.get(prop.escapedName); if (cached) { return cached; } - const result = createSymbol(SymbolFlags.Property | SymbolFlags.Optional, name); - result.type = undefinedType; - const associatedKeyType = getLiteralType(unescapeLeadingUnderscores(name)); - if (associatedKeyType.flags & TypeFlags.StringLiteral) { - result.nameType = associatedKeyType; - } - undefinedProperties.set(name, result); + const result = createSymbolWithType(prop, undefinedType); + result.flags |= SymbolFlags.Optional; + undefinedProperties.set(prop.escapedName, result); return result; } @@ -11601,9 +11665,9 @@ namespace ts { members.set(prop.escapedName, prop.flags & SymbolFlags.Property ? getWidenedProperty(prop, context) : prop); } if (context) { - for (const name of getPropertyNamesOfContext(context)) { - if (!members.has(name)) { - members.set(name, getUndefinedProperty(name)); + for (const prop of getPropertiesOfContext(context)) { + if (!members.has(prop.escapedName)) { + members.set(prop.escapedName, getUndefinedProperty(prop)); } } } @@ -12360,14 +12424,13 @@ namespace ts { inferredType = getTypeFromInference(inference); } - inferredType = getWidenedUniqueESSymbolType(inferredType); inference.inferredType = inferredType; const constraint = getConstraintOfTypeParameter(inference.typeParameter); if (constraint) { const instantiatedConstraint = instantiateType(constraint, context); if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) { - inference.inferredType = inferredType = getWidenedUniqueESSymbolType(instantiatedConstraint); + inference.inferredType = inferredType = instantiatedConstraint; } } } @@ -15311,7 +15374,7 @@ namespace ts { // type, and any union of these types (like string | number). if (links.resolvedType.flags & TypeFlags.Nullable || !isTypeAssignableToKind(links.resolvedType, TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.ESSymbolLike) && - !isTypeAssignableTo(links.resolvedType, getUnionType([stringType, numberType, esSymbolType]))) { + !isTypeAssignableTo(links.resolvedType, stringNumberSymbolType)) { error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_symbol_or_any); } else { @@ -15352,6 +15415,7 @@ namespace ts { let patternWithComputedProperties = false; let hasComputedStringProperty = false; let hasComputedNumberProperty = false; + if (isInJSFile && node.properties.length === 0) { // an empty JS object literal that nonetheless has members is a JS namespace const symbol = getSymbolOfNode(node); @@ -15367,47 +15431,28 @@ namespace ts { for (let i = 0; i < node.properties.length; i++) { const memberDecl = node.properties[i]; let member = getSymbolOfNode(memberDecl); - let literalName: __String | undefined; + const computedNameType = memberDecl.name && memberDecl.name.kind === SyntaxKind.ComputedPropertyName && !isWellKnownSymbolSyntactically(memberDecl.name.expression) ? + checkComputedPropertyName(memberDecl.name) : undefined; if (memberDecl.kind === SyntaxKind.PropertyAssignment || memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment || isObjectLiteralMethod(memberDecl)) { - let jsdocType: Type; + let type = memberDecl.kind === SyntaxKind.PropertyAssignment ? checkPropertyAssignment(memberDecl, checkMode) : + memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment ? checkExpressionForMutableLocation(memberDecl.name, checkMode) : + checkObjectLiteralMethod(memberDecl, checkMode); if (isInJSFile) { - jsdocType = getTypeForDeclarationFromJSDocComment(memberDecl); - } - - let type: Type; - if (memberDecl.kind === SyntaxKind.PropertyAssignment) { - if (memberDecl.name.kind === SyntaxKind.ComputedPropertyName) { - const t = checkComputedPropertyName(memberDecl.name); - if (t.flags & TypeFlags.Literal) { - literalName = escapeLeadingUnderscores("" + (t as LiteralType).value); - } + const jsDocType = getTypeForDeclarationFromJSDocComment(memberDecl); + if (jsDocType) { + checkTypeAssignableTo(type, jsDocType, memberDecl); + type = jsDocType; } - type = checkPropertyAssignment(memberDecl, checkMode); } - else if (memberDecl.kind === SyntaxKind.MethodDeclaration) { - type = checkObjectLiteralMethod(memberDecl, checkMode); - } - else { - Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment); - type = checkExpressionForMutableLocation(memberDecl.name, checkMode); - } - - if (jsdocType) { - checkTypeAssignableTo(type, jsdocType, memberDecl); - type = jsdocType; - } - typeFlags |= type.flags; - - const nameType = hasLateBindableName(memberDecl) ? checkComputedPropertyName(memberDecl.name) : undefined; - const hasLateBoundName = nameType && isTypeUsableAsLateBoundName(nameType); - const prop = hasLateBoundName - ? createSymbol(SymbolFlags.Property | member.flags, getLateBoundNameFromType(nameType as LiteralType | UniqueESSymbolType), CheckFlags.Late) - : createSymbol(SymbolFlags.Property | member.flags, literalName || member.escapedName); - - if (hasLateBoundName) { + const nameType = computedNameType && computedNameType.flags & TypeFlags.StringOrNumberLiteralOrUnique ? + computedNameType : undefined; + const prop = nameType ? + createSymbol(SymbolFlags.Property | member.flags, getLateBoundNameFromType(nameType), CheckFlags.Late) : + createSymbol(SymbolFlags.Property | member.flags, member.escapedName); + if (nameType) { prop.nameType = nameType; } @@ -15420,9 +15465,6 @@ namespace ts { if (isOptional) { prop.flags |= SymbolFlags.Optional; } - if (!literalName && hasDynamicName(memberDecl)) { - patternWithComputedProperties = true; - } } else if (contextualTypeHasPattern && !(getObjectFlags(contextualType) & ObjectFlags.ObjectLiteralPatternWithComputedProperties)) { // If object literal is contextually typed by the implied type of a binding pattern, and if the @@ -15478,12 +15520,17 @@ namespace ts { checkNodeDeferred(memberDecl); } - if (!literalName && hasNonBindableDynamicName(memberDecl)) { - if (isNumericName(memberDecl.name)) { - hasComputedNumberProperty = true; - } - else { - hasComputedStringProperty = true; + if (computedNameType && !(computedNameType.flags & TypeFlags.StringOrNumberLiteralOrUnique)) { + if (isTypeAssignableTo(computedNameType, stringNumberSymbolType)) { + if (isTypeAssignableTo(computedNameType, numberType)) { + hasComputedNumberProperty = true; + } + else { + hasComputedStringProperty = true; + } + if (inDestructuringPattern) { + patternWithComputedProperties = true; + } } } else { @@ -20045,6 +20092,15 @@ namespace ts { return widened; } + function isTypeParameterWithKeyofConstraint(type: Type) { + if (type.flags & TypeFlags.TypeParameter) { + const constraintDeclaration = getConstraintDeclaration(type); + return constraintDeclaration && constraintDeclaration.kind === SyntaxKind.TypeOperator && + (constraintDeclaration).operator === SyntaxKind.KeyOfKeyword; + } + return false; + } + function isLiteralOfContextualType(candidateType: Type, contextualType: Type): boolean { if (contextualType) { if (contextualType.flags & TypeFlags.UnionOrIntersection) { @@ -20056,7 +20112,8 @@ namespace ts { // this a literal context for literals of that primitive type. For example, given a // type parameter 'T extends string', infer string literal types for T. const constraint = getBaseConstraintOfType(contextualType) || emptyObjectType; - return constraint.flags & TypeFlags.String && maybeTypeOfKind(candidateType, TypeFlags.StringLiteral) || + return isTypeParameterWithKeyofConstraint(contextualType) && maybeTypeOfKind(candidateType, TypeFlags.StringLiteral | TypeFlags.NumberLiteral | TypeFlags.UniqueESSymbol) || + constraint.flags & TypeFlags.String && maybeTypeOfKind(candidateType, TypeFlags.StringLiteral) || constraint.flags & TypeFlags.Number && maybeTypeOfKind(candidateType, TypeFlags.NumberLiteral) || constraint.flags & TypeFlags.Boolean && maybeTypeOfKind(candidateType, TypeFlags.BooleanLiteral) || constraint.flags & TypeFlags.ESSymbol && maybeTypeOfKind(candidateType, TypeFlags.UniqueESSymbol) || @@ -20985,7 +21042,7 @@ namespace ts { // Check if the index type is assignable to 'keyof T' for the object type. const objectType = (type).objectType; const indexType = (type).indexType; - if (isTypeAssignableTo(indexType, getIndexType(objectType, /*includeDeclaredTypes*/ true))) { + if (isTypeAssignableTo(indexType, getIndexType(objectType, /*stringsOnly*/ false))) { if (accessNode.kind === SyntaxKind.ElementAccessExpression && isAssignmentTarget(accessNode) && getObjectFlags(objectType) & ObjectFlags.Mapped && getMappedTypeModifiers(objectType) & MappedTypeModifiers.IncludeReadonly) { error(accessNode, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType)); @@ -21017,7 +21074,7 @@ namespace ts { const type = getTypeFromMappedTypeNode(node); const constraintType = getConstraintTypeFromMappedType(type); - checkTypeAssignableTo(constraintType, stringType, node.typeParameter.constraint); + checkTypeAssignableTo(constraintType, keyofConstraintType, node.typeParameter.constraint); } function checkTypeOperator(node: TypeOperatorNode) { @@ -24090,6 +24147,9 @@ namespace ts { case SyntaxKind.AsteriskAsteriskToken: return left ** right; } } + else if (typeof left === "string" && typeof right === "string" && (expr).operatorToken.kind === SyntaxKind.PlusToken) { + return left + right; + } break; case SyntaxKind.StringLiteral: return (expr).text; diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 470bd111492..126c1529094 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -672,6 +672,12 @@ namespace ts { category: Diagnostics.Advanced_Options, description: Diagnostics.Disable_strict_checking_of_generic_signatures_in_function_types, }, + { + name: "keyofStringsOnly", + type: "boolean", + category: Diagnostics.Advanced_Options, + description: Diagnostics.Resolve_keyof_to_string_valued_property_names_only_no_numbers_or_symbols, + }, { // A list of plugins to load in the language service name: "plugins", diff --git a/src/compiler/core.ts b/src/compiler/core.ts index a615c73ec40..e13ec4537a2 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -2212,6 +2212,15 @@ namespace ts { return absolutePath; } + export function getRelativePath(path: string, directoryPath: string, getCanonicalFileName: GetCanonicalFileName) { + const relativePath = getRelativePathToDirectoryOrUrl(directoryPath, path, directoryPath, getCanonicalFileName, /*isAbsolutePathAnUrl*/ false); + return ensurePathIsRelative(relativePath); + } + + export function ensurePathIsRelative(path: string): string { + return !pathIsRelative(path) ? "./" + path : path; + } + export function getBaseFileName(path: string) { if (path === undefined) { return undefined; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a5119f7feb7..2bb6d4bec61 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3526,6 +3526,10 @@ "category": "Message", "code": 6194 }, + "Resolve 'keyof' to string valued property names only (no numbers or symbols).": { + "category": "Message", + "code": 6195 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", "code": 7005 diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 0027687c643..81aed522490 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -444,6 +444,12 @@ namespace ts { } } + export function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations | undefined { + const containingDirectory = getDirectoryPath(containingFile); + const perFolderCache = cache && cache.getOrCreateCacheForDirectory(containingDirectory); + return perFolderCache && perFolderCache.get(moduleName); + } + export function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations { const traceEnabled = isTraceEnabled(compilerOptions, host); if (traceEnabled) { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 9eb82661cf5..75cdd07845f 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -622,9 +622,6 @@ namespace ts { Debug.assert(!!missingFilePaths); - // unconditionally set moduleResolutionCache to undefined to avoid unnecessary leaks - moduleResolutionCache = undefined; - // Release any files we have acquired in the old program but are // not part of the new program. if (oldProgram && host.onReleaseOldSourceFile) { @@ -670,7 +667,8 @@ namespace ts { sourceFileToPackageName, redirectTargetsSet, isEmittedFile, - getConfigFileParsingDiagnostics + getConfigFileParsingDiagnostics, + getResolvedModuleWithFailedLookupLocationsFromCache, }; verifyCompilerOptions(); @@ -679,6 +677,10 @@ namespace ts { return program; + function getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): ResolvedModuleWithFailedLookupLocations { + return moduleResolutionCache && resolveModuleNameFromCache(moduleName, containingFile, moduleResolutionCache); + } + function toPath(fileName: string): Path { return ts.toPath(fileName, currentDirectory, getCanonicalFileName); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4ea4b7ab8cc..06f15e1d77a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2332,7 +2332,7 @@ namespace ts { } export interface JSDocTag extends Node { - parent: JSDoc; + parent: JSDoc | JSDocTypeLiteral; atToken: AtToken; tagName: Identifier; comment: string | undefined; @@ -2725,6 +2725,8 @@ namespace ts { /* @internal */ redirectTargetsSet: Map; /** Is the file emitted file */ /* @internal */ isEmittedFile(file: string): boolean; + + /* @internal */ getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined; } /* @internal */ @@ -3375,6 +3377,7 @@ namespace ts { /* @internal */ mergeId?: number; // Merge id (used to look up merged symbol) /* @internal */ parent?: Symbol; // Parent symbol /* @internal */ exportSymbol?: Symbol; // Exported symbol associated with this symbol + /* @internal */ nameType?: Type; // Type associated with a late-bound symbol /* @internal */ constEnumOnlyModule?: boolean; // True if module contains only const enums or other modules with only const enums /* @internal */ isReferenced?: SymbolFlags; // True if the symbol is referenced elsewhere. Keeps track of the meaning of a reference in case a symbol is both a type parameter and parameter. /* @internal */ isReplaceableByMethod?: boolean; // Can this Javascript class property be replaced by a method symbol? @@ -3409,7 +3412,6 @@ namespace ts { enumKind?: EnumKind; // Enum declaration classification originatingImport?: ImportDeclaration | ImportCall; // Import declaration which produced the symbol, present if the symbol is marked as uncallable but had call signatures in `resolveESModuleSymbol` lateSymbol?: Symbol; // Late-bound symbol for a computed property - nameType?: Type; // Type associate with a late-bound or mapped type property symbol's name } /* @internal */ @@ -3606,7 +3608,7 @@ namespace ts { Intrinsic = Any | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never | NonPrimitive, /* @internal */ Primitive = String | Number | Boolean | Enum | EnumLiteral | ESSymbol | Void | Undefined | Null | Literal | UniqueESSymbol, - StringLike = String | StringLiteral | Index, + StringLike = String | StringLiteral, NumberLike = Number | NumberLiteral | Enum, BooleanLike = Boolean | BooleanLiteral, EnumLike = Enum | EnumLiteral, @@ -3763,7 +3765,7 @@ namespace ts { /* @internal */ resolvedIndexType: IndexType; /* @internal */ - resolvedDeclaredIndexType: IndexType; + resolvedStringIndexType: IndexType; /* @internal */ resolvedBaseConstraint: Type; /* @internal */ @@ -3852,7 +3854,7 @@ namespace ts { /* @internal */ resolvedIndexType?: IndexType; /* @internal */ - resolvedDeclaredIndexType?: IndexType; + resolvedStringIndexType?: IndexType; } // Type parameters (TypeFlags.TypeParameter) @@ -3884,9 +3886,9 @@ namespace ts { // keyof T types (TypeFlags.Index) export interface IndexType extends InstantiableType { - /* @internal */ - isDeclaredType?: boolean; type: InstantiableType | UnionOrIntersectionType; + /* @internal */ + stringsOnly: boolean; } export interface ConditionalRoot { @@ -4045,10 +4047,10 @@ namespace ts { /* @internal */ export interface WideningContext { - parent?: WideningContext; // Parent context - propertyName?: __String; // Name of property in parent - siblings?: Type[]; // Types of siblings - resolvedPropertyNames?: __String[]; // Property names occurring in sibling object literals + parent?: WideningContext; // Parent context + propertyName?: __String; // Name of property in parent + siblings?: Type[]; // Types of siblings + resolvedProperties?: Symbol[]; // Properties occurring in sibling object literals } /* @internal */ @@ -4163,6 +4165,7 @@ namespace ts { inlineSources?: boolean; isolatedModules?: boolean; jsx?: JsxEmit; + keyofStringsOnly?: boolean; lib?: string[]; /*@internal*/listEmittedFiles?: boolean; /*@internal*/listFiles?: boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 730c3fc51d4..c5cb19e876a 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1818,10 +1818,8 @@ namespace ts { function getJSDocCommentsAndTagsWorker(node: Node): void { const parent = node.parent; - if (parent && - (parent.kind === SyntaxKind.PropertyAssignment || - parent.kind === SyntaxKind.PropertyDeclaration || - getNestedModuleDeclaration(parent))) { + if (!parent) return; + if (parent.kind === SyntaxKind.PropertyAssignment || parent.kind === SyntaxKind.PropertyDeclaration || getNestedModuleDeclaration(parent)) { getJSDocCommentsAndTagsWorker(parent); } // Try to recognize this pattern when node is initializer of variable declaration and JSDoc comments are on containing variable statement. @@ -1830,16 +1828,18 @@ namespace ts { // * @returns {number} // */ // var x = function(name) { return name.length; } - if (parent && parent.parent && + if (parent.parent && (getSingleVariableOfVariableStatement(parent.parent) === node || getSourceOfAssignment(parent.parent))) { getJSDocCommentsAndTagsWorker(parent.parent); } - if (parent && parent.parent && parent.parent.parent && - (getSingleInitializerOfVariableStatementOrPropertyDeclaration(parent.parent.parent) === node || getSourceOfDefaultedAssignment(parent.parent.parent))) { + if (parent.parent && parent.parent.parent && + (getSingleVariableOfVariableStatement(parent.parent.parent) || + getSingleInitializerOfVariableStatementOrPropertyDeclaration(parent.parent.parent) === node || + getSourceOfDefaultedAssignment(parent.parent.parent))) { getJSDocCommentsAndTagsWorker(parent.parent.parent); } if (isBinaryExpression(node) && getSpecialPropertyAssignmentKind(node) !== SpecialPropertyAssignmentKind.None || - parent && isBinaryExpression(parent) && getSpecialPropertyAssignmentKind(parent) !== SpecialPropertyAssignmentKind.None || + isBinaryExpression(parent) && getSpecialPropertyAssignmentKind(parent) !== SpecialPropertyAssignmentKind.None || node.kind === SyntaxKind.PropertyAccessExpression && node.parent && node.parent.kind === SyntaxKind.ExpressionStatement) { getJSDocCommentsAndTagsWorker(parent); } @@ -1888,6 +1888,9 @@ namespace ts { } export function getJSDocHost(node: JSDocTag): HasJSDoc { + while (node.parent.kind === SyntaxKind.JSDocTypeLiteral) { + node = node.parent.parent.parent as JSDocParameterTag; + } Debug.assert(node.parent!.kind === SyntaxKind.JSDocComment); return node.parent!.parent!; } @@ -2137,11 +2140,13 @@ namespace ts { node.kind === SyntaxKind.NamespaceImport || node.kind === SyntaxKind.ImportSpecifier || node.kind === SyntaxKind.ExportSpecifier || - node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(node); + node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(node) || + isBinaryExpression(node) && getSpecialPropertyAssignmentKind(node) === SpecialPropertyAssignmentKind.ModuleExports; } - export function exportAssignmentIsAlias(node: ExportAssignment): boolean { - return isEntityNameExpression(node.expression); + export function exportAssignmentIsAlias(node: ExportAssignment | BinaryExpression): boolean { + const e = isExportAssignment(node) ? node.expression : node.right; + return isEntityNameExpression(e) || isClassExpression(e); } export function getClassExtendsHeritageClauseElement(node: ClassLikeDeclaration | InterfaceDeclaration) { @@ -2933,11 +2938,7 @@ namespace ts { } export function getFirstConstructorWithBody(node: ClassLikeDeclaration): ConstructorDeclaration { - return forEach(node.members, member => { - if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { - return member; - } - }); + return find(node.members, (member): member is ConstructorDeclaration => isConstructorDeclaration(member) && nodeIsPresent(member.body)); } function getSetAccessorValueParameter(accessor: SetAccessorDeclaration): ParameterDeclaration | undefined { diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 37aa0118801..f0bb151b814 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -33,14 +33,32 @@ namespace ts { Diagnostics.Found_0_errors_Watching_for_file_changes.code ]; - function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions) { + /** + * @returns Whether the screen was cleared. + */ + function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions): boolean { if (system.clearScreen && !options.preserveWatchOutput && !options.extendedDiagnostics && !options.diagnostics && !contains(nonClearingMessageCodes, diagnostic.code)) { system.clearScreen(); + return true; } + + return false; + } + + /** @internal */ + export const screenStartingMessageCodes: number[] = [ + Diagnostics.Starting_compilation_in_watch_mode.code, + Diagnostics.File_change_detected_Starting_incremental_compilation.code, + ]; + + function getPlainDiagnosticFollowingNewLines(diagnostic: Diagnostic, newLine: string): string { + return contains(screenStartingMessageCodes, diagnostic.code) + ? newLine + newLine + : newLine; } /** @@ -51,13 +69,19 @@ namespace ts { (diagnostic, newLine, options) => { clearScreenIfNotWatchingForFileChanges(system, diagnostic, options); let output = `[${formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey)}] `; - output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`; + output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine}`; system.write(output); } : (diagnostic, newLine, options) => { - clearScreenIfNotWatchingForFileChanges(system, diagnostic, options); - let output = new Date().toLocaleTimeString() + " - "; - output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`; + let output = ""; + + if (!clearScreenIfNotWatchingForFileChanges(system, diagnostic, options)) { + output += newLine; + } + + output += `${new Date().toLocaleTimeString()} - `; + output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${getPlainDiagnosticFollowingNewLines(diagnostic, newLine)}`; + system.write(output); }; } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index a3f883a23b3..eb8658d82bb 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -283,14 +283,10 @@ namespace FourSlash { }); const fs = new vfs.FileSystem(/*ignoreCase*/ true, { cwd: baseDir, files }); const host = new fakes.ParseConfigHost(fs); - - const configJsonObj = ts.parseConfigFileTextToJson(configFileName, this.inputFiles.get(configFileName)); - assert.isTrue(configJsonObj.config !== undefined); - - compilationOptions = ts.parseJsonConfigFileContent(configJsonObj.config, host, baseDir, compilationOptions, configFileName).options; + const jsonSourceFile = ts.parseJsonText(configFileName, this.inputFiles.get(configFileName)); + compilationOptions = ts.parseJsonSourceFileConfigFileContent(jsonSourceFile, host, baseDir, compilationOptions, configFileName).options; } - if (compilationOptions.typeRoots) { compilationOptions.typeRoots = compilationOptions.typeRoots.map(p => ts.getNormalizedAbsolutePath(p, this.basePath)); } @@ -852,6 +848,7 @@ namespace FourSlash { const actualCompletions = this.getCompletionListAtCaret(options); if (!actualCompletions) { + if (expected === undefined) return; this.raiseError(`No completions at position '${this.currentCaretPosition}'.`); } @@ -2432,14 +2429,7 @@ Actual: ${stringify(fullActual)}`); public applyCodeActionFromCompletion(markerName: string, options: FourSlashInterface.VerifyCompletionActionOptions) { this.goToMarker(markerName); - const actualCompletion = this.getCompletionListAtCaret({ ...ts.defaultPreferences, includeCompletionsForModuleExports: true }).entries.find(e => - e.name === options.name && e.source === options.source); - - if (!actualCompletion.hasAction) { - this.raiseError(`Completion for ${options.name} does not have an associated action.`); - } - - const details = this.getCompletionEntryDetails(options.name, actualCompletion.source, options.preferences); + const details = this.getCompletionEntryDetails(options.name, options.source, options.preferences); if (details.codeActions.length !== 1) { this.raiseError(`Expected one code action, got ${details.codeActions.length}`); } @@ -3289,6 +3279,15 @@ Actual: ${stringify(fullActual)}`); private static textSpansEqual(a: ts.TextSpan, b: ts.TextSpan) { return a && b && a.start === b.start && a.length === b.length; } + + public getEditsForFileRename(options: FourSlashInterface.GetEditsForFileRenameOptions): void { + const changes = this.languageService.getEditsForFileRename(options.oldPath, options.newPath, this.formatCodeSettings); + this.applyChanges(changes); + for (const fileName in options.newFileContents) { + this.openFile(fileName); + this.verifyCurrentFileContent(options.newFileContents[fileName]); + } + } } export function runFourSlashTest(basePath: string, testType: FourSlashTestType, fileName: string) { @@ -4380,6 +4379,10 @@ namespace FourSlashInterface { public allRangesAppearInImplementationList(markerName: string) { this.state.verifyRangesInImplementationList(markerName); } + + public getEditsForFileRename(options: GetEditsForFileRenameOptions) { + this.state.getEditsForFileRename(options); + } } export class Edit { @@ -4663,10 +4666,12 @@ namespace FourSlashInterface { export type ExpectedCompletionEntry = string | { name: string, insertText?: string, replacementSpan?: FourSlash.Range }; export interface CompletionsAtOptions extends Partial { + triggerCharacter?: string; isNewIdentifierLocation?: boolean; } export interface VerifyCompletionListContainsOptions extends ts.UserPreferences { + triggerCharacter?: string; sourceDisplay: string; isRecommended?: true; insertText?: string; @@ -4720,4 +4725,10 @@ namespace FourSlashInterface { range?: FourSlash.Range; code: number; } + + export interface GetEditsForFileRenameOptions { + readonly oldPath: string; + readonly newPath: string; + readonly newFileContents: { readonly [fileName: string]: string }; + } } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 5732d9fcfe1..9f1587b85b5 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -530,6 +530,9 @@ namespace Harness.LanguageService { organizeImports(_scope: ts.OrganizeImportsScope, _formatOptions: ts.FormatCodeSettings): ReadonlyArray { throw new Error("Not supported on the shim."); } + getEditsForFileRename(): ReadonlyArray { + throw new Error("Not supported on the shim."); + } getEmitOutput(fileName: string): ts.EmitOutput { return unwrapJSONCallResult(this.shim.getEmitOutput(fileName)); } diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index 5d736fbd2ed..e9674d7e452 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -70,6 +70,7 @@ "../services/navigateTo.ts", "../services/navigationBar.ts", "../services/organizeImports.ts", + "../services/getEditsForFileRename.ts", "../services/outliningElementsCollector.ts", "../services/patternMatcher.ts", "../services/preProcess.ts", diff --git a/src/harness/unittests/session.ts b/src/harness/unittests/session.ts index a892d28808c..25df6f72ea6 100644 --- a/src/harness/unittests/session.ts +++ b/src/harness/unittests/session.ts @@ -263,6 +263,8 @@ namespace ts.server { CommandNames.GetEditsForRefactorFull, CommandNames.OrganizeImports, CommandNames.OrganizeImportsFull, + CommandNames.GetEditsForFileRename, + CommandNames.GetEditsForFileRenameFull, ]; it("should not throw when commands are executed with invalid arguments", () => { diff --git a/src/harness/unittests/tscWatchMode.ts b/src/harness/unittests/tscWatchMode.ts index c8faba855dc..44565c0ddbe 100644 --- a/src/harness/unittests/tscWatchMode.ts +++ b/src/harness/unittests/tscWatchMode.ts @@ -124,7 +124,10 @@ namespace ts.tscWatch { } function getWatchDiagnosticWithoutDate(diagnostic: Diagnostic) { - return ` - ${flattenDiagnosticMessageText(diagnostic.messageText, host.newLine)}${host.newLine + host.newLine + host.newLine}`; + const newLines = contains(screenStartingMessageCodes, diagnostic.code) + ? `${host.newLine}${host.newLine}` + : host.newLine; + return ` - ${flattenDiagnosticMessageText(diagnostic.messageText, host.newLine)}${newLines}`; } } diff --git a/src/lib/es2015.core.d.ts b/src/lib/es2015.core.d.ts index 68be040c29d..cfb300c784d 100644 --- a/src/lib/es2015.core.d.ts +++ b/src/lib/es2015.core.d.ts @@ -1,5 +1,3 @@ -declare type PropertyKey = string | number | symbol; - interface Array { /** * Returns the value of the first element in the array where predicate is true, and undefined @@ -258,20 +256,6 @@ interface NumberConstructor { parseInt(string: string, radix?: number): number; } -interface Object { - /** - * Determines whether an object has a property with the specified name. - * @param v A property name. - */ - hasOwnProperty(v: PropertyKey): boolean; - - /** - * Determines whether a specified property is enumerable. - * @param v A property name. - */ - propertyIsEnumerable(v: PropertyKey): boolean; -} - interface ObjectConstructor { /** * Copy the values of all of the enumerable own properties from one or more source objects to a @@ -327,25 +311,6 @@ interface ObjectConstructor { * @param proto The value of the new prototype or null. */ setPrototypeOf(o: any, proto: object | null): any; - - /** - * Gets the own property descriptor of the specified object. - * An own property descriptor is one that is defined directly on the object and is not - * inherited from the object's prototype. - * @param o Object that contains the property. - * @param p Name of the property. - */ - getOwnPropertyDescriptor(o: any, propertyKey: PropertyKey): PropertyDescriptor | undefined; - - /** - * Adds a property to an object, or modifies attributes of an existing property. - * @param o Object on which to add or modify the property. This can be a native JavaScript - * object (that is, a user-defined object or a built in object) or a DOM object. - * @param p The property name. - * @param attributes Descriptor for the property. It can be for a data property or an accessor - * property. - */ - defineProperty(o: any, propertyKey: PropertyKey, attributes: PropertyDescriptor): any; } interface ReadonlyArray { diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index ea59c10c83e..384d45cd75f 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -74,6 +74,8 @@ declare function escape(string: string): string; */ declare function unescape(string: string): string; +declare type PropertyKey = string | number | symbol; + interface PropertyDescriptor { configurable?: boolean; enumerable?: boolean; @@ -104,7 +106,7 @@ interface Object { * Determines whether an object has a property with the specified name. * @param v A property name. */ - hasOwnProperty(v: string): boolean; + hasOwnProperty(v: PropertyKey): boolean; /** * Determines whether an object exists in another object's prototype chain. @@ -116,7 +118,7 @@ interface Object { * Determines whether a specified property is enumerable. * @param v A property name. */ - propertyIsEnumerable(v: string): boolean; + propertyIsEnumerable(v: PropertyKey): boolean; } interface ObjectConstructor { @@ -139,7 +141,7 @@ interface ObjectConstructor { * @param o Object that contains the property. * @param p Name of the property. */ - getOwnPropertyDescriptor(o: any, p: string): PropertyDescriptor | undefined; + getOwnPropertyDescriptor(o: any, p: PropertyKey): PropertyDescriptor | undefined; /** * Returns the names of the own properties of an object. The own properties of an object are those that are defined directly @@ -167,7 +169,7 @@ interface ObjectConstructor { * @param p The property name. * @param attributes Descriptor for the property. It can be for a data property or an accessor property. */ - defineProperty(o: any, p: string, attributes: PropertyDescriptor & ThisType): any; + defineProperty(o: any, p: PropertyKey, attributes: PropertyDescriptor & ThisType): any; /** * Adds one or more properties to an object, and/or modifies attributes of existing properties. @@ -1340,7 +1342,7 @@ type Pick = { /** * Construct a type with a set of properties K of type T */ -type Record = { +type Record = { [P in K]: T; }; diff --git a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl index efac12c6e66..23b68db43f8 100644 --- a/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/cht/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -903,6 +903,12 @@ + + + + + + @@ -999,24 +1005,9 @@ - + - - - - - - - - - - - - - - - - + @@ -2388,15 +2379,6 @@ - - - - - - - - - @@ -3771,20 +3753,20 @@ - + - + - + - + - + - + diff --git a/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl index 0ef1aeed0cc..203d2c22ab9 100644 --- a/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/csy/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -912,6 +912,15 @@ + + + + + + + + + @@ -1008,27 +1017,15 @@ - + - + - + - - - - - - - - - - - - @@ -2397,15 +2394,6 @@ - - - - - - - - - @@ -3780,20 +3768,20 @@ - + - + - + - + - + - + diff --git a/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl index b2ffdf585e0..5798b852bbe 100644 --- a/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/deu/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -900,6 +900,12 @@ + + + + + + @@ -996,24 +1002,9 @@ - + - - - - - - - - - - - - - - - - + @@ -2385,15 +2376,6 @@ - - - - - - - - - @@ -3768,20 +3750,20 @@ - + - + - + - + - + - + diff --git a/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl index 259d4b3b90e..6b949870bbd 100644 --- a/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/esn/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -912,6 +912,12 @@ + + + + + + @@ -1008,24 +1014,9 @@ - + - - - - - - - - - - - - - - - - + @@ -2397,15 +2388,6 @@ - - - - - - - - - @@ -3780,20 +3762,20 @@ - + - + - + - + - + - + diff --git a/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl index d3663b384db..ca47b5dac95 100644 --- a/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/fra/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -2397,15 +2397,6 @@ - - - - - - - - - @@ -3780,20 +3771,20 @@ - + - + - + - + - + - + diff --git a/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl index c53a7b86387..619c6ea41af 100644 --- a/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/ita/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -903,6 +903,15 @@ + + + + + + + + + @@ -999,27 +1008,15 @@ - + - + - + - - - - - - - - - - - - diff --git a/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl index 43d2f167e96..07300f3ab7c 100644 --- a/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/jpn/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -903,6 +903,12 @@ + + + + + + @@ -999,24 +1005,9 @@ - + - - - - - - - - - - - - - - - - + @@ -2388,15 +2379,6 @@ - - - - - - - - - @@ -3771,20 +3753,20 @@ - + - + - + - + - + - + diff --git a/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl index 0e70ff04cca..d4801255fdb 100644 --- a/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/kor/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -903,6 +903,12 @@ + + + + + + @@ -999,24 +1005,9 @@ - + - - - - - - - - - - - - - - - - + @@ -2388,15 +2379,6 @@ - - - - - - - - - @@ -3771,20 +3753,20 @@ - + - + - + - + - + - + diff --git a/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl index 36e67c41077..94427fcd4ca 100644 --- a/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/plk/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -893,6 +893,12 @@ + + + + + + @@ -989,24 +995,9 @@ - + - - - - - - - - - - - - - - - - + @@ -2378,15 +2369,6 @@ - - - - - - - - - @@ -3761,20 +3743,20 @@ - + - + - + - + - + - + diff --git a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl index 3252fe24f15..5be5577f3a8 100644 --- a/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/ptb/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -893,6 +893,12 @@ + + + + + + @@ -989,24 +995,9 @@ - + - - - - - - - - - - - - - - - - + @@ -2378,15 +2369,6 @@ - - - - - - - - - @@ -3761,20 +3743,20 @@ - + - + - + - + - + - + diff --git a/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl index 07d26979bf8..dc4c01fcad4 100644 --- a/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/rus/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -902,6 +902,12 @@ + + + + + + @@ -998,24 +1004,9 @@ - + - - - - - - - - - - - - - - - - + @@ -2387,15 +2378,6 @@ - - - - - - - - - @@ -3770,20 +3752,20 @@ - + - + - + - + - + - + diff --git a/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl b/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl index 72116417c1b..5899715db8b 100644 --- a/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl +++ b/src/loc/lcl/trk/diagnosticMessages/diagnosticMessages.generated.json.lcl @@ -896,6 +896,12 @@ + + + + + + @@ -992,24 +998,9 @@ - + - - - - - - - - - - - - - - - - + @@ -2381,15 +2372,6 @@ - - - - - - - - - @@ -3764,20 +3746,20 @@ - + - + - + - + - + - + diff --git a/src/server/client.ts b/src/server/client.ts index 2238734e90c..d7a83ee5320 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -632,6 +632,10 @@ namespace ts.server { return notImplemented(); } + getEditsForFileRename() { + return notImplemented(); + } + private convertCodeEditsToTextChanges(edits: protocol.FileCodeEdits[]): FileTextChanges[] { return edits.map(edit => { const fileName = edit.fileName; diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 7a258a904c2..5ab62a1c33f 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -121,6 +121,9 @@ namespace ts.server.protocol { OrganizeImports = "organizeImports", /* @internal */ OrganizeImportsFull = "organizeImports-full", + GetEditsForFileRename = "getEditsForFileRename", + /* @internal */ + GetEditsForFileRenameFull = "getEditsForFileRename-full", // NOTE: If updating this, be sure to also update `allCommandNames` in `harness/unittests/session.ts`. } @@ -610,6 +613,22 @@ namespace ts.server.protocol { edits: ReadonlyArray; } + export interface GetEditsForFileRenameRequest extends Request { + command: CommandTypes.GetEditsForFileRename; + arguments: GetEditsForFileRenameRequestArgs; + } + + // Note: The file from FileRequestArgs is just any file in the project. + // We will generate code changes for every file in that project, so the choice is arbitrary. + export interface GetEditsForFileRenameRequestArgs extends FileRequestArgs { + readonly oldFilePath: string; + readonly newFilePath: string; + } + + export interface GetEditsForFileRenameResponse extends Response { + edits: ReadonlyArray; + } + /** * Request for the available codefixes at a specific position. */ @@ -1749,6 +1768,7 @@ namespace ts.server.protocol { * Optional prefix to apply to possible completions. */ prefix?: string; + triggerCharacter?: string; /** * @deprecated Use UserPreferences.includeCompletionsForModuleExports */ diff --git a/src/server/session.ts b/src/server/session.ts index 27044ec369d..19a9ee00772 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1287,6 +1287,7 @@ namespace ts.server { const completions = project.getLanguageService().getCompletionsAtPosition(file, position, { ...this.getPreferences(file), + triggerCharacter: args.triggerCharacter, includeExternalModuleExports: args.includeExternalModuleExports, includeInsertTextCompletions: args.includeInsertTextCompletions }); @@ -1664,6 +1665,12 @@ namespace ts.server { } } + private getEditsForFileRename(args: protocol.GetEditsForFileRenameRequestArgs, simplifiedResult: boolean): ReadonlyArray | ReadonlyArray { + const { file, project } = this.getFileAndProject(args); + const changes = project.getLanguageService().getEditsForFileRename(args.oldFilePath, args.newFilePath, this.getFormatOptions(file)); + return simplifiedResult ? this.mapTextChangesToCodeEdits(project, changes) : changes; + } + private getCodeFixes(args: protocol.CodeFixRequestArgs, simplifiedResult: boolean): ReadonlyArray | ReadonlyArray { if (args.errorCodes.length === 0) { return undefined; @@ -2117,7 +2124,13 @@ namespace ts.server { }, [CommandNames.OrganizeImportsFull]: (request: protocol.OrganizeImportsRequest) => { return this.requiredResponse(this.organizeImports(request.arguments, /*simplifiedResult*/ false)); - } + }, + [CommandNames.GetEditsForFileRename]: (request: protocol.GetEditsForFileRenameRequest) => { + return this.requiredResponse(this.getEditsForFileRename(request.arguments, /*simplifiedResult*/ true)); + }, + [CommandNames.GetEditsForFileRenameFull]: (request: protocol.GetEditsForFileRenameRequest) => { + return this.requiredResponse(this.getEditsForFileRename(request.arguments, /*simplifiedResult*/ false)); + }, }); public addProtocolHandler(command: string, handler: (request: protocol.Request) => HandlerResponse) { diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json index dc732604ab6..e6768f4edee 100644 --- a/src/server/tsconfig.json +++ b/src/server/tsconfig.json @@ -66,6 +66,7 @@ "../services/navigateTo.ts", "../services/navigationBar.ts", "../services/organizeImports.ts", + "../services/getEditsForFileRename.ts", "../services/outliningElementsCollector.ts", "../services/patternMatcher.ts", "../services/preProcess.ts", diff --git a/src/server/tsconfig.library.json b/src/server/tsconfig.library.json index dd0196fab76..a167d3b39a2 100644 --- a/src/server/tsconfig.library.json +++ b/src/server/tsconfig.library.json @@ -72,6 +72,7 @@ "../services/navigateTo.ts", "../services/navigationBar.ts", "../services/organizeImports.ts", + "../services/getEditsForFileRename.ts", "../services/outliningElementsCollector.ts", "../services/patternMatcher.ts", "../services/preProcess.ts", diff --git a/src/services/codefixes/fixStrictClassInitialization.ts b/src/services/codefixes/fixStrictClassInitialization.ts index 8d4e457662f..6c211b86f8d 100644 --- a/src/services/codefixes/fixStrictClassInitialization.ts +++ b/src/services/codefixes/fixStrictClassInitialization.ts @@ -127,7 +127,7 @@ namespace ts.codefix { const classDeclaration = getClassLikeDeclarationOfSymbol(type.symbol); if (!classDeclaration || hasModifier(classDeclaration, ModifierFlags.Abstract)) return undefined; - const constructorDeclaration = find(classDeclaration.members, (m): m is ConstructorDeclaration => isConstructorDeclaration(m) && !!m.body)!; + const constructorDeclaration = getFirstConstructorWithBody(classDeclaration); if (constructorDeclaration && constructorDeclaration.parameters.length) return undefined; return createNew(createIdentifier(type.symbol.name), /*typeArguments*/ undefined, /*argumentsArray*/ undefined); diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index ddd530e4246..5a10f2f48a7 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -39,7 +39,6 @@ namespace ts.codefix { } function convertToImportCodeFixContext(context: CodeFixContext, symbolToken: Node, symbolName: string): ImportCodeFixContext { - const useCaseSensitiveFileNames = context.host.useCaseSensitiveFileNames ? context.host.useCaseSensitiveFileNames() : false; const { program } = context; const checker = program.getTypeChecker(); @@ -51,7 +50,7 @@ namespace ts.codefix { checker, compilerOptions: program.getCompilerOptions(), cachedImportDeclarations: [], - getCanonicalFileName: createGetCanonicalFileName(useCaseSensitiveFileNames), + getCanonicalFileName: createGetCanonicalFileName(hostUsesCaseSensitiveFileNames(context.host)), symbolName, symbolToken, preferences: context.preferences, @@ -547,11 +546,6 @@ namespace ts.codefix { return startsWith(path, ".."); } - function getRelativePath(path: string, directoryPath: string, getCanonicalFileName: GetCanonicalFileName) { - const relativePath = getRelativePathToDirectoryOrUrl(directoryPath, path, directoryPath, getCanonicalFileName, /*isAbsolutePathAnUrl*/ false); - return !pathIsRelative(relativePath) ? "./" + relativePath : relativePath; - } - function getCodeActionsForAddImport( exportInfos: ReadonlyArray, ctx: ImportCodeFixContext, diff --git a/src/services/completions.ts b/src/services/completions.ts index 3100e4a13a9..236823992fc 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -25,7 +25,7 @@ namespace ts.Completions { const enum GlobalsSearch { Continue, Success, Fail } - export function getCompletionsAtPosition(host: LanguageServiceHost, program: Program, log: Log, sourceFile: SourceFile, position: number, preferences: UserPreferences): CompletionInfo | undefined { + export function getCompletionsAtPosition(host: LanguageServiceHost, program: Program, log: Log, sourceFile: SourceFile, position: number, preferences: UserPreferences, triggerCharacter: string | undefined): CompletionInfo | undefined { const typeChecker = program.getTypeChecker(); const compilerOptions = program.getCompilerOptions(); if (isInReferenceComment(sourceFile, position)) { @@ -34,6 +34,7 @@ namespace ts.Completions { } const contextToken = findPrecedingToken(position, sourceFile); + if (triggerCharacter && !isValidTrigger(sourceFile, triggerCharacter, contextToken, position)) return undefined; if (isInString(sourceFile, position, contextToken)) { return !contextToken || !isStringLiteralLike(contextToken) @@ -46,7 +47,7 @@ namespace ts.Completions { return getLabelCompletionAtPosition(contextToken.parent); } - const completionData = getCompletionData(program, log, sourceFile, position, preferences); + const completionData = getCompletionData(program, log, sourceFile, position, preferences, /*detailsEntryId*/ undefined); if (!completionData) { return undefined; } @@ -485,9 +486,9 @@ namespace ts.Completions { previousToken: Node; readonly isJsxInitializer: IsJsxInitializer; } - function getSymbolCompletionFromEntryId(program: Program, log: Log, sourceFile: SourceFile, position: number, { name, source }: CompletionEntryIdentifier, + function getSymbolCompletionFromEntryId(program: Program, log: Log, sourceFile: SourceFile, position: number, entryId: CompletionEntryIdentifier, ): SymbolCompletion | { type: "request", request: Request } | { type: "none" } { - const completionData = getCompletionData(program, log, sourceFile, position, { includeCompletionsForModuleExports: true, includeCompletionsWithInsertText: true }); + const completionData = getCompletionData(program, log, sourceFile, position, { includeCompletionsForModuleExports: true, includeCompletionsWithInsertText: true }, entryId); if (!completionData) { return { type: "none" }; } @@ -504,7 +505,9 @@ namespace ts.Completions { return firstDefined(symbols, (symbol): SymbolCompletion => { // TODO: Shouldn't need return type annotation (GH#12632) const origin = symbolToOriginInfoMap[getSymbolId(symbol)]; const info = getCompletionEntryDisplayNameForSymbol(symbol, program.getCompilerOptions().target, origin, completionKind); - return info && info.name === name && getSourceFromOrigin(origin) === source ? { type: "symbol" as "symbol", symbol, location, symbolToOriginInfoMap, previousToken, isJsxInitializer } : undefined; + return info && info.name === entryId.name && getSourceFromOrigin(origin) === entryId.source + ? { type: "symbol" as "symbol", symbol, location, symbolToOriginInfoMap, previousToken, isJsxInitializer } + : undefined; }) || { type: "none" }; } @@ -754,6 +757,7 @@ namespace ts.Completions { sourceFile: SourceFile, position: number, preferences: Pick, + detailsEntryId: CompletionEntryIdentifier | undefined, ): CompletionData | Request | undefined { const typeChecker = program.getTypeChecker(); @@ -1197,14 +1201,11 @@ namespace ts.Completions { // If already using commonjs, don't introduce ES6. if (sourceFile.commonJsModuleIndicator) return false; // If some file is using ES6 modules, assume that it's OK to add more. - if (program.getSourceFiles().some(s => !s.isDeclarationFile && !program.isSourceFileFromExternalLibrary(s) && !!s.externalModuleIndicator)) { - return true; - } + if (programContainsEs6Modules(program)) return true; // For JS, stay on the safe side. if (isSourceFileJavaScript(sourceFile)) return false; // If module transpilation is enabled or we're targeting es6 or above, or not emitting, OK. - const compilerOptions = program.getCompilerOptions(); - return !!compilerOptions.module || compilerOptions.target >= ScriptTarget.ES2015 || !!compilerOptions.noEmit; + return compilerOptionsIndicateEs6Modules(program.getCompilerOptions()); } function isSnippetScope(scopeNode: Node): boolean { @@ -1301,6 +1302,11 @@ namespace ts.Completions { const tokenTextLowerCase = tokenText.toLowerCase(); codefix.forEachExternalModuleToImportFrom(typeChecker, sourceFile, program.getSourceFiles(), moduleSymbol => { + // Perf -- ignore other modules if this is a request for details + if (detailsEntryId && detailsEntryId.source && stripQuotes(moduleSymbol.name) !== detailsEntryId.source) { + return; + } + for (let symbol of typeChecker.getExportsOfModule(moduleSymbol)) { // Don't add a completion for a re-export, only for the original. // The actual import fix might end up coming from a re-export -- we don't compute that until getting completion details. @@ -1319,7 +1325,7 @@ namespace ts.Completions { } const origin: SymbolOriginInfo = { type: "export", moduleSymbol, isDefaultExport }; - if (stringContainsCharactersInOrder(getSymbolName(symbol, origin, target).toLowerCase(), tokenTextLowerCase)) { + if (detailsEntryId || stringContainsCharactersInOrder(getSymbolName(symbol, origin, target).toLowerCase(), tokenTextLowerCase)) { symbols.push(symbol); symbolToOriginInfoMap[getSymbolId(symbol)] = origin; } @@ -2197,4 +2203,31 @@ namespace ts.Completions { function hasIndexSignature(type: Type): boolean { return !!type.getStringIndexType() || !!type.getNumberIndexType(); } + + function isValidTrigger(sourceFile: SourceFile, triggerCharacter: string, contextToken: Node, position: number): boolean { + switch (triggerCharacter) { + case '"': + case "'": + case "`": + // Only automatically bring up completions if this is an opening quote. + return isStringLiteralOrTemplate(contextToken) && position === contextToken.getStart(sourceFile) + 1; + case "<": + // Opening JSX tag + return contextToken.kind === SyntaxKind.LessThanToken && contextToken.parent.kind !== SyntaxKind.BinaryExpression; + default: + return Debug.fail(triggerCharacter); + } + } + + function isStringLiteralOrTemplate(node: Node): node is StringLiteralLike | TemplateExpression | TaggedTemplateExpression { + switch (node.kind) { + case SyntaxKind.StringLiteral: + case SyntaxKind.NoSubstitutionTemplateLiteral: + case SyntaxKind.TemplateExpression: + case SyntaxKind.TaggedTemplateExpression: + return true; + default: + return false; + } + } } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 57fe2a7a0e4..1b4e81928c0 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -1014,21 +1014,17 @@ namespace ts.FindAllReferences.Core { function addClassStaticThisReferences(referenceLocation: Node, search: Search, state: State): void { addReference(referenceLocation, search.symbol, state); - if (!state.options.isForRename && isClassLike(referenceLocation.parent)) { - Debug.assert(referenceLocation.parent.name === referenceLocation); - // This is the class declaration. - addStaticThisReferences(referenceLocation.parent, state.referenceAdder(search.symbol)); - } - } - - function addStaticThisReferences(classLike: ClassLikeDeclaration, pusher: (node: Node) => void): void { + const classLike = referenceLocation.parent; + if (state.options.isForRename || !isClassLike(classLike)) return; + Debug.assert(classLike.name === referenceLocation); + const addRef = state.referenceAdder(search.symbol); for (const member of classLike.members) { if (!(isMethodOrAccessor(member) && hasModifier(member, ModifierFlags.Static))) { continue; } member.body.forEachChild(function cb(node) { if (node.kind === SyntaxKind.ThisKeyword) { - pusher(node); + addRef(node); } else if (!isFunctionLike(node)) { node.forEachChild(cb); diff --git a/src/services/getEditsForFileRename.ts b/src/services/getEditsForFileRename.ts new file mode 100644 index 00000000000..09bbdc11e78 --- /dev/null +++ b/src/services/getEditsForFileRename.ts @@ -0,0 +1,76 @@ +/* @internal */ +namespace ts { + export function getEditsForFileRename(program: Program, oldFilePath: string, newFilePath: string, host: LanguageServiceHost, formatContext: formatting.FormatContext): ReadonlyArray { + const pathUpdater = getPathUpdater(oldFilePath, newFilePath, host); + return textChanges.ChangeTracker.with({ host, formatContext }, changeTracker => { + updateTsconfigFiles(program, changeTracker, oldFilePath, newFilePath); + for (const { sourceFile, toUpdate } of getImportsToUpdate(program, oldFilePath)) { + const newPath = pathUpdater(isRef(toUpdate) ? toUpdate.fileName : toUpdate.text); + if (newPath !== undefined) { + const range = isRef(toUpdate) ? toUpdate : createStringRange(toUpdate, sourceFile); + changeTracker.replaceRangeWithText(sourceFile, range, isRef(toUpdate) ? newPath : removeFileExtension(newPath)); + } + } + }); + } + + function updateTsconfigFiles(program: Program, changeTracker: textChanges.ChangeTracker, oldFilePath: string, newFilePath: string): void { + const cfg = program.getCompilerOptions().configFile; + if (!cfg) return; + const oldFile = cfg.jsonObject && getFilesEntry(cfg.jsonObject, oldFilePath); + if (oldFile) { + changeTracker.replaceRangeWithText(cfg, createStringRange(oldFile, cfg), newFilePath); + } + } + + function getFilesEntry(cfg: ObjectLiteralExpression, fileName: string): StringLiteral | undefined { + const filesProp = find(cfg.properties, (prop): prop is PropertyAssignment => + isPropertyAssignment(prop) && isStringLiteral(prop.name) && prop.name.text === "files"); + const files = filesProp && filesProp.initializer; + return files && isArrayLiteralExpression(files) ? find(files.elements, (e): e is StringLiteral => isStringLiteral(e) && e.text === fileName) : undefined; + } + + interface ToUpdate { + readonly sourceFile: SourceFile; + readonly toUpdate: StringLiteralLike | FileReference; + } + function isRef(toUpdate: StringLiteralLike | FileReference): toUpdate is FileReference { + return "fileName" in toUpdate; + } + + function getImportsToUpdate(program: Program, oldFilePath: string): ReadonlyArray { + const checker = program.getTypeChecker(); + const result: ToUpdate[] = []; + for (const sourceFile of program.getSourceFiles()) { + for (const ref of sourceFile.referencedFiles) { + if (!program.getSourceFileFromReference(sourceFile, ref) && resolveTripleslashReference(ref.fileName, sourceFile.fileName) === oldFilePath) { + result.push({ sourceFile, toUpdate: ref }); + } + } + + for (const importStringLiteral of sourceFile.imports) { + // If it resolved to something already, ignore. + if (checker.getSymbolAtLocation(importStringLiteral)) continue; + + const resolved = program.getResolvedModuleWithFailedLookupLocationsFromCache(importStringLiteral.text, sourceFile.fileName); + if (contains(resolved.failedLookupLocations, oldFilePath)) { + result.push({ sourceFile, toUpdate: importStringLiteral }); + } + } + } + return result; + } + + function getPathUpdater(oldFilePath: string, newFilePath: string, host: LanguageServiceHost): (oldPath: string) => string | undefined { + // Get the relative path from old to new location, and append it on to the end of imports and normalize. + const rel = getRelativePath(newFilePath, getDirectoryPath(oldFilePath), createGetCanonicalFileName(hostUsesCaseSensitiveFileNames(host))); + return oldPath => { + if (!pathIsRelative(oldPath)) return; + return ensurePathIsRelative(normalizePath(combinePaths(getDirectoryPath(oldPath), rel))); + }; + } + + function createStringRange(node: StringLiteralLike, sourceFile: SourceFileLike): TextRange { + return createTextRange(node.getStart(sourceFile) + 1, node.end - 1); + } +} diff --git a/src/services/jsDoc.ts b/src/services/jsDoc.ts index d0860c3e161..ca0dafbc74c 100644 --- a/src/services/jsDoc.ts +++ b/src/services/jsDoc.ts @@ -365,13 +365,10 @@ namespace ts.JsDoc { case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: return (rightHandSide).parameters; - case SyntaxKind.ClassExpression: - for (const member of (rightHandSide).members) { - if (member.kind === SyntaxKind.Constructor) { - return (member).parameters; - } - } - break; + case SyntaxKind.ClassExpression: { + const ctr = find((rightHandSide as ClassExpression).members, isConstructorDeclaration); + return ctr && ctr.parameters; + } } return emptyArray; diff --git a/src/services/services.ts b/src/services/services.ts index a192231405a..08e3c960d7a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1128,7 +1128,6 @@ namespace ts { let lastProjectVersion: string; let lastTypesRootVersion = 0; - const useCaseSensitivefileNames = host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(); const cancellationToken = new CancellationTokenObject(host.getCancellationToken && host.getCancellationToken()); const currentDirectory = host.getCurrentDirectory(); @@ -1145,7 +1144,8 @@ namespace ts { } } - const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitivefileNames); + const useCaseSensitiveFileNames = hostUsesCaseSensitiveFileNames(host); + const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames); function getValidSourceFile(fileName: string): SourceFile { const sourceFile = program.getSourceFile(fileName); @@ -1202,7 +1202,7 @@ namespace ts { getSourceFileByPath: getOrCreateSourceFileByPath, getCancellationToken: () => cancellationToken, getCanonicalFileName, - useCaseSensitiveFileNames: () => useCaseSensitivefileNames, + useCaseSensitiveFileNames: () => useCaseSensitiveFileNames, getNewLine: () => getNewLineCharacter(newSettings, () => getNewLineOrDefaultFromHost(host)), getDefaultLibFileName: (options) => host.getDefaultLibFileName(options), writeFile: noop, @@ -1409,7 +1409,8 @@ namespace ts { log, getValidSourceFile(fileName), position, - fullPreferences); + fullPreferences, + options.triggerCharacter); } function getCompletionEntryDetails(fileName: string, position: number, name: string, formattingOptions: FormatCodeSettings | undefined, source: string | undefined, preferences: UserPreferences = defaultPreferences): CompletionEntryDetails { @@ -1950,6 +1951,10 @@ namespace ts { return OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences); } + function getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings): ReadonlyArray { + return ts.getEditsForFileRename(getProgram(), oldFilePath, newFilePath, host, formatting.getFormatContext(formatOptions)); + } + function applyCodeActionCommand(action: CodeActionCommand): Promise; function applyCodeActionCommand(action: CodeActionCommand[]): Promise; function applyCodeActionCommand(action: CodeActionCommand | CodeActionCommand[]): Promise; @@ -2250,6 +2255,7 @@ namespace ts { getCombinedCodeFix, applyCodeActionCommand, organizeImports, + getEditsForFileRename, getEmitOutput, getNonBoundSourceFile, getSourceFile, diff --git a/src/services/shims.ts b/src/services/shims.ts index b8beccab20b..d0735cc1717 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -912,7 +912,7 @@ namespace ts { * to provide at the given source position and providing a member completion * list if requested. */ - public getCompletionsAtPosition(fileName: string, position: number, preferences: UserPreferences | undefined) { + public getCompletionsAtPosition(fileName: string, position: number, preferences: GetCompletionsAtPositionOptions | undefined) { return this.forwardJSONCall( `getCompletionsAtPosition('${fileName}', ${position}, ${preferences})`, () => this.languageService.getCompletionsAtPosition(fileName, position, preferences) diff --git a/src/services/suggestionDiagnostics.ts b/src/services/suggestionDiagnostics.ts index d9f55a78d82..d04f3f15cf9 100644 --- a/src/services/suggestionDiagnostics.ts +++ b/src/services/suggestionDiagnostics.ts @@ -5,7 +5,7 @@ namespace ts { const checker = program.getDiagnosticsProducingTypeChecker(); const diags: Diagnostic[] = []; - if (sourceFile.commonJsModuleIndicator) { + if (sourceFile.commonJsModuleIndicator && (programContainsEs6Modules(program) || compilerOptionsIndicateEs6Modules(program.getCompilerOptions()))) { diags.push(createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES6_module)); } diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index 7abb89befd7..854f5297d68 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -413,6 +413,9 @@ namespace ts.SymbolDisplay { displayParts.push(spacePart()); displayParts.push(keywordPart((symbol.declarations[0] as ExportAssignment).isExportEquals ? SyntaxKind.EqualsToken : SyntaxKind.DefaultKeyword)); break; + case SyntaxKind.ExportSpecifier: + displayParts.push(keywordPart(SyntaxKind.ExportKeyword)); + break; default: displayParts.push(keywordPart(SyntaxKind.ImportKeyword)); } diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index b54caf402b1..4f431e28e0e 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -365,8 +365,12 @@ namespace ts.textChanges { this.insertText(sourceFile, token.getStart(sourceFile), text); } + public replaceRangeWithText(sourceFile: SourceFile, range: TextRange, text: string) { + this.changes.push({ kind: ChangeKind.Text, sourceFile, range, text }); + } + private insertText(sourceFile: SourceFile, pos: number, text: string): void { - this.changes.push({ kind: ChangeKind.Text, sourceFile, range: { pos, end: pos }, text }); + this.replaceRangeWithText(sourceFile, createTextRange(pos), text); } /** Prefer this over replacing a node with another that has a type annotation, as it avoids reformatting the other parts of the node. */ diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 31b35a44271..75b46a5c49b 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -63,6 +63,7 @@ "navigateTo.ts", "navigationBar.ts", "organizeImports.ts", + "getEditsForFileRename.ts", "outliningElementsCollector.ts", "patternMatcher.ts", "preProcess.ts", diff --git a/src/services/types.ts b/src/services/types.ts index 01b8b5ad4d4..e835d0cdef6 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -334,6 +334,7 @@ namespace ts { getApplicableRefactors(fileName: string, positionOrRaneg: number | TextRange, preferences: UserPreferences | undefined): ApplicableRefactorInfo[]; getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined): RefactorEditInfo | undefined; organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): ReadonlyArray; + getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings): ReadonlyArray; getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean): EmitOutput; @@ -354,8 +355,9 @@ namespace ts { export type OrganizeImportsScope = CombinedCodeFixScope; - /** @deprecated Use UserPreferences */ export interface GetCompletionsAtPositionOptions extends UserPreferences { + /** If the editor is asking for completions because a certain character was typed, and not because the user explicitly requested them, this should be set. */ + triggerCharacter?: string; /** @deprecated Use includeCompletionsForModuleExports */ includeExternalModuleExports?: boolean; /** @deprecated Use includeCompletionsWithInsertText */ diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 63170678202..78f18869b37 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1213,6 +1213,21 @@ namespace ts { ? isStringOrNumericLiteral(name.expression) ? name.expression.text : undefined : getTextOfIdentifierOrLiteral(name); } + + export function programContainsEs6Modules(program: Program): boolean { + return program.getSourceFiles().some(s => !s.isDeclarationFile && !program.isSourceFileFromExternalLibrary(s) && !!s.externalModuleIndicator); + } + export function compilerOptionsIndicateEs6Modules(compilerOptions: CompilerOptions): boolean { + return !!compilerOptions.module || compilerOptions.target >= ScriptTarget.ES2015 || !!compilerOptions.noEmit; + } + + export function hostUsesCaseSensitiveFileNames(host: LanguageServiceHost): boolean { + return host.useCaseSensitiveFileNames ? host.useCaseSensitiveFileNames() : false; + } + + export function hostGetCanonicalFileName(host: LanguageServiceHost): GetCanonicalFileName { + return createGetCanonicalFileName(hostUsesCaseSensitiveFileNames(host)); + } } // Display-part writer helpers diff --git a/tests/baselines/reference/aliasDoesNotDuplicateSignatures.errors.txt b/tests/baselines/reference/aliasDoesNotDuplicateSignatures.errors.txt new file mode 100644 index 00000000000..38e2c8cfe17 --- /dev/null +++ b/tests/baselines/reference/aliasDoesNotDuplicateSignatures.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/user.ts(3,5): error TS2322: Type '() => void' is not assignable to type 'string'. +tests/cases/compiler/user.ts(4,5): error TS2322: Type '() => void' is not assignable to type 'string'. + + +==== tests/cases/compiler/demo.d.ts (0 errors) ==== + declare namespace demoNS { + function f(): void; + } + declare module 'demoModule' { + import alias = demoNS; + export = alias; + } +==== tests/cases/compiler/user.ts (2 errors) ==== + import { f } from 'demoModule'; + // Assign an incorrect type here to see the type of 'f'. + let x1: string = demoNS.f; + ~~ +!!! error TS2322: Type '() => void' is not assignable to type 'string'. + let x2: string = f; + ~~ +!!! error TS2322: Type '() => void' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/aliasDoesNotDuplicateSignatures.js b/tests/baselines/reference/aliasDoesNotDuplicateSignatures.js new file mode 100644 index 00000000000..0ae878bebc5 --- /dev/null +++ b/tests/baselines/reference/aliasDoesNotDuplicateSignatures.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/aliasDoesNotDuplicateSignatures.ts] //// + +//// [demo.d.ts] +declare namespace demoNS { + function f(): void; +} +declare module 'demoModule' { + import alias = demoNS; + export = alias; +} +//// [user.ts] +import { f } from 'demoModule'; +// Assign an incorrect type here to see the type of 'f'. +let x1: string = demoNS.f; +let x2: string = f; + +//// [user.js] +"use strict"; +exports.__esModule = true; +var demoModule_1 = require("demoModule"); +// Assign an incorrect type here to see the type of 'f'. +var x1 = demoNS.f; +var x2 = demoModule_1.f; diff --git a/tests/baselines/reference/aliasDoesNotDuplicateSignatures.symbols b/tests/baselines/reference/aliasDoesNotDuplicateSignatures.symbols new file mode 100644 index 00000000000..21ae7940f96 --- /dev/null +++ b/tests/baselines/reference/aliasDoesNotDuplicateSignatures.symbols @@ -0,0 +1,32 @@ +=== tests/cases/compiler/demo.d.ts === +declare namespace demoNS { +>demoNS : Symbol(demoNS, Decl(demo.d.ts, 0, 0)) + + function f(): void; +>f : Symbol(f, Decl(demo.d.ts, 0, 26)) +} +declare module 'demoModule' { +>'demoModule' : Symbol('demoModule', Decl(demo.d.ts, 2, 1)) + + import alias = demoNS; +>alias : Symbol(alias, Decl(demo.d.ts, 3, 29)) +>demoNS : Symbol(alias, Decl(demo.d.ts, 0, 0)) + + export = alias; +>alias : Symbol(alias, Decl(demo.d.ts, 3, 29)) +} +=== tests/cases/compiler/user.ts === +import { f } from 'demoModule'; +>f : Symbol(f, Decl(user.ts, 0, 8)) + +// Assign an incorrect type here to see the type of 'f'. +let x1: string = demoNS.f; +>x1 : Symbol(x1, Decl(user.ts, 2, 3)) +>demoNS.f : Symbol(f, Decl(demo.d.ts, 0, 26)) +>demoNS : Symbol(demoNS, Decl(demo.d.ts, 0, 0)) +>f : Symbol(f, Decl(demo.d.ts, 0, 26)) + +let x2: string = f; +>x2 : Symbol(x2, Decl(user.ts, 3, 3)) +>f : Symbol(f, Decl(user.ts, 0, 8)) + diff --git a/tests/baselines/reference/aliasDoesNotDuplicateSignatures.types b/tests/baselines/reference/aliasDoesNotDuplicateSignatures.types new file mode 100644 index 00000000000..ada54494a83 --- /dev/null +++ b/tests/baselines/reference/aliasDoesNotDuplicateSignatures.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/demo.d.ts === +declare namespace demoNS { +>demoNS : typeof demoNS + + function f(): void; +>f : () => void +} +declare module 'demoModule' { +>'demoModule' : typeof 'demoModule' + + import alias = demoNS; +>alias : typeof alias +>demoNS : typeof alias + + export = alias; +>alias : typeof alias +} +=== tests/cases/compiler/user.ts === +import { f } from 'demoModule'; +>f : () => void + +// Assign an incorrect type here to see the type of 'f'. +let x1: string = demoNS.f; +>x1 : string +>demoNS.f : () => void +>demoNS : typeof demoNS +>f : () => void + +let x2: string = f; +>x2 : string +>f : () => void + diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index b9cf50f14d9..9bd2de6aa41 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1494,7 +1494,7 @@ declare namespace ts { comment: string | undefined; } interface JSDocTag extends Node { - parent: JSDoc; + parent: JSDoc | JSDocTypeLiteral; atToken: AtToken; tagName: Identifier; comment: string | undefined; @@ -2100,7 +2100,7 @@ declare namespace ts { Unit = 13536, StringOrNumberLiteral = 96, PossiblyFalsy = 14574, - StringLike = 524322, + StringLike = 34, NumberLike = 84, BooleanLike = 136, EnumLike = 272, @@ -2340,6 +2340,7 @@ declare namespace ts { inlineSources?: boolean; isolatedModules?: boolean; jsx?: JsxEmit; + keyofStringsOnly?: boolean; lib?: string[]; locale?: string; mapRoot?: string; @@ -3402,6 +3403,7 @@ declare namespace ts { set(directory: string, result: ResolvedModuleWithFailedLookupLocations): void; } function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string): ModuleResolutionCache; + function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations | undefined; function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations; function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations; function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache): ResolvedModuleWithFailedLookupLocations; @@ -4446,6 +4448,7 @@ declare namespace ts { getApplicableRefactors(fileName: string, positionOrRaneg: number | TextRange, preferences: UserPreferences | undefined): ApplicableRefactorInfo[]; getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined): RefactorEditInfo | undefined; organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): ReadonlyArray; + getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings): ReadonlyArray; getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean): EmitOutput; getProgram(): Program; dispose(): void; @@ -4455,8 +4458,9 @@ declare namespace ts { fileName: string; } type OrganizeImportsScope = CombinedCodeFixScope; - /** @deprecated Use UserPreferences */ interface GetCompletionsAtPositionOptions extends UserPreferences { + /** If the editor is asking for completions because a certain character was typed, and not because the user explicitly requested them, this should be set. */ + triggerCharacter?: string; /** @deprecated Use includeCompletionsForModuleExports */ includeExternalModuleExports?: boolean; /** @deprecated Use includeCompletionsWithInsertText */ @@ -5409,7 +5413,8 @@ declare namespace ts.server.protocol { GetSupportedCodeFixes = "getSupportedCodeFixes", GetApplicableRefactors = "getApplicableRefactors", GetEditsForRefactor = "getEditsForRefactor", - OrganizeImports = "organizeImports" + OrganizeImports = "organizeImports", + GetEditsForFileRename = "getEditsForFileRename" } /** * A TypeScript Server message @@ -5805,6 +5810,17 @@ declare namespace ts.server.protocol { interface OrganizeImportsResponse extends Response { edits: ReadonlyArray; } + interface GetEditsForFileRenameRequest extends Request { + command: CommandTypes.GetEditsForFileRename; + arguments: GetEditsForFileRenameRequestArgs; + } + interface GetEditsForFileRenameRequestArgs extends FileRequestArgs { + readonly oldFilePath: string; + readonly newFilePath: string; + } + interface GetEditsForFileRenameResponse extends Response { + edits: ReadonlyArray; + } /** * Request for the available codefixes at a specific position. */ @@ -6667,6 +6683,7 @@ declare namespace ts.server.protocol { * Optional prefix to apply to possible completions. */ prefix?: string; + triggerCharacter?: string; /** * @deprecated Use UserPreferences.includeCompletionsForModuleExports */ @@ -8320,6 +8337,7 @@ declare namespace ts.server { private getApplicableRefactors; private getEditsForRefactor; private organizeImports; + private getEditsForFileRename; private getCodeFixes; private getCombinedCodeFix; private applyCodeActionCommand; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index f5114e2397c..3c47002061f 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1494,7 +1494,7 @@ declare namespace ts { comment: string | undefined; } interface JSDocTag extends Node { - parent: JSDoc; + parent: JSDoc | JSDocTypeLiteral; atToken: AtToken; tagName: Identifier; comment: string | undefined; @@ -2100,7 +2100,7 @@ declare namespace ts { Unit = 13536, StringOrNumberLiteral = 96, PossiblyFalsy = 14574, - StringLike = 524322, + StringLike = 34, NumberLike = 84, BooleanLike = 136, EnumLike = 272, @@ -2340,6 +2340,7 @@ declare namespace ts { inlineSources?: boolean; isolatedModules?: boolean; jsx?: JsxEmit; + keyofStringsOnly?: boolean; lib?: string[]; locale?: string; mapRoot?: string; @@ -3402,6 +3403,7 @@ declare namespace ts { set(directory: string, result: ResolvedModuleWithFailedLookupLocations): void; } function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string): ModuleResolutionCache; + function resolveModuleNameFromCache(moduleName: string, containingFile: string, cache: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations | undefined; function resolveModuleName(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations; function nodeModuleNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: ModuleResolutionCache): ResolvedModuleWithFailedLookupLocations; function classicNameResolver(moduleName: string, containingFile: string, compilerOptions: CompilerOptions, host: ModuleResolutionHost, cache?: NonRelativeModuleNameResolutionCache): ResolvedModuleWithFailedLookupLocations; @@ -4446,6 +4448,7 @@ declare namespace ts { getApplicableRefactors(fileName: string, positionOrRaneg: number | TextRange, preferences: UserPreferences | undefined): ApplicableRefactorInfo[]; getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences: UserPreferences | undefined): RefactorEditInfo | undefined; organizeImports(scope: OrganizeImportsScope, formatOptions: FormatCodeSettings, preferences: UserPreferences | undefined): ReadonlyArray; + getEditsForFileRename(oldFilePath: string, newFilePath: string, formatOptions: FormatCodeSettings): ReadonlyArray; getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean): EmitOutput; getProgram(): Program; dispose(): void; @@ -4455,8 +4458,9 @@ declare namespace ts { fileName: string; } type OrganizeImportsScope = CombinedCodeFixScope; - /** @deprecated Use UserPreferences */ interface GetCompletionsAtPositionOptions extends UserPreferences { + /** If the editor is asking for completions because a certain character was typed, and not because the user explicitly requested them, this should be set. */ + triggerCharacter?: string; /** @deprecated Use includeCompletionsForModuleExports */ includeExternalModuleExports?: boolean; /** @deprecated Use includeCompletionsWithInsertText */ diff --git a/tests/baselines/reference/classAppearsToHaveMembersOfObject.types b/tests/baselines/reference/classAppearsToHaveMembersOfObject.types index 9c87fa18ecd..44aeedacba2 100644 --- a/tests/baselines/reference/classAppearsToHaveMembersOfObject.types +++ b/tests/baselines/reference/classAppearsToHaveMembersOfObject.types @@ -17,9 +17,9 @@ var r = c.toString(); var r2 = c.hasOwnProperty(''); >r2 : boolean >c.hasOwnProperty('') : boolean ->c.hasOwnProperty : (v: string) => boolean +>c.hasOwnProperty : (v: string | number | symbol) => boolean >c : C ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >'' : "" var o: Object = c; diff --git a/tests/baselines/reference/classMemberInitializerWithLamdaScoping4.errors.txt b/tests/baselines/reference/classMemberInitializerWithLamdaScoping4.errors.txt index 58a660c1ee8..03aa27e91f8 100644 --- a/tests/baselines/reference/classMemberInitializerWithLamdaScoping4.errors.txt +++ b/tests/baselines/reference/classMemberInitializerWithLamdaScoping4.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/classMemberInitializerWithLamdaScoping3_1.ts(8,21): error TS2304: Cannot find name 'field1'. +tests/cases/compiler/classMemberInitializerWithLamdaScoping3_1.ts(8,21): error TS2663: Cannot find name 'field1'. Did you mean the instance member 'this.field1'? ==== tests/cases/compiler/classMemberInitializerWithLamdaScoping3_0.ts (0 errors) ==== @@ -14,6 +14,6 @@ tests/cases/compiler/classMemberInitializerWithLamdaScoping3_1.ts(8,21): error T messageHandler = () => { console.log(field1); // Should be error that couldnt find symbol field1 ~~~~~~ -!!! error TS2304: Cannot find name 'field1'. +!!! error TS2663: Cannot find name 'field1'. Did you mean the instance member 'this.field1'? }; } \ No newline at end of file diff --git a/tests/baselines/reference/commonJsImportClassExpression.js b/tests/baselines/reference/commonJsImportClassExpression.js new file mode 100644 index 00000000000..b460814b872 --- /dev/null +++ b/tests/baselines/reference/commonJsImportClassExpression.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/commonJsImportClassExpression.ts] //// + +//// [mod1.ts] +export = class { + chunk = 1 +} + +//// [use.ts] +import Chunk = require('./mod1') +declare var c: Chunk; +c.chunk; + + +//// [mod1.js] +"use strict"; +module.exports = /** @class */ (function () { + function class_1() { + this.chunk = 1; + } + return class_1; +}()); +//// [use.js] +"use strict"; +exports.__esModule = true; +c.chunk; diff --git a/tests/baselines/reference/commonJsImportClassExpression.symbols b/tests/baselines/reference/commonJsImportClassExpression.symbols new file mode 100644 index 00000000000..5f6bc93188f --- /dev/null +++ b/tests/baselines/reference/commonJsImportClassExpression.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/use.ts === +import Chunk = require('./mod1') +>Chunk : Symbol(Chunk, Decl(use.ts, 0, 0)) + +declare var c: Chunk; +>c : Symbol(c, Decl(use.ts, 1, 11)) +>Chunk : Symbol(Chunk, Decl(use.ts, 0, 0)) + +c.chunk; +>c.chunk : Symbol(Chunk.chunk, Decl(mod1.ts, 0, 16)) +>c : Symbol(c, Decl(use.ts, 1, 11)) +>chunk : Symbol(Chunk.chunk, Decl(mod1.ts, 0, 16)) + +=== tests/cases/compiler/mod1.ts === +export = class { + chunk = 1 +>chunk : Symbol((Anonymous class).chunk, Decl(mod1.ts, 0, 16)) +} + diff --git a/tests/baselines/reference/commonJsImportClassExpression.types b/tests/baselines/reference/commonJsImportClassExpression.types new file mode 100644 index 00000000000..7bb32dea8e5 --- /dev/null +++ b/tests/baselines/reference/commonJsImportClassExpression.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/use.ts === +import Chunk = require('./mod1') +>Chunk : typeof Chunk + +declare var c: Chunk; +>c : Chunk +>Chunk : Chunk + +c.chunk; +>c.chunk : number +>c : Chunk +>chunk : number + +=== tests/cases/compiler/mod1.ts === +export = class { +>class { chunk = 1} : typeof (Anonymous class) + + chunk = 1 +>chunk : number +>1 : 1 +} + diff --git a/tests/baselines/reference/complexRecursiveCollections.symbols b/tests/baselines/reference/complexRecursiveCollections.symbols index 4f1a675edaf..4c49735f01d 100644 --- a/tests/baselines/reference/complexRecursiveCollections.symbols +++ b/tests/baselines/reference/complexRecursiveCollections.symbols @@ -1689,7 +1689,7 @@ declare module Immutable { export interface Class { >Class : Symbol(Class, Decl(immutable.ts, 214, 70)) >T : Symbol(T, Decl(immutable.ts, 215, 27)) ->Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) (values?: Partial | Iterable<[string, any]>): Instance & Readonly; >values : Symbol(values, Decl(immutable.ts, 216, 7)) @@ -1714,7 +1714,7 @@ declare module Immutable { export interface Instance { >Instance : Symbol(Instance, Decl(immutable.ts, 218, 5)) >T : Symbol(T, Decl(immutable.ts, 219, 30)) ->Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) readonly size: number; >size : Symbol(Instance.size, Decl(immutable.ts, 219, 49)) @@ -2005,7 +2005,7 @@ declare module Immutable { toJS(): Object; >toJS : Symbol(Keyed.toJS, Decl(immutable.ts, 269, 76)) ->Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) toJSON(): { [key: string]: V }; >toJSON : Symbol(Keyed.toJSON, Decl(immutable.ts, 270, 21)) @@ -2594,7 +2594,7 @@ declare module Immutable { toJS(): Object; >toJS : Symbol(Keyed.toJS, Decl(immutable.ts, 340, 59)) ->Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) toJSON(): { [key: string]: V }; >toJSON : Symbol(Keyed.toJSON, Decl(immutable.ts, 341, 21)) diff --git a/tests/baselines/reference/computedPropertyNames10_ES5.types b/tests/baselines/reference/computedPropertyNames10_ES5.types index 717e12f7216..d12636585b6 100644 --- a/tests/baselines/reference/computedPropertyNames10_ES5.types +++ b/tests/baselines/reference/computedPropertyNames10_ES5.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [x: string]: () => void; [x: number]: () => void; [""](): void; [0](): void; } ->{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [x: string]: () => void; [x: number]: () => void; [""](): void; [0](): void; } +>v : { [x: string]: () => void; [x: number]: () => void; [""](): void; [0](): void; [`hello bye`](): void; } +>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [x: string]: () => void; [x: number]: () => void; [""](): void; [0](): void; [`hello bye`](): void; } [s]() { }, >[s] : () => void diff --git a/tests/baselines/reference/computedPropertyNames10_ES6.types b/tests/baselines/reference/computedPropertyNames10_ES6.types index b615e9e4739..fab486ff57a 100644 --- a/tests/baselines/reference/computedPropertyNames10_ES6.types +++ b/tests/baselines/reference/computedPropertyNames10_ES6.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [x: string]: () => void; [x: number]: () => void; [""](): void; [0](): void; } ->{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [x: string]: () => void; [x: number]: () => void; [""](): void; [0](): void; } +>v : { [x: string]: () => void; [x: number]: () => void; [""](): void; [0](): void; [`hello bye`](): void; } +>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : { [x: string]: () => void; [x: number]: () => void; [""](): void; [0](): void; [`hello bye`](): void; } [s]() { }, >[s] : () => void diff --git a/tests/baselines/reference/computedPropertyNames28_ES5.types b/tests/baselines/reference/computedPropertyNames28_ES5.types index b440f86c986..c353b1bdb83 100644 --- a/tests/baselines/reference/computedPropertyNames28_ES5.types +++ b/tests/baselines/reference/computedPropertyNames28_ES5.types @@ -12,8 +12,8 @@ class C extends Base { >super : typeof Base var obj = { ->obj : { [x: string]: () => void; } ->{ [(super(), "prop")]() { } } : { [x: string]: () => void; } +>obj : { [(super(), "prop")](): void; } +>{ [(super(), "prop")]() { } } : { [(super(), "prop")](): void; } [(super(), "prop")]() { } >[(super(), "prop")] : () => void diff --git a/tests/baselines/reference/computedPropertyNames28_ES6.types b/tests/baselines/reference/computedPropertyNames28_ES6.types index a947b6f8a95..97d4f9d591f 100644 --- a/tests/baselines/reference/computedPropertyNames28_ES6.types +++ b/tests/baselines/reference/computedPropertyNames28_ES6.types @@ -12,8 +12,8 @@ class C extends Base { >super : typeof Base var obj = { ->obj : { [x: string]: () => void; } ->{ [(super(), "prop")]() { } } : { [x: string]: () => void; } +>obj : { [(super(), "prop")](): void; } +>{ [(super(), "prop")]() { } } : { [(super(), "prop")](): void; } [(super(), "prop")]() { } >[(super(), "prop")] : () => void diff --git a/tests/baselines/reference/computedPropertyNames30_ES5.types b/tests/baselines/reference/computedPropertyNames30_ES5.types index 1d50a1d19f3..0344bc7924a 100644 --- a/tests/baselines/reference/computedPropertyNames30_ES5.types +++ b/tests/baselines/reference/computedPropertyNames30_ES5.types @@ -15,8 +15,8 @@ class C extends Base { >() => { var obj = { // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with //treatment of other similar violations. [(super(), "prop")]() { } }; } : () => void var obj = { ->obj : { [x: string]: () => void; } ->{ // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with //treatment of other similar violations. [(super(), "prop")]() { } } : { [x: string]: () => void; } +>obj : { [(super(), "prop")](): void; } +>{ // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with //treatment of other similar violations. [(super(), "prop")]() { } } : { [(super(), "prop")](): void; } // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with diff --git a/tests/baselines/reference/computedPropertyNames30_ES6.types b/tests/baselines/reference/computedPropertyNames30_ES6.types index 3d2a39f4fe9..ef7e95f46f2 100644 --- a/tests/baselines/reference/computedPropertyNames30_ES6.types +++ b/tests/baselines/reference/computedPropertyNames30_ES6.types @@ -15,8 +15,8 @@ class C extends Base { >() => { var obj = { // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with //treatment of other similar violations. [(super(), "prop")]() { } }; } : () => void var obj = { ->obj : { [x: string]: () => void; } ->{ // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with //treatment of other similar violations. [(super(), "prop")]() { } } : { [x: string]: () => void; } +>obj : { [(super(), "prop")](): void; } +>{ // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with //treatment of other similar violations. [(super(), "prop")]() { } } : { [(super(), "prop")](): void; } // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with diff --git a/tests/baselines/reference/computedPropertyNames5_ES5.types b/tests/baselines/reference/computedPropertyNames5_ES5.types index b185ee47f4d..64b51175c33 100644 --- a/tests/baselines/reference/computedPropertyNames5_ES5.types +++ b/tests/baselines/reference/computedPropertyNames5_ES5.types @@ -3,8 +3,8 @@ var b: boolean; >b : boolean var v = { ->v : { [x: string]: number; [x: number]: any; [true]: number; } ->{ [b]: 0, [true]: 1, [[]]: 0, [{}]: 0, [undefined]: undefined, [null]: null} : { [x: string]: number; [x: number]: null; [true]: number; } +>v : { [x: number]: any; } +>{ [b]: 0, [true]: 1, [[]]: 0, [{}]: 0, [undefined]: undefined, [null]: null} : { [x: number]: null; } [b]: 0, >[b] : number diff --git a/tests/baselines/reference/computedPropertyNames5_ES6.types b/tests/baselines/reference/computedPropertyNames5_ES6.types index 62c798a8b08..5ffcba5cbc6 100644 --- a/tests/baselines/reference/computedPropertyNames5_ES6.types +++ b/tests/baselines/reference/computedPropertyNames5_ES6.types @@ -3,8 +3,8 @@ var b: boolean; >b : boolean var v = { ->v : { [x: string]: number; [x: number]: any; [true]: number; } ->{ [b]: 0, [true]: 1, [[]]: 0, [{}]: 0, [undefined]: undefined, [null]: null} : { [x: string]: number; [x: number]: null; [true]: number; } +>v : { [x: number]: any; } +>{ [b]: 0, [true]: 1, [[]]: 0, [{}]: 0, [undefined]: undefined, [null]: null} : { [x: number]: null; } [b]: 0, >[b] : number diff --git a/tests/baselines/reference/computedPropertyNames9_ES5.types b/tests/baselines/reference/computedPropertyNames9_ES5.types index dd37aca47b9..d85aefa5f1c 100644 --- a/tests/baselines/reference/computedPropertyNames9_ES5.types +++ b/tests/baselines/reference/computedPropertyNames9_ES5.types @@ -19,8 +19,8 @@ function f(x): any { } >x : any var v = { ->v : { [x: string]: number; [x: number]: number; [f(true)]: number; } ->{ [f("")]: 0, [f(0)]: 0, [f(true)]: 0} : { [x: string]: number; [x: number]: number; [f(true)]: number; } +>v : { [x: string]: number; [x: number]: number; } +>{ [f("")]: 0, [f(0)]: 0, [f(true)]: 0} : { [x: string]: number; [x: number]: number; } [f("")]: 0, >[f("")] : number diff --git a/tests/baselines/reference/computedPropertyNames9_ES6.types b/tests/baselines/reference/computedPropertyNames9_ES6.types index 02bd0eabb9a..35aac1bbea7 100644 --- a/tests/baselines/reference/computedPropertyNames9_ES6.types +++ b/tests/baselines/reference/computedPropertyNames9_ES6.types @@ -19,8 +19,8 @@ function f(x): any { } >x : any var v = { ->v : { [x: string]: number; [x: number]: number; [f(true)]: number; } ->{ [f("")]: 0, [f(0)]: 0, [f(true)]: 0} : { [x: string]: number; [x: number]: number; [f(true)]: number; } +>v : { [x: string]: number; [x: number]: number; } +>{ [f("")]: 0, [f(0)]: 0, [f(true)]: 0} : { [x: string]: number; [x: number]: number; } [f("")]: 0, >[f("")] : number diff --git a/tests/baselines/reference/conditionalTypes1.errors.txt b/tests/baselines/reference/conditionalTypes1.errors.txt index 9599cc1bcba..7ba3a2aa934 100644 --- a/tests/baselines/reference/conditionalTypes1.errors.txt +++ b/tests/baselines/reference/conditionalTypes1.errors.txt @@ -5,9 +5,8 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(17,5): error TS23 tests/cases/conformance/types/conditional/conditionalTypes1.ts(18,9): error TS2322: Type 'T' is not assignable to type 'string'. Type 'string | undefined' is not assignable to type 'string'. Type 'undefined' is not assignable to type 'string'. -tests/cases/conformance/types/conditional/conditionalTypes1.ts(24,5): error TS2322: Type 'Partial[keyof T]' is not assignable to type 'NonNullable[keyof T]>'. - Type 'T[keyof T] | undefined' is not assignable to type 'NonNullable[keyof T]>'. - Type 'undefined' is not assignable to type 'NonNullable[keyof T]>'. +tests/cases/conformance/types/conditional/conditionalTypes1.ts(24,5): error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'NonNullable[keyof T]>'. + Type 'undefined' is not assignable to type 'NonNullable[keyof T]>'. tests/cases/conformance/types/conditional/conditionalTypes1.ts(29,5): error TS2322: Type 'T["x"]' is not assignable to type 'NonNullable'. Type 'string | undefined' is not assignable to type 'NonNullable'. Type 'undefined' is not assignable to type 'NonNullable'. @@ -17,41 +16,25 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(30,9): error TS23 tests/cases/conformance/types/conditional/conditionalTypes1.ts(103,5): error TS2322: Type 'Pick' is not assignable to type 'T'. tests/cases/conformance/types/conditional/conditionalTypes1.ts(104,5): error TS2322: Type 'Pick' is not assignable to type 'T'. tests/cases/conformance/types/conditional/conditionalTypes1.ts(106,5): error TS2322: Type 'Pick' is not assignable to type 'Pick'. - Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. - Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. - Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. - Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. - Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. - Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. - Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. - Type 'keyof T' is not assignable to type 'never'. + Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. + Type 'keyof T' is not assignable to type 'never'. + Type 'string | number | symbol' is not assignable to type 'never'. + Type 'string' is not assignable to type 'never'. tests/cases/conformance/types/conditional/conditionalTypes1.ts(108,5): error TS2322: Type 'Pick' is not assignable to type 'Pick'. - Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. - Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. - Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. - Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. - Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. - Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. - Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. - Type 'keyof T' is not assignable to type 'never'. -tests/cases/conformance/types/conditional/conditionalTypes1.ts(114,5): error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. - Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. -tests/cases/conformance/types/conditional/conditionalTypes1.ts(115,5): error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. - Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. - Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. - Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. - Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. - Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. - Type 'keyof T' is not assignable to type 'never'. -tests/cases/conformance/types/conditional/conditionalTypes1.ts(116,5): error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. - Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. -tests/cases/conformance/types/conditional/conditionalTypes1.ts(117,5): error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. - Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. - Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. - Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. - Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. - Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. - Type 'keyof T' is not assignable to type 'never'. + Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. + Type 'keyof T' is not assignable to type 'never'. +tests/cases/conformance/types/conditional/conditionalTypes1.ts(114,5): error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. + Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. + Type 'string' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. +tests/cases/conformance/types/conditional/conditionalTypes1.ts(115,5): error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. + Type 'keyof T' is not assignable to type 'never'. + Type 'string | number | symbol' is not assignable to type 'never'. + Type 'string' is not assignable to type 'never'. +tests/cases/conformance/types/conditional/conditionalTypes1.ts(116,5): error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. + Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. + Type 'string' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. +tests/cases/conformance/types/conditional/conditionalTypes1.ts(117,5): error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. + Type 'keyof T' is not assignable to type 'never'. tests/cases/conformance/types/conditional/conditionalTypes1.ts(134,10): error TS2540: Cannot assign to 'id' because it is a constant or a read-only property. tests/cases/conformance/types/conditional/conditionalTypes1.ts(135,5): error TS2542: Index signature in type 'DeepReadonlyArray' only permits reading. tests/cases/conformance/types/conditional/conditionalTypes1.ts(136,22): error TS2540: Cannot assign to 'id' because it is a constant or a read-only property. @@ -105,9 +88,8 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS x = y; y = x; // Error ~ -!!! error TS2322: Type 'Partial[keyof T]' is not assignable to type 'NonNullable[keyof T]>'. -!!! error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'NonNullable[keyof T]>'. -!!! error TS2322: Type 'undefined' is not assignable to type 'NonNullable[keyof T]>'. +!!! error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'NonNullable[keyof T]>'. +!!! error TS2322: Type 'undefined' is not assignable to type 'NonNullable[keyof T]>'. } function f4(x: T["x"], y: NonNullable) { @@ -204,26 +186,16 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS y = z; // Error ~ !!! error TS2322: Type 'Pick' is not assignable to type 'Pick'. -!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. -!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. -!!! error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. -!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. -!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. -!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. -!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. -!!! error TS2322: Type 'keyof T' is not assignable to type 'never'. +!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. +!!! error TS2322: Type 'keyof T' is not assignable to type 'never'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'never'. +!!! error TS2322: Type 'string' is not assignable to type 'never'. z = x; z = y; // Error ~ !!! error TS2322: Type 'Pick' is not assignable to type 'Pick'. -!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. -!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. -!!! error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. -!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. -!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. -!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. -!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. -!!! error TS2322: Type 'keyof T' is not assignable to type 'never'. +!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. +!!! error TS2322: Type 'keyof T' is not assignable to type 'never'. } function f8(x: keyof T, y: FunctionPropertyNames, z: NonFunctionPropertyNames) { @@ -231,30 +203,24 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS x = z; y = x; // Error ~ -!!! error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. -!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. +!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. +!!! error TS2322: Type 'string' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. y = z; // Error ~ -!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. -!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. -!!! error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]'. -!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. -!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. -!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. -!!! error TS2322: Type 'keyof T' is not assignable to type 'never'. +!!! error TS2322: Type 'T[keyof T] extends Function ? never : keyof T' is not assignable to type 'T[keyof T] extends Function ? keyof T : never'. +!!! error TS2322: Type 'keyof T' is not assignable to type 'never'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'never'. +!!! error TS2322: Type 'string' is not assignable to type 'never'. z = x; // Error ~ -!!! error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. -!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. +!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. +!!! error TS2322: Type 'string' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. z = y; // Error ~ -!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. -!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. -!!! error TS2322: Type 'keyof T' is not assignable to type '{ [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]'. -!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. -!!! error TS2322: Type '{ [K in keyof T]: T[K] extends Function ? K : never; }[keyof T]' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. -!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. -!!! error TS2322: Type 'keyof T' is not assignable to type 'never'. +!!! error TS2322: Type 'T[keyof T] extends Function ? keyof T : never' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'. +!!! error TS2322: Type 'keyof T' is not assignable to type 'never'. } type DeepReadonly = @@ -463,7 +429,7 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS // Repro from #21862 - type OldDiff = ( + type OldDiff = ( & { [P in T]: P; } & { [P in U]: never; } & { [x: string]: never; } diff --git a/tests/baselines/reference/conditionalTypes1.js b/tests/baselines/reference/conditionalTypes1.js index 3e5e385625b..552a80d58a5 100644 --- a/tests/baselines/reference/conditionalTypes1.js +++ b/tests/baselines/reference/conditionalTypes1.js @@ -301,7 +301,7 @@ function f50() { // Repro from #21862 -type OldDiff = ( +type OldDiff = ( & { [P in T]: P; } & { [P in U]: never; } & { [x: string]: never; } @@ -656,7 +656,7 @@ declare type T95 = T extends string ? boolean : number; declare const f44: (value: T94) => T95; declare const f45: (value: T95) => T94; declare function f50(): void; -declare type OldDiff = ({ +declare type OldDiff = ({ [P in T]: P; } & { [P in U]: never; diff --git a/tests/baselines/reference/conditionalTypes1.symbols b/tests/baselines/reference/conditionalTypes1.symbols index fb0ce83e0a7..5f6bb75514d 100644 --- a/tests/baselines/reference/conditionalTypes1.symbols +++ b/tests/baselines/reference/conditionalTypes1.symbols @@ -1186,10 +1186,10 @@ function f50() { // Repro from #21862 -type OldDiff = ( +type OldDiff = ( >OldDiff : Symbol(OldDiff, Decl(conditionalTypes1.ts, 298, 1)) >T : Symbol(T, Decl(conditionalTypes1.ts, 302, 13)) ->U : Symbol(U, Decl(conditionalTypes1.ts, 302, 30)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 302, 33)) & { [P in T]: P; } >P : Symbol(P, Decl(conditionalTypes1.ts, 303, 9)) @@ -1198,7 +1198,7 @@ type OldDiff = ( & { [P in U]: never; } >P : Symbol(P, Decl(conditionalTypes1.ts, 304, 9)) ->U : Symbol(U, Decl(conditionalTypes1.ts, 302, 30)) +>U : Symbol(U, Decl(conditionalTypes1.ts, 302, 33)) & { [x: string]: never; } >x : Symbol(x, Decl(conditionalTypes1.ts, 305, 9)) diff --git a/tests/baselines/reference/conditionalTypes1.types b/tests/baselines/reference/conditionalTypes1.types index 2ba376781a5..90d2703d034 100644 --- a/tests/baselines/reference/conditionalTypes1.types +++ b/tests/baselines/reference/conditionalTypes1.types @@ -1343,7 +1343,7 @@ function f50() { // Repro from #21862 -type OldDiff = ( +type OldDiff = ( >OldDiff : ({ [P in T]: P; } & { [P in U]: never; } & { [x: string]: never; })[T] >T : T >U : U diff --git a/tests/baselines/reference/conditionalTypes2.errors.txt b/tests/baselines/reference/conditionalTypes2.errors.txt index c0c4211174c..49a36be96db 100644 --- a/tests/baselines/reference/conditionalTypes2.errors.txt +++ b/tests/baselines/reference/conditionalTypes2.errors.txt @@ -6,6 +6,8 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(24,5): error TS23 Types of property 'foo' are incompatible. Type 'B extends string ? keyof B : B' is not assignable to type 'A extends string ? keyof A : A'. Type 'keyof B' is not assignable to type 'keyof A'. + Type 'string | number | symbol' is not assignable to type 'keyof A'. + Type 'string' is not assignable to type 'keyof A'. tests/cases/conformance/types/conditional/conditionalTypes2.ts(25,5): error TS2322: Type 'Invariant' is not assignable to type 'Invariant'. Types of property 'foo' are incompatible. Type 'A extends string ? keyof A : A' is not assignable to type 'B extends string ? keyof B : B'. @@ -60,6 +62,8 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2 !!! error TS2322: Types of property 'foo' are incompatible. !!! error TS2322: Type 'B extends string ? keyof B : B' is not assignable to type 'A extends string ? keyof A : A'. !!! error TS2322: Type 'keyof B' is not assignable to type 'keyof A'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'keyof A'. +!!! error TS2322: Type 'string' is not assignable to type 'keyof A'. b = a; // Error ~ !!! error TS2322: Type 'Invariant' is not assignable to type 'Invariant'. diff --git a/tests/baselines/reference/controlFlowIIFE.errors.txt b/tests/baselines/reference/controlFlowIIFE.errors.txt new file mode 100644 index 00000000000..50053a90f2c --- /dev/null +++ b/tests/baselines/reference/controlFlowIIFE.errors.txt @@ -0,0 +1,82 @@ +tests/cases/conformance/controlFlow/controlFlowIIFE.ts(64,5): error TS2454: Variable 'v' is used before being assigned. +tests/cases/conformance/controlFlow/controlFlowIIFE.ts(72,5): error TS2454: Variable 'v' is used before being assigned. + + +==== tests/cases/conformance/controlFlow/controlFlowIIFE.ts (2 errors) ==== + declare function getStringOrNumber(): string | number; + + function f1() { + let x = getStringOrNumber(); + if (typeof x === "string") { + let n = function() { + return x.length; + }(); + } + } + + function f2() { + let x = getStringOrNumber(); + if (typeof x === "string") { + let n = (function() { + return x.length; + })(); + } + } + + function f3() { + let x = getStringOrNumber(); + let y: number; + if (typeof x === "string") { + let n = (z => x.length + y + z)(y = 1); + } + } + + // Repros from #8381 + + let maybeNumber: number | undefined; + (function () { + maybeNumber = 1; + })(); + maybeNumber++; + if (maybeNumber !== undefined) { + maybeNumber++; + } + + let test: string | undefined; + if (!test) { + throw new Error('Test is not defined'); + } + (() => { + test.slice(1); // No error + })(); + + // Repro from #23565 + + function f4() { + let v: number; + (function() { + v = 1; + })(); + v; + } + + function f5() { + let v: number; + (function*() { + yield 1; + v = 1; + })(); + v; // still undefined + ~ +!!! error TS2454: Variable 'v' is used before being assigned. + } + + function f6() { + let v: number; + (async function() { + v = await 1; + })(); + v; // still undefined + ~ +!!! error TS2454: Variable 'v' is used before being assigned. + } \ No newline at end of file diff --git a/tests/baselines/reference/controlFlowIIFE.js b/tests/baselines/reference/controlFlowIIFE.js index 20bde01cba6..5c7fcb4bd52 100644 --- a/tests/baselines/reference/controlFlowIIFE.js +++ b/tests/baselines/reference/controlFlowIIFE.js @@ -44,34 +44,61 @@ if (!test) { } (() => { test.slice(1); // No error -})(); +})(); + +// Repro from #23565 + +function f4() { + let v: number; + (function() { + v = 1; + })(); + v; +} + +function f5() { + let v: number; + (function*() { + yield 1; + v = 1; + })(); + v; // still undefined +} + +function f6() { + let v: number; + (async function() { + v = await 1; + })(); + v; // still undefined +} //// [controlFlowIIFE.js] function f1() { - var x = getStringOrNumber(); + let x = getStringOrNumber(); if (typeof x === "string") { - var n = function () { + let n = function () { return x.length; }(); } } function f2() { - var x = getStringOrNumber(); + let x = getStringOrNumber(); if (typeof x === "string") { - var n = (function () { + let n = (function () { return x.length; })(); } } function f3() { - var x = getStringOrNumber(); - var y; + let x = getStringOrNumber(); + let y; if (typeof x === "string") { - var n = (function (z) { return x.length + y + z; })(y = 1); + let n = (z => x.length + y + z)(y = 1); } } // Repros from #8381 -var maybeNumber; +let maybeNumber; (function () { maybeNumber = 1; })(); @@ -79,10 +106,33 @@ maybeNumber++; if (maybeNumber !== undefined) { maybeNumber++; } -var test; +let test; if (!test) { throw new Error('Test is not defined'); } -(function () { +(() => { test.slice(1); // No error })(); +// Repro from #23565 +function f4() { + let v; + (function () { + v = 1; + })(); + v; +} +function f5() { + let v; + (function* () { + yield 1; + v = 1; + })(); + v; // still undefined +} +function f6() { + let v; + (async function () { + v = await 1; + })(); + v; // still undefined +} diff --git a/tests/baselines/reference/controlFlowIIFE.symbols b/tests/baselines/reference/controlFlowIIFE.symbols index 4df906e0684..038d398c649 100644 --- a/tests/baselines/reference/controlFlowIIFE.symbols +++ b/tests/baselines/reference/controlFlowIIFE.symbols @@ -16,9 +16,9 @@ function f1() { >n : Symbol(n, Decl(controlFlowIIFE.ts, 5, 11)) return x.length; ->x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) >x : Symbol(x, Decl(controlFlowIIFE.ts, 3, 7)) ->length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) }(); } @@ -38,9 +38,9 @@ function f2() { >n : Symbol(n, Decl(controlFlowIIFE.ts, 14, 11)) return x.length; ->x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) >x : Symbol(x, Decl(controlFlowIIFE.ts, 12, 7)) ->length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) })(); } @@ -62,9 +62,9 @@ function f3() { let n = (z => x.length + y + z)(y = 1); >n : Symbol(n, Decl(controlFlowIIFE.ts, 24, 11)) >z : Symbol(z, Decl(controlFlowIIFE.ts, 24, 17)) ->x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) >x : Symbol(x, Decl(controlFlowIIFE.ts, 21, 7)) ->length : Symbol(String.length, Decl(lib.d.ts, --, --)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) >y : Symbol(y, Decl(controlFlowIIFE.ts, 22, 7)) >z : Symbol(z, Decl(controlFlowIIFE.ts, 24, 17)) >y : Symbol(y, Decl(controlFlowIIFE.ts, 22, 7)) @@ -99,12 +99,60 @@ if (!test) { >test : Symbol(test, Decl(controlFlowIIFE.ts, 39, 3)) throw new Error('Test is not defined'); ->Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) } (() => { test.slice(1); // No error ->test.slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +>test.slice : Symbol(String.slice, Decl(lib.es5.d.ts, --, --)) >test : Symbol(test, Decl(controlFlowIIFE.ts, 39, 3)) ->slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +>slice : Symbol(String.slice, Decl(lib.es5.d.ts, --, --)) })(); + +// Repro from #23565 + +function f4() { +>f4 : Symbol(f4, Decl(controlFlowIIFE.ts, 45, 5)) + + let v: number; +>v : Symbol(v, Decl(controlFlowIIFE.ts, 50, 7)) + + (function() { + v = 1; +>v : Symbol(v, Decl(controlFlowIIFE.ts, 50, 7)) + + })(); + v; +>v : Symbol(v, Decl(controlFlowIIFE.ts, 50, 7)) +} + +function f5() { +>f5 : Symbol(f5, Decl(controlFlowIIFE.ts, 55, 1)) + + let v: number; +>v : Symbol(v, Decl(controlFlowIIFE.ts, 58, 7)) + + (function*() { + yield 1; + v = 1; +>v : Symbol(v, Decl(controlFlowIIFE.ts, 58, 7)) + + })(); + v; // still undefined +>v : Symbol(v, Decl(controlFlowIIFE.ts, 58, 7)) +} + +function f6() { +>f6 : Symbol(f6, Decl(controlFlowIIFE.ts, 64, 1)) + + let v: number; +>v : Symbol(v, Decl(controlFlowIIFE.ts, 67, 7)) + + (async function() { + v = await 1; +>v : Symbol(v, Decl(controlFlowIIFE.ts, 67, 7)) + + })(); + v; // still undefined +>v : Symbol(v, Decl(controlFlowIIFE.ts, 67, 7)) +} diff --git a/tests/baselines/reference/controlFlowIIFE.types b/tests/baselines/reference/controlFlowIIFE.types index 1132649ae09..7aaaad159fc 100644 --- a/tests/baselines/reference/controlFlowIIFE.types +++ b/tests/baselines/reference/controlFlowIIFE.types @@ -150,3 +150,73 @@ if (!test) { >1 : 1 })(); + +// Repro from #23565 + +function f4() { +>f4 : () => void + + let v: number; +>v : number + + (function() { +>(function() { v = 1; })() : void +>(function() { v = 1; }) : () => void +>function() { v = 1; } : () => void + + v = 1; +>v = 1 : 1 +>v : number +>1 : 1 + + })(); + v; +>v : number +} + +function f5() { +>f5 : () => void + + let v: number; +>v : number + + (function*() { +>(function*() { yield 1; v = 1; })() : IterableIterator +>(function*() { yield 1; v = 1; }) : () => IterableIterator +>function*() { yield 1; v = 1; } : () => IterableIterator + + yield 1; +>yield 1 : any +>1 : 1 + + v = 1; +>v = 1 : 1 +>v : number +>1 : 1 + + })(); + v; // still undefined +>v : number +} + +function f6() { +>f6 : () => void + + let v: number; +>v : number + + (async function() { +>(async function() { v = await 1; })() : Promise +>(async function() { v = await 1; }) : () => Promise +>async function() { v = await 1; } : () => Promise + + v = await 1; +>v = await 1 : 1 +>v : number +>await 1 : 1 +>1 : 1 + + })(); + v; // still undefined +>v : number +} diff --git a/tests/baselines/reference/controlFlowPropertyDeclarations.types b/tests/baselines/reference/controlFlowPropertyDeclarations.types index 286124ca346..0e698b72608 100644 --- a/tests/baselines/reference/controlFlowPropertyDeclarations.types +++ b/tests/baselines/reference/controlFlowPropertyDeclarations.types @@ -371,11 +371,11 @@ export class StyleParser { if (!this.styles.hasOwnProperty(key)) { >!this.styles.hasOwnProperty(key) : boolean >this.styles.hasOwnProperty(key) : boolean ->this.styles.hasOwnProperty : (v: string) => boolean +>this.styles.hasOwnProperty : (v: string | number | symbol) => boolean >this.styles : {} >this : this >styles : {} ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >key : string } } diff --git a/tests/baselines/reference/decoratorOnClassMethodParameter1.es6.symbols b/tests/baselines/reference/decoratorOnClassMethodParameter1.es6.symbols index aee56f5a4f8..e33f0e8f7b9 100644 --- a/tests/baselines/reference/decoratorOnClassMethodParameter1.es6.symbols +++ b/tests/baselines/reference/decoratorOnClassMethodParameter1.es6.symbols @@ -2,7 +2,7 @@ declare function dec(target: Object, propertyKey: string | symbol, parameterIndex: number): void; >dec : Symbol(dec, Decl(decoratorOnClassMethodParameter1.es6.ts, 0, 0)) >target : Symbol(target, Decl(decoratorOnClassMethodParameter1.es6.ts, 0, 21)) ->Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >propertyKey : Symbol(propertyKey, Decl(decoratorOnClassMethodParameter1.es6.ts, 0, 36)) >parameterIndex : Symbol(parameterIndex, Decl(decoratorOnClassMethodParameter1.es6.ts, 0, 66)) diff --git a/tests/baselines/reference/decoratorsOnComputedProperties.symbols b/tests/baselines/reference/decoratorsOnComputedProperties.symbols index 65652b4524e..dc069f22c56 100644 --- a/tests/baselines/reference/decoratorsOnComputedProperties.symbols +++ b/tests/baselines/reference/decoratorsOnComputedProperties.symbols @@ -3,7 +3,7 @@ function x(o: object, k: PropertyKey) { } >x : Symbol(x, Decl(decoratorsOnComputedProperties.ts, 0, 0)) >o : Symbol(o, Decl(decoratorsOnComputedProperties.ts, 0, 11)) >k : Symbol(k, Decl(decoratorsOnComputedProperties.ts, 0, 21)) ->PropertyKey : Symbol(PropertyKey, Decl(lib.es2015.core.d.ts, --, --)) +>PropertyKey : Symbol(PropertyKey, Decl(lib.es5.d.ts, --, --)) let i = 0; >i : Symbol(i, Decl(decoratorsOnComputedProperties.ts, 1, 3)) diff --git a/tests/baselines/reference/decoratorsOnComputedProperties.types b/tests/baselines/reference/decoratorsOnComputedProperties.types index 24ed343c298..efbf9c5d263 100644 --- a/tests/baselines/reference/decoratorsOnComputedProperties.types +++ b/tests/baselines/reference/decoratorsOnComputedProperties.types @@ -1,9 +1,9 @@ === tests/cases/compiler/decoratorsOnComputedProperties.ts === function x(o: object, k: PropertyKey) { } ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >o : object ->k : PropertyKey ->PropertyKey : PropertyKey +>k : string | number | symbol +>PropertyKey : string | number | symbol let i = 0; >i : number @@ -32,25 +32,25 @@ class A { >A : A @x ["property"]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property"] : any >"property" : "property" @x [Symbol.toStringTag]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.toStringTag] : any >Symbol.toStringTag : symbol >Symbol : SymbolConstructor >toStringTag : symbol @x ["property2"]: any = 2; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property2"] : any >"property2" : "property2" >2 : 2 @x [Symbol.iterator]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.iterator] : any >Symbol.iterator : symbol >Symbol : SymbolConstructor @@ -85,13 +85,13 @@ class A { >foo : () => string @x [foo()]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @x [foo()]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @@ -102,12 +102,12 @@ class A { >fieldNameA : string @x [fieldNameB]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameB] : any >fieldNameB : string @x [fieldNameC]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameC] : any >fieldNameC : string >null : null @@ -119,25 +119,25 @@ void class B { >B : typeof B @x ["property"]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property"] : any >"property" : "property" @x [Symbol.toStringTag]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.toStringTag] : any >Symbol.toStringTag : symbol >Symbol : SymbolConstructor >toStringTag : symbol @x ["property2"]: any = 2; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property2"] : any >"property2" : "property2" >2 : 2 @x [Symbol.iterator]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.iterator] : any >Symbol.iterator : symbol >Symbol : SymbolConstructor @@ -172,13 +172,13 @@ void class B { >foo : () => string @x [foo()]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @x [foo()]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @@ -189,12 +189,12 @@ void class B { >fieldNameA : string @x [fieldNameB]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameB] : any >fieldNameB : string @x [fieldNameC]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameC] : any >fieldNameC : string >null : null @@ -205,25 +205,25 @@ class C { >C : C @x ["property"]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property"] : any >"property" : "property" @x [Symbol.toStringTag]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.toStringTag] : any >Symbol.toStringTag : symbol >Symbol : SymbolConstructor >toStringTag : symbol @x ["property2"]: any = 2; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property2"] : any >"property2" : "property2" >2 : 2 @x [Symbol.iterator]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.iterator] : any >Symbol.iterator : symbol >Symbol : SymbolConstructor @@ -258,13 +258,13 @@ class C { >foo : () => string @x [foo()]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @x [foo()]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @@ -275,12 +275,12 @@ class C { >fieldNameA : string @x [fieldNameB]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameB] : any >fieldNameB : string @x [fieldNameC]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameC] : any >fieldNameC : string >null : null @@ -298,25 +298,25 @@ void class D { >D : typeof D @x ["property"]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property"] : any >"property" : "property" @x [Symbol.toStringTag]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.toStringTag] : any >Symbol.toStringTag : symbol >Symbol : SymbolConstructor >toStringTag : symbol @x ["property2"]: any = 2; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property2"] : any >"property2" : "property2" >2 : 2 @x [Symbol.iterator]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.iterator] : any >Symbol.iterator : symbol >Symbol : SymbolConstructor @@ -351,13 +351,13 @@ void class D { >foo : () => string @x [foo()]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @x [foo()]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @@ -368,12 +368,12 @@ void class D { >fieldNameA : string @x [fieldNameB]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameB] : any >fieldNameB : string @x [fieldNameC]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameC] : any >fieldNameC : string >null : null @@ -390,25 +390,25 @@ class E { >E : E @x ["property"]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property"] : any >"property" : "property" @x [Symbol.toStringTag]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.toStringTag] : any >Symbol.toStringTag : symbol >Symbol : SymbolConstructor >toStringTag : symbol @x ["property2"]: any = 2; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property2"] : any >"property2" : "property2" >2 : 2 @x [Symbol.iterator]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.iterator] : any >Symbol.iterator : symbol >Symbol : SymbolConstructor @@ -443,13 +443,13 @@ class E { >foo : () => string @x [foo()]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @x [foo()]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @@ -466,12 +466,12 @@ class E { >fieldNameA : string @x [fieldNameB]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameB] : any >fieldNameB : string @x [fieldNameC]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameC] : any >fieldNameC : string >null : null @@ -483,25 +483,25 @@ void class F { >F : typeof F @x ["property"]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property"] : any >"property" : "property" @x [Symbol.toStringTag]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.toStringTag] : any >Symbol.toStringTag : symbol >Symbol : SymbolConstructor >toStringTag : symbol @x ["property2"]: any = 2; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property2"] : any >"property2" : "property2" >2 : 2 @x [Symbol.iterator]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.iterator] : any >Symbol.iterator : symbol >Symbol : SymbolConstructor @@ -536,13 +536,13 @@ void class F { >foo : () => string @x [foo()]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @x [foo()]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @@ -559,12 +559,12 @@ void class F { >fieldNameA : string @x [fieldNameB]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameB] : any >fieldNameB : string @x [fieldNameC]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameC] : any >fieldNameC : string >null : null @@ -575,25 +575,25 @@ class G { >G : G @x ["property"]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property"] : any >"property" : "property" @x [Symbol.toStringTag]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.toStringTag] : any >Symbol.toStringTag : symbol >Symbol : SymbolConstructor >toStringTag : symbol @x ["property2"]: any = 2; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property2"] : any >"property2" : "property2" >2 : 2 @x [Symbol.iterator]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.iterator] : any >Symbol.iterator : symbol >Symbol : SymbolConstructor @@ -628,13 +628,13 @@ class G { >foo : () => string @x [foo()]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @x [foo()]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @@ -651,7 +651,7 @@ class G { >fieldNameA : string @x [fieldNameB]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameB] : any >fieldNameB : string @@ -662,7 +662,7 @@ class G { >"method2" : "method2" @x [fieldNameC]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameC] : any >fieldNameC : string >null : null @@ -674,25 +674,25 @@ void class H { >H : typeof H @x ["property"]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property"] : any >"property" : "property" @x [Symbol.toStringTag]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.toStringTag] : any >Symbol.toStringTag : symbol >Symbol : SymbolConstructor >toStringTag : symbol @x ["property2"]: any = 2; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property2"] : any >"property2" : "property2" >2 : 2 @x [Symbol.iterator]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.iterator] : any >Symbol.iterator : symbol >Symbol : SymbolConstructor @@ -727,13 +727,13 @@ void class H { >foo : () => string @x [foo()]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @x [foo()]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @@ -750,7 +750,7 @@ void class H { >fieldNameA : string @x [fieldNameB]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameB] : any >fieldNameB : string @@ -761,7 +761,7 @@ void class H { >"method2" : "method2" @x [fieldNameC]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameC] : any >fieldNameC : string >null : null @@ -772,25 +772,25 @@ class I { >I : I @x ["property"]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property"] : any >"property" : "property" @x [Symbol.toStringTag]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.toStringTag] : any >Symbol.toStringTag : symbol >Symbol : SymbolConstructor >toStringTag : symbol @x ["property2"]: any = 2; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property2"] : any >"property2" : "property2" >2 : 2 @x [Symbol.iterator]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.iterator] : any >Symbol.iterator : symbol >Symbol : SymbolConstructor @@ -825,20 +825,20 @@ class I { >foo : () => string @x [foo()]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @x [foo()]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string >null : null @x ["some" + "method"]() {} ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["some" + "method"] : () => void >"some" + "method" : string >"some" : "some" @@ -849,7 +849,7 @@ class I { >fieldNameA : string @x [fieldNameB]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameB] : any >fieldNameB : string @@ -860,7 +860,7 @@ class I { >"method2" : "method2" @x [fieldNameC]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameC] : any >fieldNameC : string >null : null @@ -872,25 +872,25 @@ void class J { >J : typeof J @x ["property"]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property"] : any >"property" : "property" @x [Symbol.toStringTag]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.toStringTag] : any >Symbol.toStringTag : symbol >Symbol : SymbolConstructor >toStringTag : symbol @x ["property2"]: any = 2; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["property2"] : any >"property2" : "property2" >2 : 2 @x [Symbol.iterator]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[Symbol.iterator] : any >Symbol.iterator : symbol >Symbol : SymbolConstructor @@ -925,20 +925,20 @@ void class J { >foo : () => string @x [foo()]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string @x [foo()]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[foo()] : any >foo() : string >foo : () => string >null : null @x ["some" + "method"]() {} ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >["some" + "method"] : () => void >"some" + "method" : string >"some" : "some" @@ -949,7 +949,7 @@ void class J { >fieldNameA : string @x [fieldNameB]: any; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameB] : any >fieldNameB : string @@ -960,7 +960,7 @@ void class J { >"method2" : "method2" @x [fieldNameC]: any = null; ->x : (o: object, k: PropertyKey) => void +>x : (o: object, k: string | number | symbol) => void >[fieldNameC] : any >fieldNameC : string >null : null diff --git a/tests/baselines/reference/deeplyNestedCheck.js b/tests/baselines/reference/deeplyNestedCheck.js index 466ae94f12d..ccd234e2580 100644 --- a/tests/baselines/reference/deeplyNestedCheck.js +++ b/tests/baselines/reference/deeplyNestedCheck.js @@ -6,7 +6,7 @@ interface DataSnapshot { } interface Snapshot extends DataSnapshot { - child(path: U): Snapshot; + child>(path: U): Snapshot; } diff --git a/tests/baselines/reference/deeplyNestedCheck.symbols b/tests/baselines/reference/deeplyNestedCheck.symbols index a8b5af60880..80c531cd6d0 100644 --- a/tests/baselines/reference/deeplyNestedCheck.symbols +++ b/tests/baselines/reference/deeplyNestedCheck.symbols @@ -16,11 +16,12 @@ interface Snapshot extends DataSnapshot { >T : Symbol(T, Decl(deeplyNestedCheck.ts, 6, 19)) >DataSnapshot : Symbol(DataSnapshot, Decl(deeplyNestedCheck.ts, 0, 0)) - child(path: U): Snapshot; + child>(path: U): Snapshot; >child : Symbol(Snapshot.child, Decl(deeplyNestedCheck.ts, 6, 44)) >U : Symbol(U, Decl(deeplyNestedCheck.ts, 7, 8)) +>Extract : Symbol(Extract, Decl(lib.d.ts, --, --)) >T : Symbol(T, Decl(deeplyNestedCheck.ts, 6, 19)) ->path : Symbol(path, Decl(deeplyNestedCheck.ts, 7, 27)) +>path : Symbol(path, Decl(deeplyNestedCheck.ts, 7, 44)) >U : Symbol(U, Decl(deeplyNestedCheck.ts, 7, 8)) >Snapshot : Symbol(Snapshot, Decl(deeplyNestedCheck.ts, 4, 1)) >T : Symbol(T, Decl(deeplyNestedCheck.ts, 6, 19)) diff --git a/tests/baselines/reference/deeplyNestedCheck.types b/tests/baselines/reference/deeplyNestedCheck.types index e500fc75ed1..dc8550bc2cb 100644 --- a/tests/baselines/reference/deeplyNestedCheck.types +++ b/tests/baselines/reference/deeplyNestedCheck.types @@ -16,9 +16,10 @@ interface Snapshot extends DataSnapshot { >T : T >DataSnapshot : DataSnapshot - child(path: U): Snapshot; ->child : (path: U) => Snapshot + child>(path: U): Snapshot; +>child : >(path: U) => Snapshot >U : U +>Extract : Extract >T : T >path : U >U : U diff --git a/tests/baselines/reference/deferredLookupTypeResolution.js b/tests/baselines/reference/deferredLookupTypeResolution.js index e5baa6891e8..126f9d1345a 100644 --- a/tests/baselines/reference/deferredLookupTypeResolution.js +++ b/tests/baselines/reference/deferredLookupTypeResolution.js @@ -6,7 +6,7 @@ type StringContains = ( { [key: string]: 'false' } )[L] -type ObjectHasKey = StringContains +type ObjectHasKey = StringContains, L> type First = ObjectHasKey; // Should be deferred @@ -43,7 +43,7 @@ declare type StringContains = ({ } & { [key: string]: 'false'; })[L]; -declare type ObjectHasKey = StringContains; +declare type ObjectHasKey = StringContains, L>; declare type First = ObjectHasKey; declare type T1 = ObjectHasKey<{ a: string; diff --git a/tests/baselines/reference/deferredLookupTypeResolution.symbols b/tests/baselines/reference/deferredLookupTypeResolution.symbols index 022dc3cc2f4..29906ac6ae1 100644 --- a/tests/baselines/reference/deferredLookupTypeResolution.symbols +++ b/tests/baselines/reference/deferredLookupTypeResolution.symbols @@ -16,16 +16,17 @@ type StringContains = ( )[L] >L : Symbol(L, Decl(deferredLookupTypeResolution.ts, 2, 37)) -type ObjectHasKey = StringContains +type ObjectHasKey = StringContains, L> >ObjectHasKey : Symbol(ObjectHasKey, Decl(deferredLookupTypeResolution.ts, 5, 6)) >O : Symbol(O, Decl(deferredLookupTypeResolution.ts, 7, 18)) >L : Symbol(L, Decl(deferredLookupTypeResolution.ts, 7, 20)) >StringContains : Symbol(StringContains, Decl(deferredLookupTypeResolution.ts, 0, 0)) +>Extract : Symbol(Extract, Decl(lib.d.ts, --, --)) >O : Symbol(O, Decl(deferredLookupTypeResolution.ts, 7, 18)) >L : Symbol(L, Decl(deferredLookupTypeResolution.ts, 7, 20)) type First = ObjectHasKey; // Should be deferred ->First : Symbol(First, Decl(deferredLookupTypeResolution.ts, 7, 67)) +>First : Symbol(First, Decl(deferredLookupTypeResolution.ts, 7, 84)) >T : Symbol(T, Decl(deferredLookupTypeResolution.ts, 9, 11)) >ObjectHasKey : Symbol(ObjectHasKey, Decl(deferredLookupTypeResolution.ts, 5, 6)) >T : Symbol(T, Decl(deferredLookupTypeResolution.ts, 9, 11)) diff --git a/tests/baselines/reference/deferredLookupTypeResolution.types b/tests/baselines/reference/deferredLookupTypeResolution.types index cd123a6019e..4826b03329a 100644 --- a/tests/baselines/reference/deferredLookupTypeResolution.types +++ b/tests/baselines/reference/deferredLookupTypeResolution.types @@ -16,28 +16,29 @@ type StringContains = ( )[L] >L : L -type ObjectHasKey = StringContains ->ObjectHasKey : ({ [K in keyof O]: "true"; } & { [key: string]: "false"; })[L] +type ObjectHasKey = StringContains, L> +>ObjectHasKey : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })[L] >O : O >L : L >StringContains : ({ [K in S]: "true"; } & { [key: string]: "false"; })[L] +>Extract : Extract >O : O >L : L type First = ObjectHasKey; // Should be deferred ->First : ({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["0"] +>First : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })["0"] >T : T ->ObjectHasKey : ({ [K in keyof O]: "true"; } & { [key: string]: "false"; })[L] +>ObjectHasKey : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })[L] >T : T type T1 = ObjectHasKey<{ a: string }, 'a'>; // 'true' >T1 : "true" ->ObjectHasKey : ({ [K in keyof O]: "true"; } & { [key: string]: "false"; })[L] +>ObjectHasKey : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })[L] >a : string type T2 = ObjectHasKey<{ a: string }, 'b'>; // 'false' >T2 : "false" ->ObjectHasKey : ({ [K in keyof O]: "true"; } & { [key: string]: "false"; })[L] +>ObjectHasKey : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })[L] >a : string // Verify that mapped type isn't eagerly resolved in type-to-string operation diff --git a/tests/baselines/reference/deferredLookupTypeResolution2.errors.txt b/tests/baselines/reference/deferredLookupTypeResolution2.errors.txt index 6d1d579c0ad..88bcd2c4340 100644 --- a/tests/baselines/reference/deferredLookupTypeResolution2.errors.txt +++ b/tests/baselines/reference/deferredLookupTypeResolution2.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/deferredLookupTypeResolution2.ts(14,13): error TS2536: Type '({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["1"]' cannot be used to index type '{ true: "true"; }'. -tests/cases/compiler/deferredLookupTypeResolution2.ts(19,21): error TS2536: Type '({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["1"]]' cannot be used to index type '{ true: "true"; }'. +tests/cases/compiler/deferredLookupTypeResolution2.ts(14,13): error TS2536: Type '({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]' cannot be used to index type '{ true: "true"; }'. +tests/cases/compiler/deferredLookupTypeResolution2.ts(19,21): error TS2536: Type '({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]]' cannot be used to index type '{ true: "true"; }'. ==== tests/cases/compiler/deferredLookupTypeResolution2.ts (2 errors) ==== @@ -7,7 +7,7 @@ tests/cases/compiler/deferredLookupTypeResolution2.ts(19,21): error TS2536: Type type StringContains = ({ [K in S]: 'true' } & { [key: string]: 'false'})[L]; - type ObjectHasKey = StringContains; + type ObjectHasKey = StringContains, L>; type A = ObjectHasKey; @@ -18,14 +18,14 @@ tests/cases/compiler/deferredLookupTypeResolution2.ts(19,21): error TS2536: Type // Error, "false" not handled type E = { true: 'true' }[ObjectHasKey]; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2536: Type '({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["1"]' cannot be used to index type '{ true: "true"; }'. +!!! error TS2536: Type '({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]' cannot be used to index type '{ true: "true"; }'. type Juxtapose = ({ true: 'otherwise' } & { [k: string]: 'true' })[ObjectHasKey]; // Error, "otherwise" is missing type DeepError = { true: 'true' }[Juxtapose]; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2536: Type '({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["1"]]' cannot be used to index type '{ true: "true"; }'. +!!! error TS2536: Type '({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]]' cannot be used to index type '{ true: "true"; }'. type DeepOK = { true: 'true', otherwise: 'false' }[Juxtapose]; \ No newline at end of file diff --git a/tests/baselines/reference/deferredLookupTypeResolution2.js b/tests/baselines/reference/deferredLookupTypeResolution2.js index 97289f47f9c..3d40dcb4bbf 100644 --- a/tests/baselines/reference/deferredLookupTypeResolution2.js +++ b/tests/baselines/reference/deferredLookupTypeResolution2.js @@ -3,7 +3,7 @@ type StringContains = ({ [K in S]: 'true' } & { [key: string]: 'false'})[L]; -type ObjectHasKey = StringContains; +type ObjectHasKey = StringContains, L>; type A = ObjectHasKey; @@ -33,7 +33,7 @@ declare type StringContains = ({ } & { [key: string]: 'false'; })[L]; -declare type ObjectHasKey = StringContains; +declare type ObjectHasKey = StringContains, L>; declare type A = ObjectHasKey; declare type B = ObjectHasKey<[string, number], '1'>; declare type C = ObjectHasKey<[string, number], '2'>; diff --git a/tests/baselines/reference/deferredLookupTypeResolution2.symbols b/tests/baselines/reference/deferredLookupTypeResolution2.symbols index ca55b3e407e..41064fae533 100644 --- a/tests/baselines/reference/deferredLookupTypeResolution2.symbols +++ b/tests/baselines/reference/deferredLookupTypeResolution2.symbols @@ -10,16 +10,17 @@ type StringContains = ({ [K in S]: 'true' } >key : Symbol(key, Decl(deferredLookupTypeResolution2.ts, 2, 85)) >L : Symbol(L, Decl(deferredLookupTypeResolution2.ts, 2, 37)) -type ObjectHasKey = StringContains; +type ObjectHasKey = StringContains, L>; >ObjectHasKey : Symbol(ObjectHasKey, Decl(deferredLookupTypeResolution2.ts, 2, 112)) >O : Symbol(O, Decl(deferredLookupTypeResolution2.ts, 4, 18)) >L : Symbol(L, Decl(deferredLookupTypeResolution2.ts, 4, 20)) >StringContains : Symbol(StringContains, Decl(deferredLookupTypeResolution2.ts, 0, 0)) +>Extract : Symbol(Extract, Decl(lib.d.ts, --, --)) >O : Symbol(O, Decl(deferredLookupTypeResolution2.ts, 4, 18)) >L : Symbol(L, Decl(deferredLookupTypeResolution2.ts, 4, 20)) type A = ObjectHasKey; ->A : Symbol(A, Decl(deferredLookupTypeResolution2.ts, 4, 68)) +>A : Symbol(A, Decl(deferredLookupTypeResolution2.ts, 4, 85)) >T : Symbol(T, Decl(deferredLookupTypeResolution2.ts, 6, 7)) >ObjectHasKey : Symbol(ObjectHasKey, Decl(deferredLookupTypeResolution2.ts, 2, 112)) >T : Symbol(T, Decl(deferredLookupTypeResolution2.ts, 6, 7)) @@ -34,7 +35,7 @@ type C = ObjectHasKey<[string, number], '2'>; // "false" type D = A<[string]>; // "true" >D : Symbol(D, Decl(deferredLookupTypeResolution2.ts, 9, 45)) ->A : Symbol(A, Decl(deferredLookupTypeResolution2.ts, 4, 68)) +>A : Symbol(A, Decl(deferredLookupTypeResolution2.ts, 4, 85)) // Error, "false" not handled type E = { true: 'true' }[ObjectHasKey]; diff --git a/tests/baselines/reference/deferredLookupTypeResolution2.types b/tests/baselines/reference/deferredLookupTypeResolution2.types index 76354731097..88994722a2e 100644 --- a/tests/baselines/reference/deferredLookupTypeResolution2.types +++ b/tests/baselines/reference/deferredLookupTypeResolution2.types @@ -10,61 +10,62 @@ type StringContains = ({ [K in S]: 'true' } >key : string >L : L -type ObjectHasKey = StringContains; ->ObjectHasKey : ({ [K in keyof O]: "true"; } & { [key: string]: "false"; })[L] +type ObjectHasKey = StringContains, L>; +>ObjectHasKey : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })[L] >O : O >L : L >StringContains : ({ [K in S]: "true"; } & { [key: string]: "false"; })[L] +>Extract : Extract >O : O >L : L type A = ObjectHasKey; ->A : ({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["0"] +>A : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })["0"] >T : T ->ObjectHasKey : ({ [K in keyof O]: "true"; } & { [key: string]: "false"; })[L] +>ObjectHasKey : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })[L] >T : T type B = ObjectHasKey<[string, number], '1'>; // "true" >B : "true" ->ObjectHasKey : ({ [K in keyof O]: "true"; } & { [key: string]: "false"; })[L] +>ObjectHasKey : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })[L] type C = ObjectHasKey<[string, number], '2'>; // "false" >C : "false" ->ObjectHasKey : ({ [K in keyof O]: "true"; } & { [key: string]: "false"; })[L] +>ObjectHasKey : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })[L] type D = A<[string]>; // "true" >D : "true" ->A : ({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["0"] +>A : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })["0"] // Error, "false" not handled type E = { true: 'true' }[ObjectHasKey]; ->E : { true: "true"; }[({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["1"]] +>E : { true: "true"; }[({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]] >T : T >true : "true" ->ObjectHasKey : ({ [K in keyof O]: "true"; } & { [key: string]: "false"; })[L] +>ObjectHasKey : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })[L] >T : T type Juxtapose = ({ true: 'otherwise' } & { [k: string]: 'true' })[ObjectHasKey]; ->Juxtapose : ({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["1"]] +>Juxtapose : ({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]] >T : T >true : "otherwise" >k : string ->ObjectHasKey : ({ [K in keyof O]: "true"; } & { [key: string]: "false"; })[L] +>ObjectHasKey : ({ [K in Extract]: "true"; } & { [key: string]: "false"; })[L] >T : T // Error, "otherwise" is missing type DeepError = { true: 'true' }[Juxtapose]; ->DeepError : { true: "true"; }[({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["1"]]] +>DeepError : { true: "true"; }[({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]]] >T : T >true : "true" ->Juxtapose : ({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["1"]] +>Juxtapose : ({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]] >T : T type DeepOK = { true: 'true', otherwise: 'false' }[Juxtapose]; ->DeepOK : { true: "true"; otherwise: "false"; }[({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["1"]]] +>DeepOK : { true: "true"; otherwise: "false"; }[({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]]] >T : T >true : "true" >otherwise : "false" ->Juxtapose : ({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in keyof T]: "true"; } & { [key: string]: "false"; })["1"]] +>Juxtapose : ({ true: "otherwise"; } & { [k: string]: "true"; })[({ [K in Extract]: "true"; } & { [key: string]: "false"; })["1"]] >T : T diff --git a/tests/baselines/reference/enumConstantMemberWithString.errors.txt b/tests/baselines/reference/enumConstantMemberWithString.errors.txt new file mode 100644 index 00000000000..99f089e2bb3 --- /dev/null +++ b/tests/baselines/reference/enumConstantMemberWithString.errors.txt @@ -0,0 +1,45 @@ +tests/cases/conformance/enums/enumConstantMemberWithString.ts(5,9): error TS2553: Computed values are not permitted in an enum with string valued members. +tests/cases/conformance/enums/enumConstantMemberWithString.ts(6,9): error TS2553: Computed values are not permitted in an enum with string valued members. +tests/cases/conformance/enums/enumConstantMemberWithString.ts(18,9): error TS2553: Computed values are not permitted in an enum with string valued members. + + +==== tests/cases/conformance/enums/enumConstantMemberWithString.ts (3 errors) ==== + enum T1 { + a = "1", + b = "1" + "2", + c = "1" + "2" + "3", + d = "a" - "a", + ~~~~~~~~~ +!!! error TS2553: Computed values are not permitted in an enum with string valued members. + e = "a" + 1 + ~~~~~~~ +!!! error TS2553: Computed values are not permitted in an enum with string valued members. + } + + enum T2 { + a = "1", + b = "1" + "2" + } + + enum T3 { + a = "1", + b = "1" + "2", + c = 1, + d = 1 + 2 + ~~~~~ +!!! error TS2553: Computed values are not permitted in an enum with string valued members. + } + + enum T4 { + a = "1" + } + + enum T5 { + a = "1" + "2" + } + + declare enum T6 { + a = "1", + b = "1" + "2" + } + \ No newline at end of file diff --git a/tests/baselines/reference/enumConstantMemberWithString.js b/tests/baselines/reference/enumConstantMemberWithString.js new file mode 100644 index 00000000000..fc61ed484c8 --- /dev/null +++ b/tests/baselines/reference/enumConstantMemberWithString.js @@ -0,0 +1,64 @@ +//// [enumConstantMemberWithString.ts] +enum T1 { + a = "1", + b = "1" + "2", + c = "1" + "2" + "3", + d = "a" - "a", + e = "a" + 1 +} + +enum T2 { + a = "1", + b = "1" + "2" +} + +enum T3 { + a = "1", + b = "1" + "2", + c = 1, + d = 1 + 2 +} + +enum T4 { + a = "1" +} + +enum T5 { + a = "1" + "2" +} + +declare enum T6 { + a = "1", + b = "1" + "2" +} + + +//// [enumConstantMemberWithString.js] +var T1; +(function (T1) { + T1["a"] = "1"; + T1["b"] = "12"; + T1["c"] = "123"; + T1[T1["d"] = 0] = "d"; + T1[T1["e"] = 0] = "e"; +})(T1 || (T1 = {})); +var T2; +(function (T2) { + T2["a"] = "1"; + T2["b"] = "12"; +})(T2 || (T2 = {})); +var T3; +(function (T3) { + T3["a"] = "1"; + T3["b"] = "12"; + T3[T3["c"] = 1] = "c"; + T3[T3["d"] = 0] = "d"; +})(T3 || (T3 = {})); +var T4; +(function (T4) { + T4["a"] = "1"; +})(T4 || (T4 = {})); +var T5; +(function (T5) { + T5["a"] = "12"; +})(T5 || (T5 = {})); diff --git a/tests/baselines/reference/enumConstantMemberWithString.symbols b/tests/baselines/reference/enumConstantMemberWithString.symbols new file mode 100644 index 00000000000..625c24fdfef --- /dev/null +++ b/tests/baselines/reference/enumConstantMemberWithString.symbols @@ -0,0 +1,70 @@ +=== tests/cases/conformance/enums/enumConstantMemberWithString.ts === +enum T1 { +>T1 : Symbol(T1, Decl(enumConstantMemberWithString.ts, 0, 0)) + + a = "1", +>a : Symbol(T1.a, Decl(enumConstantMemberWithString.ts, 0, 9)) + + b = "1" + "2", +>b : Symbol(T1.b, Decl(enumConstantMemberWithString.ts, 1, 12)) + + c = "1" + "2" + "3", +>c : Symbol(T1.c, Decl(enumConstantMemberWithString.ts, 2, 18)) + + d = "a" - "a", +>d : Symbol(T1.d, Decl(enumConstantMemberWithString.ts, 3, 24)) + + e = "a" + 1 +>e : Symbol(T1.e, Decl(enumConstantMemberWithString.ts, 4, 18)) +} + +enum T2 { +>T2 : Symbol(T2, Decl(enumConstantMemberWithString.ts, 6, 1)) + + a = "1", +>a : Symbol(T2.a, Decl(enumConstantMemberWithString.ts, 8, 9)) + + b = "1" + "2" +>b : Symbol(T2.b, Decl(enumConstantMemberWithString.ts, 9, 12)) +} + +enum T3 { +>T3 : Symbol(T3, Decl(enumConstantMemberWithString.ts, 11, 1)) + + a = "1", +>a : Symbol(T3.a, Decl(enumConstantMemberWithString.ts, 13, 9)) + + b = "1" + "2", +>b : Symbol(T3.b, Decl(enumConstantMemberWithString.ts, 14, 12)) + + c = 1, +>c : Symbol(T3.c, Decl(enumConstantMemberWithString.ts, 15, 18)) + + d = 1 + 2 +>d : Symbol(T3.d, Decl(enumConstantMemberWithString.ts, 16, 10)) +} + +enum T4 { +>T4 : Symbol(T4, Decl(enumConstantMemberWithString.ts, 18, 1)) + + a = "1" +>a : Symbol(T4.a, Decl(enumConstantMemberWithString.ts, 20, 9)) +} + +enum T5 { +>T5 : Symbol(T5, Decl(enumConstantMemberWithString.ts, 22, 1)) + + a = "1" + "2" +>a : Symbol(T5.a, Decl(enumConstantMemberWithString.ts, 24, 9)) +} + +declare enum T6 { +>T6 : Symbol(T6, Decl(enumConstantMemberWithString.ts, 26, 1)) + + a = "1", +>a : Symbol(T6.a, Decl(enumConstantMemberWithString.ts, 28, 17)) + + b = "1" + "2" +>b : Symbol(T6.b, Decl(enumConstantMemberWithString.ts, 29, 12)) +} + diff --git a/tests/baselines/reference/enumConstantMemberWithString.types b/tests/baselines/reference/enumConstantMemberWithString.types new file mode 100644 index 00000000000..91bc2f97072 --- /dev/null +++ b/tests/baselines/reference/enumConstantMemberWithString.types @@ -0,0 +1,105 @@ +=== tests/cases/conformance/enums/enumConstantMemberWithString.ts === +enum T1 { +>T1 : T1 + + a = "1", +>a : T1.a +>"1" : "1" + + b = "1" + "2", +>b : T1.b +>"1" + "2" : string +>"1" : "1" +>"2" : "2" + + c = "1" + "2" + "3", +>c : T1.c +>"1" + "2" + "3" : string +>"1" + "2" : string +>"1" : "1" +>"2" : "2" +>"3" : "3" + + d = "a" - "a", +>d : T1.d +>"a" - "a" : number +>"a" : "a" +>"a" : "a" + + e = "a" + 1 +>e : T1.d +>"a" + 1 : string +>"a" : "a" +>1 : 1 +} + +enum T2 { +>T2 : T2 + + a = "1", +>a : T2.a +>"1" : "1" + + b = "1" + "2" +>b : T2.b +>"1" + "2" : string +>"1" : "1" +>"2" : "2" +} + +enum T3 { +>T3 : T3 + + a = "1", +>a : T3.a +>"1" : "1" + + b = "1" + "2", +>b : T3.b +>"1" + "2" : string +>"1" : "1" +>"2" : "2" + + c = 1, +>c : T3.c +>1 : 1 + + d = 1 + 2 +>d : T3.d +>1 + 2 : number +>1 : 1 +>2 : 2 +} + +enum T4 { +>T4 : T4 + + a = "1" +>a : T4 +>"1" : "1" +} + +enum T5 { +>T5 : T5 + + a = "1" + "2" +>a : T5 +>"1" + "2" : string +>"1" : "1" +>"2" : "2" +} + +declare enum T6 { +>T6 : T6 + + a = "1", +>a : T6.a +>"1" : "1" + + b = "1" + "2" +>b : T6.b +>"1" + "2" : string +>"1" : "1" +>"2" : "2" +} + diff --git a/tests/baselines/reference/enumConstantMemberWithStringEmitDeclaration.js b/tests/baselines/reference/enumConstantMemberWithStringEmitDeclaration.js new file mode 100644 index 00000000000..d78ce824256 --- /dev/null +++ b/tests/baselines/reference/enumConstantMemberWithStringEmitDeclaration.js @@ -0,0 +1,82 @@ +//// [enumConstantMemberWithStringEmitDeclaration.ts] +enum T1 { + a = "1", + b = "1" + "2", + c = "1" + "2" + "3" +} + +enum T2 { + a = "1", + b = "1" + "2" +} + +enum T3 { + a = "1", + b = "1" + "2" +} + +enum T4 { + a = "1" +} + +enum T5 { + a = "1" + "2" +} + +declare enum T6 { + a = "1", + b = "1" + "2" +} + + +//// [enumConstantMemberWithStringEmitDeclaration.js] +var T1; +(function (T1) { + T1["a"] = "1"; + T1["b"] = "12"; + T1["c"] = "123"; +})(T1 || (T1 = {})); +var T2; +(function (T2) { + T2["a"] = "1"; + T2["b"] = "12"; +})(T2 || (T2 = {})); +var T3; +(function (T3) { + T3["a"] = "1"; + T3["b"] = "12"; +})(T3 || (T3 = {})); +var T4; +(function (T4) { + T4["a"] = "1"; +})(T4 || (T4 = {})); +var T5; +(function (T5) { + T5["a"] = "12"; +})(T5 || (T5 = {})); + + +//// [enumConstantMemberWithStringEmitDeclaration.d.ts] +declare enum T1 { + a = "1", + b = "12", + c = "123" +} +declare enum T2 { + a = "1", + b = "12" +} +declare enum T3 { + a = "1", + b = "12" +} +declare enum T4 { + a = "1" +} +declare enum T5 { + a = "12" +} +declare enum T6 { + a = "1", + b = "12" +} diff --git a/tests/baselines/reference/enumConstantMemberWithStringEmitDeclaration.symbols b/tests/baselines/reference/enumConstantMemberWithStringEmitDeclaration.symbols new file mode 100644 index 00000000000..1bb70c7882b --- /dev/null +++ b/tests/baselines/reference/enumConstantMemberWithStringEmitDeclaration.symbols @@ -0,0 +1,58 @@ +=== tests/cases/conformance/enums/enumConstantMemberWithStringEmitDeclaration.ts === +enum T1 { +>T1 : Symbol(T1, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 0, 0)) + + a = "1", +>a : Symbol(T1.a, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 0, 9)) + + b = "1" + "2", +>b : Symbol(T1.b, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 1, 12)) + + c = "1" + "2" + "3" +>c : Symbol(T1.c, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 2, 18)) +} + +enum T2 { +>T2 : Symbol(T2, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 4, 1)) + + a = "1", +>a : Symbol(T2.a, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 6, 9)) + + b = "1" + "2" +>b : Symbol(T2.b, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 7, 12)) +} + +enum T3 { +>T3 : Symbol(T3, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 9, 1)) + + a = "1", +>a : Symbol(T3.a, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 11, 9)) + + b = "1" + "2" +>b : Symbol(T3.b, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 12, 12)) +} + +enum T4 { +>T4 : Symbol(T4, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 14, 1)) + + a = "1" +>a : Symbol(T4.a, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 16, 9)) +} + +enum T5 { +>T5 : Symbol(T5, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 18, 1)) + + a = "1" + "2" +>a : Symbol(T5.a, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 20, 9)) +} + +declare enum T6 { +>T6 : Symbol(T6, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 22, 1)) + + a = "1", +>a : Symbol(T6.a, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 24, 17)) + + b = "1" + "2" +>b : Symbol(T6.b, Decl(enumConstantMemberWithStringEmitDeclaration.ts, 25, 12)) +} + diff --git a/tests/baselines/reference/enumConstantMemberWithStringEmitDeclaration.types b/tests/baselines/reference/enumConstantMemberWithStringEmitDeclaration.types new file mode 100644 index 00000000000..b613ec306e4 --- /dev/null +++ b/tests/baselines/reference/enumConstantMemberWithStringEmitDeclaration.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/enums/enumConstantMemberWithStringEmitDeclaration.ts === +enum T1 { +>T1 : T1 + + a = "1", +>a : T1.a +>"1" : "1" + + b = "1" + "2", +>b : T1.b +>"1" + "2" : string +>"1" : "1" +>"2" : "2" + + c = "1" + "2" + "3" +>c : T1.c +>"1" + "2" + "3" : string +>"1" + "2" : string +>"1" : "1" +>"2" : "2" +>"3" : "3" +} + +enum T2 { +>T2 : T2 + + a = "1", +>a : T2.a +>"1" : "1" + + b = "1" + "2" +>b : T2.b +>"1" + "2" : string +>"1" : "1" +>"2" : "2" +} + +enum T3 { +>T3 : T3 + + a = "1", +>a : T3.a +>"1" : "1" + + b = "1" + "2" +>b : T3.b +>"1" + "2" : string +>"1" : "1" +>"2" : "2" +} + +enum T4 { +>T4 : T4 + + a = "1" +>a : T4 +>"1" : "1" +} + +enum T5 { +>T5 : T5 + + a = "1" + "2" +>a : T5 +>"1" + "2" : string +>"1" : "1" +>"2" : "2" +} + +declare enum T6 { +>T6 : T6 + + a = "1", +>a : T6.a +>"1" : "1" + + b = "1" + "2" +>b : T6.b +>"1" + "2" : string +>"1" : "1" +>"2" : "2" +} + diff --git a/tests/baselines/reference/es5ExportEquals.types b/tests/baselines/reference/es5ExportEquals.types index 3397cf1df72..6c9e8930537 100644 --- a/tests/baselines/reference/es5ExportEquals.types +++ b/tests/baselines/reference/es5ExportEquals.types @@ -1,6 +1,6 @@ === tests/cases/compiler/es5ExportEquals.ts === export function f() { } ->f : () => void +>f : typeof f export = f; >f : () => void diff --git a/tests/baselines/reference/es6ExportEquals.types b/tests/baselines/reference/es6ExportEquals.types index 3503812aead..3ba761dc8e5 100644 --- a/tests/baselines/reference/es6ExportEquals.types +++ b/tests/baselines/reference/es6ExportEquals.types @@ -1,6 +1,6 @@ === tests/cases/compiler/es6ExportEquals.ts === export function f() { } ->f : () => void +>f : typeof f export = f; >f : () => void diff --git a/tests/baselines/reference/excessPropertyCheckWithEmptyObject.types b/tests/baselines/reference/excessPropertyCheckWithEmptyObject.types index ecf15c74da5..9748820aacd 100644 --- a/tests/baselines/reference/excessPropertyCheckWithEmptyObject.types +++ b/tests/baselines/reference/excessPropertyCheckWithEmptyObject.types @@ -4,9 +4,9 @@ // Excess property error expected here Object.defineProperty(window, "prop", { value: "v1.0.0", readonly: false }); >Object.defineProperty(window, "prop", { value: "v1.0.0", readonly: false }) : any ->Object.defineProperty : (o: any, p: string, attributes: PropertyDescriptor & ThisType) => any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any >Object : ObjectConstructor ->defineProperty : (o: any, p: string, attributes: PropertyDescriptor & ThisType) => any +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any >window : any >"prop" : "prop" >{ value: "v1.0.0", readonly: false } : { value: string; readonly: boolean; } diff --git a/tests/baselines/reference/fixSignatureCaching.types b/tests/baselines/reference/fixSignatureCaching.types index c3f4dbc1522..8b66a3f7b95 100644 --- a/tests/baselines/reference/fixSignatureCaching.types +++ b/tests/baselines/reference/fixSignatureCaching.types @@ -1068,12 +1068,12 @@ define(function () { }; var hasOwnProp = Object.prototype.hasOwnProperty, ->hasOwnProp : (v: string) => boolean ->Object.prototype.hasOwnProperty : (v: string) => boolean +>hasOwnProp : (v: string | number | symbol) => boolean +>Object.prototype.hasOwnProperty : (v: string | number | symbol) => boolean >Object.prototype : Object >Object : ObjectConstructor >prototype : Object ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean isArray; >isArray : any @@ -1249,7 +1249,7 @@ define(function () { if (hasOwnProp.call(object, key)) { >hasOwnProp.call(object, key) : any >hasOwnProp.call : (this: Function, thisArg: any, ...argArray: any[]) => any ->hasOwnProp : (v: string) => boolean +>hasOwnProp : (v: string | number | symbol) => boolean >call : (this: Function, thisArg: any, ...argArray: any[]) => any >object : any >key : string @@ -1296,7 +1296,7 @@ define(function () { if (hasOwnProp.call(mobileDetectRules.props, key)) { >hasOwnProp.call(mobileDetectRules.props, key) : any >hasOwnProp.call : (this: Function, thisArg: any, ...argArray: any[]) => any ->hasOwnProp : (v: string) => boolean +>hasOwnProp : (v: string | number | symbol) => boolean >call : (this: Function, thisArg: any, ...argArray: any[]) => any >mobileDetectRules.props : any >mobileDetectRules : any @@ -1487,7 +1487,7 @@ define(function () { if (hasOwnProp.call(rules, key)) { >hasOwnProp.call(rules, key) : any >hasOwnProp.call : (this: Function, thisArg: any, ...argArray: any[]) => any ->hasOwnProp : (v: string) => boolean +>hasOwnProp : (v: string | number | symbol) => boolean >call : (this: Function, thisArg: any, ...argArray: any[]) => any >rules : any >key : string @@ -1538,7 +1538,7 @@ define(function () { if (hasOwnProp.call(rules, key)) { >hasOwnProp.call(rules, key) : any >hasOwnProp.call : (this: Function, thisArg: any, ...argArray: any[]) => any ->hasOwnProp : (v: string) => boolean +>hasOwnProp : (v: string | number | symbol) => boolean >call : (this: Function, thisArg: any, ...argArray: any[]) => any >rules : any >key : string @@ -1598,7 +1598,7 @@ define(function () { if (hasOwnProp.call(props, propertyName)) { >hasOwnProp.call(props, propertyName) : any >hasOwnProp.call : (this: Function, thisArg: any, ...argArray: any[]) => any ->hasOwnProp : (v: string) => boolean +>hasOwnProp : (v: string | number | symbol) => boolean >call : (this: Function, thisArg: any, ...argArray: any[]) => any >props : any >propertyName : any diff --git a/tests/baselines/reference/for-inStatements.errors.txt b/tests/baselines/reference/for-inStatements.errors.txt index 2ae4cdb79f0..50f31d669cd 100644 --- a/tests/baselines/reference/for-inStatements.errors.txt +++ b/tests/baselines/reference/for-inStatements.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(33,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. -tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(50,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. +tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(33,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. +tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(50,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(79,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'Color.Blue'. @@ -38,7 +38,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(79,15): for (var x in this.biz) { } for (var x in this) { } ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. return null; } @@ -57,7 +57,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(79,15): for (var x in this.biz) { } for (var x in this) { } ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. for (var x in super.biz) { } for (var x in super.biz()) { } diff --git a/tests/baselines/reference/for-inStatementsInvalid.errors.txt b/tests/baselines/reference/for-inStatementsInvalid.errors.txt index 3d7dd1c79f3..8e1bb29d083 100644 --- a/tests/baselines/reference/for-inStatementsInvalid.errors.txt +++ b/tests/baselines/reference/for-inStatementsInvalid.errors.txt @@ -9,10 +9,10 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(1 tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(20,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(22,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'. tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(29,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'number'. -tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(31,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. +tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(31,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(38,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'number'. tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(46,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'number'. -tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(48,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. +tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(48,18): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(51,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'number'. tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(62,15): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'number'. @@ -72,7 +72,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(6 for (var x in this.biz) { } for (var x in this) { } ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. return null; } @@ -95,7 +95,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(6 for (var x in this.biz) { } for (var x in this) { } ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'keyof this'. +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. for (var x in super.biz) { } for (var x in super.biz()) { } diff --git a/tests/baselines/reference/forInStatement3.types b/tests/baselines/reference/forInStatement3.types index 09e6cf3ad96..9fe63651f55 100644 --- a/tests/baselines/reference/forInStatement3.types +++ b/tests/baselines/reference/forInStatement3.types @@ -8,7 +8,7 @@ function F() { >T : T for (var a in expr) { ->a : keyof T +>a : Extract >expr : T } } diff --git a/tests/baselines/reference/getterSetterNonAccessor.types b/tests/baselines/reference/getterSetterNonAccessor.types index 7253dcc07e6..fc707c22c36 100644 --- a/tests/baselines/reference/getterSetterNonAccessor.types +++ b/tests/baselines/reference/getterSetterNonAccessor.types @@ -9,9 +9,9 @@ function setFunc(v){} Object.defineProperty({}, "0", ({ >Object.defineProperty({}, "0", ({ get: getFunc, set: setFunc, configurable: true })) : any ->Object.defineProperty : (o: any, p: string, attributes: PropertyDescriptor & ThisType) => any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any >Object : ObjectConstructor ->defineProperty : (o: any, p: string, attributes: PropertyDescriptor & ThisType) => any +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any >{} : {} >"0" : "0" >({ get: getFunc, set: setFunc, configurable: true }) : PropertyDescriptor diff --git a/tests/baselines/reference/implicitAnyInCatch.types b/tests/baselines/reference/implicitAnyInCatch.types index 93cce09928e..6f70165407f 100644 --- a/tests/baselines/reference/implicitAnyInCatch.types +++ b/tests/baselines/reference/implicitAnyInCatch.types @@ -22,7 +22,7 @@ class C { >temp : () => void for (var x in this) { ->x : keyof this +>x : Extract >this : this } } diff --git a/tests/baselines/reference/inOperatorWithGeneric.types b/tests/baselines/reference/inOperatorWithGeneric.types index eba9bf1419b..dd373d8e075 100644 --- a/tests/baselines/reference/inOperatorWithGeneric.types +++ b/tests/baselines/reference/inOperatorWithGeneric.types @@ -9,7 +9,7 @@ class C { >T : T for (var p in x) { ->p : keyof T +>p : Extract >x : T } } diff --git a/tests/baselines/reference/indexedAccessRetainsIndexSignature.js b/tests/baselines/reference/indexedAccessRetainsIndexSignature.js index 1b77b95527b..92952515779 100644 --- a/tests/baselines/reference/indexedAccessRetainsIndexSignature.js +++ b/tests/baselines/reference/indexedAccessRetainsIndexSignature.js @@ -1,5 +1,5 @@ //// [indexedAccessRetainsIndexSignature.ts] -type Diff = +type Diff = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T] type Omit = Pick> type Omit1 = Pick>; diff --git a/tests/baselines/reference/indexedAccessRetainsIndexSignature.symbols b/tests/baselines/reference/indexedAccessRetainsIndexSignature.symbols index 9858f6fc162..ad46c367ba6 100644 --- a/tests/baselines/reference/indexedAccessRetainsIndexSignature.symbols +++ b/tests/baselines/reference/indexedAccessRetainsIndexSignature.symbols @@ -1,15 +1,15 @@ === tests/cases/compiler/indexedAccessRetainsIndexSignature.ts === -type Diff = +type Diff = >Diff : Symbol(Diff, Decl(indexedAccessRetainsIndexSignature.ts, 0, 0)) >T : Symbol(T, Decl(indexedAccessRetainsIndexSignature.ts, 0, 10)) ->U : Symbol(U, Decl(indexedAccessRetainsIndexSignature.ts, 0, 27)) +>U : Symbol(U, Decl(indexedAccessRetainsIndexSignature.ts, 0, 30)) ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T] >P : Symbol(P, Decl(indexedAccessRetainsIndexSignature.ts, 1, 8)) >T : Symbol(T, Decl(indexedAccessRetainsIndexSignature.ts, 0, 10)) >P : Symbol(P, Decl(indexedAccessRetainsIndexSignature.ts, 1, 8)) >P : Symbol(P, Decl(indexedAccessRetainsIndexSignature.ts, 1, 26)) ->U : Symbol(U, Decl(indexedAccessRetainsIndexSignature.ts, 0, 27)) +>U : Symbol(U, Decl(indexedAccessRetainsIndexSignature.ts, 0, 30)) >x : Symbol(x, Decl(indexedAccessRetainsIndexSignature.ts, 1, 48)) >T : Symbol(T, Decl(indexedAccessRetainsIndexSignature.ts, 0, 10)) diff --git a/tests/baselines/reference/indexedAccessRetainsIndexSignature.types b/tests/baselines/reference/indexedAccessRetainsIndexSignature.types index 8dcbe9bf218..5334cf891df 100644 --- a/tests/baselines/reference/indexedAccessRetainsIndexSignature.types +++ b/tests/baselines/reference/indexedAccessRetainsIndexSignature.types @@ -1,5 +1,5 @@ === tests/cases/compiler/indexedAccessRetainsIndexSignature.ts === -type Diff = +type Diff = >Diff : ({ [P in T]: P; } & { [P in U]: never; } & { [x: string]: never; })[T] >T : T >U : U diff --git a/tests/baselines/reference/inferTypes1.errors.txt b/tests/baselines/reference/inferTypes1.errors.txt index 01907bdc95b..4684b8f5e34 100644 --- a/tests/baselines/reference/inferTypes1.errors.txt +++ b/tests/baselines/reference/inferTypes1.errors.txt @@ -17,7 +17,8 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(75,43): error TS2304: C tests/cases/conformance/types/conditional/inferTypes1.ts(75,43): error TS4081: Exported type alias 'T62' has or is using private name 'U'. tests/cases/conformance/types/conditional/inferTypes1.ts(82,44): error TS2344: Type 'U' does not satisfy the constraint 'string'. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/types/conditional/inferTypes1.ts(144,40): error TS2322: Type 'T' is not assignable to type 'string'. +tests/cases/conformance/types/conditional/inferTypes1.ts(144,40): error TS2322: Type 'T' is not assignable to type 'string | number | symbol'. + Type 'T' is not assignable to type 'symbol'. ==== tests/cases/conformance/types/conditional/inferTypes1.ts (16 errors) ==== @@ -200,7 +201,8 @@ tests/cases/conformance/types/conditional/inferTypes1.ts(144,40): error TS2322: type A = T extends string ? { [P in T]: void; } : T; type B = string extends T ? { [P in T]: void; } : T; // Error ~ -!!! error TS2322: Type 'T' is not assignable to type 'string'. +!!! error TS2322: Type 'T' is not assignable to type 'string | number | symbol'. +!!! error TS2322: Type 'T' is not assignable to type 'symbol'. // Repro from #22302 diff --git a/tests/baselines/reference/isomorphicMappedTypeInference.types b/tests/baselines/reference/isomorphicMappedTypeInference.types index b24bb071eeb..d0db5608b6f 100644 --- a/tests/baselines/reference/isomorphicMappedTypeInference.types +++ b/tests/baselines/reference/isomorphicMappedTypeInference.types @@ -64,19 +64,19 @@ function boxify(obj: T): Boxified { >T : T for (let k in obj) { ->k : keyof T +>k : Extract >obj : T result[k] = box(obj[k]); ->result[k] = box(obj[k]) : Box ->result[k] : Boxified[keyof T] +>result[k] = box(obj[k]) : Box]> +>result[k] : Boxified[Extract] >result : Boxified ->k : keyof T ->box(obj[k]) : Box +>k : Extract +>box(obj[k]) : Box]> >box : (x: T) => Box ->obj[k] : T[keyof T] +>obj[k] : T[Extract] >obj : T ->k : keyof T +>k : Extract } return result; >result : Boxified @@ -97,19 +97,19 @@ function unboxify(obj: Boxified): T { >T : T for (let k in obj) { ->k : keyof T +>k : Extract >obj : Boxified result[k] = unbox(obj[k]); ->result[k] = unbox(obj[k]) : T[keyof T] ->result[k] : T[keyof T] +>result[k] = unbox(obj[k]) : T[Extract] +>result[k] : T[Extract] >result : T ->k : keyof T ->unbox(obj[k]) : T[keyof T] +>k : Extract +>unbox(obj[k]) : T[Extract] >unbox : (x: Box) => T ->obj[k] : Boxified[keyof T] +>obj[k] : Boxified[Extract] >obj : Boxified ->k : keyof T +>k : Extract } return result; >result : T @@ -125,19 +125,19 @@ function assignBoxified(obj: Boxified, values: T) { >T : T for (let k in values) { ->k : keyof T +>k : Extract >values : T obj[k].value = values[k]; ->obj[k].value = values[k] : T[keyof T] ->obj[k].value : T[keyof T] ->obj[k] : Boxified[keyof T] +>obj[k].value = values[k] : T[Extract] +>obj[k].value : T[Extract] +>obj[k] : Boxified[Extract] >obj : Boxified ->k : keyof T ->value : T[keyof T] ->values[k] : T[keyof T] +>k : Extract +>value : T[Extract] +>values[k] : T[Extract] >values : T ->k : keyof T +>k : Extract } } diff --git a/tests/baselines/reference/jsdocImportType.symbols b/tests/baselines/reference/jsdocImportType.symbols new file mode 100644 index 00000000000..657ad6801f1 --- /dev/null +++ b/tests/baselines/reference/jsdocImportType.symbols @@ -0,0 +1,56 @@ +=== tests/cases/conformance/jsdoc/use.js === +/// +/** @typedef {import("./mod1")} C + * @type {C} */ +var c; +>c : Symbol(c, Decl(use.js, 3, 3)) + +c.chunk; +>c.chunk : Symbol(Chunk.chunk, Decl(mod1.js, 2, 19)) +>c : Symbol(c, Decl(use.js, 3, 3)) +>chunk : Symbol(Chunk.chunk, Decl(mod1.js, 2, 19)) + +const D = require("./mod1"); +>D : Symbol(D, Decl(use.js, 6, 5)) +>require : Symbol(require, Decl(types.d.ts, 0, 0)) +>"./mod1" : Symbol("tests/cases/conformance/jsdoc/mod1", Decl(mod1.js, 0, 0)) + +/** @type {D} */ +var d; +>d : Symbol(d, Decl(use.js, 8, 3)) + +d.chunk; +>d.chunk : Symbol(Chunk.chunk, Decl(mod1.js, 2, 19)) +>d : Symbol(d, Decl(use.js, 8, 3)) +>chunk : Symbol(Chunk.chunk, Decl(mod1.js, 2, 19)) + +=== tests/cases/conformance/jsdoc/types.d.ts === +declare function require(name: string): any; +>require : Symbol(require, Decl(types.d.ts, 0, 0)) +>name : Symbol(name, Decl(types.d.ts, 0, 25)) + +declare var exports: any; +>exports : Symbol(exports, Decl(types.d.ts, 1, 11)) + +declare var module: { exports: any }; +>module : Symbol(module, Decl(types.d.ts, 2, 11)) +>exports : Symbol(exports, Decl(types.d.ts, 2, 21)) + +=== tests/cases/conformance/jsdoc/mod1.js === +/// +class Chunk { +>Chunk : Symbol(Chunk, Decl(mod1.js, 0, 0)) + + constructor() { + this.chunk = 1; +>this.chunk : Symbol(Chunk.chunk, Decl(mod1.js, 2, 19)) +>this : Symbol(Chunk, Decl(mod1.js, 0, 0)) +>chunk : Symbol(Chunk.chunk, Decl(mod1.js, 2, 19)) + } +} +module.exports = Chunk; +>module.exports : Symbol(exports, Decl(types.d.ts, 2, 21)) +>module : Symbol(export=, Decl(mod1.js, 5, 1)) +>exports : Symbol(export=, Decl(mod1.js, 5, 1)) +>Chunk : Symbol(Chunk, Decl(mod1.js, 0, 0)) + diff --git a/tests/baselines/reference/jsdocImportType.types b/tests/baselines/reference/jsdocImportType.types new file mode 100644 index 00000000000..b2ac2764cd5 --- /dev/null +++ b/tests/baselines/reference/jsdocImportType.types @@ -0,0 +1,60 @@ +=== tests/cases/conformance/jsdoc/use.js === +/// +/** @typedef {import("./mod1")} C + * @type {C} */ +var c; +>c : Chunk + +c.chunk; +>c.chunk : number +>c : Chunk +>chunk : number + +const D = require("./mod1"); +>D : typeof Chunk +>require("./mod1") : typeof Chunk +>require : (name: string) => any +>"./mod1" : "./mod1" + +/** @type {D} */ +var d; +>d : Chunk + +d.chunk; +>d.chunk : number +>d : Chunk +>chunk : number + +=== tests/cases/conformance/jsdoc/types.d.ts === +declare function require(name: string): any; +>require : (name: string) => any +>name : string + +declare var exports: any; +>exports : any + +declare var module: { exports: any }; +>module : { exports: any; } +>exports : any + +=== tests/cases/conformance/jsdoc/mod1.js === +/// +class Chunk { +>Chunk : Chunk + + constructor() { + this.chunk = 1; +>this.chunk = 1 : 1 +>this.chunk : number +>this : this +>chunk : number +>1 : 1 + } +} +module.exports = Chunk; +>module.exports = Chunk : typeof Chunk +>module.exports : any +>module : { exports: any; } +>exports : any +>Chunk : typeof Chunk + diff --git a/tests/baselines/reference/jsdocImportType2.symbols b/tests/baselines/reference/jsdocImportType2.symbols new file mode 100644 index 00000000000..e67d250ca3d --- /dev/null +++ b/tests/baselines/reference/jsdocImportType2.symbols @@ -0,0 +1,54 @@ +=== tests/cases/conformance/jsdoc/use.js === +/// +/** @typedef {import("./mod1")} C + * @type {C} */ +var c; +>c : Symbol(c, Decl(use.js, 3, 3)) + +c.chunk; +>c.chunk : Symbol(Chunk.chunk, Decl(mod1.js, 2, 19)) +>c : Symbol(c, Decl(use.js, 3, 3)) +>chunk : Symbol(Chunk.chunk, Decl(mod1.js, 2, 19)) + +const D = require("./mod1"); +>D : Symbol(D, Decl(use.js, 6, 5)) +>require : Symbol(require, Decl(types.d.ts, 0, 0)) +>"./mod1" : Symbol("tests/cases/conformance/jsdoc/mod1", Decl(mod1.js, 0, 0)) + +/** @type {D} */ +var d; +>d : Symbol(d, Decl(use.js, 8, 3)) + +d.chunk; +>d.chunk : Symbol(Chunk.chunk, Decl(mod1.js, 2, 19)) +>d : Symbol(d, Decl(use.js, 8, 3)) +>chunk : Symbol(Chunk.chunk, Decl(mod1.js, 2, 19)) + +=== tests/cases/conformance/jsdoc/types.d.ts === +declare function require(name: string): any; +>require : Symbol(require, Decl(types.d.ts, 0, 0)) +>name : Symbol(name, Decl(types.d.ts, 0, 25)) + +declare var exports: any; +>exports : Symbol(exports, Decl(types.d.ts, 1, 11)) + +declare var module: { exports: any }; +>module : Symbol(module, Decl(types.d.ts, 2, 11)) +>exports : Symbol(exports, Decl(types.d.ts, 2, 21)) + +=== tests/cases/conformance/jsdoc/mod1.js === +/// +module.exports = class Chunk { +>module.exports : Symbol(exports, Decl(types.d.ts, 2, 21)) +>module : Symbol(export=, Decl(mod1.js, 0, 0)) +>exports : Symbol(export=, Decl(mod1.js, 0, 0)) +>Chunk : Symbol(Chunk, Decl(mod1.js, 1, 16)) + + constructor() { + this.chunk = 1; +>this.chunk : Symbol(Chunk.chunk, Decl(mod1.js, 2, 19)) +>this : Symbol(Chunk, Decl(mod1.js, 1, 16)) +>chunk : Symbol(Chunk.chunk, Decl(mod1.js, 2, 19)) + } +} + diff --git a/tests/baselines/reference/jsdocImportType2.types b/tests/baselines/reference/jsdocImportType2.types new file mode 100644 index 00000000000..c0dfb2d925a --- /dev/null +++ b/tests/baselines/reference/jsdocImportType2.types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/jsdoc/use.js === +/// +/** @typedef {import("./mod1")} C + * @type {C} */ +var c; +>c : Chunk + +c.chunk; +>c.chunk : number +>c : Chunk +>chunk : number + +const D = require("./mod1"); +>D : typeof Chunk +>require("./mod1") : typeof Chunk +>require : (name: string) => any +>"./mod1" : "./mod1" + +/** @type {D} */ +var d; +>d : Chunk + +d.chunk; +>d.chunk : number +>d : Chunk +>chunk : number + +=== tests/cases/conformance/jsdoc/types.d.ts === +declare function require(name: string): any; +>require : (name: string) => any +>name : string + +declare var exports: any; +>exports : any + +declare var module: { exports: any }; +>module : { exports: any; } +>exports : any + +=== tests/cases/conformance/jsdoc/mod1.js === +/// +module.exports = class Chunk { +>module.exports = class Chunk { constructor() { this.chunk = 1; }} : typeof Chunk +>module.exports : any +>module : { exports: any; } +>exports : any +>class Chunk { constructor() { this.chunk = 1; }} : typeof Chunk +>Chunk : typeof Chunk + + constructor() { + this.chunk = 1; +>this.chunk = 1 : 1 +>this.chunk : number +>this : this +>chunk : number +>1 : 1 + } +} + diff --git a/tests/baselines/reference/jsdocTemplateConstructorFunction2.errors.txt b/tests/baselines/reference/jsdocTemplateConstructorFunction2.errors.txt new file mode 100644 index 00000000000..db54928b288 --- /dev/null +++ b/tests/baselines/reference/jsdocTemplateConstructorFunction2.errors.txt @@ -0,0 +1,28 @@ +tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js(21,1): error TS2322: Type 'false' is not assignable to type 'number'. + + +==== tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js (1 errors) ==== + /** + * @template {T} + * @param {T} t + */ + function Zet(t) { + /** @type {T} */ + this.u + this.t = t + } + /** + * @param {T} v + * @param {object} o + * @param {T} o.nested + */ + Zet.prototype.add = function(v, o) { + this.u = v || o.nested + return this.u + } + var z = new Zet(1) + z.t = 2 + z.u = false + ~~~ +!!! error TS2322: Type 'false' is not assignable to type 'number'. + \ No newline at end of file diff --git a/tests/baselines/reference/jsdocTemplateConstructorFunction2.symbols b/tests/baselines/reference/jsdocTemplateConstructorFunction2.symbols new file mode 100644 index 00000000000..1913ee53cdf --- /dev/null +++ b/tests/baselines/reference/jsdocTemplateConstructorFunction2.symbols @@ -0,0 +1,56 @@ +=== tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js === +/** + * @template {T} + * @param {T} t + */ +function Zet(t) { +>Zet : Symbol(Zet, Decl(templateTagWithNestedTypeLiteral.js, 0, 0)) +>t : Symbol(t, Decl(templateTagWithNestedTypeLiteral.js, 4, 13)) + + /** @type {T} */ + this.u + this.t = t +>t : Symbol(Zet.t, Decl(templateTagWithNestedTypeLiteral.js, 6, 10)) +>t : Symbol(t, Decl(templateTagWithNestedTypeLiteral.js, 4, 13)) +} +/** + * @param {T} v + * @param {object} o + * @param {T} o.nested + */ +Zet.prototype.add = function(v, o) { +>Zet.prototype : Symbol(Zet.add, Decl(templateTagWithNestedTypeLiteral.js, 8, 1)) +>Zet : Symbol(Zet, Decl(templateTagWithNestedTypeLiteral.js, 0, 0)) +>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) +>add : Symbol(Zet.add, Decl(templateTagWithNestedTypeLiteral.js, 8, 1)) +>v : Symbol(v, Decl(templateTagWithNestedTypeLiteral.js, 14, 29)) +>o : Symbol(o, Decl(templateTagWithNestedTypeLiteral.js, 14, 31)) + + this.u = v || o.nested +>this.u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36)) +>this : Symbol(Zet, Decl(templateTagWithNestedTypeLiteral.js, 0, 0)) +>u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36)) +>v : Symbol(v, Decl(templateTagWithNestedTypeLiteral.js, 14, 29)) +>o.nested : Symbol(nested, Decl(templateTagWithNestedTypeLiteral.js, 12, 3)) +>o : Symbol(o, Decl(templateTagWithNestedTypeLiteral.js, 14, 31)) +>nested : Symbol(nested, Decl(templateTagWithNestedTypeLiteral.js, 12, 3)) + + return this.u +>this.u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36)) +>this : Symbol(Zet, Decl(templateTagWithNestedTypeLiteral.js, 0, 0)) +>u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36)) +} +var z = new Zet(1) +>z : Symbol(z, Decl(templateTagWithNestedTypeLiteral.js, 18, 3)) +>Zet : Symbol(Zet, Decl(templateTagWithNestedTypeLiteral.js, 0, 0)) + +z.t = 2 +>z.t : Symbol(Zet.t, Decl(templateTagWithNestedTypeLiteral.js, 6, 10)) +>z : Symbol(z, Decl(templateTagWithNestedTypeLiteral.js, 18, 3)) +>t : Symbol(Zet.t, Decl(templateTagWithNestedTypeLiteral.js, 6, 10)) + +z.u = false +>z.u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36)) +>z : Symbol(z, Decl(templateTagWithNestedTypeLiteral.js, 18, 3)) +>u : Symbol(Zet.u, Decl(templateTagWithNestedTypeLiteral.js, 4, 17), Decl(templateTagWithNestedTypeLiteral.js, 14, 36)) + diff --git a/tests/baselines/reference/jsdocTemplateConstructorFunction2.types b/tests/baselines/reference/jsdocTemplateConstructorFunction2.types new file mode 100644 index 00000000000..9f0a55289f3 --- /dev/null +++ b/tests/baselines/reference/jsdocTemplateConstructorFunction2.types @@ -0,0 +1,74 @@ +=== tests/cases/conformance/jsdoc/templateTagWithNestedTypeLiteral.js === +/** + * @template {T} + * @param {T} t + */ +function Zet(t) { +>Zet : typeof Zet +>t : T + + /** @type {T} */ + this.u +>this.u : any +>this : any +>u : any + + this.t = t +>this.t = t : T +>this.t : any +>this : any +>t : any +>t : T +} +/** + * @param {T} v + * @param {object} o + * @param {T} o.nested + */ +Zet.prototype.add = function(v, o) { +>Zet.prototype.add = function(v, o) { this.u = v || o.nested return this.u} : (v: T, o: { nested: T; }) => T +>Zet.prototype.add : any +>Zet.prototype : any +>Zet : typeof Zet +>prototype : any +>add : any +>function(v, o) { this.u = v || o.nested return this.u} : (v: T, o: { nested: T; }) => T +>v : T +>o : { nested: T; } + + this.u = v || o.nested +>this.u = v || o.nested : T +>this.u : T +>this : Zet +>u : T +>v || o.nested : T +>v : T +>o.nested : T +>o : { nested: T; } +>nested : T + + return this.u +>this.u : T +>this : Zet +>u : T +} +var z = new Zet(1) +>z : typeof Zet +>new Zet(1) : typeof Zet +>Zet : typeof Zet +>1 : 1 + +z.t = 2 +>z.t = 2 : 2 +>z.t : number +>z : typeof Zet +>t : number +>2 : 2 + +z.u = false +>z.u = false : false +>z.u : number +>z : typeof Zet +>u : number +>false : false + diff --git a/tests/baselines/reference/keyofAndForIn.types b/tests/baselines/reference/keyofAndForIn.types index c4997c05bfe..9de1b651843 100644 --- a/tests/baselines/reference/keyofAndForIn.types +++ b/tests/baselines/reference/keyofAndForIn.types @@ -33,14 +33,14 @@ function f1(obj: { [P in K]: T }, k: K) { >k1 : K } for (let k2 in obj) { ->k2 : K +>k2 : Extract >obj : { [P in K]: T; } let x2 = obj[k2]; ->x2 : { [P in K]: T; }[K] ->obj[k2] : { [P in K]: T; }[K] +>x2 : { [P in K]: T; }[Extract] +>obj[k2] : { [P in K]: T; }[Extract] >obj : { [P in K]: T; } ->k2 : K +>k2 : Extract } } @@ -76,14 +76,14 @@ function f2(obj: { [P in keyof T]: T[P] }, k: keyof T) { >k1 : keyof T } for (let k2 in obj) { ->k2 : keyof T +>k2 : Extract >obj : { [P in keyof T]: T[P]; } let x2 = obj[k2]; ->x2 : { [P in keyof T]: T[P]; }[keyof T] ->obj[k2] : { [P in keyof T]: T[P]; }[keyof T] +>x2 : { [P in keyof T]: T[P]; }[Extract] +>obj[k2] : { [P in keyof T]: T[P]; }[Extract] >obj : { [P in keyof T]: T[P]; } ->k2 : keyof T +>k2 : Extract } } @@ -121,13 +121,13 @@ function f3(obj: { [P in K]: T[P] }, k: K) { >k1 : K } for (let k2 in obj) { ->k2 : K +>k2 : Extract >obj : { [P in K]: T[P]; } let x2 = obj[k2]; ->x2 : { [P in K]: T[P]; }[K] ->obj[k2] : { [P in K]: T[P]; }[K] +>x2 : { [P in K]: T[P]; }[Extract] +>obj[k2] : { [P in K]: T[P]; }[Extract] >obj : { [P in K]: T[P]; } ->k2 : K +>k2 : Extract } } diff --git a/tests/baselines/reference/keyofAndIndexedAccess.js b/tests/baselines/reference/keyofAndIndexedAccess.js index 1ee6bfc218b..422cef5a574 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.js +++ b/tests/baselines/reference/keyofAndIndexedAccess.js @@ -188,13 +188,13 @@ function f51(k: K, s: string) { const x2 = k as string; } -function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) { +function f52(obj: { [x: string]: boolean }, k: Exclude, s: string, n: number) { const x1 = obj[s]; const x2 = obj[n]; const x3 = obj[k]; } -function f53(obj: { [x: string]: boolean }, k: K, s: string, n: number) { +function f53>(obj: { [x: string]: boolean }, k: K, s: string, n: number) { const x1 = obj[s]; const x2 = obj[n]; const x3 = obj[k]; @@ -554,7 +554,7 @@ class AnotherSampleClass extends SampleClass { new AnotherSampleClass({}); // Positive repro from #17166 -function f3(t: T, k: K, tk: T[K]): void { +function f3>(t: T, k: K, tk: T[K]): void { for (let key in t) { key = k // ok, K ==> keyof T t[key] = tk; // ok, T[K] ==> T[keyof T] @@ -1048,8 +1048,8 @@ declare function f50(k: keyof T, s: string): void; declare function f51(k: K, s: string): void; declare function f52(obj: { [x: string]: boolean; -}, k: keyof T, s: string, n: number): void; -declare function f53(obj: { +}, k: Exclude, s: string, n: number): void; +declare function f53>(obj: { [x: string]: boolean; }, k: K, s: string, n: number): void; declare function f54(obj: T, key: keyof T): void; @@ -1208,7 +1208,7 @@ declare class AnotherSampleClass extends SampleClass { constructor(props: T); brokenMethod(): void; } -declare function f3(t: T, k: K, tk: T[K]): void; +declare function f3>(t: T, k: K, tk: T[K]): void; declare type Predicates = { [T in keyof TaggedRecord]: (variant: TaggedRecord[keyof TaggedRecord]) => variant is TaggedRecord[T]; }; diff --git a/tests/baselines/reference/keyofAndIndexedAccess.symbols b/tests/baselines/reference/keyofAndIndexedAccess.symbols index c1a3449991f..b1206a49388 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess.symbols @@ -651,25 +651,26 @@ function f51(k: K, s: string) { >k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 184, 35)) } -function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) { +function f52(obj: { [x: string]: boolean }, k: Exclude, s: string, n: number) { >f52 : Symbol(f52, Decl(keyofAndIndexedAccess.ts, 187, 1)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 189, 13)) >obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 189, 16)) >x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 189, 24)) >k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 189, 46)) +>Exclude : Symbol(Exclude, Decl(lib.d.ts, --, --)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 189, 13)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 189, 58)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 189, 69)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 189, 75)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 189, 86)) const x1 = obj[s]; >x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 190, 9)) >obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 189, 16)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 189, 58)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 189, 75)) const x2 = obj[n]; >x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 191, 9)) >obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 189, 16)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 189, 69)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 189, 86)) const x3 = obj[k]; >x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 192, 9)) @@ -677,32 +678,33 @@ function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) >k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 189, 46)) } -function f53(obj: { [x: string]: boolean }, k: K, s: string, n: number) { +function f53>(obj: { [x: string]: boolean }, k: K, s: string, n: number) { >f53 : Symbol(f53, Decl(keyofAndIndexedAccess.ts, 193, 1)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 195, 13)) >K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 195, 15)) +>Exclude : Symbol(Exclude, Decl(lib.d.ts, --, --)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 195, 13)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 195, 35)) ->x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 195, 43)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 195, 65)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 195, 52)) +>x : Symbol(x, Decl(keyofAndIndexedAccess.ts, 195, 60)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 195, 82)) >K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 195, 15)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 195, 71)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 195, 82)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 195, 88)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 195, 99)) const x1 = obj[s]; >x1 : Symbol(x1, Decl(keyofAndIndexedAccess.ts, 196, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 195, 35)) ->s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 195, 71)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 195, 52)) +>s : Symbol(s, Decl(keyofAndIndexedAccess.ts, 195, 88)) const x2 = obj[n]; >x2 : Symbol(x2, Decl(keyofAndIndexedAccess.ts, 197, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 195, 35)) ->n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 195, 82)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 195, 52)) +>n : Symbol(n, Decl(keyofAndIndexedAccess.ts, 195, 99)) const x3 = obj[k]; >x3 : Symbol(x3, Decl(keyofAndIndexedAccess.ts, 198, 9)) ->obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 195, 35)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 195, 65)) +>obj : Symbol(obj, Decl(keyofAndIndexedAccess.ts, 195, 52)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 195, 82)) } function f54(obj: T, key: keyof T) { @@ -1963,31 +1965,32 @@ new AnotherSampleClass({}); >AnotherSampleClass : Symbol(AnotherSampleClass, Decl(keyofAndIndexedAccess.ts, 540, 54)) // Positive repro from #17166 -function f3(t: T, k: K, tk: T[K]): void { +function f3>(t: T, k: K, tk: T[K]): void { >f3 : Symbol(f3, Decl(keyofAndIndexedAccess.ts, 552, 27)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 555, 12)) >K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 555, 14)) +>Extract : Symbol(Extract, Decl(lib.d.ts, --, --)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 555, 12)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 555, 34)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 555, 51)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 555, 12)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 555, 39)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 555, 56)) >K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 555, 14)) ->tk : Symbol(tk, Decl(keyofAndIndexedAccess.ts, 555, 45)) +>tk : Symbol(tk, Decl(keyofAndIndexedAccess.ts, 555, 62)) >T : Symbol(T, Decl(keyofAndIndexedAccess.ts, 555, 12)) >K : Symbol(K, Decl(keyofAndIndexedAccess.ts, 555, 14)) for (let key in t) { >key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 556, 12)) ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 555, 34)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 555, 51)) key = k // ok, K ==> keyof T >key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 556, 12)) ->k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 555, 39)) +>k : Symbol(k, Decl(keyofAndIndexedAccess.ts, 555, 56)) t[key] = tk; // ok, T[K] ==> T[keyof T] ->t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 555, 34)) +>t : Symbol(t, Decl(keyofAndIndexedAccess.ts, 555, 51)) >key : Symbol(key, Decl(keyofAndIndexedAccess.ts, 556, 12)) ->tk : Symbol(tk, Decl(keyofAndIndexedAccess.ts, 555, 45)) +>tk : Symbol(tk, Decl(keyofAndIndexedAccess.ts, 555, 62)) } } diff --git a/tests/baselines/reference/keyofAndIndexedAccess.types b/tests/baselines/reference/keyofAndIndexedAccess.types index 694abf7d10e..4e41b58e664 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess.types +++ b/tests/baselines/reference/keyofAndIndexedAccess.types @@ -59,10 +59,10 @@ const enum E { A, B, C } >C : E.C type K00 = keyof any; // string ->K00 : string +>K00 : string | number | symbol type K01 = keyof string; // "toString" | "charAt" | ... ->K01 : "length" | "toString" | "concat" | "slice" | "indexOf" | "lastIndexOf" | "charAt" | "charCodeAt" | "localeCompare" | "match" | "replace" | "search" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" | "valueOf" +>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" @@ -88,11 +88,11 @@ type K10 = keyof Shape; // "name" | "width" | "height" | "visible" >Shape : Shape type K11 = keyof Shape[]; // "length" | "toString" | ... ->K11 : "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" +>K11 : number | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" >Shape : Shape type K12 = keyof Dictionary; // string ->K12 : string +>K12 : string | number >Dictionary : Dictionary >Shape : Shape @@ -108,7 +108,7 @@ type K15 = keyof E; // "toString" | "toFixed" | "toExponential" | ... >E : E type K16 = keyof [string, number]; // "0" | "1" | "length" | "toString" | ... ->K16 : "0" | "1" | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" +>K16 : number | "0" | "1" | "length" | "toString" | "toLocaleString" | "push" | "pop" | "concat" | "join" | "reverse" | "shift" | "slice" | "sort" | "splice" | "unshift" | "indexOf" | "lastIndexOf" | "every" | "some" | "forEach" | "map" | "filter" | "reduce" | "reduceRight" type K17 = keyof (Shape | Item); // "name" >K17 : "name" @@ -121,7 +121,7 @@ type K18 = keyof (Shape & Item); // "name" | "width" | "height" | "visible" | " >Item : Item type K19 = keyof NumericallyIndexed // never ->K19 : never +>K19 : number >NumericallyIndexed : NumericallyIndexed >Shape : Shape @@ -136,7 +136,7 @@ type K20 = KeyOf; // "name" | "width" | "height" | "visible" >Shape : Shape type K21 = KeyOf>; // string ->K21 : string +>K21 : string | number >KeyOf : keyof T >Dictionary : Dictionary >Shape : Shape @@ -756,12 +756,13 @@ function f51(k: K, s: string) { >k : K } -function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) { ->f52 : (obj: { [x: string]: boolean; }, k: keyof T, s: string, n: number) => void +function f52(obj: { [x: string]: boolean }, k: Exclude, s: string, n: number) { +>f52 : (obj: { [x: string]: boolean; }, k: Exclude, s: string, n: number) => void >T : T >obj : { [x: string]: boolean; } >x : string ->k : keyof T +>k : Exclude +>Exclude : Exclude >T : T >s : string >n : number @@ -779,16 +780,17 @@ function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) >n : number const x3 = obj[k]; ->x3 : { [x: string]: boolean; }[keyof T] ->obj[k] : { [x: string]: boolean; }[keyof T] +>x3 : { [x: string]: boolean; }[Exclude] +>obj[k] : { [x: string]: boolean; }[Exclude] >obj : { [x: string]: boolean; } ->k : keyof T +>k : Exclude } -function f53(obj: { [x: string]: boolean }, k: K, s: string, n: number) { ->f53 : (obj: { [x: string]: boolean; }, k: K, s: string, n: number) => void +function f53>(obj: { [x: string]: boolean }, k: K, s: string, n: number) { +>f53 : >(obj: { [x: string]: boolean; }, k: K, s: string, n: number) => void >T : T >K : K +>Exclude : Exclude >T : T >obj : { [x: string]: boolean; } >x : string @@ -825,7 +827,7 @@ function f54(obj: T, key: keyof T) { >T : T for (let s in obj[key]) { ->s : keyof T[keyof T] +>s : Extract >obj[key] : T[keyof T] >obj : T >key : keyof T @@ -850,7 +852,7 @@ function f55(obj: T, key: K) { >K : K for (let s in obj[key]) { ->s : keyof T[K] +>s : Extract >obj[key] : T[K] >obj : T >key : K @@ -873,17 +875,17 @@ function f60(source: T, target: T) { >T : T for (let k in source) { ->k : keyof T +>k : Extract >source : T target[k] = source[k]; ->target[k] = source[k] : T[keyof T] ->target[k] : T[keyof T] +>target[k] = source[k] : T[Extract] +>target[k] : T[Extract] >target : T ->k : keyof T ->source[k] : T[keyof T] +>k : Extract +>source[k] : T[Extract] >source : T ->k : keyof T +>k : Extract } } @@ -2295,10 +2297,11 @@ new AnotherSampleClass({}); >{} : {} // Positive repro from #17166 -function f3(t: T, k: K, tk: T[K]): void { ->f3 : (t: T, k: K, tk: T[K]) => void +function f3>(t: T, k: K, tk: T[K]): void { +>f3 : >(t: T, k: K, tk: T[K]) => void >T : T >K : K +>Extract : Extract >T : T >t : T >T : T @@ -2309,19 +2312,19 @@ function f3(t: T, k: K, tk: T[K]): void { >K : K for (let key in t) { ->key : keyof T +>key : Extract >t : T key = k // ok, K ==> keyof T >key = k : K ->key : keyof T +>key : Extract >k : K t[key] = tk; // ok, T[K] ==> T[keyof T] >t[key] = tk : T[K] ->t[key] : T[keyof T] +>t[key] : T[Extract] >t : T ->key : keyof T +>key : Extract >tk : T[K] } } diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt index 49f44115e72..f9bb63c43b1 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt @@ -28,16 +28,22 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(76,5): error Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(77,5): error TS2322: Type 'keyof T | keyof U' is not assignable to type 'keyof (T | U)'. Type 'keyof T' is not assignable to type 'keyof (T | U)'. -tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(86,9): error TS2322: Type 'keyof T' is not assignable to type 'K'. -tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(88,9): error TS2322: Type 'T[keyof T]' is not assignable to type 'T[K]'. - Type 'keyof T' is not assignable to type 'K'. + Type 'string | number | symbol' is not assignable to type 'keyof (T | U)'. + Type 'string' is not assignable to type 'keyof (T | U)'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(86,9): error TS2322: Type 'Extract' is not assignable to type 'K'. + Type 'string & keyof T' is not assignable to type 'K'. + Type 'string' is not assignable to type 'K'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(88,9): error TS2322: Type 'T[Extract]' is not assignable to type 'T[K]'. + Type 'Extract' is not assignable to type 'K'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(91,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(94,5): error TS2322: Type 'T[J]' is not assignable to type 'U[J]'. Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(97,5): error TS2322: Type 'T[K]' is not assignable to type 'T[J]'. Type 'K' is not assignable to type 'J'. - Type 'keyof T' is not assignable to type 'J'. + Type 'Extract' is not assignable to type 'J'. + Type 'string & keyof T' is not assignable to type 'J'. + Type 'string' is not assignable to type 'J'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(100,5): error TS2322: Type 'T[K]' is not assignable to type 'U[J]'. Type 'T' is not assignable to type 'U'. @@ -175,22 +181,26 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(100,5): error ~~ !!! error TS2322: Type 'keyof T | keyof U' is not assignable to type 'keyof (T | U)'. !!! error TS2322: Type 'keyof T' is not assignable to type 'keyof (T | U)'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'keyof (T | U)'. +!!! error TS2322: Type 'string' is not assignable to type 'keyof (T | U)'. k2 = k1; } // Repro from #17166 - function f3( + function f3, U extends T, J extends K>( t: T, k: K, tk: T[K], u: U, j: J, uk: U[K], tj: T[J], uj: U[J]): void { for (let key in t) { key = k // ok, K ==> keyof T k = key // error, keyof T =/=> K ~ -!!! error TS2322: Type 'keyof T' is not assignable to type 'K'. +!!! error TS2322: Type 'Extract' is not assignable to type 'K'. +!!! error TS2322: Type 'string & keyof T' is not assignable to type 'K'. +!!! error TS2322: Type 'string' is not assignable to type 'K'. t[key] = tk; // ok, T[K] ==> T[keyof T] tk = t[key]; // error, T[keyof T] =/=> T[K] ~~ -!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'T[K]'. -!!! error TS2322: Type 'keyof T' is not assignable to type 'K'. +!!! error TS2322: Type 'T[Extract]' is not assignable to type 'T[K]'. +!!! error TS2322: Type 'Extract' is not assignable to type 'K'. } tk = uk; uk = tk; // error @@ -209,7 +219,9 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(100,5): error ~~ !!! error TS2322: Type 'T[K]' is not assignable to type 'T[J]'. !!! error TS2322: Type 'K' is not assignable to type 'J'. -!!! error TS2322: Type 'keyof T' is not assignable to type 'J'. +!!! error TS2322: Type 'Extract' is not assignable to type 'J'. +!!! error TS2322: Type 'string & keyof T' is not assignable to type 'J'. +!!! error TS2322: Type 'string' is not assignable to type 'J'. tk = uj; uj = tk; // error diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.js b/tests/baselines/reference/keyofAndIndexedAccessErrors.js index d267699ffd6..0f026d5d2e5 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.js +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.js @@ -80,7 +80,7 @@ function f20(k1: keyof (T | U), k2: keyof (T & U), o1: T | U, o2: T & U) { } // Repro from #17166 -function f3( +function f3, U extends T, J extends K>( t: T, k: K, tk: T[K], u: U, j: J, uk: U[K], tj: T[J], uj: U[J]): void { for (let key in t) { key = k // ok, K ==> keyof T diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols index 47b22af2541..d062677fa02 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols @@ -270,18 +270,19 @@ function f20(k1: keyof (T | U), k2: keyof (T & U), o1: T | U, o2: T & U) { } // Repro from #17166 -function f3( +function f3, U extends T, J extends K>( >f3 : Symbol(f3, Decl(keyofAndIndexedAccessErrors.ts, 78, 1)) >T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 81, 12)) >K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 81, 14)) +>Extract : Symbol(Extract, Decl(lib.d.ts, --, --)) >T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 81, 12)) ->U : Symbol(U, Decl(keyofAndIndexedAccessErrors.ts, 81, 33)) +>U : Symbol(U, Decl(keyofAndIndexedAccessErrors.ts, 81, 50)) >T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 81, 12)) ->J : Symbol(J, Decl(keyofAndIndexedAccessErrors.ts, 81, 46)) +>J : Symbol(J, Decl(keyofAndIndexedAccessErrors.ts, 81, 63)) >K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 81, 14)) t: T, k: K, tk: T[K], u: U, j: J, uk: U[K], tj: T[J], uj: U[J]): void { ->t : Symbol(t, Decl(keyofAndIndexedAccessErrors.ts, 81, 60)) +>t : Symbol(t, Decl(keyofAndIndexedAccessErrors.ts, 81, 77)) >T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 81, 12)) >k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 82, 9)) >K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 81, 14)) @@ -289,22 +290,22 @@ function f3( >T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 81, 12)) >K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 81, 14)) >u : Symbol(u, Decl(keyofAndIndexedAccessErrors.ts, 82, 25)) ->U : Symbol(U, Decl(keyofAndIndexedAccessErrors.ts, 81, 33)) +>U : Symbol(U, Decl(keyofAndIndexedAccessErrors.ts, 81, 50)) >j : Symbol(j, Decl(keyofAndIndexedAccessErrors.ts, 82, 31)) ->J : Symbol(J, Decl(keyofAndIndexedAccessErrors.ts, 81, 46)) +>J : Symbol(J, Decl(keyofAndIndexedAccessErrors.ts, 81, 63)) >uk : Symbol(uk, Decl(keyofAndIndexedAccessErrors.ts, 82, 37)) ->U : Symbol(U, Decl(keyofAndIndexedAccessErrors.ts, 81, 33)) +>U : Symbol(U, Decl(keyofAndIndexedAccessErrors.ts, 81, 50)) >K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 81, 14)) >tj : Symbol(tj, Decl(keyofAndIndexedAccessErrors.ts, 82, 47)) >T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 81, 12)) ->J : Symbol(J, Decl(keyofAndIndexedAccessErrors.ts, 81, 46)) +>J : Symbol(J, Decl(keyofAndIndexedAccessErrors.ts, 81, 63)) >uj : Symbol(uj, Decl(keyofAndIndexedAccessErrors.ts, 82, 57)) ->U : Symbol(U, Decl(keyofAndIndexedAccessErrors.ts, 81, 33)) ->J : Symbol(J, Decl(keyofAndIndexedAccessErrors.ts, 81, 46)) +>U : Symbol(U, Decl(keyofAndIndexedAccessErrors.ts, 81, 50)) +>J : Symbol(J, Decl(keyofAndIndexedAccessErrors.ts, 81, 63)) for (let key in t) { >key : Symbol(key, Decl(keyofAndIndexedAccessErrors.ts, 83, 12)) ->t : Symbol(t, Decl(keyofAndIndexedAccessErrors.ts, 81, 60)) +>t : Symbol(t, Decl(keyofAndIndexedAccessErrors.ts, 81, 77)) key = k // ok, K ==> keyof T >key : Symbol(key, Decl(keyofAndIndexedAccessErrors.ts, 83, 12)) @@ -315,13 +316,13 @@ function f3( >key : Symbol(key, Decl(keyofAndIndexedAccessErrors.ts, 83, 12)) t[key] = tk; // ok, T[K] ==> T[keyof T] ->t : Symbol(t, Decl(keyofAndIndexedAccessErrors.ts, 81, 60)) +>t : Symbol(t, Decl(keyofAndIndexedAccessErrors.ts, 81, 77)) >key : Symbol(key, Decl(keyofAndIndexedAccessErrors.ts, 83, 12)) >tk : Symbol(tk, Decl(keyofAndIndexedAccessErrors.ts, 82, 15)) tk = t[key]; // error, T[keyof T] =/=> T[K] >tk : Symbol(tk, Decl(keyofAndIndexedAccessErrors.ts, 82, 15)) ->t : Symbol(t, Decl(keyofAndIndexedAccessErrors.ts, 81, 60)) +>t : Symbol(t, Decl(keyofAndIndexedAccessErrors.ts, 81, 77)) >key : Symbol(key, Decl(keyofAndIndexedAccessErrors.ts, 83, 12)) } tk = uk; diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.types b/tests/baselines/reference/keyofAndIndexedAccessErrors.types index bcd3878013d..2f50ef5c53c 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.types +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.types @@ -22,7 +22,7 @@ type Dictionary = { [x: string]: T }; >T : T type T00 = keyof K0; // Error ->T00 : string +>T00 : string | number | symbol >K0 : No type information available! type T01 = keyof Object; @@ -30,23 +30,23 @@ type T01 = keyof Object; >Object : Object type T02 = keyof keyof Object; ->T02 : "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" | "valueOf" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" >Object : Object type T03 = keyof keyof keyof Object; ->T03 : "length" | "toString" | "valueOf" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" +>T03 : "toString" | "toLocaleString" | "valueOf" >Object : Object type T04 = keyof keyof keyof keyof Object; ->T04 : "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" | "valueOf" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" >Object : Object type T05 = keyof keyof keyof keyof keyof Object; ->T05 : "length" | "toString" | "valueOf" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" +>T05 : "toString" | "toLocaleString" | "valueOf" >Object : Object type T06 = keyof keyof keyof keyof keyof keyof Object; ->T06 : "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" | "valueOf" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "substr" >Object : Object type T10 = Shape["name"]; @@ -301,10 +301,11 @@ function f20(k1: keyof (T | U), k2: keyof (T & U), o1: T | U, o2: T & U) { } // Repro from #17166 -function f3( ->f3 : (t: T, k: K, tk: T[K], u: U, j: J, uk: U[K], tj: T[J], uj: U[J]) => void +function f3, U extends T, J extends K>( +>f3 : , U extends T, J extends K>(t: T, k: K, tk: T[K], u: U, j: J, uk: U[K], tj: T[J], uj: U[J]) => void >T : T >K : K +>Extract : Extract >T : T >U : U >T : T @@ -334,32 +335,32 @@ function f3( >J : J for (let key in t) { ->key : keyof T +>key : Extract >t : T key = k // ok, K ==> keyof T >key = k : K ->key : keyof T +>key : Extract >k : K k = key // error, keyof T =/=> K ->k = key : keyof T +>k = key : Extract >k : K ->key : keyof T +>key : Extract t[key] = tk; // ok, T[K] ==> T[keyof T] >t[key] = tk : T[K] ->t[key] : T[keyof T] +>t[key] : T[Extract] >t : T ->key : keyof T +>key : Extract >tk : T[K] tk = t[key]; // error, T[keyof T] =/=> T[K] ->tk = t[key] : T[keyof T] +>tk = t[key] : T[Extract] >tk : T[K] ->t[key] : T[keyof T] +>t[key] : T[Extract] >t : T ->key : keyof T +>key : Extract } tk = uk; >tk = uk : U[K] diff --git a/tests/baselines/reference/library_ObjectPrototypeProperties.types b/tests/baselines/reference/library_ObjectPrototypeProperties.types index 2f41dd7c1eb..093b787a0ce 100644 --- a/tests/baselines/reference/library_ObjectPrototypeProperties.types +++ b/tests/baselines/reference/library_ObjectPrototypeProperties.types @@ -34,11 +34,11 @@ Object.prototype.valueOf(); Object.prototype.hasOwnProperty("string"); >Object.prototype.hasOwnProperty("string") : boolean ->Object.prototype.hasOwnProperty : (v: string) => boolean +>Object.prototype.hasOwnProperty : (v: string | number | symbol) => boolean >Object.prototype : Object >Object : ObjectConstructor >prototype : Object ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >"string" : "string" Object.prototype.isPrototypeOf(Object); @@ -52,10 +52,10 @@ Object.prototype.isPrototypeOf(Object); Object.prototype.propertyIsEnumerable("string"); >Object.prototype.propertyIsEnumerable("string") : boolean ->Object.prototype.propertyIsEnumerable : (v: string) => boolean +>Object.prototype.propertyIsEnumerable : (v: string | number | symbol) => boolean >Object.prototype : Object >Object : ObjectConstructor >prototype : Object ->propertyIsEnumerable : (v: string) => boolean +>propertyIsEnumerable : (v: string | number | symbol) => boolean >"string" : "string" diff --git a/tests/baselines/reference/limitDeepInstantiations.errors.txt b/tests/baselines/reference/limitDeepInstantiations.errors.txt index 70718199d2b..99ff4c789f4 100644 --- a/tests/baselines/reference/limitDeepInstantiations.errors.txt +++ b/tests/baselines/reference/limitDeepInstantiations.errors.txt @@ -1,8 +1,7 @@ tests/cases/compiler/limitDeepInstantiations.ts(3,35): error TS2502: '"true"' is referenced directly or indirectly in its own type annotation. -tests/cases/compiler/limitDeepInstantiations.ts(5,13): error TS2344: Type '"false"' does not satisfy the constraint '"true"'. -==== tests/cases/compiler/limitDeepInstantiations.ts (2 errors) ==== +==== tests/cases/compiler/limitDeepInstantiations.ts (1 errors) ==== // Repro from #14837 type Foo = { "true": Foo> }[T]; @@ -10,6 +9,4 @@ tests/cases/compiler/limitDeepInstantiations.ts(5,13): error TS2344: Type '"fals !!! error TS2502: '"true"' is referenced directly or indirectly in its own type annotation. let f1: Foo<"true", {}>; let f2: Foo<"false", {}>; - ~~~~~~~ -!!! error TS2344: Type '"false"' does not satisfy the constraint '"true"'. \ No newline at end of file diff --git a/tests/baselines/reference/mappedTypeErrors.errors.txt b/tests/baselines/reference/mappedTypeErrors.errors.txt index 3245f9932f0..f78c32531a4 100644 --- a/tests/baselines/reference/mappedTypeErrors.errors.txt +++ b/tests/baselines/reference/mappedTypeErrors.errors.txt @@ -1,7 +1,8 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(19,20): error TS2313: Type parameter 'P' has a circular constraint. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(20,20): error TS2322: Type 'number' is not assignable to type 'string'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(21,20): error TS2322: Type 'Date' is not assignable to type 'string'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(22,19): error TS2344: Type 'Date' does not satisfy the constraint 'string'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(21,20): error TS2322: Type 'Date' is not assignable to type 'string | number | symbol'. + Type 'Date' is not assignable to type 'symbol'. +tests/cases/conformance/types/mapped/mappedTypeErrors.ts(22,19): error TS2344: Type 'Date' does not satisfy the constraint 'string | number | symbol'. + Type 'Date' is not assignable to type 'symbol'. tests/cases/conformance/types/mapped/mappedTypeErrors.ts(25,24): error TS2344: Type '"foo"' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. tests/cases/conformance/types/mapped/mappedTypeErrors.ts(26,24): error TS2344: Type '"name" | "foo"' does not satisfy the constraint '"name" | "width" | "height" | "visible"'. Type '"foo"' is not assignable to type '"name" | "width" | "height" | "visible"'. @@ -45,11 +46,12 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(129,5): error TS2322: T tests/cases/conformance/types/mapped/mappedTypeErrors.ts(130,5): error TS2322: Type '{ a: string; }' is not assignable to type '{ [x: string]: any; a?: number | undefined; }'. Types of property 'a' are incompatible. Type 'string' is not assignable to type 'number | undefined'. -tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,16): error TS2322: Type 'T' is not assignable to type 'string'. +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 (26 errors) ==== +==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (25 errors) ==== interface Shape { name: string; width: number; @@ -72,14 +74,14 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,21): error TS2536: ~ !!! error TS2313: Type parameter 'P' has a circular constraint. type T01 = { [P in number]: string }; // Error - ~~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'string'. type T02 = { [P in Date]: number }; // Error ~~~~ -!!! error TS2322: Type 'Date' is not assignable to type 'string'. +!!! error TS2322: Type 'Date' is not assignable to type 'string | number | symbol'. +!!! error TS2322: Type 'Date' is not assignable to type 'symbol'. type T03 = Record; // Error ~~~~ -!!! error TS2344: Type 'Date' does not satisfy the constraint 'string'. +!!! error TS2344: Type 'Date' does not satisfy the constraint 'string | number | symbol'. +!!! error TS2344: Type 'Date' is not assignable to type 'symbol'. type T10 = Pick; type T11 = Pick; // Error @@ -258,7 +260,8 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,21): error TS2536: pf: {[P in F]?: T[P]}, pt: {[P in T]?: T[P]}, // note: should be in keyof T ~ -!!! error TS2322: Type 'T' is not assignable to type 'string'. +!!! error TS2322: Type 'T' is not assignable to type 'string | number | symbol'. +!!! error TS2322: Type 'T' is not assignable to type 'symbol'. ~~~~ !!! error TS2536: Type 'P' cannot be used to index type 'T'. }; diff --git a/tests/baselines/reference/mappedTypeErrors.types b/tests/baselines/reference/mappedTypeErrors.types index ab0ae55a0e1..3faae85af8b 100644 --- a/tests/baselines/reference/mappedTypeErrors.types +++ b/tests/baselines/reference/mappedTypeErrors.types @@ -373,17 +373,17 @@ function setState(obj: T, props: Pick) { >K : K for (let k in props) { ->k : K +>k : Extract >props : Pick obj[k] = props[k]; ->obj[k] = props[k] : Pick[K] ->obj[k] : T[K] +>obj[k] = props[k] : Pick[Extract] +>obj[k] : T[Extract] >obj : T ->k : K ->props[k] : Pick[K] +>k : Extract +>props[k] : Pick[Extract] >props : Pick ->k : K +>k : Extract } } @@ -468,19 +468,19 @@ class C { >K : K for (let k in props) { ->k : K +>k : Extract >props : Pick this.state[k] = props[k]; ->this.state[k] = props[k] : Pick[K] ->this.state[k] : T[K] +>this.state[k] = props[k] : Pick[Extract] +>this.state[k] : T[Extract] >this.state : T >this : this >state : T ->k : K ->props[k] : Pick[K] +>k : Extract +>props[k] : Pick[Extract] >props : Pick ->k : K +>k : Extract } } } diff --git a/tests/baselines/reference/mappedTypeErrors2.errors.txt b/tests/baselines/reference/mappedTypeErrors2.errors.txt index 18bc7cc7239..9178731d189 100644 --- a/tests/baselines/reference/mappedTypeErrors2.errors.txt +++ b/tests/baselines/reference/mappedTypeErrors2.errors.txt @@ -1,10 +1,13 @@ tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(9,30): error TS2536: Type 'K' cannot be used to index type 'T1'. tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(13,30): error TS2536: Type 'K' cannot be used to index type 'T3'. +tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(15,38): error TS2536: Type 'S' cannot be used to index type '{ [key in AB[S]]: true; }'. +tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(15,47): error TS2322: Type 'AB[S]' is not assignable to type 'string | number | symbol'. + Type 'AB[S]' is not assignable to type 'symbol'. tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(15,47): error TS2536: Type 'S' cannot be used to index type 'AB'. tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(17,49): error TS2536: Type 'L' cannot be used to index type '{ [key in AB[S]]: true; }'. -==== tests/cases/conformance/types/mapped/mappedTypeErrors2.ts (4 errors) ==== +==== tests/cases/conformance/types/mapped/mappedTypeErrors2.ts (6 errors) ==== // Repros from #17238 type AB = { @@ -24,6 +27,11 @@ tests/cases/conformance/types/mapped/mappedTypeErrors2.ts(17,49): error TS2536: !!! error TS2536: Type 'K' cannot be used to index type 'T3'. type T5 = {[key in AB[S]]: true}[S]; // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2536: Type 'S' cannot be used to index type '{ [key in AB[S]]: true; }'. + ~~~~~ +!!! error TS2322: Type 'AB[S]' is not assignable to type 'string | number | symbol'. +!!! error TS2322: Type 'AB[S]' is not assignable to type 'symbol'. ~~~~~ !!! error TS2536: Type 'S' cannot be used to index type 'AB'. diff --git a/tests/baselines/reference/mappedTypeRelationships.errors.txt b/tests/baselines/reference/mappedTypeRelationships.errors.txt index f5d0e66ff3f..60a06e000c2 100644 --- a/tests/baselines/reference/mappedTypeRelationships.errors.txt +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -10,29 +10,27 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(25,5): error TS2 tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(26,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(26,12): error TS2536: Type 'K' cannot be used to index type 'T'. -tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(30,5): error TS2322: Type 'Partial[keyof T]' is not assignable to type 'T[keyof T]'. - Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'. - Type 'undefined' is not assignable to type 'T[keyof T]'. -tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(35,5): error TS2322: Type 'Partial[K]' is not assignable to type 'T[K]'. - Type 'T[K] | undefined' is not assignable to type 'T[K]'. - Type 'undefined' is not assignable to type 'T[K]'. -tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(40,5): error TS2322: Type 'Partial[keyof T]' is not assignable to type 'T[keyof T]'. - Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'. - Type 'undefined' is not assignable to type 'T[keyof T]'. -tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(45,5): error TS2322: Type 'Partial[K]' is not assignable to type 'T[K]'. - Type 'U[K] | undefined' is not assignable to type 'T[K]'. - Type 'undefined' is not assignable to type 'T[K]'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(30,5): error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'. + Type 'undefined' is not assignable to type 'T[keyof T]'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(35,5): error TS2322: Type 'T[K] | undefined' is not assignable to type 'T[K]'. + Type 'undefined' is not assignable to type 'T[K]'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(40,5): error TS2322: Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'. + Type 'undefined' is not assignable to type 'T[keyof T]'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(41,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'. + Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. + Type 'T' is not assignable to type 'U'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(45,5): error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'. + Type 'undefined' is not assignable to type 'T[K]'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(46,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'. + Type 'T[K]' is not assignable to type 'U[K]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(51,5): error TS2542: Index signature in type 'Readonly' only permits reading. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(56,5): error TS2542: Index signature in type 'Readonly' only permits reading. -tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(61,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'Readonly[keyof T]'. - Type 'T' is not assignable to type 'Readonly'. - Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. - Type 'T' is not assignable to type 'U'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(61,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(61,5): error TS2542: Index signature in type 'Readonly' only permits reading. -tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(66,5): error TS2322: Type 'T[K]' is not assignable to type 'Readonly[K]'. - Type 'T' is not assignable to type 'Readonly'. - Type 'T[K]' is not assignable to type 'U[K]'. - Type 'T' is not assignable to type 'U'. +tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(66,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. + Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(66,5): error TS2542: Index signature in type 'Readonly' only permits reading. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(72,5): error TS2322: Type 'Partial' is not assignable to type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(78,5): error TS2322: Type 'Partial' is not assignable to type 'Partial'. @@ -43,18 +41,26 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(143,5): error TS Type 'T' is not assignable to type 'U'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(148,5): error TS2322: Type '{ [P in keyof T]: T[P]; }' is not assignable to type '{ [P in keyof U]: U[P]; }'. Type 'keyof U' is not assignable to type 'keyof T'. + Type 'string | number | symbol' is not assignable to type 'keyof T'. + Type 'string' is not assignable to type 'keyof T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(153,5): error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in keyof T]: T[P]; }'. Type 'keyof T' is not assignable to type 'K'. + Type 'string | number | symbol' is not assignable to type 'K'. + Type 'string' is not assignable to type 'K'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(158,5): error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in keyof U]: U[P]; }'. Type 'keyof U' is not assignable to type 'K'. + Type 'string | number | symbol' is not assignable to type 'K'. + Type 'string' is not assignable to type 'K'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(163,5): error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in keyof T]: U[P]; }'. Type 'keyof T' is not assignable to type 'K'. + Type 'string | number | symbol' is not assignable to type 'K'. + Type 'string' is not assignable to type 'K'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in K]: U[P]; }'. Type 'T[P]' is not assignable to type 'U[P]'. Type 'T' is not assignable to type 'U'. -==== tests/cases/conformance/types/mapped/mappedTypeRelationships.ts (28 errors) ==== +==== tests/cases/conformance/types/mapped/mappedTypeRelationships.ts (30 errors) ==== function f1(x: T, k: keyof T) { return x[k]; } @@ -106,37 +112,41 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS function f10(x: T, y: Partial, k: keyof T) { x[k] = y[k]; // Error ~~~~ -!!! error TS2322: Type 'Partial[keyof T]' is not assignable to type 'T[keyof T]'. -!!! error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'. -!!! error TS2322: Type 'undefined' is not assignable to type 'T[keyof T]'. +!!! error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'. +!!! error TS2322: Type 'undefined' is not assignable to type 'T[keyof T]'. y[k] = x[k]; } function f11(x: T, y: Partial, k: K) { x[k] = y[k]; // Error ~~~~ -!!! error TS2322: Type 'Partial[K]' is not assignable to type 'T[K]'. -!!! error TS2322: Type 'T[K] | undefined' is not assignable to type 'T[K]'. -!!! error TS2322: Type 'undefined' is not assignable to type 'T[K]'. +!!! error TS2322: Type 'T[K] | undefined' is not assignable to type 'T[K]'. +!!! error TS2322: Type 'undefined' is not assignable to type 'T[K]'. y[k] = x[k]; } function f12(x: T, y: Partial, k: keyof T) { x[k] = y[k]; // Error ~~~~ -!!! error TS2322: Type 'Partial[keyof T]' is not assignable to type 'T[keyof T]'. -!!! error TS2322: Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'. -!!! error TS2322: Type 'undefined' is not assignable to type 'T[keyof T]'. +!!! error TS2322: Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'. +!!! error TS2322: Type 'undefined' is not assignable to type 'T[keyof T]'. y[k] = x[k]; // Error + ~~~~ +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } function f13(x: T, y: Partial, k: K) { x[k] = y[k]; // Error ~~~~ -!!! error TS2322: Type 'Partial[K]' is not assignable to type 'T[K]'. -!!! error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'. -!!! error TS2322: Type 'undefined' is not assignable to type 'T[K]'. +!!! error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'. +!!! error TS2322: Type 'undefined' is not assignable to type 'T[K]'. y[k] = x[k]; // Error + ~~~~ +!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'. +!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. } function f20(x: T, y: Readonly, k: keyof T) { @@ -157,10 +167,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS x[k] = y[k]; y[k] = x[k]; // Error ~~~~ -!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'Readonly[keyof T]'. -!!! error TS2322: Type 'T' is not assignable to type 'Readonly'. -!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. ~~~~ !!! error TS2542: Index signature in type 'Readonly' only permits reading. } @@ -169,10 +177,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS x[k] = y[k]; y[k] = x[k]; // Error ~~~~ -!!! error TS2322: Type 'T[K]' is not assignable to type 'Readonly[K]'. -!!! error TS2322: Type 'T' is not assignable to type 'Readonly'. -!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. +!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. ~~~~ !!! error TS2542: Index signature in type 'Readonly' only permits reading. } @@ -272,6 +278,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS ~ !!! error TS2322: Type '{ [P in keyof T]: T[P]; }' is not assignable to type '{ [P in keyof U]: U[P]; }'. !!! error TS2322: Type 'keyof U' is not assignable to type 'keyof T'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'keyof T'. +!!! error TS2322: Type 'string' is not assignable to type 'keyof T'. } function f73(x: { [P in K]: T[P] }, y: { [P in keyof T]: T[P] }) { @@ -280,6 +288,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS ~ !!! error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in keyof T]: T[P]; }'. !!! error TS2322: Type 'keyof T' is not assignable to type 'K'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'K'. +!!! error TS2322: Type 'string' is not assignable to type 'K'. } function f74(x: { [P in K]: T[P] }, y: { [P in keyof U]: U[P] }) { @@ -288,6 +298,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS ~ !!! error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in keyof U]: U[P]; }'. !!! error TS2322: Type 'keyof U' is not assignable to type 'K'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'K'. +!!! error TS2322: Type 'string' is not assignable to type 'K'. } function f75(x: { [P in K]: T[P] }, y: { [P in keyof T]: U[P] }) { @@ -296,6 +308,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS ~ !!! error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in keyof T]: U[P]; }'. !!! error TS2322: Type 'keyof T' is not assignable to type 'K'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'K'. +!!! error TS2322: Type 'string' is not assignable to type 'K'. } function f76(x: { [P in K]: T[P] }, y: { [P in K]: U[P] }) { diff --git a/tests/baselines/reference/mappedTypeWithAny.types b/tests/baselines/reference/mappedTypeWithAny.types index 36fad9140cc..6bf62c9730c 100644 --- a/tests/baselines/reference/mappedTypeWithAny.types +++ b/tests/baselines/reference/mappedTypeWithAny.types @@ -11,7 +11,7 @@ type ItemMap = { [P in keyof T]: Item }; >Item : Item declare let x0: keyof any; ->x0 : string +>x0 : string | number | symbol declare let x1: { [P in any]: Item }; >x1 : { [x: string]: Item; } diff --git a/tests/baselines/reference/mappedTypes4.types b/tests/baselines/reference/mappedTypes4.types index c003765d517..7292e143b42 100644 --- a/tests/baselines/reference/mappedTypes4.types +++ b/tests/baselines/reference/mappedTypes4.types @@ -40,19 +40,19 @@ function boxify(obj: T): Boxified { >T : T for (let k in obj) { ->k : keyof T +>k : Extract >obj : T result[k] = { value: obj[k] }; ->result[k] = { value: obj[k] } : { value: T[keyof T]; } ->result[k] : Boxified[keyof T] +>result[k] = { value: obj[k] } : { value: T[Extract]; } +>result[k] : Boxified[Extract] >result : Boxified ->k : keyof T ->{ value: obj[k] } : { value: T[keyof T]; } ->value : T[keyof T] ->obj[k] : T[keyof T] +>k : Extract +>{ value: obj[k] } : { value: T[Extract]; } +>value : T[Extract] +>obj[k] : T[Extract] >obj : T ->k : keyof T +>k : Extract } return result; >result : Boxified diff --git a/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt b/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt index 82bc36819a5..4c758633a26 100644 --- a/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt +++ b/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.errors.txt @@ -1,12 +1,14 @@ error TS2318: Cannot find global type 'Boolean'. error TS2318: Cannot find global type 'IArguments'. error TS2318: Cannot find global type 'Number'. +error TS2318: Cannot find global type 'Object'. tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.ts(3,12): error TS2693: 'Array' only refers to a type, but is being used as a value here. !!! error TS2318: Cannot find global type 'Boolean'. !!! error TS2318: Cannot find global type 'IArguments'. !!! error TS2318: Cannot find global type 'Number'. +!!! error TS2318: Cannot find global type 'Object'. ==== tests/cases/compiler/modularizeLibrary_ErrorFromUsingES6ArrayWithOnlyES6ArrayLib.ts (1 errors) ==== // Error missing basic JavaScript objects function f(x: number, y: number, z: number) { diff --git a/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.types b/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.types index 834449a5a82..6081b16c835 100644 --- a/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.types +++ b/tests/baselines/reference/modularizeLibrary_ErrorFromUsingES6FeaturesWithOnlyES5Lib.types @@ -80,9 +80,9 @@ var o = { }; o.hasOwnProperty(Symbol.hasInstance); >o.hasOwnProperty(Symbol.hasInstance) : boolean ->o.hasOwnProperty : (v: string) => boolean +>o.hasOwnProperty : (v: string | number | symbol) => boolean >o : { a: number; [Symbol.hasInstance](value: any): boolean; } ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >Symbol.hasInstance : any >Symbol : any >hasInstance : any diff --git a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.symbols b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.symbols index d99084339dd..d3cd86ccfe4 100644 --- a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.symbols +++ b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.symbols @@ -100,9 +100,9 @@ var o = { } }; o.hasOwnProperty(Symbol.hasInstance); ->o.hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>o.hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es5.d.ts, --, --)) >o : Symbol(o, Decl(modularizeLibrary_NoErrorDuplicateLibOptions1.ts, 38, 3)) ->hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es5.d.ts, --, --)) >Symbol.hasInstance : Symbol(SymbolConstructor.hasInstance, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) >hasInstance : Symbol(SymbolConstructor.hasInstance, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) diff --git a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.types b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.types index 78e6a6bc3f5..4fdc3764e88 100644 --- a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.types +++ b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.types @@ -124,9 +124,9 @@ var o = { }; o.hasOwnProperty(Symbol.hasInstance); >o.hasOwnProperty(Symbol.hasInstance) : boolean ->o.hasOwnProperty : { (v: PropertyKey): boolean; (v: string): boolean; } +>o.hasOwnProperty : (v: string | number | symbol) => boolean >o : { a: number; [Symbol.hasInstance](value: any): boolean; } ->hasOwnProperty : { (v: PropertyKey): boolean; (v: string): boolean; } +>hasOwnProperty : (v: string | number | symbol) => boolean >Symbol.hasInstance : symbol >Symbol : SymbolConstructor >hasInstance : symbol diff --git a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.symbols b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.symbols index 5bb813f5c32..0450449ba64 100644 --- a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.symbols +++ b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.symbols @@ -100,9 +100,9 @@ var o = { } }; o.hasOwnProperty(Symbol.hasInstance); ->o.hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>o.hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es5.d.ts, --, --)) >o : Symbol(o, Decl(modularizeLibrary_NoErrorDuplicateLibOptions2.ts, 38, 3)) ->hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es5.d.ts, --, --)) >Symbol.hasInstance : Symbol(SymbolConstructor.hasInstance, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) >hasInstance : Symbol(SymbolConstructor.hasInstance, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) diff --git a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.types b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.types index 4aabae824ee..8c3ad5b55af 100644 --- a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.types +++ b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.types @@ -124,9 +124,9 @@ var o = { }; o.hasOwnProperty(Symbol.hasInstance); >o.hasOwnProperty(Symbol.hasInstance) : boolean ->o.hasOwnProperty : { (v: PropertyKey): boolean; (v: string): boolean; } +>o.hasOwnProperty : (v: string | number | symbol) => boolean >o : { a: number; [Symbol.hasInstance](value: any): boolean; } ->hasOwnProperty : { (v: PropertyKey): boolean; (v: string): boolean; } +>hasOwnProperty : (v: string | number | symbol) => boolean >Symbol.hasInstance : symbol >Symbol : SymbolConstructor >hasInstance : symbol diff --git a/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.symbols b/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.symbols index c3c24d4690e..3793215b9e2 100644 --- a/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.symbols +++ b/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.symbols @@ -100,9 +100,9 @@ var o = { } }; o.hasOwnProperty(Symbol.hasInstance); ->o.hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>o.hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es5.d.ts, --, --)) >o : Symbol(o, Decl(modularizeLibrary_TargetES5UsingES6Lib.ts, 38, 3)) ->hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es5.d.ts, --, --)) >Symbol.hasInstance : Symbol(SymbolConstructor.hasInstance, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) >hasInstance : Symbol(SymbolConstructor.hasInstance, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) diff --git a/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.types b/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.types index 2782c70ebd9..df4e231ba80 100644 --- a/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.types +++ b/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.types @@ -124,9 +124,9 @@ var o = { }; o.hasOwnProperty(Symbol.hasInstance); >o.hasOwnProperty(Symbol.hasInstance) : boolean ->o.hasOwnProperty : { (v: PropertyKey): boolean; (v: string): boolean; } +>o.hasOwnProperty : (v: string | number | symbol) => boolean >o : { a: number; [Symbol.hasInstance](value: any): boolean; } ->hasOwnProperty : { (v: PropertyKey): boolean; (v: string): boolean; } +>hasOwnProperty : (v: string | number | symbol) => boolean >Symbol.hasInstance : symbol >Symbol : SymbolConstructor >hasInstance : symbol diff --git a/tests/baselines/reference/modularizeLibrary_TargetES6UsingES6Lib.symbols b/tests/baselines/reference/modularizeLibrary_TargetES6UsingES6Lib.symbols index ba9dd82df1e..2275ddb55ff 100644 --- a/tests/baselines/reference/modularizeLibrary_TargetES6UsingES6Lib.symbols +++ b/tests/baselines/reference/modularizeLibrary_TargetES6UsingES6Lib.symbols @@ -65,9 +65,9 @@ var o = { } }; o.hasOwnProperty(Symbol.hasInstance); ->o.hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>o.hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es5.d.ts, --, --)) >o : Symbol(o, Decl(modularizeLibrary_TargetES6UsingES6Lib.ts, 21, 3)) ->hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>hasOwnProperty : Symbol(Object.hasOwnProperty, Decl(lib.es5.d.ts, --, --)) >Symbol.hasInstance : Symbol(SymbolConstructor.hasInstance, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) >hasInstance : Symbol(SymbolConstructor.hasInstance, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) diff --git a/tests/baselines/reference/modularizeLibrary_TargetES6UsingES6Lib.types b/tests/baselines/reference/modularizeLibrary_TargetES6UsingES6Lib.types index 9c0f81701dc..1902ac93f05 100644 --- a/tests/baselines/reference/modularizeLibrary_TargetES6UsingES6Lib.types +++ b/tests/baselines/reference/modularizeLibrary_TargetES6UsingES6Lib.types @@ -79,9 +79,9 @@ var o = { }; o.hasOwnProperty(Symbol.hasInstance); >o.hasOwnProperty(Symbol.hasInstance) : boolean ->o.hasOwnProperty : { (v: string): boolean; (v: PropertyKey): boolean; } +>o.hasOwnProperty : (v: string | number | symbol) => boolean >o : { a: number; [Symbol.hasInstance](value: any): boolean; } ->hasOwnProperty : { (v: string): boolean; (v: PropertyKey): boolean; } +>hasOwnProperty : (v: string | number | symbol) => boolean >Symbol.hasInstance : symbol >Symbol : SymbolConstructor >hasInstance : symbol diff --git a/tests/baselines/reference/modularizeLibrary_UsingES5LibAndES6FeatureLibs.types b/tests/baselines/reference/modularizeLibrary_UsingES5LibAndES6FeatureLibs.types index ab24aaf12ba..e9213203637 100644 --- a/tests/baselines/reference/modularizeLibrary_UsingES5LibAndES6FeatureLibs.types +++ b/tests/baselines/reference/modularizeLibrary_UsingES5LibAndES6FeatureLibs.types @@ -16,10 +16,10 @@ var p = new Proxy(t, {}); >{} : {} Reflect.ownKeys({}); ->Reflect.ownKeys({}) : PropertyKey[] ->Reflect.ownKeys : (target: object) => PropertyKey[] +>Reflect.ownKeys({}) : (string | number | symbol)[] +>Reflect.ownKeys : (target: object) => (string | number | symbol)[] >Reflect : typeof Reflect ->ownKeys : (target: object) => PropertyKey[] +>ownKeys : (target: object) => (string | number | symbol)[] >{} : {} function* idGen() { diff --git a/tests/baselines/reference/moduleExportWithExportPropertyAssignment4.symbols b/tests/baselines/reference/moduleExportWithExportPropertyAssignment4.symbols index b62a68c83f3..e7cbcfa0828 100644 --- a/tests/baselines/reference/moduleExportWithExportPropertyAssignment4.symbols +++ b/tests/baselines/reference/moduleExportWithExportPropertyAssignment4.symbols @@ -13,14 +13,14 @@ mod1.justExport.toFixed() >toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) mod1.bothBefore.toFixed() // error ->mod1.bothBefore : Symbol(bothBefore) +>mod1.bothBefore : Symbol(A.bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0)) >mod1 : Symbol(mod1, Decl(a.js, 1, 3)) ->bothBefore : Symbol(bothBefore) +>bothBefore : Symbol(A.bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0)) mod1.bothAfter.toFixed() ->mod1.bothAfter : Symbol(bothAfter) +>mod1.bothAfter : Symbol(A.bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1)) >mod1 : Symbol(mod1, Decl(a.js, 1, 3)) ->bothAfter : Symbol(bothAfter) +>bothAfter : Symbol(A.bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1)) mod1.justProperty.length >mod1.justProperty.length : Symbol(String.length, Decl(lib.d.ts, --, --)) @@ -41,10 +41,10 @@ declare function require(name: string): any; === tests/cases/conformance/salsa/mod1.js === /// module.exports.bothBefore = 'string' ->module.exports : Symbol(bothBefore, Decl(mod1.js, 0, 0)) +>module.exports : Symbol(A.bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0)) >module : Symbol(module, Decl(requires.d.ts, 0, 11)) >exports : Symbol(exports, Decl(requires.d.ts, 0, 21)) ->bothBefore : Symbol(bothBefore, Decl(mod1.js, 0, 0)) +>bothBefore : Symbol(A.bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0)) A.justExport = 4 >A.justExport : Symbol(A.justExport, Decl(mod1.js, 1, 36)) @@ -74,10 +74,10 @@ function A() { >p : Symbol(A.p, Decl(mod1.js, 6, 14)) } module.exports.bothAfter = 'string' ->module.exports : Symbol(bothAfter, Decl(mod1.js, 8, 1)) +>module.exports : Symbol(A.bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1)) >module : Symbol(module, Decl(requires.d.ts, 0, 11)) >exports : Symbol(exports, Decl(requires.d.ts, 0, 21)) ->bothAfter : Symbol(bothAfter, Decl(mod1.js, 8, 1)) +>bothAfter : Symbol(A.bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1)) module.exports.justProperty = 'string' >module.exports : Symbol(justProperty, Decl(mod1.js, 9, 35)) diff --git a/tests/baselines/reference/numberPropertyAccess.types b/tests/baselines/reference/numberPropertyAccess.types index e7ffcbc246d..b2baf38873c 100644 --- a/tests/baselines/reference/numberPropertyAccess.types +++ b/tests/baselines/reference/numberPropertyAccess.types @@ -13,9 +13,9 @@ var a = x.toExponential(); var b = x.hasOwnProperty('toFixed'); >b : boolean >x.hasOwnProperty('toFixed') : boolean ->x.hasOwnProperty : (v: string) => boolean +>x.hasOwnProperty : (v: string | number | symbol) => boolean >x : number ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >'toFixed' : "toFixed" var c = x['toExponential'](); @@ -28,7 +28,7 @@ var c = x['toExponential'](); var d = x['hasOwnProperty']('toFixed'); >d : boolean >x['hasOwnProperty']('toFixed') : boolean ->x['hasOwnProperty'] : (v: string) => boolean +>x['hasOwnProperty'] : (v: string | number | symbol) => boolean >x : number >'hasOwnProperty' : "hasOwnProperty" >'toFixed' : "toFixed" diff --git a/tests/baselines/reference/objectLitGetterSetter.types b/tests/baselines/reference/objectLitGetterSetter.types index c2ce173e029..05c748162d9 100644 --- a/tests/baselines/reference/objectLitGetterSetter.types +++ b/tests/baselines/reference/objectLitGetterSetter.types @@ -5,9 +5,9 @@ Object.defineProperty(obj, "accProperty", ({ >Object.defineProperty(obj, "accProperty", ({ get: function () { eval("public = 1;"); return 11; }, set: function (v) { } })) : any ->Object.defineProperty : (o: any, p: string, attributes: PropertyDescriptor & ThisType) => any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any >Object : ObjectConstructor ->defineProperty : (o: any, p: string, attributes: PropertyDescriptor & ThisType) => any +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any >obj : {} >"accProperty" : "accProperty" >({ get: function () { eval("public = 1;"); return 11; }, set: function (v) { } }) : PropertyDescriptor diff --git a/tests/baselines/reference/objectLiteralNormalization.symbols b/tests/baselines/reference/objectLiteralNormalization.symbols index 69882d81f76..416065ee5c9 100644 --- a/tests/baselines/reference/objectLiteralNormalization.symbols +++ b/tests/baselines/reference/objectLiteralNormalization.symbols @@ -15,14 +15,14 @@ a1.a; // number >a : Symbol(a, Decl(objectLiteralNormalization.ts, 1, 11), Decl(objectLiteralNormalization.ts, 1, 21), Decl(objectLiteralNormalization.ts, 1, 39)) a1.b; // string | undefined ->a1.b : Symbol(b, Decl(objectLiteralNormalization.ts, 1, 27), Decl(objectLiteralNormalization.ts, 1, 45)) +>a1.b : Symbol(b, Decl(objectLiteralNormalization.ts, 1, 45), Decl(objectLiteralNormalization.ts, 1, 27), Decl(objectLiteralNormalization.ts, 1, 45)) >a1 : Symbol(a1, Decl(objectLiteralNormalization.ts, 1, 3)) ->b : Symbol(b, Decl(objectLiteralNormalization.ts, 1, 27), Decl(objectLiteralNormalization.ts, 1, 45)) +>b : Symbol(b, Decl(objectLiteralNormalization.ts, 1, 45), Decl(objectLiteralNormalization.ts, 1, 27), Decl(objectLiteralNormalization.ts, 1, 45)) a1.c; // boolean | undefined ->a1.c : Symbol(c, Decl(objectLiteralNormalization.ts, 1, 53)) +>a1.c : Symbol(c, Decl(objectLiteralNormalization.ts, 1, 53), Decl(objectLiteralNormalization.ts, 1, 53)) >a1 : Symbol(a1, Decl(objectLiteralNormalization.ts, 1, 3)) ->c : Symbol(c, Decl(objectLiteralNormalization.ts, 1, 53)) +>c : Symbol(c, Decl(objectLiteralNormalization.ts, 1, 53), Decl(objectLiteralNormalization.ts, 1, 53)) a1 = { a: 1 }; >a1 : Symbol(a1, Decl(objectLiteralNormalization.ts, 1, 3)) @@ -48,14 +48,14 @@ let a2 = [{ a: 1, b: 2 }, { a: "abc" }, {}][0]; >a : Symbol(a, Decl(objectLiteralNormalization.ts, 10, 27)) a2.a; // string | number | undefined ->a2.a : Symbol(a, Decl(objectLiteralNormalization.ts, 10, 11), Decl(objectLiteralNormalization.ts, 10, 27)) +>a2.a : Symbol(a, Decl(objectLiteralNormalization.ts, 10, 11), Decl(objectLiteralNormalization.ts, 10, 27), Decl(objectLiteralNormalization.ts, 10, 27)) >a2 : Symbol(a2, Decl(objectLiteralNormalization.ts, 10, 3)) ->a : Symbol(a, Decl(objectLiteralNormalization.ts, 10, 11), Decl(objectLiteralNormalization.ts, 10, 27)) +>a : Symbol(a, Decl(objectLiteralNormalization.ts, 10, 11), Decl(objectLiteralNormalization.ts, 10, 27), Decl(objectLiteralNormalization.ts, 10, 27)) a2.b; // number | undefined ->a2.b : Symbol(b, Decl(objectLiteralNormalization.ts, 10, 17)) +>a2.b : Symbol(b, Decl(objectLiteralNormalization.ts, 10, 17), Decl(objectLiteralNormalization.ts, 1, 45)) >a2 : Symbol(a2, Decl(objectLiteralNormalization.ts, 10, 3)) ->b : Symbol(b, Decl(objectLiteralNormalization.ts, 10, 17)) +>b : Symbol(b, Decl(objectLiteralNormalization.ts, 10, 17), Decl(objectLiteralNormalization.ts, 1, 45)) a2 = { a: 10, b: 20 }; >a2 : Symbol(a2, Decl(objectLiteralNormalization.ts, 10, 3)) @@ -144,32 +144,32 @@ d1.pos; >pos : Symbol(pos, Decl(objectLiteralNormalization.ts, 33, 22), Decl(objectLiteralNormalization.ts, 33, 58)) d1.pos.x; ->d1.pos.x : Symbol(x, Decl(objectLiteralNormalization.ts, 33, 29)) +>d1.pos.x : Symbol(x, Decl(objectLiteralNormalization.ts, 33, 29), Decl(objectLiteralNormalization.ts, 33, 29)) >d1.pos : Symbol(pos, Decl(objectLiteralNormalization.ts, 33, 22), Decl(objectLiteralNormalization.ts, 33, 58)) >d1 : Symbol(d1, Decl(objectLiteralNormalization.ts, 33, 3)) >pos : Symbol(pos, Decl(objectLiteralNormalization.ts, 33, 22), Decl(objectLiteralNormalization.ts, 33, 58)) ->x : Symbol(x, Decl(objectLiteralNormalization.ts, 33, 29)) +>x : Symbol(x, Decl(objectLiteralNormalization.ts, 33, 29), Decl(objectLiteralNormalization.ts, 33, 29)) d1.pos.y; ->d1.pos.y : Symbol(y, Decl(objectLiteralNormalization.ts, 33, 35)) +>d1.pos.y : Symbol(y, Decl(objectLiteralNormalization.ts, 33, 35), Decl(objectLiteralNormalization.ts, 33, 35)) >d1.pos : Symbol(pos, Decl(objectLiteralNormalization.ts, 33, 22), Decl(objectLiteralNormalization.ts, 33, 58)) >d1 : Symbol(d1, Decl(objectLiteralNormalization.ts, 33, 3)) >pos : Symbol(pos, Decl(objectLiteralNormalization.ts, 33, 22), Decl(objectLiteralNormalization.ts, 33, 58)) ->y : Symbol(y, Decl(objectLiteralNormalization.ts, 33, 35)) +>y : Symbol(y, Decl(objectLiteralNormalization.ts, 33, 35), Decl(objectLiteralNormalization.ts, 33, 35)) d1.pos.a; ->d1.pos.a : Symbol(a, Decl(objectLiteralNormalization.ts, 33, 73)) +>d1.pos.a : Symbol(a, Decl(objectLiteralNormalization.ts, 10, 27), Decl(objectLiteralNormalization.ts, 33, 73)) >d1.pos : Symbol(pos, Decl(objectLiteralNormalization.ts, 33, 22), Decl(objectLiteralNormalization.ts, 33, 58)) >d1 : Symbol(d1, Decl(objectLiteralNormalization.ts, 33, 3)) >pos : Symbol(pos, Decl(objectLiteralNormalization.ts, 33, 22), Decl(objectLiteralNormalization.ts, 33, 58)) ->a : Symbol(a, Decl(objectLiteralNormalization.ts, 33, 73)) +>a : Symbol(a, Decl(objectLiteralNormalization.ts, 10, 27), Decl(objectLiteralNormalization.ts, 33, 73)) d1.pos.b; ->d1.pos.b : Symbol(b, Decl(objectLiteralNormalization.ts, 33, 86)) +>d1.pos.b : Symbol(b, Decl(objectLiteralNormalization.ts, 1, 45), Decl(objectLiteralNormalization.ts, 33, 86)) >d1.pos : Symbol(pos, Decl(objectLiteralNormalization.ts, 33, 22), Decl(objectLiteralNormalization.ts, 33, 58)) >d1 : Symbol(d1, Decl(objectLiteralNormalization.ts, 33, 3)) >pos : Symbol(pos, Decl(objectLiteralNormalization.ts, 33, 22), Decl(objectLiteralNormalization.ts, 33, 58)) ->b : Symbol(b, Decl(objectLiteralNormalization.ts, 33, 86)) +>b : Symbol(b, Decl(objectLiteralNormalization.ts, 1, 45), Decl(objectLiteralNormalization.ts, 33, 86)) declare function f(...items: T[]): T; >f : Symbol(f, Decl(objectLiteralNormalization.ts, 39, 9)) diff --git a/tests/baselines/reference/objectTypeHidingMembersOfExtendedObject.errors.txt b/tests/baselines/reference/objectTypeHidingMembersOfExtendedObject.errors.txt index 19c12ebf62f..4f27c62e67d 100644 --- a/tests/baselines/reference/objectTypeHidingMembersOfExtendedObject.errors.txt +++ b/tests/baselines/reference/objectTypeHidingMembersOfExtendedObject.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'constructor' of type 'Function' is not assignable to string index type 'Object'. tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'data' of type 'A' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'hasOwnProperty' of type '(v: string) => boolean' is not assignable to string index type 'Object'. +tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'propertyIsEnumerable' of type '(v: string) => boolean' is not assignable to string index type 'Object'. +tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to string index type 'Object'. tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'toString' of type '() => string' is not assignable to string index type 'Object'. tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts(11,5): error TS2411: Property 'valueOf' of type '() => Object' is not assignable to string index type 'Object'. @@ -25,11 +25,11 @@ tests/cases/conformance/types/members/objectTypeHidingMembersOfExtendedObject.ts ~~~~~~~~~~~~~~~~~~~~ !!! error TS2411: Property 'data' of type 'A' is not assignable to string index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'hasOwnProperty' of type '(v: string) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ !!! error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to string index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'propertyIsEnumerable' of type '(v: string) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ !!! error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to string index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/objectTypeWithStringIndexerHidingObjectIndexer.errors.txt b/tests/baselines/reference/objectTypeWithStringIndexerHidingObjectIndexer.errors.txt index d09701c3b06..2fadffd195d 100644 --- a/tests/baselines/reference/objectTypeWithStringIndexerHidingObjectIndexer.errors.txt +++ b/tests/baselines/reference/objectTypeWithStringIndexerHidingObjectIndexer.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'constructor' of type 'Function' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'hasOwnProperty' of type '(v: string) => boolean' is not assignable to string index type 'Object'. +tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to string index type 'Object'. -tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'propertyIsEnumerable' of type '(v: string) => boolean' is not assignable to string index type 'Object'. +tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to string index type 'Object'. tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'toString' of type '() => string' is not assignable to string index type 'Object'. tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectIndexer.ts(5,5): error TS2411: Property 'valueOf' of type '() => Object' is not assignable to string index type 'Object'. @@ -16,11 +16,11 @@ tests/cases/conformance/types/members/objectTypeWithStringIndexerHidingObjectInd ~~~~~~~~~~~~~~~~~~~~ !!! error TS2411: Property 'constructor' of type 'Function' is not assignable to string index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'hasOwnProperty' of type '(v: string) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'hasOwnProperty' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ !!! error TS2411: Property 'isPrototypeOf' of type '(v: Object) => boolean' is not assignable to string index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'propertyIsEnumerable' of type '(v: string) => boolean' is not assignable to string index type 'Object'. +!!! error TS2411: Property 'propertyIsEnumerable' of type '(v: string | number | symbol) => boolean' is not assignable to string index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ !!! error TS2411: Property 'toLocaleString' of type '() => string' is not assignable to string index type 'Object'. ~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/parserComputedPropertyName41.types b/tests/baselines/reference/parserComputedPropertyName41.types index 897c4252f26..071ee36e18f 100644 --- a/tests/baselines/reference/parserComputedPropertyName41.types +++ b/tests/baselines/reference/parserComputedPropertyName41.types @@ -1,7 +1,7 @@ === tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName41.ts === var v = { ->v : { [x: string]: boolean; } ->{ [0 in []]: true} : { [x: string]: boolean; } +>v : {} +>{ [0 in []]: true} : {} [0 in []]: true >[0 in []] : boolean diff --git a/tests/baselines/reference/parserUsingConstructorAsIdentifier.types b/tests/baselines/reference/parserUsingConstructorAsIdentifier.types index fa5e60a12b8..d0cd25f887d 100644 --- a/tests/baselines/reference/parserUsingConstructorAsIdentifier.types +++ b/tests/baselines/reference/parserUsingConstructorAsIdentifier.types @@ -90,9 +90,9 @@ Object.defineProperty(constructor.prototype, "constructor", { value: constructor, writable: true, configurable: true, enumerable: true }); >Object.defineProperty(constructor.prototype, "constructor", { value: constructor, writable: true, configurable: true, enumerable: true }) : any ->Object.defineProperty : (o: any, p: string, attributes: PropertyDescriptor & ThisType) => any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any >Object : ObjectConstructor ->defineProperty : (o: any, p: string, attributes: PropertyDescriptor & ThisType) => any +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any >constructor.prototype : any >constructor : any >prototype : any diff --git a/tests/baselines/reference/parserharness.types b/tests/baselines/reference/parserharness.types index 505cfe67c82..cc8bae97706 100644 --- a/tests/baselines/reference/parserharness.types +++ b/tests/baselines/reference/parserharness.types @@ -2810,11 +2810,11 @@ module Harness { if (this.fileCollection.hasOwnProperty(p)) { >this.fileCollection.hasOwnProperty(p) : boolean ->this.fileCollection.hasOwnProperty : (v: string) => boolean +>this.fileCollection.hasOwnProperty : (v: string | number | symbol) => boolean >this.fileCollection : {} >this : this >fileCollection : {} ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >p : string var current = this.fileCollection[p]; diff --git a/tests/baselines/reference/propertyAccess.types b/tests/baselines/reference/propertyAccess.types index 983718ee1fd..82af3d51316 100644 --- a/tests/baselines/reference/propertyAccess.types +++ b/tests/baselines/reference/propertyAccess.types @@ -139,10 +139,10 @@ var aa = obj.x; // Dotted property access of property that exists on value's apparent type var bb = obj.hasOwnProperty; ->bb : (v: string) => boolean ->obj.hasOwnProperty : (v: string) => boolean +>bb : (v: string | number | symbol) => boolean +>obj.hasOwnProperty : (v: string | number | symbol) => boolean >obj : { 10: string; x: string; y: number; z: { n: string; m: number; o: () => boolean; }; 'literal property': number; } ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean // Dotted property access of property that doesn't exist on value's apparent type var cc = obj.qqq; // error diff --git a/tests/baselines/reference/recursiveTypeRelations.errors.txt b/tests/baselines/reference/recursiveTypeRelations.errors.txt index f29d5742185..8c5596958c3 100644 --- a/tests/baselines/reference/recursiveTypeRelations.errors.txt +++ b/tests/baselines/reference/recursiveTypeRelations.errors.txt @@ -6,7 +6,7 @@ tests/cases/compiler/recursiveTypeRelations.ts(27,61): error TS2304: Cannot find ==== tests/cases/compiler/recursiveTypeRelations.ts (3 errors) ==== // Repro from #14896 - type Attributes = { + type Attributes = { [Key in Keys]: string; } diff --git a/tests/baselines/reference/recursiveTypeRelations.js b/tests/baselines/reference/recursiveTypeRelations.js index c477ecf1294..9c0887ab446 100644 --- a/tests/baselines/reference/recursiveTypeRelations.js +++ b/tests/baselines/reference/recursiveTypeRelations.js @@ -1,7 +1,7 @@ //// [recursiveTypeRelations.ts] // Repro from #14896 -type Attributes = { +type Attributes = { [Key in Keys]: string; } diff --git a/tests/baselines/reference/recursiveTypeRelations.symbols b/tests/baselines/reference/recursiveTypeRelations.symbols index 2c940df2487..39032cd2f94 100644 --- a/tests/baselines/reference/recursiveTypeRelations.symbols +++ b/tests/baselines/reference/recursiveTypeRelations.symbols @@ -1,7 +1,7 @@ === tests/cases/compiler/recursiveTypeRelations.ts === // Repro from #14896 -type Attributes = { +type Attributes = { >Attributes : Symbol(Attributes, Decl(recursiveTypeRelations.ts, 0, 0)) >Keys : Symbol(Keys, Decl(recursiveTypeRelations.ts, 2, 16)) diff --git a/tests/baselines/reference/recursiveTypeRelations.types b/tests/baselines/reference/recursiveTypeRelations.types index ce6d007d066..f3d56637b18 100644 --- a/tests/baselines/reference/recursiveTypeRelations.types +++ b/tests/baselines/reference/recursiveTypeRelations.types @@ -1,7 +1,7 @@ === tests/cases/compiler/recursiveTypeRelations.ts === // Repro from #14896 -type Attributes = { +type Attributes = { >Attributes : { [Key in Keys]: string; } >Keys : Keys @@ -97,7 +97,7 @@ export function css(styles: S, ...classNam if (typeof arg == "object") { >typeof arg == "object" : boolean >typeof arg : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function" ->arg : object & { [K in keyof S]?: boolean; } +>arg : keyof S | (object & { [K in keyof S]?: boolean; }) >"object" : "object" return Object.keys(arg).reduce((obj: ClassNameObject, key: keyof S) => { diff --git a/tests/baselines/reference/staticInstanceResolution2.types b/tests/baselines/reference/staticInstanceResolution2.types index 68abb3a08ce..e44f99d212f 100644 --- a/tests/baselines/reference/staticInstanceResolution2.types +++ b/tests/baselines/reference/staticInstanceResolution2.types @@ -4,9 +4,9 @@ class A { } A.hasOwnProperty('foo'); >A.hasOwnProperty('foo') : boolean ->A.hasOwnProperty : (v: string) => boolean +>A.hasOwnProperty : (v: string | number | symbol) => boolean >A : typeof A ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >'foo' : "foo" class B { @@ -16,9 +16,9 @@ class B { } B.hasOwnProperty('foo'); >B.hasOwnProperty('foo') : boolean ->B.hasOwnProperty : (v: string) => boolean +>B.hasOwnProperty : (v: string | number | symbol) => boolean >B : typeof B ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >'foo' : "foo" diff --git a/tests/baselines/reference/stringPropertyAccess.types b/tests/baselines/reference/stringPropertyAccess.types index fd2ec13da74..da8298178b6 100644 --- a/tests/baselines/reference/stringPropertyAccess.types +++ b/tests/baselines/reference/stringPropertyAccess.types @@ -14,9 +14,9 @@ var a = x.charAt(0); var b = x.hasOwnProperty('charAt'); >b : boolean >x.hasOwnProperty('charAt') : boolean ->x.hasOwnProperty : (v: string) => boolean +>x.hasOwnProperty : (v: string | number | symbol) => boolean >x : string ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >'charAt' : "charAt" var c = x['charAt'](0); @@ -30,7 +30,7 @@ var c = x['charAt'](0); var e = x['hasOwnProperty']('toFixed'); >e : boolean >x['hasOwnProperty']('toFixed') : boolean ->x['hasOwnProperty'] : (v: string) => boolean +>x['hasOwnProperty'] : (v: string | number | symbol) => boolean >x : string >'hasOwnProperty' : "hasOwnProperty" >'toFixed' : "toFixed" diff --git a/tests/baselines/reference/symbolProperty3.types b/tests/baselines/reference/symbolProperty3.types index df4707a207c..6975051d002 100644 --- a/tests/baselines/reference/symbolProperty3.types +++ b/tests/baselines/reference/symbolProperty3.types @@ -4,8 +4,8 @@ var s = Symbol; >Symbol : SymbolConstructor var x = { ->x : { [x: string]: number | (() => void); } ->{ [s]: 0, [s]() { }, get [s]() { return 0; }} : { [x: string]: number | (() => void); } +>x : {} +>{ [s]: 0, [s]() { }, get [s]() { return 0; }} : {} [s]: 0, >[s] : number diff --git a/tests/baselines/reference/symbolType1.symbols b/tests/baselines/reference/symbolType1.symbols index ded0dcff47b..98c6a263632 100644 --- a/tests/baselines/reference/symbolType1.symbols +++ b/tests/baselines/reference/symbolType1.symbols @@ -9,7 +9,7 @@ Symbol instanceof Symbol(); (Symbol() || {}) instanceof Object; // This one should be okay, it's a valid way of distinguishing types >Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) ->Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) Symbol instanceof (Symbol() || {}); >Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) diff --git a/tests/baselines/reference/typeGuardsTypeParameters.types b/tests/baselines/reference/typeGuardsTypeParameters.types index 13fb9965235..c508c92a979 100644 --- a/tests/baselines/reference/typeGuardsTypeParameters.types +++ b/tests/baselines/reference/typeGuardsTypeParameters.types @@ -80,19 +80,19 @@ function fun(item: { [P in keyof T]: T[P] }) { >[] : never[] for (const key in item) { ->key : keyof T +>key : Extract >item : { [P in keyof T]: T[P]; } const value = item[key]; ->value : { [P in keyof T]: T[P]; }[keyof T] ->item[key] : { [P in keyof T]: T[P]; }[keyof T] +>value : { [P in keyof T]: T[P]; }[Extract] +>item[key] : { [P in keyof T]: T[P]; }[Extract] >item : { [P in keyof T]: T[P]; } ->key : keyof T +>key : Extract if (typeof value === "string") { >typeof value === "string" : boolean >typeof value : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function" ->value : { [P in keyof T]: T[P]; }[keyof T] +>value : { [P in keyof T]: T[P]; }[Extract] >"string" : "string" strings.push(value); @@ -100,7 +100,7 @@ function fun(item: { [P in keyof T]: T[P] }) { >strings.push : (...items: string[]) => number >strings : string[] >push : (...items: string[]) => number ->value : { [P in keyof T]: T[P]; }[keyof T] & string +>value : { [P in keyof T]: T[P]; }[Extract] & string } } } diff --git a/tests/baselines/reference/typePredicateStructuralMatch.types b/tests/baselines/reference/typePredicateStructuralMatch.types index 9f7a129da15..c01f5f5b06a 100644 --- a/tests/baselines/reference/typePredicateStructuralMatch.types +++ b/tests/baselines/reference/typePredicateStructuralMatch.types @@ -46,9 +46,9 @@ function isResponseInData(value: T | { data: T}): value is { data: T } { return value.hasOwnProperty('data'); >value.hasOwnProperty('data') : boolean ->value.hasOwnProperty : (v: string) => boolean +>value.hasOwnProperty : (v: string | number | symbol) => boolean >value : T | { data: T; } ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >'data' : "data" } @@ -84,9 +84,9 @@ function isPlainResponse(value: T | { data: T}): value is T { return !value.hasOwnProperty('data'); >!value.hasOwnProperty('data') : boolean >value.hasOwnProperty('data') : boolean ->value.hasOwnProperty : (v: string) => boolean +>value.hasOwnProperty : (v: string | number | symbol) => boolean >value : T | { data: T; } ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >'data' : "data" } diff --git a/tests/baselines/reference/uniqueSymbols.types b/tests/baselines/reference/uniqueSymbols.types index 621d3df4236..55ce8d9c87e 100644 --- a/tests/baselines/reference/uniqueSymbols.types +++ b/tests/baselines/reference/uniqueSymbols.types @@ -402,8 +402,8 @@ const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNest // type argument inference const promiseForConstCall = Promise.resolve(constCall); ->promiseForConstCall : Promise ->Promise.resolve(constCall) : Promise +>promiseForConstCall : Promise +>Promise.resolve(constCall) : Promise >Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } >Promise : PromiseConstructor >resolve : { (value: T | PromiseLike): Promise; (): Promise; } @@ -454,19 +454,19 @@ declare function g(x: typeof N.s): void; // argument inference f(s); ->f(s) : symbol +>f(s) : unique symbol >f : (x: T) => T >s : unique symbol f(N.s); ->f(N.s) : symbol +>f(N.s) : unique symbol >f : (x: T) => T >N.s : unique symbol >N : typeof N >s : unique symbol f(N["s"]); ->f(N["s"]) : symbol +>f(N["s"]) : unique symbol >f : (x: T) => T >N["s"] : unique symbol >N : typeof N diff --git a/tests/baselines/reference/uniqueSymbolsDeclarations.js b/tests/baselines/reference/uniqueSymbolsDeclarations.js index 6b52b210977..728c507c747 100644 --- a/tests/baselines/reference/uniqueSymbolsDeclarations.js +++ b/tests/baselines/reference/uniqueSymbolsDeclarations.js @@ -482,7 +482,7 @@ declare const constInitToLReadonlyTypeWithTypeQuery: typeof l.readonlyType; declare const constInitToLReadonlyNestedTypeWithTypeQuery: typeof l.nested.readonlyNestedType; declare const constInitToLReadonlyTypeWithIndexedAccess: L["readonlyType"]; declare const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNestedType"]; -declare const promiseForConstCall: Promise; +declare const promiseForConstCall: Promise; declare const arrayOfConstCall: symbol[]; declare const s: unique symbol; declare namespace N { diff --git a/tests/baselines/reference/uniqueSymbolsDeclarations.types b/tests/baselines/reference/uniqueSymbolsDeclarations.types index a841354269f..6bfee5a0403 100644 --- a/tests/baselines/reference/uniqueSymbolsDeclarations.types +++ b/tests/baselines/reference/uniqueSymbolsDeclarations.types @@ -402,8 +402,8 @@ const constInitToLReadonlyNestedTypeWithIndexedAccess: L["nested"]["readonlyNest // type argument inference const promiseForConstCall = Promise.resolve(constCall); ->promiseForConstCall : Promise ->Promise.resolve(constCall) : Promise +>promiseForConstCall : Promise +>Promise.resolve(constCall) : Promise >Promise.resolve : { (value: T | PromiseLike): Promise; (): Promise; } >Promise : PromiseConstructor >resolve : { (value: T | PromiseLike): Promise; (): Promise; } @@ -454,19 +454,19 @@ declare function g(x: typeof N.s): void; // argument inference f(s); ->f(s) : symbol +>f(s) : unique symbol >f : (x: T) => T >s : unique symbol f(N.s); ->f(N.s) : symbol +>f(N.s) : unique symbol >f : (x: T) => T >N.s : unique symbol >N : typeof N >s : unique symbol f(N["s"]); ->f(N["s"]) : symbol +>f(N["s"]) : unique symbol >f : (x: T) => T >N["s"] : unique symbol >N : typeof N diff --git a/tests/baselines/reference/unspecializedConstraints.types b/tests/baselines/reference/unspecializedConstraints.types index f5d081968d9..4c3d0c00d0d 100644 --- a/tests/baselines/reference/unspecializedConstraints.types +++ b/tests/baselines/reference/unspecializedConstraints.types @@ -464,12 +464,12 @@ module ts { var hasOwnProperty = Object.prototype.hasOwnProperty; ->hasOwnProperty : (v: string) => boolean ->Object.prototype.hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean +>Object.prototype.hasOwnProperty : (v: string | number | symbol) => boolean >Object.prototype : Object >Object : ObjectConstructor >prototype : Object ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean function getProperty(map: Map, key: string): T { >getProperty : (map: Map, key: string) => T @@ -484,7 +484,7 @@ module ts { >!hasOwnProperty.call(map, key) : boolean >hasOwnProperty.call(map, key) : any >hasOwnProperty.call : (this: Function, thisArg: any, ...argArray: any[]) => any ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >call : (this: Function, thisArg: any, ...argArray: any[]) => any >map : Map >key : string @@ -507,7 +507,7 @@ module ts { return hasOwnProperty.call(map, key); >hasOwnProperty.call(map, key) : any >hasOwnProperty.call : (this: Function, thisArg: any, ...argArray: any[]) => any ->hasOwnProperty : (v: string) => boolean +>hasOwnProperty : (v: string | number | symbol) => boolean >call : (this: Function, thisArg: any, ...argArray: any[]) => any >map : Map >key : string diff --git a/tests/baselines/reference/useObjectValuesAndEntries3.symbols b/tests/baselines/reference/useObjectValuesAndEntries3.symbols index 65d5175eaa6..51f2b14cc93 100644 --- a/tests/baselines/reference/useObjectValuesAndEntries3.symbols +++ b/tests/baselines/reference/useObjectValuesAndEntries3.symbols @@ -6,7 +6,7 @@ var o = { a: 1, b: 2 }; for (var x of Object.values(o)) { >x : Symbol(x, Decl(useObjectValuesAndEntries3.ts, 2, 8)) ->Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >o : Symbol(o, Decl(useObjectValuesAndEntries3.ts, 0, 3)) let y = x; @@ -16,6 +16,6 @@ for (var x of Object.values(o)) { var entries = Object.entries(o); >entries : Symbol(entries, Decl(useObjectValuesAndEntries3.ts, 6, 3)) ->Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >o : Symbol(o, Decl(useObjectValuesAndEntries3.ts, 0, 3)) diff --git a/tests/baselines/reference/useObjectValuesAndEntries4.symbols b/tests/baselines/reference/useObjectValuesAndEntries4.symbols index adef865c04c..8c087361e7d 100644 --- a/tests/baselines/reference/useObjectValuesAndEntries4.symbols +++ b/tests/baselines/reference/useObjectValuesAndEntries4.symbols @@ -7,7 +7,7 @@ var o = { a: 1, b: 2 }; for (var x of Object.values(o)) { >x : Symbol(x, Decl(useObjectValuesAndEntries4.ts, 2, 8)) >Object.values : Symbol(ObjectConstructor.values, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) ->Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >values : Symbol(ObjectConstructor.values, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) >o : Symbol(o, Decl(useObjectValuesAndEntries4.ts, 0, 3)) @@ -19,7 +19,7 @@ for (var x of Object.values(o)) { var entries = Object.entries(o); >entries : Symbol(entries, Decl(useObjectValuesAndEntries4.ts, 6, 3)) >Object.entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) ->Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >entries : Symbol(ObjectConstructor.entries, Decl(lib.es2017.object.d.ts, --, --), Decl(lib.es2017.object.d.ts, --, --)) >o : Symbol(o, Decl(useObjectValuesAndEntries4.ts, 0, 3)) diff --git a/tests/cases/compiler/aliasDoesNotDuplicateSignatures.ts b/tests/cases/compiler/aliasDoesNotDuplicateSignatures.ts new file mode 100644 index 00000000000..fcae45f3dc1 --- /dev/null +++ b/tests/cases/compiler/aliasDoesNotDuplicateSignatures.ts @@ -0,0 +1,13 @@ +// @filename: demo.d.ts +declare namespace demoNS { + function f(): void; +} +declare module 'demoModule' { + import alias = demoNS; + export = alias; +} +// @filename: user.ts +import { f } from 'demoModule'; +// Assign an incorrect type here to see the type of 'f'. +let x1: string = demoNS.f; +let x2: string = f; \ No newline at end of file diff --git a/tests/cases/compiler/commonJsImportClassExpression.ts b/tests/cases/compiler/commonJsImportClassExpression.ts new file mode 100644 index 00000000000..1cd856d4b1b --- /dev/null +++ b/tests/cases/compiler/commonJsImportClassExpression.ts @@ -0,0 +1,9 @@ +// @Filename: mod1.ts +export = class { + chunk = 1 +} + +// @Filename: use.ts +import Chunk = require('./mod1') +declare var c: Chunk; +c.chunk; diff --git a/tests/cases/compiler/deeplyNestedCheck.ts b/tests/cases/compiler/deeplyNestedCheck.ts index e95233af985..366599be966 100644 --- a/tests/cases/compiler/deeplyNestedCheck.ts +++ b/tests/cases/compiler/deeplyNestedCheck.ts @@ -5,5 +5,5 @@ interface DataSnapshot { } interface Snapshot extends DataSnapshot { - child(path: U): Snapshot; + child>(path: U): Snapshot; } diff --git a/tests/cases/compiler/deferredLookupTypeResolution.ts b/tests/cases/compiler/deferredLookupTypeResolution.ts index 6c9853266ad..2970540afbd 100644 --- a/tests/cases/compiler/deferredLookupTypeResolution.ts +++ b/tests/cases/compiler/deferredLookupTypeResolution.ts @@ -8,7 +8,7 @@ type StringContains = ( { [key: string]: 'false' } )[L] -type ObjectHasKey = StringContains +type ObjectHasKey = StringContains, L> type First = ObjectHasKey; // Should be deferred diff --git a/tests/cases/compiler/deferredLookupTypeResolution2.ts b/tests/cases/compiler/deferredLookupTypeResolution2.ts index 4aa18c092ba..6b8a161e6df 100644 --- a/tests/cases/compiler/deferredLookupTypeResolution2.ts +++ b/tests/cases/compiler/deferredLookupTypeResolution2.ts @@ -5,7 +5,7 @@ type StringContains = ({ [K in S]: 'true' } & { [key: string]: 'false'})[L]; -type ObjectHasKey = StringContains; +type ObjectHasKey = StringContains, L>; type A = ObjectHasKey; diff --git a/tests/cases/compiler/indexedAccessRetainsIndexSignature.ts b/tests/cases/compiler/indexedAccessRetainsIndexSignature.ts index d23cbe87ddf..11abf771edc 100644 --- a/tests/cases/compiler/indexedAccessRetainsIndexSignature.ts +++ b/tests/cases/compiler/indexedAccessRetainsIndexSignature.ts @@ -1,4 +1,4 @@ -type Diff = +type Diff = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T] type Omit = Pick> type Omit1 = Pick>; diff --git a/tests/cases/compiler/keyofDoesntContainSymbols.ts b/tests/cases/compiler/keyofDoesntContainSymbols.ts index 5690d4c6b88..3c62d10b3fc 100644 --- a/tests/cases/compiler/keyofDoesntContainSymbols.ts +++ b/tests/cases/compiler/keyofDoesntContainSymbols.ts @@ -1,4 +1,6 @@ // @lib: es6 +// @keyofStringsOnly: true + const sym = Symbol(); const num = 0; const obj = { num: 0, str: 's', [num]: num as 0, [sym]: sym }; diff --git a/tests/cases/compiler/lateBoundConstraintTypeChecksCorrectly.ts b/tests/cases/compiler/lateBoundConstraintTypeChecksCorrectly.ts index 09aa9cfdd94..e756b4ef4e0 100644 --- a/tests/cases/compiler/lateBoundConstraintTypeChecksCorrectly.ts +++ b/tests/cases/compiler/lateBoundConstraintTypeChecksCorrectly.ts @@ -1,3 +1,5 @@ +// @keyofStringsOnly: true + declare const fooProp: unique symbol; declare const barProp: unique symbol; diff --git a/tests/cases/compiler/recursiveTypeRelations.ts b/tests/cases/compiler/recursiveTypeRelations.ts index 18545300f77..f9f71ae04b1 100644 --- a/tests/cases/compiler/recursiveTypeRelations.ts +++ b/tests/cases/compiler/recursiveTypeRelations.ts @@ -1,6 +1,6 @@ // Repro from #14896 -type Attributes = { +type Attributes = { [Key in Keys]: string; } diff --git a/tests/cases/conformance/controlFlow/controlFlowIIFE.ts b/tests/cases/conformance/controlFlow/controlFlowIIFE.ts index c72f038c1ec..8cd9047cb05 100644 --- a/tests/cases/conformance/controlFlow/controlFlowIIFE.ts +++ b/tests/cases/conformance/controlFlow/controlFlowIIFE.ts @@ -1,4 +1,5 @@ // @strictNullChecks: true +// @target: ES2017 declare function getStringOrNumber(): string | number; @@ -45,4 +46,31 @@ if (!test) { } (() => { test.slice(1); // No error -})(); \ No newline at end of file +})(); + +// Repro from #23565 + +function f4() { + let v: number; + (function() { + v = 1; + })(); + v; +} + +function f5() { + let v: number; + (function*() { + yield 1; + v = 1; + })(); + v; // still undefined +} + +function f6() { + let v: number; + (async function() { + v = await 1; + })(); + v; // still undefined +} \ No newline at end of file diff --git a/tests/cases/conformance/enums/enumConstantMemberWithString.ts b/tests/cases/conformance/enums/enumConstantMemberWithString.ts new file mode 100644 index 00000000000..0d2e3a207e2 --- /dev/null +++ b/tests/cases/conformance/enums/enumConstantMemberWithString.ts @@ -0,0 +1,32 @@ +enum T1 { + a = "1", + b = "1" + "2", + c = "1" + "2" + "3", + d = "a" - "a", + e = "a" + 1 +} + +enum T2 { + a = "1", + b = "1" + "2" +} + +enum T3 { + a = "1", + b = "1" + "2", + c = 1, + d = 1 + 2 +} + +enum T4 { + a = "1" +} + +enum T5 { + a = "1" + "2" +} + +declare enum T6 { + a = "1", + b = "1" + "2" +} diff --git a/tests/cases/conformance/enums/enumConstantMemberWithStringEmitDeclaration.ts b/tests/cases/conformance/enums/enumConstantMemberWithStringEmitDeclaration.ts new file mode 100644 index 00000000000..37667dca79c --- /dev/null +++ b/tests/cases/conformance/enums/enumConstantMemberWithStringEmitDeclaration.ts @@ -0,0 +1,29 @@ +// @declaration: true +enum T1 { + a = "1", + b = "1" + "2", + c = "1" + "2" + "3" +} + +enum T2 { + a = "1", + b = "1" + "2" +} + +enum T3 { + a = "1", + b = "1" + "2" +} + +enum T4 { + a = "1" +} + +enum T5 { + a = "1" + "2" +} + +declare enum T6 { + a = "1", + b = "1" + "2" +} diff --git a/tests/cases/conformance/jsdoc/jsdocImportType.ts b/tests/cases/conformance/jsdoc/jsdocImportType.ts new file mode 100644 index 00000000000..7b960601dc7 --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocImportType.ts @@ -0,0 +1,27 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @Filename: types.d.ts +declare function require(name: string): any; +declare var exports: any; +declare var module: { exports: any }; +// @Filename: mod1.js +/// +class Chunk { + constructor() { + this.chunk = 1; + } +} +module.exports = Chunk; + +// @Filename: use.js +/// +/** @typedef {import("./mod1")} C + * @type {C} */ +var c; +c.chunk; + +const D = require("./mod1"); +/** @type {D} */ +var d; +d.chunk; diff --git a/tests/cases/conformance/jsdoc/jsdocImportType2.ts b/tests/cases/conformance/jsdoc/jsdocImportType2.ts new file mode 100644 index 00000000000..98ffc506144 --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocImportType2.ts @@ -0,0 +1,26 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @Filename: types.d.ts +declare function require(name: string): any; +declare var exports: any; +declare var module: { exports: any }; +// @Filename: mod1.js +/// +module.exports = class Chunk { + constructor() { + this.chunk = 1; + } +} + +// @Filename: use.js +/// +/** @typedef {import("./mod1")} C + * @type {C} */ +var c; +c.chunk; + +const D = require("./mod1"); +/** @type {D} */ +var d; +d.chunk; diff --git a/tests/cases/conformance/jsdoc/jsdocTemplateConstructorFunction2.ts b/tests/cases/conformance/jsdoc/jsdocTemplateConstructorFunction2.ts new file mode 100644 index 00000000000..750126a05b9 --- /dev/null +++ b/tests/cases/conformance/jsdoc/jsdocTemplateConstructorFunction2.ts @@ -0,0 +1,26 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @Filename: templateTagWithNestedTypeLiteral.js + +/** + * @template {T} + * @param {T} t + */ +function Zet(t) { + /** @type {T} */ + this.u + this.t = t +} +/** + * @param {T} v + * @param {object} o + * @param {T} o.nested + */ +Zet.prototype.add = function(v, o) { + this.u = v || o.nested + return this.u +} +var z = new Zet(1) +z.t = 2 +z.u = false diff --git a/tests/cases/conformance/types/conditional/conditionalTypes1.ts b/tests/cases/conformance/types/conditional/conditionalTypes1.ts index 638cf473e19..f5c67f678eb 100644 --- a/tests/cases/conformance/types/conditional/conditionalTypes1.ts +++ b/tests/cases/conformance/types/conditional/conditionalTypes1.ts @@ -303,7 +303,7 @@ function f50() { // Repro from #21862 -type OldDiff = ( +type OldDiff = ( & { [P in T]: P; } & { [P in U]: never; } & { [x: string]: never; } diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts index 9ec4e820f73..e0c1f544d97 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts @@ -190,13 +190,13 @@ function f51(k: K, s: string) { const x2 = k as string; } -function f52(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) { +function f52(obj: { [x: string]: boolean }, k: Exclude, s: string, n: number) { const x1 = obj[s]; const x2 = obj[n]; const x3 = obj[k]; } -function f53(obj: { [x: string]: boolean }, k: K, s: string, n: number) { +function f53>(obj: { [x: string]: boolean }, k: K, s: string, n: number) { const x1 = obj[s]; const x2 = obj[n]; const x3 = obj[k]; @@ -556,7 +556,7 @@ class AnotherSampleClass extends SampleClass { new AnotherSampleClass({}); // Positive repro from #17166 -function f3(t: T, k: K, tk: T[K]): void { +function f3>(t: T, k: K, tk: T[K]): void { for (let key in t) { key = k // ok, K ==> keyof T t[key] = tk; // ok, T[K] ==> T[keyof T] diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts index f96bcdb6234..618f483655e 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts @@ -79,7 +79,7 @@ function f20(k1: keyof (T | U), k2: keyof (T & U), o1: T | U, o2: T & U) { } // Repro from #17166 -function f3( +function f3, U extends T, J extends K>( t: T, k: K, tk: T[K], u: U, j: J, uk: U[K], tj: T[J], uj: U[J]): void { for (let key in t) { key = k // ok, K ==> keyof T diff --git a/tests/cases/fourslash/commentsVariables.ts b/tests/cases/fourslash/commentsVariables.ts index 4d5682ef401..bf7e13ee51c 100644 --- a/tests/cases/fourslash/commentsVariables.ts +++ b/tests/cases/fourslash/commentsVariables.ts @@ -59,8 +59,8 @@ verify.currentSignatureHelpDocCommentIs("foos comment"); verify.quickInfoAt("5q", "function foo(): void", "foos comment"); goTo.marker('6'); -verify.currentSignatureHelpDocCommentIs(""); -verify.quickInfoAt("6q", "var fooVar: () => void"); +verify.currentSignatureHelpDocCommentIs("fooVar comment"); +verify.quickInfoAt("6q", "var fooVar: () => void", "fooVar comment"); goTo.marker('7'); verify.completionListContains("foo", "function foo(): void", "foos comment"); @@ -71,9 +71,9 @@ verify.currentSignatureHelpDocCommentIs("foos comment"); verify.quickInfoAt("8q", "function foo(): void", "foos comment"); goTo.marker('9'); -verify.currentSignatureHelpDocCommentIs(""); +verify.currentSignatureHelpDocCommentIs("fooVar comment"); verify.quickInfos({ - "9q": "var fooVar: () => void", + "9q": ["var fooVar: () => void", "fooVar comment"], "9aq": ["var fooVar: () => void", "fooVar comment"] }); diff --git a/tests/cases/fourslash/completionsImport_details_withMisspelledName.ts b/tests/cases/fourslash/completionsImport_details_withMisspelledName.ts new file mode 100644 index 00000000000..098f2e5d46e --- /dev/null +++ b/tests/cases/fourslash/completionsImport_details_withMisspelledName.ts @@ -0,0 +1,17 @@ +/// + +// @Filename: /a.ts +////export const abc = 0; + +// @Filename: /b.ts +////acb/**/; + +goTo.marker(""); +verify.applyCodeActionFromCompletion("", { + name: "abc", + source: "/a", + description: `Import 'abc' from module "./a"`, + newFileContent: `import { abc } from "./a"; + +acb;`, +}); diff --git a/tests/cases/fourslash/completionsImport_ofAlias.ts b/tests/cases/fourslash/completionsImport_ofAlias.ts index 903f724722e..e81f66ed2aa 100644 --- a/tests/cases/fourslash/completionsImport_ofAlias.ts +++ b/tests/cases/fourslash/completionsImport_ofAlias.ts @@ -21,9 +21,7 @@ goTo.marker(""); const options = { includeExternalModuleExports: true, sourceDisplay: "./a" }; -// TODO: https://github.com/Microsoft/TypeScript/issues/14003 -//TODO: verify that there's only one! -verify.completionListContains({ name: "foo", source: "/a" }, "(alias) const foo: 0\nimport foo", "", "alias", /*spanIndex*/ undefined, /*hasAction*/ true, options); +verify.completionListContains({ name: "foo", source: "/a" }, "(alias) const foo: 0\nexport foo", "", "alias", /*spanIndex*/ undefined, /*hasAction*/ true, options); verify.not.completionListContains({ name: "foo", source: "/a_reexport" }, undefined, undefined, undefined, undefined, undefined, options); verify.not.completionListContains({ name: "foo", source: "/a_reexport_2" }, undefined, undefined, undefined, undefined, undefined, options); diff --git a/tests/cases/fourslash/completionsTriggerCharacter.ts b/tests/cases/fourslash/completionsTriggerCharacter.ts new file mode 100644 index 00000000000..06e2a123c52 --- /dev/null +++ b/tests/cases/fourslash/completionsTriggerCharacter.ts @@ -0,0 +1,39 @@ +/// + +// @jsx: preserve + +////const x: "a" | "b" = "/*openQuote*/"/*closeQuote*/; +////const y: 'a' | 'b' = '/*openSingleQuote*/'/*closeSingleQuote*/; +////const z: 'a' | 'b' = `/*openTemplate*/`/*closeTemplate*/; +////const q: "`a`" | "`b`" = "`/*openTemplateInQuote*/a`/*closeTemplateInQuote*/"; + +////// "/*quoteInComment*/ ): void; ProjectInfo(expected: string[]): void; allRangesAppearInImplementationList(markerName: string): void; + getEditsForFileRename(options: { + oldPath: string; + newPath: string; + newFileContents: { [fileName: string]: string }; + }); } class edit { backspace(count?: number): void; @@ -530,6 +536,7 @@ declare namespace FourSlashInterface { importModuleSpecifierPreference?: "relative" | "non-relative"; } interface CompletionsAtOptions extends UserPreferences { + triggerCharacter?: string; isNewIdentifierLocation?: boolean; } } diff --git a/tests/cases/fourslash/getEditsForFileRename.ts b/tests/cases/fourslash/getEditsForFileRename.ts new file mode 100644 index 00000000000..f2694818d1d --- /dev/null +++ b/tests/cases/fourslash/getEditsForFileRename.ts @@ -0,0 +1,27 @@ +/// + +// @Filename: /a.ts +/////// +////import old from "./src/old"; + +// @Filename: /src/a.ts +/////// +////import old from "./old"; + +// @Filename: /src/foo/a.ts +/////// +////import old from "../old"; + +// @Filename: /tsconfig.json +////{ "files": ["/a.ts", "/src/a.ts", "/src/foo/a.ts", "/src/old.ts"] } + +verify.getEditsForFileRename({ + oldPath: "/src/old.ts", + newPath: "/src/new.ts", + newFileContents: { + "/a.ts": '/// \nimport old from "./src/new";', + "/src/a.ts": '/// \nimport old from "./new";', + "/src/foo/a.ts": '/// \nimport old from "../new";', + "/tsconfig.json": '{ "files": ["/a.ts", "/src/a.ts", "/src/foo/a.ts", "/src/new.ts"] }', + }, +}); diff --git a/tests/cases/fourslash/quickInfoImportedTypesWithMergedMeanings.ts b/tests/cases/fourslash/quickInfoImportedTypesWithMergedMeanings.ts index 8ffce0bbb28..d904fb59b9b 100644 --- a/tests/cases/fourslash/quickInfoImportedTypesWithMergedMeanings.ts +++ b/tests/cases/fourslash/quickInfoImportedTypesWithMergedMeanings.ts @@ -17,7 +17,7 @@ verify.quickInfoAt("1", [ "(alias) function Original(): void", "(alias) type Original = () => T", "(alias) namespace Original", - "import Original", + "export Original", ].join("\n"), "some docs "); verify.quickInfoAt("2", [ diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_alias.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_alias.ts index 8749488b88e..56fe9d0808c 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_alias.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_alias.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////const exportsAlias = exports; diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_dotDefault.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_dotDefault.ts index 1283b0053a8..8bd74041dec 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_dotDefault.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_dotDefault.ts @@ -3,6 +3,7 @@ // Test that we leave it alone if the name is a keyword. // @allowJs: true +// @target: esnext // @Filename: /a.js ////exports.default = 0; diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_invalidName.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_invalidName.ts index 83a831effb0..bec40f756ad 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_invalidName.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_invalidName.ts @@ -3,6 +3,7 @@ // Test that we leave it alone if the name is a keyword. // @allowJs: true +// @target: esnext // @Filename: /a.js ////exports.class = 0; diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExports.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExports.ts index 3382228babb..327f7b480a9 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExports.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExports.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////module.exports = function() {} diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExportsEqualsRequire.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExportsEqualsRequire.ts index 81877c8a98b..8dd77f06e1d 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExportsEqualsRequire.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExportsEqualsRequire.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.d.ts ////export const x: number; diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExports_changesImports.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExports_changesImports.ts index 84f081d24b3..277525e10fe 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExports_changesImports.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_moduleDotExports_changesImports.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////module.exports = 0; diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts index a748b9844a6..e7ee2908580 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_named.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////[|exports.f|] = function() {}; diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_namedClassExpression.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_namedClassExpression.ts index ff14f00867d..e1cb86e8d68 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_namedClassExpression.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_namedClassExpression.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////exports.C = class E { static instance = new E(); } diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_namedFunctionExpression.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_namedFunctionExpression.ts index 94a14d1a4c3..c4468a1a189 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_namedFunctionExpression.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_namedFunctionExpression.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////exports.f = function g() { g(); } diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_object.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_object.ts index 61c46c98b3c..5b9107f275c 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_object.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_object.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////module.exports = { diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_object_shorthand.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_object_shorthand.ts index f6fe1048820..62588f6a531 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_object_shorthand.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_object_shorthand.ts @@ -3,6 +3,7 @@ // TODO: Maybe we could transform this to `export function f() {}`. // @allowJs: true +// @target: esnext // @Filename: /a.js ////function f() {} diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_export_referenced.ts b/tests/cases/fourslash/refactorConvertToEs6Module_export_referenced.ts index 0811ea13e99..7a5b94b0a98 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_export_referenced.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_export_referenced.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////exports.x = 0; @@ -15,8 +16,6 @@ //// exports.z; z; ////} -// TODO: GH#22492 Should be a able access `exports.z` inside `exports.f` - verify.codeFix({ description: "Convert to ES6 module", newFileContent: diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_expressionToDeclaration.ts b/tests/cases/fourslash/refactorConvertToEs6Module_expressionToDeclaration.ts index e22aa176738..47ff26f459e 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_expressionToDeclaration.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_expressionToDeclaration.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////exports.f = async function* f(p) { p; } diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_import_arrayBindingPattern.ts b/tests/cases/fourslash/refactorConvertToEs6Module_import_arrayBindingPattern.ts index 2c53f48a6eb..f373f00dfe7 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_import_arrayBindingPattern.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_import_arrayBindingPattern.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////const [x, y] = /*a*/require/*b*/("x"); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_import_includeDefaultUses.ts b/tests/cases/fourslash/refactorConvertToEs6Module_import_includeDefaultUses.ts index 0e69f9519ee..a75854595f3 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_import_includeDefaultUses.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_import_includeDefaultUses.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////const x = /*a*/require/*b*/("x"); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_import_multipleUniqueIdentifiers.ts b/tests/cases/fourslash/refactorConvertToEs6Module_import_multipleUniqueIdentifiers.ts index 44750b76e6e..faf8ec5eb69 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_import_multipleUniqueIdentifiers.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_import_multipleUniqueIdentifiers.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////const x = require("x"); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_import_multipleVariableDeclarations.ts b/tests/cases/fourslash/refactorConvertToEs6Module_import_multipleVariableDeclarations.ts index ae387c060c7..33f31299f8b 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_import_multipleVariableDeclarations.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_import_multipleVariableDeclarations.ts @@ -3,6 +3,7 @@ // Test that we leave it alone if the name is a keyword. // @allowJs: true +// @target: esnext // @Filename: /a.js ////const x = require("x"), y = 0, { z } = require("z"); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_import_nameFromModuleSpecifier.ts b/tests/cases/fourslash/refactorConvertToEs6Module_import_nameFromModuleSpecifier.ts index 510b610315a..3427e62fb9c 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_import_nameFromModuleSpecifier.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_import_nameFromModuleSpecifier.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////const [] = require("a-b"); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_import_objectBindingPattern_complex.ts b/tests/cases/fourslash/refactorConvertToEs6Module_import_objectBindingPattern_complex.ts index f1397e46207..74071ba55fb 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_import_objectBindingPattern_complex.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_import_objectBindingPattern_complex.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////const { x: { a, b } } = require("x"); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_import_objectBindingPattern_plain.ts b/tests/cases/fourslash/refactorConvertToEs6Module_import_objectBindingPattern_plain.ts index 52cb72783b1..31b9cb41f62 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_import_objectBindingPattern_plain.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_import_objectBindingPattern_plain.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////const { x, y: z } = require("x"); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_import_onlyNamedImports.ts b/tests/cases/fourslash/refactorConvertToEs6Module_import_onlyNamedImports.ts index 7f66b67685e..2b40e1ade36 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_import_onlyNamedImports.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_import_onlyNamedImports.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////const x = require("x"); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_import_propertyAccess.ts b/tests/cases/fourslash/refactorConvertToEs6Module_import_propertyAccess.ts index 8d299d4f0ec..dea48380597 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_import_propertyAccess.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_import_propertyAccess.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////const x = require("x").default; diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_import_shadowing.ts b/tests/cases/fourslash/refactorConvertToEs6Module_import_shadowing.ts index dec87859901..f506f970085 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_import_shadowing.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_import_shadowing.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////const mod = require("mod"); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_import_sideEffect.ts b/tests/cases/fourslash/refactorConvertToEs6Module_import_sideEffect.ts index 28caeaf2411..e8023ac414a 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_import_sideEffect.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_import_sideEffect.ts @@ -3,6 +3,7 @@ // Test that we leave it alone if the name is a keyword. // @allowJs: true +// @target: esnext // @Filename: /a.js ////require("foo"); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_missingInitializer.ts b/tests/cases/fourslash/refactorConvertToEs6Module_missingInitializer.ts index 77c4ce0fc43..90a256c2480 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_missingInitializer.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_missingInitializer.ts @@ -1,6 +1,7 @@ /// // @allowJs: true +// @target: esnext // @Filename: /a.js ////require("m"); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_notInCommonjsProject.ts b/tests/cases/fourslash/refactorConvertToEs6Module_notInCommonjsProject.ts new file mode 100644 index 00000000000..5286091bce9 --- /dev/null +++ b/tests/cases/fourslash/refactorConvertToEs6Module_notInCommonjsProject.ts @@ -0,0 +1,10 @@ +/// + +// @allowJs: true + +// @Filename: /a.js +////exports.x = 0; + +// No suggestion to convert to an ES6 module, +// since there are no es6 modules in this project and we don't have a high enough target. +verify.getSuggestionDiagnostics([]); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_notInCommonjsProject_yesIfSomeEs6Module.ts b/tests/cases/fourslash/refactorConvertToEs6Module_notInCommonjsProject_yesIfSomeEs6Module.ts new file mode 100644 index 00000000000..491b61a0bc2 --- /dev/null +++ b/tests/cases/fourslash/refactorConvertToEs6Module_notInCommonjsProject_yesIfSomeEs6Module.ts @@ -0,0 +1,14 @@ +/// + +// @allowJs: true + +// @Filename: /a.js +////exports.x = 0; + +// @Filename: /b.js +////export const y = 0; + +verify.codeFix({ + description: "Convert to ES6 module", + newFileContent: "export const x = 0;", +}); diff --git a/tests/cases/fourslash/refactorConvertToEs6Module_preserveQuotes.ts b/tests/cases/fourslash/refactorConvertToEs6Module_preserveQuotes.ts index 8aa81538887..d8c48d0e971 100644 --- a/tests/cases/fourslash/refactorConvertToEs6Module_preserveQuotes.ts +++ b/tests/cases/fourslash/refactorConvertToEs6Module_preserveQuotes.ts @@ -1,6 +1,8 @@ /// // @allowJs: true +// @target: esnext + // @Filename: /a.js ////const a = require('a'); a; diff --git a/tests/cases/fourslash/renameImportOfExportEquals2.ts b/tests/cases/fourslash/renameImportOfExportEquals2.ts index 83ff1794bde..dfb472caab8 100644 --- a/tests/cases/fourslash/renameImportOfExportEquals2.ts +++ b/tests/cases/fourslash/renameImportOfExportEquals2.ts @@ -25,7 +25,7 @@ const qRanges = [Q0, Q1]; const ns = { definition: "namespace N", ranges: nRanges }; const os = { definition: "(alias) namespace O\nimport O", ranges: oRanges }; -const ps = { definition: "(alias) namespace P\nimport P", ranges: pRanges }; +const ps = { definition: "(alias) namespace P\nexport P", ranges: pRanges }; const qs = { definition: "(alias) namespace Q\nimport Q", ranges: qRanges }; verify.referenceGroups(nRanges, [ns, os, ps, qs]); diff --git a/tests/cases/fourslash/renameImportOfReExport.ts b/tests/cases/fourslash/renameImportOfReExport.ts index 6afb953ad53..2c684fde193 100644 --- a/tests/cases/fourslash/renameImportOfReExport.ts +++ b/tests/cases/fourslash/renameImportOfReExport.ts @@ -20,7 +20,7 @@ const ranges = test.ranges(); const [r0, r1, r2, r3] = ranges; const importRanges = [r2, r3]; const classes = { definition: "class C", ranges: [r0] }; -const bs = { definition: "(alias) class C\nimport C", ranges: [r1] }; +const bs = { definition: "(alias) class C\nexport C", ranges: [r1] }; const imports = { definition: "(alias) class C\nimport C", ranges: importRanges }; verify.referenceGroups(r0, [classes, bs, imports]); verify.referenceGroups(r1, [bs, imports, classes]); diff --git a/tests/cases/fourslash/renameImportOfReExport2.ts b/tests/cases/fourslash/renameImportOfReExport2.ts index bcaa0e41c8a..81b62249441 100644 --- a/tests/cases/fourslash/renameImportOfReExport2.ts +++ b/tests/cases/fourslash/renameImportOfReExport2.ts @@ -18,7 +18,7 @@ const cRanges = ranges.get("C"); const [d0, d1, d2] = ranges.get("D"); const classes = { definition: "class C", ranges: cRanges }; -const bImports = { definition: "(alias) class D\nimport D", ranges: [d0] }; +const bImports = { definition: "(alias) class D\nexport D", ranges: [d0] }; const cImports = { definition: "(alias) class D\nimport D", ranges: [d1, d2] }; verify.referenceGroups(cRanges, [classes, bImports, cImports]); diff --git a/tests/cases/fourslash/transitiveExportImports3.ts b/tests/cases/fourslash/transitiveExportImports3.ts index abb7b2a2983..aeac07476e4 100644 --- a/tests/cases/fourslash/transitiveExportImports3.ts +++ b/tests/cases/fourslash/transitiveExportImports3.ts @@ -13,7 +13,7 @@ verify.noErrors(); const [f0, f1, g0, f2, g1] = test.ranges(); const af = { definition: "function f(): void", ranges: [f0, f1] }; -const g0Group = { definition: "(alias) function g(): void\nimport g", ranges: [g0] }; +const g0Group = { definition: "(alias) function g(): void\nexport g", ranges: [g0] }; const g1Group = { definition: "(alias) function g(): void\nimport g", ranges: [g1] }; const bf = { definition: "(alias) function f(): void\nimport f", ranges: [f2] };