diff --git a/.travis.yml b/.travis.yml index efbd00d5034..c16ae086448 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ language: node_js node_js: - 'stable' - '4' - - '0.10' sudo: false @@ -12,13 +11,6 @@ env: matrix: fast_finish: true - include: - - os: osx - node_js: stable - osx_image: xcode7.3 - env: workerCount=2 - allow_failures: - - os: osx branches: only: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index dc834c7f403..a95ff22e4e9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -132,6 +132,7 @@ namespace ts { const esSymbolType = createIntrinsicType(TypeFlags.ESSymbol, "symbol"); const voidType = createIntrinsicType(TypeFlags.Void, "void"); const neverType = createIntrinsicType(TypeFlags.Never, "never"); + const silentNeverType = createIntrinsicType(TypeFlags.Never, "never"); const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); const emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -147,6 +148,7 @@ namespace ts { const anySignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false); const unknownSignature = createSignature(undefined, undefined, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false); const resolvingSignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false); + const silentNeverSignature = createSignature(undefined, undefined, undefined, emptyArray, silentNeverType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false); const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true); @@ -2013,6 +2015,10 @@ namespace ts { isExternalModuleAugmentation(node.parent.parent); } + function literalTypeToString(type: LiteralType) { + return type.flags & TypeFlags.StringLiteral ? `"${escapeString((type).text)}"` : (type).text; + } + function getSymbolDisplayBuilder(): SymbolDisplayBuilder { function getNameOfSymbol(symbol: Symbol): string { @@ -2188,11 +2194,8 @@ namespace ts { else if (type.flags & TypeFlags.Anonymous) { writeAnonymousType(type, nextFlags); } - else if (type.flags & TypeFlags.StringLiteral) { - writer.writeStringLiteral(`"${escapeString((type).text)}"`); - } - else if (type.flags & TypeFlags.NumberLiteral) { - writer.writeStringLiteral((type).text); + else if (type.flags & TypeFlags.StringOrNumberLiteral) { + writer.writeStringLiteral(literalTypeToString(type)); } else { // Should never get here @@ -2744,8 +2747,9 @@ namespace ts { // Type parameters are always visible case SyntaxKind.TypeParameter: - // Source file is always visible + // Source file and namespace export are always visible case SyntaxKind.SourceFile: + case SyntaxKind.NamespaceExportDeclaration: return true; // Export assignments do not create name bindings outside the module @@ -3836,6 +3840,14 @@ namespace ts { return true; } + function createEnumLiteralType(symbol: Symbol, baseType: EnumType, text: string) { + const type = createType(TypeFlags.EnumLiteral); + type.symbol = symbol; + type.baseType = baseType; + type.text = text; + return type; + } + function getDeclaredTypeOfEnum(symbol: Symbol): Type { const links = getSymbolLinks(symbol); if (!links.declaredType) { @@ -3851,10 +3863,7 @@ namespace ts { const memberSymbol = getSymbolOfNode(member); const value = getEnumMemberValue(member); if (!memberTypes[value]) { - const memberType = memberTypes[value] = createType(TypeFlags.EnumLiteral); - memberType.symbol = memberSymbol; - memberType.baseType = enumType; - memberType.text = "" + value; + const memberType = memberTypes[value] = createEnumLiteralType(memberSymbol, enumType, "" + value); memberTypeList.push(memberType); } } @@ -5333,6 +5342,9 @@ namespace ts { containsUndefined?: boolean; containsNull?: boolean; containsNonWideningType?: boolean; + containsString?: boolean; + containsNumber?: boolean; + containsStringOrNumberLiteral?: boolean; } function binarySearchTypes(types: Type[], type: Type): number { @@ -5360,22 +5372,26 @@ namespace ts { } function addTypeToUnion(typeSet: TypeSet, type: Type) { - if (type.flags & TypeFlags.Union) { + const flags = type.flags; + if (flags & TypeFlags.Union) { addTypesToUnion(typeSet, (type).types); } - else if (type.flags & TypeFlags.Any) { + else if (flags & TypeFlags.Any) { typeSet.containsAny = true; } - else if (!strictNullChecks && type.flags & TypeFlags.Nullable) { - if (type.flags & TypeFlags.Undefined) typeSet.containsUndefined = true; - if (type.flags & TypeFlags.Null) typeSet.containsNull = true; - if (!(type.flags & TypeFlags.ContainsWideningType)) typeSet.containsNonWideningType = true; + else if (!strictNullChecks && flags & TypeFlags.Nullable) { + if (flags & TypeFlags.Undefined) typeSet.containsUndefined = true; + if (flags & TypeFlags.Null) typeSet.containsNull = true; + if (!(flags & TypeFlags.ContainsWideningType)) typeSet.containsNonWideningType = true; } - else if (!(type.flags & TypeFlags.Never)) { + else if (!(flags & TypeFlags.Never)) { + if (flags & TypeFlags.String) typeSet.containsString = true; + if (flags & TypeFlags.Number) typeSet.containsNumber = true; + if (flags & TypeFlags.StringOrNumberLiteral) typeSet.containsStringOrNumberLiteral = true; const len = typeSet.length; const index = len && type.id > typeSet[len - 1].id ? ~len : binarySearchTypes(typeSet, type); if (index < 0) { - if (!(type.flags & TypeFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && containsIdenticalType(typeSet, type))) { + if (!(flags & TypeFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && containsIdenticalType(typeSet, type))) { typeSet.splice(~index, 0, type); } } @@ -5408,7 +5424,7 @@ namespace ts { return false; } - function removeSubtypes(types: Type[]) { + function removeSubtypes(types: TypeSet) { let i = types.length; while (i > 0) { i--; @@ -5418,6 +5434,21 @@ namespace ts { } } + function removeRedundantLiteralTypes(types: TypeSet) { + let i = types.length; + while (i > 0) { + i--; + const t = types[i]; + const remove = + t.flags & TypeFlags.StringLiteral && types.containsString || + t.flags & TypeFlags.NumberLiteral && types.containsNumber || + t.flags & TypeFlags.StringOrNumberLiteral && t.flags & TypeFlags.FreshLiteral && containsType(types, (t).regularType); + if (remove) { + orderedRemoveItemAt(types, i); + } + } + } + // We sort and deduplicate the constituent types based on object identity. If the subtypeReduction // flag is specified we also reduce the constituent type set to only include types that aren't subtypes // of other types. Subtype reduction is expensive for large union types and is possible only when union @@ -5440,6 +5471,9 @@ namespace ts { if (subtypeReduction) { removeSubtypes(typeSet); } + else if (typeSet.containsStringOrNumberLiteral) { + removeRedundantLiteralTypes(typeSet); + } if (typeSet.length === 0) { return typeSet.containsNull ? typeSet.containsNonWideningType ? nullType : nullWideningType : typeSet.containsUndefined ? typeSet.containsNonWideningType ? undefinedType : undefinedWideningType : @@ -5551,6 +5585,22 @@ namespace ts { return type; } + function getFreshTypeOfLiteralType(type: Type) { + if (type.flags & TypeFlags.StringOrNumberLiteral && !(type.flags & TypeFlags.FreshLiteral)) { + if (!(type).freshType) { + const freshType = createLiteralType(type.flags | TypeFlags.FreshLiteral, (type).text); + freshType.regularType = type; + (type).freshType = freshType; + } + return (type).freshType; + } + return type; + } + + function getRegularTypeOfLiteralType(type: Type) { + return type.flags & TypeFlags.StringOrNumberLiteral && type.flags & TypeFlags.FreshLiteral ? (type).regularType : type; + } + function getLiteralTypeForText(flags: TypeFlags, text: string) { const map = flags & TypeFlags.StringLiteral ? stringLiteralTypes : numericLiteralTypes; return map[text] || (map[text] = createLiteralType(flags, text)); @@ -5559,7 +5609,7 @@ namespace ts { function getTypeFromLiteralTypeNode(node: LiteralTypeNode): Type { const links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = checkExpression(node.literal); + links.resolvedType = getRegularTypeOfLiteralType(checkExpression(node.literal)); } return links.resolvedType; } @@ -5945,7 +5995,7 @@ namespace ts { // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. - function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElement): boolean { + function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElementLike): boolean { Debug.assert(node.kind !== SyntaxKind.MethodDeclaration || isObjectLiteralMethod(node)); switch (node.kind) { case SyntaxKind.FunctionExpression: @@ -6271,7 +6321,7 @@ namespace ts { if ((source.flags & TypeFlags.Number | source.flags & TypeFlags.NumberLiteral) && target.flags & TypeFlags.EnumLike) return true; if (source.flags & TypeFlags.EnumLiteral && target.flags & TypeFlags.EnumLiteral && - (source).text === (target).text && + (source).text === (target).text && isEnumTypeRelatedTo((source).baseType, (target).baseType, errorReporter)) { return true; } @@ -6285,6 +6335,12 @@ namespace ts { } function isTypeRelatedTo(source: Type, target: Type, relation: Map) { + if (source.flags & TypeFlags.StringOrNumberLiteral && source.flags & TypeFlags.FreshLiteral) { + source = (source).regularType; + } + if (target.flags & TypeFlags.StringOrNumberLiteral && target.flags & TypeFlags.FreshLiteral) { + target = (target).regularType; + } if (source === target || relation !== identityRelation && isSimpleTypeRelatedTo(source, target, relation)) { return true; } @@ -6382,6 +6438,12 @@ namespace ts { // Ternary.False if they are not related. function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary { let result: Ternary; + if (source.flags & TypeFlags.StringOrNumberLiteral && source.flags & TypeFlags.FreshLiteral) { + source = (source).regularType; + } + if (target.flags & TypeFlags.StringOrNumberLiteral && target.flags & TypeFlags.FreshLiteral) { + target = (target).regularType; + } // 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; @@ -6391,7 +6453,7 @@ namespace ts { if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True; - if (source.flags & TypeFlags.FreshObjectLiteral) { + if (source.flags & TypeFlags.ObjectLiteral && source.flags & TypeFlags.FreshLiteral) { if (hasExcessProperties(source, target, reportErrors)) { if (reportErrors) { reportRelationError(headMessage, source, target); @@ -6502,6 +6564,9 @@ namespace ts { if (source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.Primitive) { tryElaborateErrorsForPrimitivesAndObjects(source, target); } + else if (source.symbol && source.flags & TypeFlags.ObjectType && globalObjectType === source) { + reportError(Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead); + } reportRelationError(headMessage, source, target); } return Ternary.False; @@ -7297,6 +7362,15 @@ namespace ts { type; } + function getWidenedLiteralType(type: Type): Type { + return type.flags & TypeFlags.StringLiteral && type.flags & TypeFlags.FreshLiteral ? stringType : + type.flags & TypeFlags.NumberLiteral && type.flags & TypeFlags.FreshLiteral ? numberType : + type.flags & TypeFlags.BooleanLiteral ? booleanType : + type.flags & TypeFlags.EnumLiteral ? (type).baseType : + type.flags & TypeFlags.Union && !(type.flags & TypeFlags.Enum) ? getUnionType(map((type).types, getWidenedLiteralType)) : + type; + } + /** * Check if a Type was written as a tuple type literal. * Prefer using isTupleLikeType() unless the use of `elementTypes` is required. @@ -7318,8 +7392,8 @@ namespace ts { // no flags for all other types (including non-falsy literal types). function getFalsyFlags(type: Type): TypeFlags { return type.flags & TypeFlags.Union ? getFalsyFlagsOfTypes((type).types) : - type.flags & TypeFlags.StringLiteral ? type === emptyStringType ? TypeFlags.StringLiteral : 0 : - type.flags & TypeFlags.NumberLiteral ? type === zeroType ? TypeFlags.NumberLiteral : 0 : + type.flags & TypeFlags.StringLiteral ? (type).text === "" ? TypeFlags.StringLiteral : 0 : + type.flags & TypeFlags.NumberLiteral ? (type).text === "0" ? TypeFlags.NumberLiteral : 0 : type.flags & TypeFlags.BooleanLiteral ? type === falseType ? TypeFlags.BooleanLiteral : 0 : type.flags & TypeFlags.PossiblyFalsy; } @@ -7386,7 +7460,7 @@ namespace ts { * Leave signatures alone since they are not subject to the check. */ function getRegularTypeOfObjectLiteral(type: Type): Type { - if (!(type.flags & TypeFlags.FreshObjectLiteral)) { + if (!(type.flags & TypeFlags.ObjectLiteral && type.flags & TypeFlags.FreshLiteral)) { return type; } const regularType = (type).regularType; @@ -7402,7 +7476,7 @@ namespace ts { resolved.constructSignatures, resolved.stringIndexInfo, resolved.numberIndexInfo); - regularNew.flags = resolved.flags & ~TypeFlags.FreshObjectLiteral; + regularNew.flags = resolved.flags & ~TypeFlags.FreshLiteral; (type).regularType = regularNew; return regularNew; } @@ -7853,7 +7927,7 @@ namespace ts { const widenLiteralTypes = context.inferences[index].topLevel && !hasPrimitiveConstraint(signature.typeParameters[index]) && (context.inferences[index].isFixed || !isTypeParameterAtTopLevel(getReturnTypeOfSignature(signature), signature.typeParameters[index])); - const baseInferences = widenLiteralTypes ? map(inferences, getBaseTypeOfLiteralType) : inferences; + const baseInferences = widenLiteralTypes ? map(inferences, getWidenedLiteralType) : inferences; // Infer widened union or supertype, or the unknown type for no common supertype const unionOrSuperType = context.inferUnionTypes ? getUnionType(baseInferences, /*subtypeReduction*/ true) : getCommonSupertype(baseInferences); inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType; @@ -8070,8 +8144,11 @@ namespace ts { // we remove type string. function getAssignmentReducedType(declaredType: UnionType, assignedType: Type) { if (declaredType !== assignedType) { + if (assignedType.flags & TypeFlags.Never) { + return assignedType; + } const reducedType = filterType(declaredType, t => typeMaybeAssignableTo(assignedType, t)); - if (reducedType !== neverType) { + if (!(reducedType.flags & TypeFlags.Never)) { return reducedType; } } @@ -8101,14 +8178,14 @@ namespace ts { } if (flags & TypeFlags.StringLiteral) { return strictNullChecks ? - type === emptyStringType ? TypeFacts.EmptyStringStrictFacts : TypeFacts.NonEmptyStringStrictFacts : - type === emptyStringType ? TypeFacts.EmptyStringFacts : TypeFacts.NonEmptyStringFacts; + (type).text === "" ? TypeFacts.EmptyStringStrictFacts : TypeFacts.NonEmptyStringStrictFacts : + (type).text === "" ? TypeFacts.EmptyStringFacts : TypeFacts.NonEmptyStringFacts; } if (flags & (TypeFlags.Number | TypeFlags.Enum)) { return strictNullChecks ? TypeFacts.NumberStrictFacts : TypeFacts.NumberFacts; } if (flags & (TypeFlags.NumberLiteral | TypeFlags.EnumLiteral)) { - const isZero = type === zeroType || type.flags & TypeFlags.EnumLiteral && (type).text === "0"; + const isZero = (type).text === "0"; return strictNullChecks ? isZero ? TypeFacts.ZeroStrictFacts : TypeFacts.NonZeroStrictFacts : isZero ? TypeFacts.ZeroFacts : TypeFacts.NonZeroFacts; @@ -8281,7 +8358,7 @@ namespace ts { function getTypeOfSwitchClause(clause: CaseClause | DefaultClause) { if (clause.kind === SyntaxKind.CaseClause) { - const caseType = checkExpression((clause).expression); + const caseType = getRegularTypeOfLiteralType(checkExpression((clause).expression)); return isUnitType(caseType) ? caseType : undefined; } return neverType; @@ -8351,7 +8428,7 @@ namespace ts { const visitedFlowStart = visitedFlowCount; const result = getTypeFromFlowType(getTypeAtFlowNode(reference.flowNode)); visitedFlowCount = visitedFlowStart; - if (reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(result, TypeFacts.NEUndefinedOrNull) === neverType) { + if (reference.parent.kind === SyntaxKind.NonNullExpression && getTypeWithFacts(result, TypeFacts.NEUndefinedOrNull).flags & TypeFlags.Never) { return declaredType; } return result; @@ -8440,17 +8517,18 @@ namespace ts { function getTypeAtFlowCondition(flow: FlowCondition): FlowType { const flowType = getTypeAtFlowNode(flow.antecedent); let type = getTypeFromFlowType(flowType); - if (type !== neverType) { + if (!(type.flags & TypeFlags.Never)) { // If we have an antecedent type (meaning we're reachable in some way), we first // attempt to narrow the antecedent type. If that produces the never type, and if // the antecedent type is incomplete (i.e. a transient type in a loop), then we // take the type guard as an indication that control *could* reach here once we - // have the complete type. We proceed by reverting to the declared type and then - // narrow that. + // have the complete type. We proceed by switching to the silent never type which + // doesn't report errors when operators are applied to it. Note that this is the + // *only* place a silent never type is ever generated. const assumeTrue = (flow.flags & FlowFlags.TrueCondition) !== 0; type = narrowType(type, flow.expression, assumeTrue); - if (type === neverType && isIncomplete(flowType)) { - type = narrowType(declaredType, flow.expression, assumeTrue); + if (type.flags & TypeFlags.Never && isIncomplete(flowType)) { + type = silentNeverType; } } return createFlowType(type, isIncomplete(flowType)); @@ -8659,9 +8737,13 @@ namespace ts { } if (assumeTrue) { const narrowedType = filterType(type, t => areTypesComparable(t, valueType)); - return narrowedType !== neverType ? narrowedType : type; + return narrowedType.flags & TypeFlags.Never ? type : narrowedType; } - return isUnitType(valueType) ? filterType(type, t => t !== valueType) : type; + if (isUnitType(valueType)) { + const regularType = getRegularTypeOfLiteralType(valueType); + return filterType(type, t => getRegularTypeOfLiteralType(t) !== regularType); + } + return type; } function narrowTypeByTypeof(type: Type, typeOfExpr: TypeOfExpression, operator: SyntaxKind, literal: LiteralExpression, assumeTrue: boolean): Type { @@ -8702,12 +8784,12 @@ namespace ts { const clauseTypes = switchTypes.slice(clauseStart, clauseEnd); const hasDefaultClause = clauseStart === clauseEnd || contains(clauseTypes, neverType); const discriminantType = getUnionType(clauseTypes); - const caseType = discriminantType === neverType ? neverType : filterType(type, t => isTypeComparableTo(discriminantType, t)); + const caseType = discriminantType.flags & TypeFlags.Never ? neverType : filterType(type, t => isTypeComparableTo(discriminantType, t)); if (!hasDefaultClause) { return caseType; } - const defaultType = filterType(type, t => !(isUnitType(t) && contains(switchTypes, t))); - return caseType === neverType ? defaultType : getUnionType([caseType, defaultType]); + const defaultType = filterType(type, t => !(isUnitType(t) && contains(switchTypes, getRegularTypeOfLiteralType(t)))); + return caseType.flags & TypeFlags.Never ? defaultType : getUnionType([caseType, defaultType]); } function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { @@ -8771,7 +8853,7 @@ namespace ts { // the candidate type. If one or more constituents remain, return a union of those. if (type.flags & TypeFlags.Union) { const assignableType = filterType(type, t => isTypeInstanceOf(t, candidate)); - if (assignableType !== neverType) { + if (!(assignableType.flags & TypeFlags.Never)) { return assignableType; } } @@ -9541,14 +9623,14 @@ namespace ts { if (parameter.dotDotDotToken) { const restTypes: Type[] = []; for (let i = indexOfParameter; i < iife.arguments.length; i++) { - restTypes.push(getBaseTypeOfLiteralType(checkExpression(iife.arguments[i]))); + restTypes.push(getWidenedLiteralType(checkExpression(iife.arguments[i]))); } return createArrayType(getUnionType(restTypes)); } const links = getNodeLinks(iife); const cached = links.resolvedSignature; links.resolvedSignature = anySignature; - const type = getBaseTypeOfLiteralType(checkExpression(iife.arguments[indexOfParameter])); + const type = getWidenedLiteralType(checkExpression(iife.arguments[indexOfParameter])); links.resolvedSignature = cached; return type; } @@ -9783,7 +9865,7 @@ namespace ts { return getContextualTypeForObjectLiteralElement(node); } - function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElement) { + function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElementLike) { const objectLiteral = element.parent; const type = getApparentTypeOfContextualType(objectLiteral); if (type) { @@ -9900,7 +9982,7 @@ namespace ts { return getContextualTypeForBinaryOperand(node); case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: - return getContextualTypeForObjectLiteralElement(parent); + return getContextualTypeForObjectLiteralElement(parent); case SyntaxKind.ArrayLiteralExpression: return getContextualTypeForElementExpression(node); case SyntaxKind.ConditionalExpression: @@ -10280,7 +10362,7 @@ namespace ts { const stringIndexInfo = hasComputedStringProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.String) : undefined; const numberIndexInfo = hasComputedNumberProperty ? getObjectLiteralIndexInfo(node, propertiesArray, IndexKind.Number) : undefined; const result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo); - const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshObjectLiteral; + const freshObjectLiteralFlag = compilerOptions.suppressExcessPropertyErrors ? 0 : TypeFlags.FreshLiteral; result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | freshObjectLiteralFlag | (typeFlags & TypeFlags.PropagatingFlags) | (patternWithComputedProperties ? TypeFlags.ObjectLiteralPatternWithComputedProperties : 0); if (inDestructuringPattern) { result.pattern = node; @@ -10889,7 +10971,7 @@ namespace ts { function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) { const type = checkNonNullExpression(left); - if (isTypeAny(type)) { + if (isTypeAny(type) || type === silentNeverType) { return type; } @@ -11036,8 +11118,8 @@ namespace ts { const objectType = getApparentType(checkNonNullExpression(node.expression)); const indexType = node.argumentExpression ? checkExpression(node.argumentExpression) : unknownType; - if (objectType === unknownType) { - return unknownType; + if (objectType === unknownType || objectType === silentNeverType) { + return objectType; } const isConstEnum = isConstEnumObjectType(objectType); @@ -12087,6 +12169,9 @@ namespace ts { } const funcType = checkNonNullExpression(node.expression); + if (funcType === silentNeverType) { + return silentNeverSignature; + } const apparentType = getApparentType(funcType); if (apparentType === unknownType) { @@ -12159,6 +12244,9 @@ namespace ts { } let expressionType = checkNonNullExpression(node.expression); + if (expressionType === silentNeverType) { + return silentNeverSignature; + } // If expressionType's apparent type(section 3.8.1) is an object type with one or // more construct signatures, the expression is processed in the same manner as a @@ -12644,7 +12732,7 @@ namespace ts { reportErrorsFromWidening(func, type); } if (isUnitType(type) && !(contextualSignature && isLiteralContextualType(getReturnTypeOfSignature(contextualSignature)))) { - type = getBaseTypeOfLiteralType(type); + type = getWidenedLiteralType(type); } const widenedType = getWidenedType(type); @@ -12718,7 +12806,7 @@ namespace ts { // the native Promise type by the caller. type = checkAwaitedType(type, func, Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member); } - if (type === neverType) { + if (type.flags & TypeFlags.Never) { hasReturnOfTypeNever = true; } else if (!contains(aggregatedTypes, type)) { @@ -12768,7 +12856,7 @@ namespace ts { const hasExplicitReturn = func.flags & NodeFlags.HasExplicitReturn; - if (returnType === neverType) { + if (returnType && returnType.flags & TypeFlags.Never) { error(func.type, Diagnostics.A_function_returning_never_cannot_have_a_reachable_end_point); } else if (returnType && !hasExplicitReturn) { @@ -13024,8 +13112,11 @@ namespace ts { function checkPrefixUnaryExpression(node: PrefixUnaryExpression): Type { const operandType = checkExpression(node.operand); + if (operandType === silentNeverType) { + return silentNeverType; + } if (node.operator === SyntaxKind.MinusToken && node.operand.kind === SyntaxKind.NumericLiteral) { - return getLiteralTypeForText(TypeFlags.NumberLiteral, "" + -(node.operand).text); + return getFreshTypeOfLiteralType(getLiteralTypeForText(TypeFlags.NumberLiteral, "" + -(node.operand).text)); } switch (node.operator) { case SyntaxKind.PlusToken: @@ -13057,6 +13148,9 @@ namespace ts { function checkPostfixUnaryExpression(node: PostfixUnaryExpression): Type { const operandType = checkExpression(node.operand); + if (operandType === silentNeverType) { + return silentNeverType; + } const ok = checkArithmeticOperandType(node.operand, getNonNullableType(operandType), Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type); if (ok) { @@ -13121,6 +13215,9 @@ namespace ts { } function checkInstanceOfExpression(left: Expression, right: Expression, leftType: Type, rightType: Type): Type { + if (leftType === silentNeverType || rightType === silentNeverType) { + return silentNeverType; + } // TypeScript 1.0 spec (April 2014): 4.15.4 // The instanceof operator requires the left operand to be of type Any, an object type, or a type parameter type, // and the right operand to be of type Any or a subtype of the 'Function' interface type. @@ -13137,6 +13234,9 @@ namespace ts { } function checkInExpression(left: Expression, right: Expression, leftType: Type, rightType: Type): Type { + if (leftType === silentNeverType || rightType === silentNeverType) { + return silentNeverType; + } // TypeScript 1.0 spec (April 2014): 4.15.5 // The in operator requires the left operand to be of type Any, the String primitive type, or the Number primitive type, // and the right operand to be of type Any, an object type, or a type parameter type. @@ -13158,7 +13258,7 @@ namespace ts { return sourceType; } - function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElement, contextualMapper?: TypeMapper) { + function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike, contextualMapper?: TypeMapper) { if (property.kind === SyntaxKind.PropertyAssignment || property.kind === SyntaxKind.ShorthandPropertyAssignment) { const name = (property).name; if (name.kind === SyntaxKind.ComputedPropertyName) { @@ -13401,6 +13501,9 @@ namespace ts { case SyntaxKind.CaretEqualsToken: case SyntaxKind.AmpersandToken: case SyntaxKind.AmpersandEqualsToken: + if (leftType === silentNeverType || rightType === silentNeverType) { + return silentNeverType; + } // TypeScript 1.0 spec (April 2014): 4.19.1 // These operators require their operands to be of type Any, the Number primitive type, // or an enum type. Operands of an enum type are treated @@ -13433,6 +13536,9 @@ namespace ts { return numberType; case SyntaxKind.PlusToken: case SyntaxKind.PlusEqualsToken: + if (leftType === silentNeverType || rightType === silentNeverType) { + return silentNeverType; + } // TypeScript 1.0 spec (April 2014): 4.19.2 // The binary + operator requires both operands to be of the Number primitive type or an enum type, // or at least one of the operands to be of type Any or the String primitive type. @@ -13649,12 +13755,13 @@ namespace ts { } switch (node.kind) { case SyntaxKind.StringLiteral: - return getLiteralTypeForText(TypeFlags.StringLiteral, (node).text); + return getFreshTypeOfLiteralType(getLiteralTypeForText(TypeFlags.StringLiteral, (node).text)); case SyntaxKind.NumericLiteral: - return getLiteralTypeForText(TypeFlags.NumberLiteral, (node).text); + return getFreshTypeOfLiteralType(getLiteralTypeForText(TypeFlags.NumberLiteral, (node).text)); case SyntaxKind.TrueKeyword: + return trueType; case SyntaxKind.FalseKeyword: - return node.kind === SyntaxKind.TrueKeyword ? trueType : falseType; + return falseType; } } @@ -13702,7 +13809,7 @@ namespace ts { const type = checkExpressionCached(declaration.initializer); return getCombinedNodeFlags(declaration) & NodeFlags.Const || getCombinedModifierFlags(declaration) & ModifierFlags.Readonly || - isTypeAssertion(declaration.initializer) ? type : getBaseTypeOfLiteralType(type); + isTypeAssertion(declaration.initializer) ? type : getWidenedLiteralType(type); } function isLiteralContextualType(contextualType: Type) { @@ -13724,7 +13831,7 @@ namespace ts { function checkExpressionForMutableLocation(node: Expression, contextualMapper?: TypeMapper): Type { const type = checkExpression(node, contextualMapper); - return isTypeAssertion(node) || isLiteralContextualType(getContextualType(node)) ? type : getBaseTypeOfLiteralType(type); + return isTypeAssertion(node) || isLiteralContextualType(getContextualType(node)) ? type : getWidenedLiteralType(type); } function checkPropertyAssignment(node: PropertyAssignment, contextualMapper?: TypeMapper): Type { @@ -16266,7 +16373,7 @@ namespace ts { // Now that we've removed all the StringLike types, if no constituents remain, then the entire // arrayOrStringType was a string. - if (arrayType === neverType) { + if (arrayType.flags & TypeFlags.Never) { return stringType; } } @@ -16327,7 +16434,7 @@ namespace ts { if (func) { const signature = getSignatureFromDeclaration(func); const returnType = getReturnTypeOfSignature(signature); - if (strictNullChecks || node.expression || returnType === neverType) { + if (strictNullChecks || node.expression || returnType.flags & TypeFlags.Never) { const exprType = node.expression ? checkExpressionCached(node.expression) : undefinedType; if (func.asteriskToken) { @@ -18413,7 +18520,7 @@ namespace ts { // for ({ skills: { primary, secondary } } = multiRobot, i = 0; i < 1; i++) { if (expr.parent.kind === SyntaxKind.PropertyAssignment) { const typeOfParentObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(expr.parent.parent); - return checkObjectLiteralDestructuringPropertyAssignment(typeOfParentObjectLiteral || unknownType, expr.parent); + return checkObjectLiteralDestructuringPropertyAssignment(typeOfParentObjectLiteral || unknownType, expr.parent); } // Array literal assignment - array destructuring pattern Debug.assert(expr.parent.kind === SyntaxKind.ArrayLiteralExpression); @@ -18440,7 +18547,7 @@ namespace ts { if (isRightSideOfQualifiedNameOrPropertyAccess(expr)) { expr = expr.parent; } - return checkExpression(expr); + return getRegularTypeOfLiteralType(checkExpression(expr)); } /** @@ -18851,7 +18958,7 @@ namespace ts { // Get type of the symbol if this is the valid symbol otherwise get type at location const symbol = getSymbolOfNode(declaration); const type = symbol && !(symbol.flags & (SymbolFlags.TypeLiteral | SymbolFlags.Signature)) - ? getTypeOfSymbol(symbol) + ? getWidenedLiteralType(getTypeOfSymbol(symbol)) : unknownType; getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); @@ -18911,6 +19018,19 @@ namespace ts { return undefined; } + function isLiteralConstDeclaration(node: VariableDeclaration): boolean { + if (isConst(node)) { + const type = getTypeOfSymbol(getSymbolOfNode(node)); + return !!(type.flags & TypeFlags.StringOrNumberLiteral && type.flags & TypeFlags.FreshLiteral); + } + return false; + } + + function writeLiteralConstValue(node: VariableDeclaration, writer: SymbolWriter) { + const type = getTypeOfSymbol(getSymbolOfNode(node)); + writer.writeStringLiteral(literalTypeToString(type)); + } + function createResolver(): EmitResolver { // this variable and functions that use it are deliberately moved here from the outer scope // to avoid scope pollution @@ -18955,7 +19075,9 @@ namespace ts { isArgumentsLocalBinding, getExternalModuleFileFromDeclaration, getTypeReferenceDirectivesForEntityName, - getTypeReferenceDirectivesForSymbol + getTypeReferenceDirectivesForSymbol, + isLiteralConstDeclaration, + writeLiteralConstValue }; // defined here to avoid outer scope pollution @@ -20101,10 +20223,29 @@ namespace ts { } } + function isStringOrNumberLiteralExpression(expr: Expression) { + return expr.kind === SyntaxKind.StringLiteral || expr.kind === SyntaxKind.NumericLiteral || + expr.kind === SyntaxKind.PrefixUnaryExpression && (expr).operator === SyntaxKind.MinusToken && + (expr).operand.kind === SyntaxKind.NumericLiteral; + } + function checkGrammarVariableDeclaration(node: VariableDeclaration) { if (node.parent.parent.kind !== SyntaxKind.ForInStatement && node.parent.parent.kind !== SyntaxKind.ForOfStatement) { if (isInAmbientContext(node)) { if (node.initializer) { + if (isConst(node) && !node.type) { + if (!isStringOrNumberLiteralExpression(node.initializer)) { + return grammarErrorOnNode(node.initializer, Diagnostics.A_const_initializer_in_an_ambient_context_must_be_a_string_or_numeric_literal); + } + } + else { + // Error on equals token which immediate precedes the initializer + const equalsTokenLength = "=".length; + return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, + equalsTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts); + } + } + if (node.initializer && !(isConst(node) && isStringOrNumberLiteralExpression(node.initializer))) { // Error on equals token which immediate precedes the initializer const equalsTokenLength = "=".length; return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 4e8b81da81b..c097f18eaec 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -408,6 +408,7 @@ namespace ts { "es2017": "lib.es2017.d.ts", // Host only "dom": "lib.dom.d.ts", + "dom.iterable": "lib.dom.iterable.d.ts", "webworker": "lib.webworker.d.ts", "scripthost": "lib.scripthost.d.ts", // ES2015 Or ESNext By-feature options diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index a015ad79b97..dfca14bd0d1 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1142,6 +1142,10 @@ namespace ts { if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { emitTypeOfVariableDeclarationFromTypeLiteral(node); } + else if (resolver.isLiteralConstDeclaration(node)) { + write(" = "); + resolver.writeLiteralConstValue(node, writer); + } else if (!hasModifier(node, ModifierFlags.Private)) { writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 0f3e90405a6..11eb12bb2b4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -819,6 +819,10 @@ "category": "Error", "code": 1253 }, + "A 'const' initializer in an ambient context must be a string or numeric literal.": { + "category": "Error", + "code": 1254 + }, "'with' statements are not allowed in an async function block.": { "category": "Error", "code": 1300 @@ -1959,6 +1963,10 @@ "category": "Error", "code": 2695 }, + "The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?": { + "category": "Error", + "code": 2696 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 16eeb86f59a..48296145dbc 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -416,7 +416,7 @@ namespace ts { return node; } - export function createObjectLiteral(properties?: ObjectLiteralElement[], location?: TextRange, multiLine?: boolean) { + export function createObjectLiteral(properties?: ObjectLiteralElementLike[], location?: TextRange, multiLine?: boolean) { const node = createNode(SyntaxKind.ObjectLiteralExpression, location); node.properties = createNodeArray(properties); if (multiLine) { @@ -425,7 +425,7 @@ namespace ts { return node; } - export function updateObjectLiteral(node: ObjectLiteralExpression, properties: ObjectLiteralElement[]) { + export function updateObjectLiteral(node: ObjectLiteralExpression, properties: ObjectLiteralElementLike[]) { if (node.properties !== properties) { return updateNode(createObjectLiteral(properties, node, node.multiLine), node); } @@ -2069,7 +2069,7 @@ namespace ts { } } - export function createExpressionForObjectLiteralElement(node: ObjectLiteralExpression, property: ObjectLiteralElement, receiver: Expression): Expression { + export function createExpressionForObjectLiteralElementLike(node: ObjectLiteralExpression, property: ObjectLiteralElementLike, receiver: Expression): Expression { switch (property.kind) { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: @@ -2086,7 +2086,7 @@ namespace ts { function createExpressionForAccessorDeclaration(properties: NodeArray, property: AccessorDeclaration, receiver: Expression, multiLine: boolean) { const { firstAccessor, getAccessor, setAccessor } = getAllAccessorDeclarations(properties, property); if (property === firstAccessor) { - const properties: ObjectLiteralElement[] = []; + const properties: ObjectLiteralElementLike[] = []; if (getAccessor) { const getterFunction = createFunctionExpression( /*asteriskToken*/ undefined, diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 1aec63bc588..9bd9311b749 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4121,7 +4121,7 @@ namespace ts { return undefined; } - function parseObjectLiteralElement(): ObjectLiteralElement { + function parseObjectLiteralElement(): ObjectLiteralElementLike { const fullStart = scanner.getStartPos(); const decorators = parseDecorators(); const modifiers = parseModifiers(); diff --git a/src/compiler/transformers/destructuring.ts b/src/compiler/transformers/destructuring.ts index c6079ee1378..a66f5e21d78 100644 --- a/src/compiler/transformers/destructuring.ts +++ b/src/compiler/transformers/destructuring.ts @@ -126,14 +126,22 @@ namespace ts { context: TransformationContext, node: VariableDeclaration, value?: Expression, - visitor?: (node: Node) => VisitResult) { + visitor?: (node: Node) => VisitResult, + recordTempVariable?: (node: Identifier) => void) { const declarations: VariableDeclaration[] = []; + let pendingAssignments: Expression[]; flattenDestructuring(context, node, value, node, emitAssignment, emitTempVariableAssignment, visitor); return declarations; function emitAssignment(name: Identifier, value: Expression, location: TextRange, original: Node) { + if (pendingAssignments) { + pendingAssignments.push(value); + value = inlineExpressions(pendingAssignments); + pendingAssignments = undefined; + } + const declaration = createVariableDeclaration(name, /*type*/ undefined, value, location); declaration.original = original; @@ -146,8 +154,19 @@ namespace ts { } function emitTempVariableAssignment(value: Expression, location: TextRange) { - const name = createTempVariable(/*recordTempVariable*/ undefined); - emitAssignment(name, value, location, /*original*/ undefined); + const name = createTempVariable(recordTempVariable); + if (recordTempVariable) { + const assignment = createAssignment(name, value, location); + if (pendingAssignments) { + pendingAssignments.push(assignment); + } + else { + pendingAssignments = [assignment]; + } + } + else { + emitAssignment(name, value, location, /*original*/ undefined); + } return name; } } diff --git a/src/compiler/transformers/es6.ts b/src/compiler/transformers/es6.ts index a69dcdfbe6a..995b04c74da 100644 --- a/src/compiler/transformers/es6.ts +++ b/src/compiler/transformers/es6.ts @@ -187,12 +187,12 @@ namespace ts { let currentText: string; let currentParent: Node; let currentNode: Node; + let enclosingVariableStatement: VariableStatement; let enclosingBlockScopeContainer: Node; let enclosingBlockScopeContainerParent: Node; - let containingNonArrowFunction: FunctionLikeDeclaration | ClassElement; - - /** Tracks the container that determines whether `super.x` is a static. */ - let superScopeContainer: FunctionLikeDeclaration | ClassElement; + let enclosingFunction: FunctionLikeDeclaration; + let enclosingNonArrowFunction: FunctionLikeDeclaration; + let enclosingNonAsyncFunctionBody: FunctionLikeDeclaration | ClassElement; /** * Used to track if we are emitting body of the converted loop @@ -206,11 +206,6 @@ namespace ts { */ let enabledSubstitutions: ES6SubstitutionFlags; - /** - * This is used to determine whether we need to emit `_this` instead of `this`. - */ - let useCapturedThis: boolean; - return transformSourceFile; function transformSourceFile(node: SourceFile) { @@ -230,13 +225,14 @@ namespace ts { } function saveStateAndInvoke(node: Node, f: (node: Node) => T): T { - const savedContainingNonArrowFunction = containingNonArrowFunction; - const savedSuperScopeContainer = superScopeContainer; - const savedCurrentParent = currentParent; - const savedCurrentNode = currentNode; + const savedEnclosingFunction = enclosingFunction; + const savedEnclosingNonArrowFunction = enclosingNonArrowFunction; + const savedEnclosingNonAsyncFunctionBody = enclosingNonAsyncFunctionBody; const savedEnclosingBlockScopeContainer = enclosingBlockScopeContainer; const savedEnclosingBlockScopeContainerParent = enclosingBlockScopeContainerParent; - + const savedEnclosingVariableStatement = enclosingVariableStatement; + const savedCurrentParent = currentParent; + const savedCurrentNode = currentNode; const savedConvertedLoopState = convertedLoopState; if (nodeStartsNewLexicalEnvironment(node)) { // don't treat content of nodes that start new lexical environment as part of converted loop copy @@ -247,12 +243,14 @@ namespace ts { const visited = f(node); convertedLoopState = savedConvertedLoopState; - containingNonArrowFunction = savedContainingNonArrowFunction; - superScopeContainer = savedSuperScopeContainer; - currentParent = savedCurrentParent; - currentNode = savedCurrentNode; + enclosingFunction = savedEnclosingFunction; + enclosingNonArrowFunction = savedEnclosingNonArrowFunction; + enclosingNonAsyncFunctionBody = savedEnclosingNonAsyncFunctionBody; enclosingBlockScopeContainer = savedEnclosingBlockScopeContainer; enclosingBlockScopeContainerParent = savedEnclosingBlockScopeContainerParent; + enclosingVariableStatement = savedEnclosingVariableStatement; + currentParent = savedCurrentParent; + currentNode = savedCurrentNode; return visited; } @@ -275,22 +273,13 @@ namespace ts { } function visitorForConvertedLoopWorker(node: Node): VisitResult { - const savedUseCapturedThis = useCapturedThis; - - if (nodeStartsNewLexicalEnvironment(node)) { - useCapturedThis = false; - } - let result: VisitResult; - if (shouldCheckNode(node)) { result = visitJavaScript(node); } else { result = visitNodesInConvertedLoop(node); } - - useCapturedThis = savedUseCapturedThis; return result; } @@ -344,7 +333,7 @@ namespace ts { return visitFunctionExpression(node); case SyntaxKind.VariableDeclaration: - return visitVariableDeclaration(node, /*offset*/ undefined); + return visitVariableDeclaration(node); case SyntaxKind.Identifier: return visitIdentifier(node); @@ -433,30 +422,44 @@ namespace ts { } function onBeforeVisitNode(node: Node) { - const currentGrandparent = currentParent; - currentParent = currentNode; - currentNode = node; - - if (currentParent) { - if (isBlockScope(currentParent, currentGrandparent)) { - enclosingBlockScopeContainer = currentParent; - enclosingBlockScopeContainerParent = currentGrandparent; + if (currentNode) { + if (isBlockScope(currentNode, currentParent)) { + enclosingBlockScopeContainer = currentNode; + enclosingBlockScopeContainerParent = currentParent; } - switch (currentParent.kind) { - case SyntaxKind.FunctionExpression: - case SyntaxKind.Constructor: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.FunctionDeclaration: - containingNonArrowFunction = currentParent; - if (!(containingNonArrowFunction.emitFlags & NodeEmitFlags.AsyncFunctionBody)) { - superScopeContainer = containingNonArrowFunction; + if (isFunctionLike(currentNode)) { + enclosingFunction = currentNode; + if (currentNode.kind !== SyntaxKind.ArrowFunction) { + enclosingNonArrowFunction = currentNode; + if (!(currentNode.emitFlags & NodeEmitFlags.AsyncFunctionBody)) { + enclosingNonAsyncFunctionBody = currentNode; } + } + } + + // keep track of the enclosing variable statement when in the context of + // variable statements, variable declarations, binding elements, and binding + // patterns. + switch (currentNode.kind) { + case SyntaxKind.VariableStatement: + enclosingVariableStatement = currentNode; break; + + case SyntaxKind.VariableDeclarationList: + case SyntaxKind.VariableDeclaration: + case SyntaxKind.BindingElement: + case SyntaxKind.ObjectBindingPattern: + case SyntaxKind.ArrayBindingPattern: + break; + + default: + enclosingVariableStatement = undefined; } } + + currentParent = currentNode; + currentNode = node; } function visitSwitchStatement(node: SwitchStatement): SwitchStatement { @@ -492,9 +495,8 @@ namespace ts { function visitThisKeyword(node: Node): Node { Debug.assert(convertedLoopState !== undefined); - - if (useCapturedThis) { - // if useCapturedThis is true then 'this' keyword is contained inside an arrow function. + if (enclosingFunction && enclosingFunction.kind === SyntaxKind.ArrowFunction) { + // if the enclosing function is an ArrowFunction is then we use the captured 'this' keyword. convertedLoopState.containsLexicalThis = true; return node; } @@ -1430,7 +1432,7 @@ namespace ts { setNodeEmitFlags(propertyName, NodeEmitFlags.NoComments | NodeEmitFlags.NoLeadingSourceMap); setSourceMapRange(propertyName, firstAccessor.name); - const properties: ObjectLiteralElement[] = []; + const properties: ObjectLiteralElementLike[] = []; if (getAccessor) { const getterFunction = transformFunctionLikeToExpression(getAccessor, /*location*/ undefined, /*name*/ undefined); setSourceMapRange(getterFunction, getSourceMapRange(getAccessor)); @@ -1477,12 +1479,7 @@ namespace ts { enableSubstitutionsForCapturedThis(); } - const savedUseCapturedThis = useCapturedThis; - useCapturedThis = true; - const func = transformFunctionLikeToExpression(node, /*location*/ node, /*name*/ undefined); - - useCapturedThis = savedUseCapturedThis; setNodeEmitFlags(func, NodeEmitFlags.CapturesThis); return func; } @@ -1505,7 +1502,7 @@ namespace ts { return setOriginalNode( createFunctionDeclaration( /*decorators*/ undefined, - /*modifiers*/ undefined, + node.modifiers, node.asteriskToken, node.name, /*typeParameters*/ undefined, @@ -1525,9 +1522,9 @@ namespace ts { * @param name The name of the new FunctionExpression. */ function transformFunctionLikeToExpression(node: FunctionLikeDeclaration, location: TextRange, name: Identifier): FunctionExpression { - const savedContainingNonArrowFunction = containingNonArrowFunction; + const savedContainingNonArrowFunction = enclosingNonArrowFunction; if (node.kind !== SyntaxKind.ArrowFunction) { - containingNonArrowFunction = node; + enclosingNonArrowFunction = node; } const expression = setOriginalNode( @@ -1543,7 +1540,7 @@ namespace ts { /*original*/ node ); - containingNonArrowFunction = savedContainingNonArrowFunction; + enclosingNonArrowFunction = savedContainingNonArrowFunction; return expression; } @@ -1834,13 +1831,13 @@ namespace ts { * * @param node A VariableDeclaration node. */ - function visitVariableDeclarationInLetDeclarationList(node: VariableDeclaration, offset: number) { + function visitVariableDeclarationInLetDeclarationList(node: VariableDeclaration) { // For binding pattern names that lack initializers there is no point to emit // explicit initializer since downlevel codegen for destructuring will fail // in the absence of initializer so all binding elements will say uninitialized const name = node.name; if (isBindingPattern(name)) { - return visitVariableDeclaration(node, offset); + return visitVariableDeclaration(node); } if (!node.initializer && shouldEmitExplicitInitializerForLetDeclaration(node)) { @@ -1857,10 +1854,13 @@ namespace ts { * * @param node A VariableDeclaration node. */ - function visitVariableDeclaration(node: VariableDeclaration, offset: number): VisitResult { + function visitVariableDeclaration(node: VariableDeclaration): VisitResult { // If we are here it is because the name contains a binding pattern. if (isBindingPattern(node.name)) { - return flattenVariableDestructuring(context, node, /*value*/ undefined, visitor); + const recordTempVariablesInLine = !enclosingVariableStatement + || !hasModifier(enclosingVariableStatement, ModifierFlags.Export); + return flattenVariableDestructuring(context, node, /*value*/ undefined, visitor, + recordTempVariablesInLine ? undefined : hoistVariableDeclaration); } return visitEachChild(node, visitor, context); @@ -1936,7 +1936,7 @@ namespace ts { // Note also that because an extra statement is needed to assign to the LHS, // for-of bodies are always emitted as blocks. - const expression = node.expression; + const expression = visitNode(node.expression, visitor, isExpression); const initializer = node.initializer; const statements: Statement[] = []; @@ -2111,7 +2111,7 @@ namespace ts { temp, setNodeEmitFlags( createObjectLiteral( - visitNodes(properties, visitor, isObjectLiteralElement, 0, numInitialProperties), + visitNodes(properties, visitor, isObjectLiteralElementLike, 0, numInitialProperties), /*location*/ undefined, node.multiLine ), @@ -2185,7 +2185,7 @@ namespace ts { case SyntaxKind.ForOfStatement: const initializer = (node).initializer; if (initializer && initializer.kind === SyntaxKind.VariableDeclarationList) { - loopInitializer = (node).initializer; + loopInitializer = initializer; } break; } @@ -2237,8 +2237,8 @@ namespace ts { } const isAsyncBlockContainingAwait = - containingNonArrowFunction - && (containingNonArrowFunction.emitFlags & NodeEmitFlags.AsyncFunctionBody) !== 0 + enclosingNonArrowFunction + && (enclosingNonArrowFunction.emitFlags & NodeEmitFlags.AsyncFunctionBody) !== 0 && (node.statement.transformFlags & TransformFlags.ContainsYield) !== 0; let loopBodyFlags: NodeEmitFlags = 0; @@ -2645,7 +2645,7 @@ namespace ts { * * @param node A MethodDeclaration node. */ - function visitMethodDeclaration(node: MethodDeclaration): ObjectLiteralElement { + function visitMethodDeclaration(node: MethodDeclaration): ObjectLiteralElementLike { // We should only get here for methods on an object literal with regular identifier names. // Methods on classes are handled in visitClassDeclaration/visitClassExpression. // Methods with computed property names are handled in visitObjectLiteralExpression. @@ -2664,7 +2664,7 @@ namespace ts { * * @param node A ShorthandPropertyAssignment node. */ - function visitShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElement { + function visitShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike { return createPropertyAssignment( node.name, getSynthesizedClone(node.name), @@ -3026,9 +3026,9 @@ namespace ts { * Visits the `super` keyword */ function visitSuperKeyword(node: PrimaryExpression): LeftHandSideExpression { - return superScopeContainer - && isClassElement(superScopeContainer) - && !hasModifier(superScopeContainer, ModifierFlags.Static) + return enclosingNonAsyncFunctionBody + && isClassElement(enclosingNonAsyncFunctionBody) + && !hasModifier(enclosingNonAsyncFunctionBody, ModifierFlags.Static) && currentParent.kind !== SyntaxKind.CallExpression ? createPropertyAccess(createIdentifier("_super"), "prototype") : createIdentifier("_super"); @@ -3053,17 +3053,16 @@ namespace ts { * @param node The node to be printed. */ function onEmitNode(node: Node, emit: (node: Node) => void) { - const savedUseCapturedThis = useCapturedThis; + const savedEnclosingFunction = enclosingFunction; if (enabledSubstitutions & ES6SubstitutionFlags.CapturedThis && isFunctionLike(node)) { - // If we are tracking a captured `this`, push a bit that indicates whether the - // containing function is an arrow function. - useCapturedThis = (getNodeEmitFlags(node) & NodeEmitFlags.CapturesThis) !== 0; + // If we are tracking a captured `this`, keep track of the enclosing function. + enclosingFunction = node; } previousOnEmitNode(node, emit); - useCapturedThis = savedUseCapturedThis; + enclosingFunction = savedEnclosingFunction; } /** @@ -3191,7 +3190,9 @@ namespace ts { * @param node The ThisKeyword node. */ function substituteThisKeyword(node: PrimaryExpression): PrimaryExpression { - if (enabledSubstitutions & ES6SubstitutionFlags.CapturedThis && useCapturedThis) { + if (enabledSubstitutions & ES6SubstitutionFlags.CapturedThis + && enclosingFunction + && enclosingFunction.emitFlags & NodeEmitFlags.CapturesThis) { return createIdentifier("_this", /*location*/ node); } diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index d1e2b6033a6..5f142b6abe9 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -573,11 +573,11 @@ namespace ts { operationLocations = undefined; state = createTempVariable(/*recordTempVariable*/ undefined); - const statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor); - // Build the generator startLexicalEnvironment(); + const statementOffset = addPrologueDirectives(statements, body.statements, /*ensureUseStrict*/ false, visitor); + transformAndEmitStatements(body.statements, statementOffset); const buildResult = build(); @@ -615,6 +615,11 @@ namespace ts { return undefined; } else { + // Do not hoist custom prologues. + if (node.emitFlags & NodeEmitFlags.CustomPrologue) { + return node; + } + for (const variable of node.declarationList.declarations) { hoistVariableDeclaration(variable.name); } @@ -1020,7 +1025,7 @@ namespace ts { const temp = declareLocal(); emitAssignment(temp, createObjectLiteral( - visitNodes(properties, visitor, isObjectLiteralElement, 0, numInitialProperties), + visitNodes(properties, visitor, isObjectLiteralElementLike, 0, numInitialProperties), /*location*/ undefined, multiLine ) @@ -1030,13 +1035,13 @@ namespace ts { expressions.push(multiLine ? startOnNewLine(getMutableClone(temp)) : temp); return inlineExpressions(expressions); - function reduceProperty(expressions: Expression[], property: ObjectLiteralElement) { + function reduceProperty(expressions: Expression[], property: ObjectLiteralElementLike) { if (containsYield(property) && expressions.length > 0) { emitStatement(createStatement(inlineExpressions(expressions))); expressions = []; } - const expression = createExpressionForObjectLiteralElement(node, property, temp); + const expression = createExpressionForObjectLiteralElementLike(node, property, temp); const visited = visitNode(expression, visitor, isExpression); if (visited) { if (multiLine) { diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 9abd91b47c8..53004da2c17 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -850,7 +850,7 @@ namespace ts { return node; } - function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElement { + function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike { const name = node.name; const exportedOrImportedName = substituteExpressionIdentifier(name); if (exportedOrImportedName !== name) { diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 7b013e18e7d..5e3b0281227 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -288,7 +288,7 @@ namespace ts { } } - const exportedNames: ObjectLiteralElement[] = []; + const exportedNames: ObjectLiteralElementLike[] = []; if (exportedLocalNames) { for (const exportedLocalName of exportedLocalNames) { // write name of exported declaration, i.e 'export var x...' @@ -1107,7 +1107,7 @@ namespace ts { return false; } - function hasExportedReferenceInObjectDestructuringElement(node: ObjectLiteralElement): boolean { + function hasExportedReferenceInObjectDestructuringElement(node: ObjectLiteralElementLike): boolean { if (isShorthandPropertyAssignment(node)) { return isExportedBinding(node.name); } diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index d41a32d92c7..1d01e51f6d8 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -1560,7 +1560,7 @@ namespace ts { function addNewTypeMetadata(node: Declaration, decoratorExpressions: Expression[]) { if (compilerOptions.emitDecoratorMetadata) { - let properties: ObjectLiteralElement[]; + let properties: ObjectLiteralElementLike[]; if (shouldAddTypeMetadata(node)) { (properties || (properties = [])).push(createPropertyAssignment("type", createArrowFunction(/*modifiers*/ undefined, /*typeParameters*/ undefined, [], /*type*/ undefined, /*equalsGreaterThanToken*/ undefined, serializeTypeOfNode(node)))); } @@ -3273,7 +3273,7 @@ namespace ts { return node; } - function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElement { + function substituteShorthandPropertyAssignment(node: ShorthandPropertyAssignment): ObjectLiteralElementLike { if (enabledSubstitutions & TypeScriptSubstitutionFlags.NamespaceExports) { const name = node.name; const exportedName = trySubstituteNamespaceExportedName(name); diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 916d32841a4..b39c017384e 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -667,7 +667,7 @@ namespace ts { } function printHelp() { - let output = ""; + const output: string[] = []; // We want to align our "syntax" and "examples" commands to a certain margin. const syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length; @@ -678,17 +678,17 @@ namespace ts { let syntax = makePadding(marginLength - syntaxLength); syntax += "tsc [" + getDiagnosticText(Diagnostics.options) + "] [" + getDiagnosticText(Diagnostics.file) + " ...]"; - output += getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax); - output += sys.newLine + sys.newLine; + output.push(getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax)); + output.push(sys.newLine + sys.newLine); // Build up the list of examples. const padding = makePadding(marginLength); - output += getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine; - output += padding + "tsc --outFile file.js file.ts" + sys.newLine; - output += padding + "tsc @args.txt" + sys.newLine; - output += sys.newLine; + output.push(getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine); + output.push(padding + "tsc --outFile file.js file.ts" + sys.newLine); + output.push(padding + "tsc @args.txt" + sys.newLine); + output.push(sys.newLine); - output += getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine; + output.push(getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine); // Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch") const optsList = filter(optionDeclarations.slice(), v => !v.experimental); @@ -755,18 +755,20 @@ namespace ts { const usage = usageColumn[i]; const description = descriptionColumn[i]; const kindsList = optionsDescriptionMap[description]; - output += usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine; + output.push(usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine); if (kindsList) { - output += makePadding(marginLength + 4); + output.push(makePadding(marginLength + 4)); for (const kind of kindsList) { - output += kind + " "; + output.push(kind + " "); } - output += sys.newLine; + output.push(sys.newLine); } } - sys.write(output); + for (const line of output) { + sys.write(line); + } return; function getParamType(option: CommandLineOption) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e4bc9a29d5b..af71846145f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -648,6 +648,8 @@ namespace ts { name?: PropertyName; } + export type ObjectLiteralElementLike = PropertyAssignment | ShorthandPropertyAssignment | MethodDeclaration | AccessorDeclaration; + // @kind(SyntaxKind.PropertyAssignment) export interface PropertyAssignment extends ObjectLiteralElement { _propertyAssignmentBrand: any; @@ -1048,10 +1050,19 @@ namespace ts { expression: Expression; } + /** + * This interface is a base interface for ObjectLiteralExpression and JSXAttributes to extend from. JSXAttributes is similar to + * ObjectLiteralExpression in that it contains array of properties; however, JSXAttributes' properties can only be + * JSXAttribute or JSXSpreadAttribute. ObjectLiteralExpression, on the other hand, can only have properties of type + * ObjectLiteralElement (e.g. PropertyAssignment, ShorthandPropertyAssignment etc.) + **/ + export interface ObjectLiteralExpressionBase extends PrimaryExpression, Declaration { + properties: NodeArray; + } + // An ObjectLiteralExpression is the declaration node for an anonymous symbol. // @kind(SyntaxKind.ObjectLiteralExpression) - export interface ObjectLiteralExpression extends PrimaryExpression, Declaration { - properties: NodeArray; + export interface ObjectLiteralExpression extends ObjectLiteralExpressionBase { /* @internal */ multiLine?: boolean; } @@ -2156,6 +2167,8 @@ namespace ts { getExternalModuleFileFromDeclaration(declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration): SourceFile; getTypeReferenceDirectivesForEntityName(name: EntityNameOrEntityNameExpression): string[]; getTypeReferenceDirectivesForSymbol(symbol: Symbol, meaning?: SymbolFlags): string[]; + isLiteralConstDeclaration(node: VariableDeclaration): boolean; + writeLiteralConstValue(node: VariableDeclaration, writer: SymbolWriter): void; } export const enum SymbolFlags { @@ -2372,7 +2385,7 @@ namespace ts { /* @internal */ ObjectLiteral = 1 << 23, // Originates in an object literal /* @internal */ - FreshObjectLiteral = 1 << 24, // Fresh object literal type + FreshLiteral = 1 << 24, // Fresh literal type /* @internal */ ContainsWideningType = 1 << 25, // Type is or contains undefined or null widening type /* @internal */ @@ -2385,6 +2398,7 @@ namespace ts { /* @internal */ Nullable = Undefined | Null, Literal = StringLiteral | NumberLiteral | BooleanLiteral | EnumLiteral, + StringOrNumberLiteral = StringLiteral | NumberLiteral, /* @internal */ DefinitelyFalsy = StringLiteral | NumberLiteral | BooleanLiteral | Void | Undefined | Null, PossiblyFalsy = DefinitelyFalsy | String | Number | Boolean, @@ -2426,12 +2440,15 @@ namespace ts { /* @internal */ // Intrinsic types (TypeFlags.Intrinsic) export interface IntrinsicType extends Type { - intrinsicName: string; // Name of intrinsic type + intrinsicName: string; // Name of intrinsic type } // String literal types (TypeFlags.StringLiteral) + // Numeric literal types (TypeFlags.NumberLiteral) export interface LiteralType extends Type { - text: string; // Text of string literal + text: string; // Text of literal + freshType?: LiteralType; // Fresh version of type + regularType?: LiteralType; // Regular version of type } // Enum types (TypeFlags.Enum) @@ -2441,7 +2458,7 @@ namespace ts { // Enum types (TypeFlags.EnumLiteral) export interface EnumLiteralType extends LiteralType { - baseType: EnumType & UnionType; + baseType: EnumType & UnionType; // Base enum type } // Object types (TypeFlags.ObjectType) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 43ac7b0c9e0..fa615180f9d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3736,7 +3736,7 @@ namespace ts { || kind === SyntaxKind.SemicolonClassElement; } - export function isObjectLiteralElement(node: Node): node is ObjectLiteralElement { + export function isObjectLiteralElementLike(node: Node): node is ObjectLiteralElementLike { const kind = node.kind; return kind === SyntaxKind.PropertyAssignment || kind === SyntaxKind.ShorthandPropertyAssignment diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 1e0cadaaa6b..e147eda8535 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -772,7 +772,7 @@ namespace ts { case SyntaxKind.ObjectLiteralExpression: return updateObjectLiteral(node, - visitNodes((node).properties, visitor, isObjectLiteralElement)); + visitNodes((node).properties, visitor, isObjectLiteralElementLike)); case SyntaxKind.PropertyAccessExpression: return updatePropertyAccess(node, diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 63e01f0f814..70c6fdac329 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -136,9 +136,7 @@ class CompilerBaselineRunner extends RunnerBase { // check errors it("Correct errors for " + fileName, () => { - if (this.errors) { - Harness.Compiler.doErrorBaseline(justName, toBeCompiled.concat(otherFiles), result.errors); - } + Harness.Compiler.doErrorBaseline(justName, toBeCompiled.concat(otherFiles), result.errors); }); it (`Correct module resolution tracing for ${fileName}`, () => { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 0863c58851d..b4fd8736b2f 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1407,7 +1407,7 @@ namespace Harness { export function doErrorBaseline(baselinePath: string, inputFiles: TestFile[], errors: ts.Diagnostic[]) { Harness.Baseline.runBaseline(baselinePath.replace(/\.tsx?$/, ".errors.txt"), (): string => { - if (errors.length === 0) { + if (!errors || (errors.length === 0)) { /* tslint:disable:no-null-keyword */ return null; /* tslint:enable:no-null-keyword */ diff --git a/src/harness/unittests/commandLineParsing.ts b/src/harness/unittests/commandLineParsing.ts index afd0ff6f0ea..028786eef24 100644 --- a/src/harness/unittests/commandLineParsing.ts +++ b/src/harness/unittests/commandLineParsing.ts @@ -60,7 +60,7 @@ namespace ts { assertParseResult(["--lib", "es5,invalidOption", "0.ts"], { errors: [{ - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -263,7 +263,7 @@ namespace ts { assertParseResult(["--lib", "es5,", "es7", "0.ts"], { errors: [{ - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -283,7 +283,7 @@ namespace ts { assertParseResult(["--lib", "es5, ", "es7", "0.ts"], { errors: [{ - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, diff --git a/src/harness/unittests/convertCompilerOptionsFromJson.ts b/src/harness/unittests/convertCompilerOptionsFromJson.ts index 9de18850477..3f4314a9976 100644 --- a/src/harness/unittests/convertCompilerOptionsFromJson.ts +++ b/src/harness/unittests/convertCompilerOptionsFromJson.ts @@ -233,7 +233,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -264,7 +264,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -295,7 +295,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -326,7 +326,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] diff --git a/src/lib/dom.iterable.d.ts b/src/lib/dom.iterable.d.ts index 4f6378f038e..7f653dc8e0c 100644 --- a/src/lib/dom.iterable.d.ts +++ b/src/lib/dom.iterable.d.ts @@ -1,4 +1,4 @@ -/// +/// interface DOMTokenList { [Symbol.iterator](): IterableIterator; diff --git a/tests/baselines/reference/ambientConstLiterals.js b/tests/baselines/reference/ambientConstLiterals.js new file mode 100644 index 00000000000..4a590826b1d --- /dev/null +++ b/tests/baselines/reference/ambientConstLiterals.js @@ -0,0 +1,72 @@ +//// [ambientConstLiterals.ts] + +function f(x: T): T { + return x; +} + +enum E { A, B, C } + +const c1 = "abc"; +const c2 = 123; +const c3 = c1; +const c4 = c2; +const c5 = f(123); +const c6 = f(-123); +const c7 = true; +const c8 = E.A; +const c9 = { x: "abc" }; +const c10 = [123]; +const c11 = "abc" + "def"; +const c12 = 123 + 456; +const c13 = Math.random() > 0.5 ? "abc" : "def"; +const c14 = Math.random() > 0.5 ? 123 : 456; + +//// [ambientConstLiterals.js] +function f(x) { + return x; +} +var E; +(function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; +})(E || (E = {})); +var c1 = "abc"; +var c2 = 123; +var c3 = c1; +var c4 = c2; +var c5 = f(123); +var c6 = f(-123); +var c7 = true; +var c8 = E.A; +var c9 = { x: "abc" }; +var c10 = [123]; +var c11 = "abc" + "def"; +var c12 = 123 + 456; +var c13 = Math.random() > 0.5 ? "abc" : "def"; +var c14 = Math.random() > 0.5 ? 123 : 456; + + +//// [ambientConstLiterals.d.ts] +declare function f(x: T): T; +declare enum E { + A = 0, + B = 1, + C = 2, +} +declare const c1 = "abc"; +declare const c2 = 123; +declare const c3 = "abc"; +declare const c4 = 123; +declare const c5 = 123; +declare const c6 = -123; +declare const c7: boolean; +declare const c8: E; +declare const c9: { + x: string; +}; +declare const c10: number[]; +declare const c11: string; +declare const c12: number; +declare const c13: string; +declare const c14: number; diff --git a/tests/baselines/reference/ambientConstLiterals.symbols b/tests/baselines/reference/ambientConstLiterals.symbols new file mode 100644 index 00000000000..67d168a0750 --- /dev/null +++ b/tests/baselines/reference/ambientConstLiterals.symbols @@ -0,0 +1,75 @@ +=== tests/cases/compiler/ambientConstLiterals.ts === + +function f(x: T): T { +>f : Symbol(f, Decl(ambientConstLiterals.ts, 0, 0)) +>T : Symbol(T, Decl(ambientConstLiterals.ts, 1, 11)) +>x : Symbol(x, Decl(ambientConstLiterals.ts, 1, 14)) +>T : Symbol(T, Decl(ambientConstLiterals.ts, 1, 11)) +>T : Symbol(T, Decl(ambientConstLiterals.ts, 1, 11)) + + return x; +>x : Symbol(x, Decl(ambientConstLiterals.ts, 1, 14)) +} + +enum E { A, B, C } +>E : Symbol(E, Decl(ambientConstLiterals.ts, 3, 1)) +>A : Symbol(E.A, Decl(ambientConstLiterals.ts, 5, 8)) +>B : Symbol(E.B, Decl(ambientConstLiterals.ts, 5, 11)) +>C : Symbol(E.C, Decl(ambientConstLiterals.ts, 5, 14)) + +const c1 = "abc"; +>c1 : Symbol(c1, Decl(ambientConstLiterals.ts, 7, 5)) + +const c2 = 123; +>c2 : Symbol(c2, Decl(ambientConstLiterals.ts, 8, 5)) + +const c3 = c1; +>c3 : Symbol(c3, Decl(ambientConstLiterals.ts, 9, 5)) +>c1 : Symbol(c1, Decl(ambientConstLiterals.ts, 7, 5)) + +const c4 = c2; +>c4 : Symbol(c4, Decl(ambientConstLiterals.ts, 10, 5)) +>c2 : Symbol(c2, Decl(ambientConstLiterals.ts, 8, 5)) + +const c5 = f(123); +>c5 : Symbol(c5, Decl(ambientConstLiterals.ts, 11, 5)) +>f : Symbol(f, Decl(ambientConstLiterals.ts, 0, 0)) + +const c6 = f(-123); +>c6 : Symbol(c6, Decl(ambientConstLiterals.ts, 12, 5)) +>f : Symbol(f, Decl(ambientConstLiterals.ts, 0, 0)) + +const c7 = true; +>c7 : Symbol(c7, Decl(ambientConstLiterals.ts, 13, 5)) + +const c8 = E.A; +>c8 : Symbol(c8, Decl(ambientConstLiterals.ts, 14, 5)) +>E.A : Symbol(E.A, Decl(ambientConstLiterals.ts, 5, 8)) +>E : Symbol(E, Decl(ambientConstLiterals.ts, 3, 1)) +>A : Symbol(E.A, Decl(ambientConstLiterals.ts, 5, 8)) + +const c9 = { x: "abc" }; +>c9 : Symbol(c9, Decl(ambientConstLiterals.ts, 15, 5)) +>x : Symbol(x, Decl(ambientConstLiterals.ts, 15, 12)) + +const c10 = [123]; +>c10 : Symbol(c10, Decl(ambientConstLiterals.ts, 16, 5)) + +const c11 = "abc" + "def"; +>c11 : Symbol(c11, Decl(ambientConstLiterals.ts, 17, 5)) + +const c12 = 123 + 456; +>c12 : Symbol(c12, Decl(ambientConstLiterals.ts, 18, 5)) + +const c13 = Math.random() > 0.5 ? "abc" : "def"; +>c13 : Symbol(c13, Decl(ambientConstLiterals.ts, 19, 5)) +>Math.random : Symbol(Math.random, Decl(lib.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.d.ts, --, --)) + +const c14 = Math.random() > 0.5 ? 123 : 456; +>c14 : Symbol(c14, Decl(ambientConstLiterals.ts, 20, 5)) +>Math.random : Symbol(Math.random, Decl(lib.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>random : Symbol(Math.random, Decl(lib.d.ts, --, --)) + diff --git a/tests/baselines/reference/ambientConstLiterals.types b/tests/baselines/reference/ambientConstLiterals.types new file mode 100644 index 00000000000..8b6fc984628 --- /dev/null +++ b/tests/baselines/reference/ambientConstLiterals.types @@ -0,0 +1,105 @@ +=== tests/cases/compiler/ambientConstLiterals.ts === + +function f(x: T): T { +>f : (x: T) => T +>T : T +>x : T +>T : T +>T : T + + return x; +>x : T +} + +enum E { A, B, C } +>E : E +>A : E.A +>B : E.B +>C : E.C + +const c1 = "abc"; +>c1 : "abc" +>"abc" : "abc" + +const c2 = 123; +>c2 : 123 +>123 : 123 + +const c3 = c1; +>c3 : "abc" +>c1 : "abc" + +const c4 = c2; +>c4 : 123 +>c2 : 123 + +const c5 = f(123); +>c5 : 123 +>f(123) : 123 +>f : (x: T) => T +>123 : 123 + +const c6 = f(-123); +>c6 : -123 +>f(-123) : -123 +>f : (x: T) => T +>-123 : -123 +>123 : 123 + +const c7 = true; +>c7 : true +>true : true + +const c8 = E.A; +>c8 : E.A +>E.A : E.A +>E : typeof E +>A : E.A + +const c9 = { x: "abc" }; +>c9 : { x: string; } +>{ x: "abc" } : { x: string; } +>x : string +>"abc" : "abc" + +const c10 = [123]; +>c10 : number[] +>[123] : number[] +>123 : 123 + +const c11 = "abc" + "def"; +>c11 : string +>"abc" + "def" : string +>"abc" : "abc" +>"def" : "def" + +const c12 = 123 + 456; +>c12 : number +>123 + 456 : number +>123 : 123 +>456 : 456 + +const c13 = Math.random() > 0.5 ? "abc" : "def"; +>c13 : "abc" | "def" +>Math.random() > 0.5 ? "abc" : "def" : "abc" | "def" +>Math.random() > 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>0.5 : 0.5 +>"abc" : "abc" +>"def" : "def" + +const c14 = Math.random() > 0.5 ? 123 : 456; +>c14 : 123 | 456 +>Math.random() > 0.5 ? 123 : 456 : 123 | 456 +>Math.random() > 0.5 : boolean +>Math.random() : number +>Math.random : () => number +>Math : Math +>random : () => number +>0.5 : 0.5 +>123 : 123 +>456 : 456 + diff --git a/tests/baselines/reference/arrayconcat.types b/tests/baselines/reference/arrayconcat.types index 27724c63ab1..adbb1f7d021 100644 --- a/tests/baselines/reference/arrayconcat.types +++ b/tests/baselines/reference/arrayconcat.types @@ -46,7 +46,7 @@ class parser { >this : this >options : IOptions[] >sort : (compareFn?: (a: IOptions, b: IOptions) => number) => IOptions[] ->function(a, b) { var aName = a.name.toLowerCase(); var bName = b.name.toLowerCase(); if (aName > bName) { return 1; } else if (aName < bName) { return -1; } else { return 0; } } : (a: IOptions, b: IOptions) => 0 | 1 | -1 +>function(a, b) { var aName = a.name.toLowerCase(); var bName = b.name.toLowerCase(); if (aName > bName) { return 1; } else if (aName < bName) { return -1; } else { return 0; } } : (a: IOptions, b: IOptions) => 1 | -1 | 0 >a : IOptions >b : IOptions diff --git a/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt b/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt new file mode 100644 index 00000000000..289883d7471 --- /dev/null +++ b/tests/baselines/reference/assigningFromObjectToAnythingElse.errors.txt @@ -0,0 +1,38 @@ +tests/cases/compiler/assigningFromObjectToAnythingElse.ts(3,1): error TS2322: Type 'Object' is not assignable to type 'RegExp'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'exec' is missing in type 'Object'. +tests/cases/compiler/assigningFromObjectToAnythingElse.ts(5,5): error TS2322: Type 'Object' is not assignable to type 'String'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'charAt' is missing in type 'Object'. +tests/cases/compiler/assigningFromObjectToAnythingElse.ts(6,5): error TS2322: Type 'Number' is not assignable to type 'String'. + Property 'charAt' is missing in type 'Number'. +tests/cases/compiler/assigningFromObjectToAnythingElse.ts(8,5): error TS2322: Type 'Object' is not assignable to type 'Error'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'name' is missing in type 'Object'. + + +==== tests/cases/compiler/assigningFromObjectToAnythingElse.ts (4 errors) ==== + var x: Object; + var y: RegExp; + y = x; + ~ +!!! error TS2322: Type 'Object' is not assignable to type 'RegExp'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'exec' is missing in type 'Object'. + + var a: String = Object.create(""); + ~ +!!! error TS2322: Type 'Object' is not assignable to type 'String'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'charAt' is missing in type 'Object'. + var c: String = Object.create(1); + ~ +!!! error TS2322: Type 'Number' is not assignable to type 'String'. +!!! error TS2322: Property 'charAt' is missing in type 'Number'. + + var w: Error = new Object(); + ~ +!!! error TS2322: Type 'Object' is not assignable to type 'Error'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'name' is missing in type 'Object'. + \ No newline at end of file diff --git a/tests/baselines/reference/assigningFromObjectToAnythingElse.js b/tests/baselines/reference/assigningFromObjectToAnythingElse.js new file mode 100644 index 00000000000..61c4a6ede22 --- /dev/null +++ b/tests/baselines/reference/assigningFromObjectToAnythingElse.js @@ -0,0 +1,18 @@ +//// [assigningFromObjectToAnythingElse.ts] +var x: Object; +var y: RegExp; +y = x; + +var a: String = Object.create(""); +var c: String = Object.create(1); + +var w: Error = new Object(); + + +//// [assigningFromObjectToAnythingElse.js] +var x; +var y; +y = x; +var a = Object.create(""); +var c = Object.create(1); +var w = new Object(); diff --git a/tests/baselines/reference/asyncArrowFunction7_es5.js b/tests/baselines/reference/asyncArrowFunction7_es5.js index 19e589fa542..f2edb2b6537 100644 --- a/tests/baselines/reference/asyncArrowFunction7_es5.js +++ b/tests/baselines/reference/asyncArrowFunction7_es5.js @@ -9,7 +9,7 @@ var bar = async (): Promise => { //// [asyncArrowFunction7_es5.js] var _this = this; var bar = function () { return __awaiter(_this, void 0, void 0, function () { - _this = this; + var _this = this; var foo; return __generator(this, function (_a) { foo = function (a) { @@ -22,4 +22,4 @@ var bar = function () { return __awaiter(_this, void 0, void 0, function () { }; return [2 /*return*/]; }); -}); var _this; }; +}); }; diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.types b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.types index ad09c274c9b..997f4ea5249 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.types +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.types @@ -30,7 +30,7 @@ var derived2: Derived2; var r2 = true ? 1 : ''; >r2 : string | number ->true ? 1 : '' : "" | 1 +>true ? 1 : '' : 1 | "" >true : true >1 : 1 >'' : "" diff --git a/tests/baselines/reference/blockScopedBindingCaptureThisInFunction.js b/tests/baselines/reference/blockScopedBindingCaptureThisInFunction.js new file mode 100644 index 00000000000..27568fd51ec --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingCaptureThisInFunction.js @@ -0,0 +1,21 @@ +//// [blockScopedBindingCaptureThisInFunction.ts] +// https://github.com/Microsoft/TypeScript/issues/11038 +() => function () { + for (let someKey in {}) { + this.helloWorld(); + () => someKey; + } +}; + +//// [blockScopedBindingCaptureThisInFunction.js] +// https://github.com/Microsoft/TypeScript/issues/11038 +(function () { return function () { + var _loop_1 = function (someKey) { + this_1.helloWorld(); + (function () { return someKey; }); + }; + var this_1 = this; + for (var someKey in {}) { + _loop_1(someKey); + } +}; }); diff --git a/tests/baselines/reference/blockScopedBindingCaptureThisInFunction.symbols b/tests/baselines/reference/blockScopedBindingCaptureThisInFunction.symbols new file mode 100644 index 00000000000..e19b805dc5c --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingCaptureThisInFunction.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/blockScopedBindingCaptureThisInFunction.ts === +// https://github.com/Microsoft/TypeScript/issues/11038 +() => function () { + for (let someKey in {}) { +>someKey : Symbol(someKey, Decl(blockScopedBindingCaptureThisInFunction.ts, 2, 12)) + + this.helloWorld(); + () => someKey; +>someKey : Symbol(someKey, Decl(blockScopedBindingCaptureThisInFunction.ts, 2, 12)) + } +}; diff --git a/tests/baselines/reference/blockScopedBindingCaptureThisInFunction.types b/tests/baselines/reference/blockScopedBindingCaptureThisInFunction.types new file mode 100644 index 00000000000..34d1dae9a94 --- /dev/null +++ b/tests/baselines/reference/blockScopedBindingCaptureThisInFunction.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/blockScopedBindingCaptureThisInFunction.ts === +// https://github.com/Microsoft/TypeScript/issues/11038 +() => function () { +>() => function () { for (let someKey in {}) { this.helloWorld(); () => someKey; }} : () => () => void +>function () { for (let someKey in {}) { this.helloWorld(); () => someKey; }} : () => void + + for (let someKey in {}) { +>someKey : string +>{} : {} + + this.helloWorld(); +>this.helloWorld() : any +>this.helloWorld : any +>this : any +>helloWorld : any + + () => someKey; +>() => someKey : () => string +>someKey : string + } +}; diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types index 63651072644..91ad88c8ade 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types @@ -19,7 +19,7 @@ declare function foo(obj: I): T foo({ >foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | number | boolean | (() => void) | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: true | "" | 0 | (() => void) | number[]; [x: number]: 0 | (() => void) | number[]; 0: () => void; p: ""; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: true | "" | (() => void) | 0 | number[]; [x: number]: (() => void) | 0 | number[]; 0: () => void; p: ""; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types index fa34f015a23..131e49dd173 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types @@ -19,7 +19,7 @@ declare function foo(obj: I): T foo({ >foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | number | boolean | (() => void) | number[] >foo : (obj: I) => T ->{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: true | "" | 0 | (() => void) | number[]; [x: number]: 0 | (() => void) | number[]; 0: () => void; p: ""; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: true | "" | (() => void) | 0 | number[]; [x: number]: (() => void) | 0 | number[]; 0: () => void; p: ""; } p: "", >p : string diff --git a/tests/baselines/reference/conditionalExpression1.errors.txt b/tests/baselines/reference/conditionalExpression1.errors.txt index 66af5336808..2b342129523 100644 --- a/tests/baselines/reference/conditionalExpression1.errors.txt +++ b/tests/baselines/reference/conditionalExpression1.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2322: Type '"" | 1' is not assignable to type 'boolean'. - Type '""' is not assignable to type 'boolean'. +tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2322: Type '1 | ""' is not assignable to type 'boolean'. + Type '1' is not assignable to type 'boolean'. ==== tests/cases/compiler/conditionalExpression1.ts (1 errors) ==== var x: boolean = (true ? 1 : ""); // should be an error ~ -!!! error TS2322: Type '"" | 1' is not assignable to type 'boolean'. -!!! error TS2322: Type '""' is not assignable to type 'boolean'. \ No newline at end of file +!!! error TS2322: Type '1 | ""' is not assignable to type 'boolean'. +!!! error TS2322: Type '1' is not assignable to type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/conditionalExpressions2.types b/tests/baselines/reference/conditionalExpressions2.types index 0247b0f649d..c2b2e23e57b 100644 --- a/tests/baselines/reference/conditionalExpressions2.types +++ b/tests/baselines/reference/conditionalExpressions2.types @@ -16,7 +16,7 @@ var b = false ? undefined : 0; var c = false ? 1 : 0; >c : number ->false ? 1 : 0 : 0 | 1 +>false ? 1 : 0 : 1 | 0 >false : false >1 : 1 >0 : 0 diff --git a/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt b/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt index 6e2d00dc4c4..2ecc7fc7ed3 100644 --- a/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt +++ b/tests/baselines/reference/constDeclarations-ambient-errors.errors.txt @@ -1,13 +1,12 @@ tests/cases/compiler/constDeclarations-ambient-errors.ts(3,27): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/compiler/constDeclarations-ambient-errors.ts(4,26): error TS1039: Initializers are not allowed in ambient contexts. -tests/cases/compiler/constDeclarations-ambient-errors.ts(5,18): error TS1039: Initializers are not allowed in ambient contexts. +tests/cases/compiler/constDeclarations-ambient-errors.ts(5,20): error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal. tests/cases/compiler/constDeclarations-ambient-errors.ts(5,37): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/compiler/constDeclarations-ambient-errors.ts(5,51): error TS1039: Initializers are not allowed in ambient contexts. -tests/cases/compiler/constDeclarations-ambient-errors.ts(8,14): error TS1039: Initializers are not allowed in ambient contexts. tests/cases/compiler/constDeclarations-ambient-errors.ts(9,22): error TS1039: Initializers are not allowed in ambient contexts. -==== tests/cases/compiler/constDeclarations-ambient-errors.ts (7 errors) ==== +==== tests/cases/compiler/constDeclarations-ambient-errors.ts (6 errors) ==== // error: no intialization expected in ambient declarations declare const c1: boolean = true; @@ -17,8 +16,8 @@ tests/cases/compiler/constDeclarations-ambient-errors.ts(9,22): error TS1039: In ~ !!! error TS1039: Initializers are not allowed in ambient contexts. declare const c3 = null, c4 :string = "", c5: any = 0; - ~ -!!! error TS1039: Initializers are not allowed in ambient contexts. + ~~~~ +!!! error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal. ~ !!! error TS1039: Initializers are not allowed in ambient contexts. ~ @@ -26,8 +25,6 @@ tests/cases/compiler/constDeclarations-ambient-errors.ts(9,22): error TS1039: In declare module M { const c6 = 0; - ~ -!!! error TS1039: Initializers are not allowed in ambient contexts. const c7: number = 7; ~ !!! error TS1039: Initializers are not allowed in ambient contexts. diff --git a/tests/baselines/reference/constDeclarations.js b/tests/baselines/reference/constDeclarations.js index 7e5902ed5a1..00d0a61ef9b 100644 --- a/tests/baselines/reference/constDeclarations.js +++ b/tests/baselines/reference/constDeclarations.js @@ -25,6 +25,6 @@ for (const c5 = 0, c6 = 0; c5 < c6;) { //// [constDeclarations.d.ts] -declare const c1: false; +declare const c1: boolean; declare const c2: number; -declare const c3: 0, c4: string, c5: any; +declare const c3 = 0, c4: string, c5: any; diff --git a/tests/baselines/reference/constDeclarations2.js b/tests/baselines/reference/constDeclarations2.js index ea7134d4664..0c372924b50 100644 --- a/tests/baselines/reference/constDeclarations2.js +++ b/tests/baselines/reference/constDeclarations2.js @@ -20,7 +20,7 @@ var M; //// [constDeclarations2.d.ts] declare module M { - const c1: false; + const c1: boolean; const c2: number; - const c3: 0, c4: string, c5: any; + const c3 = 0, c4: string, c5: any; } diff --git a/tests/baselines/reference/controlFlowWithIncompleteTypes.js b/tests/baselines/reference/controlFlowWithIncompleteTypes.js new file mode 100644 index 00000000000..83940df6753 --- /dev/null +++ b/tests/baselines/reference/controlFlowWithIncompleteTypes.js @@ -0,0 +1,53 @@ +//// [controlFlowWithIncompleteTypes.ts] +// Repro from #11000 + +declare var cond: boolean; + +function foo1() { + let x: string | number | boolean = 0; + while (cond) { + if (typeof x === "string") { + x = x.slice(); + } + else { + x = "abc"; + } + } +} + +function foo2() { + let x: string | number | boolean = 0; + while (cond) { + if (typeof x === "number") { + x = "abc"; + } + else { + x = x.slice(); + } + } +} + +//// [controlFlowWithIncompleteTypes.js] +// Repro from #11000 +function foo1() { + var x = 0; + while (cond) { + if (typeof x === "string") { + x = x.slice(); + } + else { + x = "abc"; + } + } +} +function foo2() { + var x = 0; + while (cond) { + if (typeof x === "number") { + x = "abc"; + } + else { + x = x.slice(); + } + } +} diff --git a/tests/baselines/reference/controlFlowWithIncompleteTypes.symbols b/tests/baselines/reference/controlFlowWithIncompleteTypes.symbols new file mode 100644 index 00000000000..2ad709140cb --- /dev/null +++ b/tests/baselines/reference/controlFlowWithIncompleteTypes.symbols @@ -0,0 +1,55 @@ +=== tests/cases/compiler/controlFlowWithIncompleteTypes.ts === +// Repro from #11000 + +declare var cond: boolean; +>cond : Symbol(cond, Decl(controlFlowWithIncompleteTypes.ts, 2, 11)) + +function foo1() { +>foo1 : Symbol(foo1, Decl(controlFlowWithIncompleteTypes.ts, 2, 26)) + + let x: string | number | boolean = 0; +>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 5, 7)) + + while (cond) { +>cond : Symbol(cond, Decl(controlFlowWithIncompleteTypes.ts, 2, 11)) + + if (typeof x === "string") { +>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 5, 7)) + + x = x.slice(); +>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 5, 7)) +>x.slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 5, 7)) +>slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) + } + else { + x = "abc"; +>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 5, 7)) + } + } +} + +function foo2() { +>foo2 : Symbol(foo2, Decl(controlFlowWithIncompleteTypes.ts, 14, 1)) + + let x: string | number | boolean = 0; +>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 17, 7)) + + while (cond) { +>cond : Symbol(cond, Decl(controlFlowWithIncompleteTypes.ts, 2, 11)) + + if (typeof x === "number") { +>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 17, 7)) + + x = "abc"; +>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 17, 7)) + } + else { + x = x.slice(); +>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 17, 7)) +>x.slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(controlFlowWithIncompleteTypes.ts, 17, 7)) +>slice : Symbol(String.slice, Decl(lib.d.ts, --, --)) + } + } +} diff --git a/tests/baselines/reference/controlFlowWithIncompleteTypes.types b/tests/baselines/reference/controlFlowWithIncompleteTypes.types new file mode 100644 index 00000000000..784f22a3966 --- /dev/null +++ b/tests/baselines/reference/controlFlowWithIncompleteTypes.types @@ -0,0 +1,71 @@ +=== tests/cases/compiler/controlFlowWithIncompleteTypes.ts === +// Repro from #11000 + +declare var cond: boolean; +>cond : boolean + +function foo1() { +>foo1 : () => void + + let x: string | number | boolean = 0; +>x : string | number | boolean +>0 : 0 + + while (cond) { +>cond : boolean + + if (typeof x === "string") { +>typeof x === "string" : boolean +>typeof x : string +>x : string | number +>"string" : "string" + + x = x.slice(); +>x = x.slice() : string +>x : string | number | boolean +>x.slice() : string +>x.slice : (start?: number, end?: number) => string +>x : string +>slice : (start?: number, end?: number) => string + } + else { + x = "abc"; +>x = "abc" : "abc" +>x : string | number | boolean +>"abc" : "abc" + } + } +} + +function foo2() { +>foo2 : () => void + + let x: string | number | boolean = 0; +>x : string | number | boolean +>0 : 0 + + while (cond) { +>cond : boolean + + if (typeof x === "number") { +>typeof x === "number" : boolean +>typeof x : string +>x : string | number +>"number" : "number" + + x = "abc"; +>x = "abc" : "abc" +>x : string | number | boolean +>"abc" : "abc" + } + else { + x = x.slice(); +>x = x.slice() : string +>x : string | number | boolean +>x.slice() : string +>x.slice : (start?: number, end?: number) => string +>x : string +>slice : (start?: number, end?: number) => string + } + } +} diff --git a/tests/baselines/reference/declFileTypeAnnotationParenType.types b/tests/baselines/reference/declFileTypeAnnotationParenType.types index f3c8db5533a..1fd0b6ee5d9 100644 --- a/tests/baselines/reference/declFileTypeAnnotationParenType.types +++ b/tests/baselines/reference/declFileTypeAnnotationParenType.types @@ -25,7 +25,7 @@ var y = [() => new c()]; var k: (() => c) | string = (() => new c()) || ""; >k : string | (() => c) >c : c ->(() => new c()) || "" : "" | (() => c) +>(() => new c()) || "" : (() => c) | "" >(() => new c()) : () => c >() => new c() : () => c >new c() : c diff --git a/tests/baselines/reference/declarationEmitClassMemberNameConflict2.js b/tests/baselines/reference/declarationEmitClassMemberNameConflict2.js index 233ca0fe138..c5f8203a659 100644 --- a/tests/baselines/reference/declarationEmitClassMemberNameConflict2.js +++ b/tests/baselines/reference/declarationEmitClassMemberNameConflict2.js @@ -45,7 +45,7 @@ var Foo = (function () { //// [declarationEmitClassMemberNameConflict2.d.ts] -declare const Bar: "bar"; +declare const Bar = "bar"; declare enum Hello { World = 0, } diff --git a/tests/baselines/reference/es6modulekindWithES5Target6.js b/tests/baselines/reference/es6modulekindWithES5Target6.js index 6f8de9db816..d305c60e54e 100644 --- a/tests/baselines/reference/es6modulekindWithES5Target6.js +++ b/tests/baselines/reference/es6modulekindWithES5Target6.js @@ -11,15 +11,15 @@ export default function f3(d = 0) { //// [es6modulekindWithES5Target6.js] -function f1(d) { +export function f1(d) { if (d === void 0) { d = 0; } } -function f2() { +export function f2() { var arg = []; for (var _i = 0; _i < arguments.length; _i++) { arg[_i - 0] = arguments[_i]; } } -function f3(d) { +export default function f3(d) { if (d === void 0) { d = 0; } } diff --git a/tests/baselines/reference/forOfTransformsExpression.js b/tests/baselines/reference/forOfTransformsExpression.js new file mode 100644 index 00000000000..4b953b5cba1 --- /dev/null +++ b/tests/baselines/reference/forOfTransformsExpression.js @@ -0,0 +1,13 @@ +//// [forOfTransformsExpression.ts] +// https://github.com/Microsoft/TypeScript/issues/11024 +let items = [{ name: "A" }, { name: "C" }, { name: "B" }]; +for (var item of items.sort((a, b) => a.name.localeCompare(b.name))) { + +} + +//// [forOfTransformsExpression.js] +// https://github.com/Microsoft/TypeScript/issues/11024 +var items = [{ name: "A" }, { name: "C" }, { name: "B" }]; +for (var _i = 0, _a = items.sort(function (a, b) { return a.name.localeCompare(b.name); }); _i < _a.length; _i++) { + var item = _a[_i]; +} diff --git a/tests/baselines/reference/forOfTransformsExpression.symbols b/tests/baselines/reference/forOfTransformsExpression.symbols new file mode 100644 index 00000000000..9348f587084 --- /dev/null +++ b/tests/baselines/reference/forOfTransformsExpression.symbols @@ -0,0 +1,25 @@ +=== tests/cases/compiler/forOfTransformsExpression.ts === +// https://github.com/Microsoft/TypeScript/issues/11024 +let items = [{ name: "A" }, { name: "C" }, { name: "B" }]; +>items : Symbol(items, Decl(forOfTransformsExpression.ts, 1, 3)) +>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14)) +>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 29)) +>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 44)) + +for (var item of items.sort((a, b) => a.name.localeCompare(b.name))) { +>item : Symbol(item, Decl(forOfTransformsExpression.ts, 2, 8)) +>items.sort : Symbol(Array.sort, Decl(lib.d.ts, --, --)) +>items : Symbol(items, Decl(forOfTransformsExpression.ts, 1, 3)) +>sort : Symbol(Array.sort, Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(forOfTransformsExpression.ts, 2, 29)) +>b : Symbol(b, Decl(forOfTransformsExpression.ts, 2, 31)) +>a.name.localeCompare : Symbol(String.localeCompare, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>a.name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14)) +>a : Symbol(a, Decl(forOfTransformsExpression.ts, 2, 29)) +>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14)) +>localeCompare : Symbol(String.localeCompare, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>b.name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14)) +>b : Symbol(b, Decl(forOfTransformsExpression.ts, 2, 31)) +>name : Symbol(name, Decl(forOfTransformsExpression.ts, 1, 14)) + +} diff --git a/tests/baselines/reference/forOfTransformsExpression.types b/tests/baselines/reference/forOfTransformsExpression.types new file mode 100644 index 00000000000..212cb202aab --- /dev/null +++ b/tests/baselines/reference/forOfTransformsExpression.types @@ -0,0 +1,35 @@ +=== tests/cases/compiler/forOfTransformsExpression.ts === +// https://github.com/Microsoft/TypeScript/issues/11024 +let items = [{ name: "A" }, { name: "C" }, { name: "B" }]; +>items : { name: string; }[] +>[{ name: "A" }, { name: "C" }, { name: "B" }] : { name: string; }[] +>{ name: "A" } : { name: string; } +>name : string +>"A" : "A" +>{ name: "C" } : { name: string; } +>name : string +>"C" : "C" +>{ name: "B" } : { name: string; } +>name : string +>"B" : "B" + +for (var item of items.sort((a, b) => a.name.localeCompare(b.name))) { +>item : { name: string; } +>items.sort((a, b) => a.name.localeCompare(b.name)) : { name: string; }[] +>items.sort : (compareFn?: (a: { name: string; }, b: { name: string; }) => number) => { name: string; }[] +>items : { name: string; }[] +>sort : (compareFn?: (a: { name: string; }, b: { name: string; }) => number) => { name: string; }[] +>(a, b) => a.name.localeCompare(b.name) : (a: { name: string; }, b: { name: string; }) => number +>a : { name: string; } +>b : { name: string; } +>a.name.localeCompare(b.name) : number +>a.name.localeCompare : { (that: string): number; (that: string, locales?: string | string[], options?: Intl.CollatorOptions): number; } +>a.name : string +>a : { name: string; } +>name : string +>localeCompare : { (that: string): number; (that: string, locales?: string | string[], options?: Intl.CollatorOptions): number; } +>b.name : string +>b : { name: string; } +>name : string + +} diff --git a/tests/baselines/reference/functionWithMultipleReturnStatements.types b/tests/baselines/reference/functionWithMultipleReturnStatements.types index 775ca52e1db..fec29e5a01b 100644 --- a/tests/baselines/reference/functionWithMultipleReturnStatements.types +++ b/tests/baselines/reference/functionWithMultipleReturnStatements.types @@ -4,7 +4,7 @@ // it is an error if there is no single BCT, these are error cases function f1() { ->f1 : () => "" | 1 +>f1 : () => 1 | "" if (true) { >true : true @@ -19,7 +19,7 @@ function f1() { } function f2() { ->f2 : () => "" | 1 | 2 +>f2 : () => 1 | "" | 2 if (true) { >true : true @@ -40,7 +40,7 @@ function f2() { } function f3() { ->f3 : () => "" | 1 +>f3 : () => 1 | "" try { return 1; @@ -55,7 +55,7 @@ function f3() { } function f4() { ->f4 : () => "" | 1 +>f4 : () => 1 | "" try { return 1; @@ -72,7 +72,7 @@ function f4() { } function f5() { ->f5 : () => "" | 1 +>f5 : () => 1 | "" return 1; >1 : 1 diff --git a/tests/baselines/reference/functionsWithModifiersInBlocks1.js b/tests/baselines/reference/functionsWithModifiersInBlocks1.js index 3edd17321cb..873411afd2a 100644 --- a/tests/baselines/reference/functionsWithModifiersInBlocks1.js +++ b/tests/baselines/reference/functionsWithModifiersInBlocks1.js @@ -7,5 +7,5 @@ //// [functionsWithModifiersInBlocks1.js] { - function f() { } + export function f() { } } diff --git a/tests/baselines/reference/intTypeCheck.errors.txt b/tests/baselines/reference/intTypeCheck.errors.txt index 2214c685956..f8b4fef7310 100644 --- a/tests/baselines/reference/intTypeCheck.errors.txt +++ b/tests/baselines/reference/intTypeCheck.errors.txt @@ -2,7 +2,8 @@ tests/cases/compiler/intTypeCheck.ts(35,6): error TS2304: Cannot find name 'p'. tests/cases/compiler/intTypeCheck.ts(71,6): error TS2304: Cannot find name 'p'. tests/cases/compiler/intTypeCheck.ts(85,5): error TS2386: Overload signatures must all be optional or required. tests/cases/compiler/intTypeCheck.ts(99,5): error TS2322: Type 'Object' is not assignable to type 'i1'. - Property 'p' is missing in type 'Object'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'p' is missing in type 'Object'. tests/cases/compiler/intTypeCheck.ts(100,16): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(101,5): error TS2322: Type 'Base' is not assignable to type 'i1'. Property 'p' is missing in type 'Base'. @@ -15,7 +16,8 @@ tests/cases/compiler/intTypeCheck.ts(107,17): error TS2351: Cannot use 'new' wit tests/cases/compiler/intTypeCheck.ts(112,5): error TS2322: Type '{}' is not assignable to type 'i2'. Type '{}' provides no match for the signature '(): any' tests/cases/compiler/intTypeCheck.ts(113,5): error TS2322: Type 'Object' is not assignable to type 'i2'. - Type 'Object' provides no match for the signature '(): any' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature '(): any' tests/cases/compiler/intTypeCheck.ts(114,17): error TS2350: Only a void function can be called with the 'new' keyword. tests/cases/compiler/intTypeCheck.ts(115,5): error TS2322: Type 'Base' is not assignable to type 'i2'. Type 'Base' provides no match for the signature '(): any' @@ -26,7 +28,8 @@ tests/cases/compiler/intTypeCheck.ts(121,17): error TS2351: Cannot use 'new' wit tests/cases/compiler/intTypeCheck.ts(126,5): error TS2322: Type '{}' is not assignable to type 'i3'. Type '{}' provides no match for the signature 'new (): any' tests/cases/compiler/intTypeCheck.ts(127,5): error TS2322: Type 'Object' is not assignable to type 'i3'. - Type 'Object' provides no match for the signature 'new (): any' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature 'new (): any' tests/cases/compiler/intTypeCheck.ts(129,5): error TS2322: Type 'Base' is not assignable to type 'i3'. Type 'Base' provides no match for the signature 'new (): any' tests/cases/compiler/intTypeCheck.ts(131,5): error TS2322: Type '() => void' is not assignable to type 'i3'. @@ -43,7 +46,8 @@ tests/cases/compiler/intTypeCheck.ts(149,17): error TS2351: Cannot use 'new' wit tests/cases/compiler/intTypeCheck.ts(154,5): error TS2322: Type '{}' is not assignable to type 'i5'. Property 'p' is missing in type '{}'. tests/cases/compiler/intTypeCheck.ts(155,5): error TS2322: Type 'Object' is not assignable to type 'i5'. - Property 'p' is missing in type 'Object'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Property 'p' is missing in type 'Object'. tests/cases/compiler/intTypeCheck.ts(156,17): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. tests/cases/compiler/intTypeCheck.ts(157,5): error TS2322: Type 'Base' is not assignable to type 'i5'. Property 'p' is missing in type 'Base'. @@ -56,7 +60,8 @@ tests/cases/compiler/intTypeCheck.ts(163,17): error TS2351: Cannot use 'new' wit tests/cases/compiler/intTypeCheck.ts(168,5): error TS2322: Type '{}' is not assignable to type 'i6'. Type '{}' provides no match for the signature '(): any' tests/cases/compiler/intTypeCheck.ts(169,5): error TS2322: Type 'Object' is not assignable to type 'i6'. - Type 'Object' provides no match for the signature '(): any' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature '(): any' tests/cases/compiler/intTypeCheck.ts(170,17): error TS2350: Only a void function can be called with the 'new' keyword. tests/cases/compiler/intTypeCheck.ts(171,5): error TS2322: Type 'Base' is not assignable to type 'i6'. Type 'Base' provides no match for the signature '(): any' @@ -69,7 +74,8 @@ tests/cases/compiler/intTypeCheck.ts(177,17): error TS2351: Cannot use 'new' wit tests/cases/compiler/intTypeCheck.ts(182,5): error TS2322: Type '{}' is not assignable to type 'i7'. Type '{}' provides no match for the signature 'new (): any' tests/cases/compiler/intTypeCheck.ts(183,5): error TS2322: Type 'Object' is not assignable to type 'i7'. - Type 'Object' provides no match for the signature 'new (): any' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature 'new (): any' tests/cases/compiler/intTypeCheck.ts(185,17): error TS2352: Type 'Base' cannot be converted to type 'i7'. Type 'Base' provides no match for the signature 'new (): any' tests/cases/compiler/intTypeCheck.ts(187,5): error TS2322: Type '() => void' is not assignable to type 'i7'. @@ -193,7 +199,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj2: i1 = new Object(); ~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i1'. -!!! error TS2322: Property 'p' is missing in type 'Object'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'p' is missing in type 'Object'. var obj3: i1 = new obj0; ~~~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -229,7 +236,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj13: i2 = new Object(); ~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i2'. -!!! error TS2322: Type 'Object' provides no match for the signature '(): any' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature '(): any' var obj14: i2 = new obj11; ~~~~~~~~~ !!! error TS2350: Only a void function can be called with the 'new' keyword. @@ -262,7 +270,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj24: i3 = new Object(); ~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i3'. -!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' var obj25: i3 = new obj22; var obj26: i3 = new Base; ~~~~~ @@ -320,7 +329,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj46: i5 = new Object(); ~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i5'. -!!! error TS2322: Property 'p' is missing in type 'Object'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Property 'p' is missing in type 'Object'. var obj47: i5 = new obj44; ~~~~~~~~~ !!! error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature. @@ -356,7 +366,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj57: i6 = new Object(); ~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i6'. -!!! error TS2322: Type 'Object' provides no match for the signature '(): any' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature '(): any' var obj58: i6 = new obj55; ~~~~~~~~~ !!! error TS2350: Only a void function can be called with the 'new' keyword. @@ -392,7 +403,8 @@ tests/cases/compiler/intTypeCheck.ts(205,17): error TS2351: Cannot use 'new' wit var obj68: i7 = new Object(); ~~~~~ !!! error TS2322: Type 'Object' is not assignable to type 'i7'. -!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' var obj69: i7 = new obj66; var obj70: i7 = new Base; ~~~~~~~~~~~~ diff --git a/tests/baselines/reference/literalTypeWidening.js b/tests/baselines/reference/literalTypeWidening.js new file mode 100644 index 00000000000..58002123557 --- /dev/null +++ b/tests/baselines/reference/literalTypeWidening.js @@ -0,0 +1,174 @@ +//// [literalTypeWidening.ts] +// Widening vs. non-widening literal types + +function f1() { + const c1 = "hello"; // Widening type "hello" + let v1 = c1; // Type string + const c2 = c1; // Widening type "hello" + let v2 = c2; // Type string + const c3: "hello" = "hello"; // Type "hello" + let v3 = c3; // Type "hello" + const c4: "hello" = c1; // Type "hello" + let v4 = c4; // Type "hello" +} + +function f2(cond: boolean) { + const c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar" + const c2: "foo" | "bar" = c1; // "foo" | "bar" + const c3 = cond ? c1 : c2; // "foo" | "bar" + const c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz" + const c5: "foo" | "bar" | "baz" = c4; // "foo" | "bar" | "baz" + let v1 = c1; // string + let v2 = c2; // "foo" | "bar" + let v3 = c3; // "foo" | "bar" + let v4 = c4; // string + let v5 = c5; // "foo" | "bar" | "baz" +} + +function f3() { + const c1 = 123; // Widening type 123 + let v1 = c1; // Type number + const c2 = c1; // Widening type 123 + let v2 = c2; // Type number + const c3: 123 = 123; // Type 123 + let v3 = c3; // Type 123 + const c4: 123 = c1; // Type 123 + let v4 = c4; // Type 123 +} + +function f4(cond: boolean) { + const c1 = cond ? 123 : 456; // widening 123 | widening 456 + const c2: 123 | 456 = c1; // 123 | 456 + const c3 = cond ? c1 : c2; // 123 | 456 + const c4 = cond ? c3 : 789; // 123 | 456 | widening 789 + const c5: 123 | 456 | 789 = c4; // 123 | 456 | 789 + let v1 = c1; // number + let v2 = c2; // 123 | 456 + let v3 = c3; // 123 | 456 + let v4 = c4; // number + let v5 = c5; // 123 | 456 | 789 +} + +function f5() { + const c1 = "foo"; + let v1 = c1; + const c2: "foo" = "foo"; + let v2 = c2; + const c3 = "foo" as "foo"; + let v3 = c3; + const c4 = <"foo">"foo"; + let v4 = c4; +} + +// Repro from #10898 + +type FAILURE = "FAILURE"; +const FAILURE = "FAILURE"; + +type Result = T | FAILURE; + +function doWork(): Result { + return FAILURE; +} + +function isSuccess(result: Result): result is T { + return !isFailure(result); +} + +function isFailure(result: Result): result is FAILURE { + return result === FAILURE; +} + +function increment(x: number): number { + return x + 1; +} + +let result = doWork(); + +if (isSuccess(result)) { + increment(result); +} + +// Repro from #10898 + +type TestEvent = "onmouseover" | "onmouseout"; + +function onMouseOver(): TestEvent { return "onmouseover"; } + +let x = onMouseOver(); + +//// [literalTypeWidening.js] +// Widening vs. non-widening literal types +function f1() { + var c1 = "hello"; // Widening type "hello" + var v1 = c1; // Type string + var c2 = c1; // Widening type "hello" + var v2 = c2; // Type string + var c3 = "hello"; // Type "hello" + var v3 = c3; // Type "hello" + var c4 = c1; // Type "hello" + var v4 = c4; // Type "hello" +} +function f2(cond) { + var c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar" + var c2 = c1; // "foo" | "bar" + var c3 = cond ? c1 : c2; // "foo" | "bar" + var c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz" + var c5 = c4; // "foo" | "bar" | "baz" + var v1 = c1; // string + var v2 = c2; // "foo" | "bar" + var v3 = c3; // "foo" | "bar" + var v4 = c4; // string + var v5 = c5; // "foo" | "bar" | "baz" +} +function f3() { + var c1 = 123; // Widening type 123 + var v1 = c1; // Type number + var c2 = c1; // Widening type 123 + var v2 = c2; // Type number + var c3 = 123; // Type 123 + var v3 = c3; // Type 123 + var c4 = c1; // Type 123 + var v4 = c4; // Type 123 +} +function f4(cond) { + var c1 = cond ? 123 : 456; // widening 123 | widening 456 + var c2 = c1; // 123 | 456 + var c3 = cond ? c1 : c2; // 123 | 456 + var c4 = cond ? c3 : 789; // 123 | 456 | widening 789 + var c5 = c4; // 123 | 456 | 789 + var v1 = c1; // number + var v2 = c2; // 123 | 456 + var v3 = c3; // 123 | 456 + var v4 = c4; // number + var v5 = c5; // 123 | 456 | 789 +} +function f5() { + var c1 = "foo"; + var v1 = c1; + var c2 = "foo"; + var v2 = c2; + var c3 = "foo"; + var v3 = c3; + var c4 = "foo"; + var v4 = c4; +} +var FAILURE = "FAILURE"; +function doWork() { + return FAILURE; +} +function isSuccess(result) { + return !isFailure(result); +} +function isFailure(result) { + return result === FAILURE; +} +function increment(x) { + return x + 1; +} +var result = doWork(); +if (isSuccess(result)) { + increment(result); +} +function onMouseOver() { return "onmouseover"; } +var x = onMouseOver(); diff --git a/tests/baselines/reference/literalTypeWidening.symbols b/tests/baselines/reference/literalTypeWidening.symbols new file mode 100644 index 00000000000..e0da630180e --- /dev/null +++ b/tests/baselines/reference/literalTypeWidening.symbols @@ -0,0 +1,285 @@ +=== tests/cases/conformance/types/literal/literalTypeWidening.ts === +// Widening vs. non-widening literal types + +function f1() { +>f1 : Symbol(f1, Decl(literalTypeWidening.ts, 0, 0)) + + const c1 = "hello"; // Widening type "hello" +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 3, 9)) + + let v1 = c1; // Type string +>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 4, 7)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 3, 9)) + + const c2 = c1; // Widening type "hello" +>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 5, 9)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 3, 9)) + + let v2 = c2; // Type string +>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 6, 7)) +>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 5, 9)) + + const c3: "hello" = "hello"; // Type "hello" +>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 7, 9)) + + let v3 = c3; // Type "hello" +>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 8, 7)) +>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 7, 9)) + + const c4: "hello" = c1; // Type "hello" +>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 9, 9)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 3, 9)) + + let v4 = c4; // Type "hello" +>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 10, 7)) +>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 9, 9)) +} + +function f2(cond: boolean) { +>f2 : Symbol(f2, Decl(literalTypeWidening.ts, 11, 1)) +>cond : Symbol(cond, Decl(literalTypeWidening.ts, 13, 12)) + + const c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar" +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 14, 9)) +>cond : Symbol(cond, Decl(literalTypeWidening.ts, 13, 12)) + + const c2: "foo" | "bar" = c1; // "foo" | "bar" +>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 15, 9)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 14, 9)) + + const c3 = cond ? c1 : c2; // "foo" | "bar" +>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 16, 9)) +>cond : Symbol(cond, Decl(literalTypeWidening.ts, 13, 12)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 14, 9)) +>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 15, 9)) + + const c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz" +>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 17, 9)) +>cond : Symbol(cond, Decl(literalTypeWidening.ts, 13, 12)) +>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 16, 9)) + + const c5: "foo" | "bar" | "baz" = c4; // "foo" | "bar" | "baz" +>c5 : Symbol(c5, Decl(literalTypeWidening.ts, 18, 9)) +>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 17, 9)) + + let v1 = c1; // string +>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 19, 7)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 14, 9)) + + let v2 = c2; // "foo" | "bar" +>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 20, 7)) +>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 15, 9)) + + let v3 = c3; // "foo" | "bar" +>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 21, 7)) +>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 16, 9)) + + let v4 = c4; // string +>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 22, 7)) +>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 17, 9)) + + let v5 = c5; // "foo" | "bar" | "baz" +>v5 : Symbol(v5, Decl(literalTypeWidening.ts, 23, 7)) +>c5 : Symbol(c5, Decl(literalTypeWidening.ts, 18, 9)) +} + +function f3() { +>f3 : Symbol(f3, Decl(literalTypeWidening.ts, 24, 1)) + + const c1 = 123; // Widening type 123 +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 27, 9)) + + let v1 = c1; // Type number +>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 28, 7)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 27, 9)) + + const c2 = c1; // Widening type 123 +>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 29, 9)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 27, 9)) + + let v2 = c2; // Type number +>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 30, 7)) +>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 29, 9)) + + const c3: 123 = 123; // Type 123 +>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 31, 9)) + + let v3 = c3; // Type 123 +>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 32, 7)) +>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 31, 9)) + + const c4: 123 = c1; // Type 123 +>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 33, 9)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 27, 9)) + + let v4 = c4; // Type 123 +>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 34, 7)) +>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 33, 9)) +} + +function f4(cond: boolean) { +>f4 : Symbol(f4, Decl(literalTypeWidening.ts, 35, 1)) +>cond : Symbol(cond, Decl(literalTypeWidening.ts, 37, 12)) + + const c1 = cond ? 123 : 456; // widening 123 | widening 456 +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 38, 9)) +>cond : Symbol(cond, Decl(literalTypeWidening.ts, 37, 12)) + + const c2: 123 | 456 = c1; // 123 | 456 +>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 39, 9)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 38, 9)) + + const c3 = cond ? c1 : c2; // 123 | 456 +>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 40, 9)) +>cond : Symbol(cond, Decl(literalTypeWidening.ts, 37, 12)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 38, 9)) +>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 39, 9)) + + const c4 = cond ? c3 : 789; // 123 | 456 | widening 789 +>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 41, 9)) +>cond : Symbol(cond, Decl(literalTypeWidening.ts, 37, 12)) +>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 40, 9)) + + const c5: 123 | 456 | 789 = c4; // 123 | 456 | 789 +>c5 : Symbol(c5, Decl(literalTypeWidening.ts, 42, 9)) +>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 41, 9)) + + let v1 = c1; // number +>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 43, 7)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 38, 9)) + + let v2 = c2; // 123 | 456 +>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 44, 7)) +>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 39, 9)) + + let v3 = c3; // 123 | 456 +>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 45, 7)) +>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 40, 9)) + + let v4 = c4; // number +>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 46, 7)) +>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 41, 9)) + + let v5 = c5; // 123 | 456 | 789 +>v5 : Symbol(v5, Decl(literalTypeWidening.ts, 47, 7)) +>c5 : Symbol(c5, Decl(literalTypeWidening.ts, 42, 9)) +} + +function f5() { +>f5 : Symbol(f5, Decl(literalTypeWidening.ts, 48, 1)) + + const c1 = "foo"; +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 51, 9)) + + let v1 = c1; +>v1 : Symbol(v1, Decl(literalTypeWidening.ts, 52, 7)) +>c1 : Symbol(c1, Decl(literalTypeWidening.ts, 51, 9)) + + const c2: "foo" = "foo"; +>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 53, 9)) + + let v2 = c2; +>v2 : Symbol(v2, Decl(literalTypeWidening.ts, 54, 7)) +>c2 : Symbol(c2, Decl(literalTypeWidening.ts, 53, 9)) + + const c3 = "foo" as "foo"; +>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 55, 9)) + + let v3 = c3; +>v3 : Symbol(v3, Decl(literalTypeWidening.ts, 56, 7)) +>c3 : Symbol(c3, Decl(literalTypeWidening.ts, 55, 9)) + + const c4 = <"foo">"foo"; +>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 57, 9)) + + let v4 = c4; +>v4 : Symbol(v4, Decl(literalTypeWidening.ts, 58, 7)) +>c4 : Symbol(c4, Decl(literalTypeWidening.ts, 57, 9)) +} + +// Repro from #10898 + +type FAILURE = "FAILURE"; +>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5)) + +const FAILURE = "FAILURE"; +>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5)) + +type Result = T | FAILURE; +>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26)) +>T : Symbol(T, Decl(literalTypeWidening.ts, 66, 12)) +>T : Symbol(T, Decl(literalTypeWidening.ts, 66, 12)) +>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5)) + +function doWork(): Result { +>doWork : Symbol(doWork, Decl(literalTypeWidening.ts, 66, 29)) +>T : Symbol(T, Decl(literalTypeWidening.ts, 68, 16)) +>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26)) +>T : Symbol(T, Decl(literalTypeWidening.ts, 68, 16)) + + return FAILURE; +>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5)) +} + +function isSuccess(result: Result): result is T { +>isSuccess : Symbol(isSuccess, Decl(literalTypeWidening.ts, 70, 1)) +>T : Symbol(T, Decl(literalTypeWidening.ts, 72, 19)) +>result : Symbol(result, Decl(literalTypeWidening.ts, 72, 22)) +>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26)) +>T : Symbol(T, Decl(literalTypeWidening.ts, 72, 19)) +>result : Symbol(result, Decl(literalTypeWidening.ts, 72, 22)) +>T : Symbol(T, Decl(literalTypeWidening.ts, 72, 19)) + + return !isFailure(result); +>isFailure : Symbol(isFailure, Decl(literalTypeWidening.ts, 74, 1)) +>result : Symbol(result, Decl(literalTypeWidening.ts, 72, 22)) +} + +function isFailure(result: Result): result is FAILURE { +>isFailure : Symbol(isFailure, Decl(literalTypeWidening.ts, 74, 1)) +>T : Symbol(T, Decl(literalTypeWidening.ts, 76, 19)) +>result : Symbol(result, Decl(literalTypeWidening.ts, 76, 22)) +>Result : Symbol(Result, Decl(literalTypeWidening.ts, 64, 26)) +>T : Symbol(T, Decl(literalTypeWidening.ts, 76, 19)) +>result : Symbol(result, Decl(literalTypeWidening.ts, 76, 22)) +>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5)) + + return result === FAILURE; +>result : Symbol(result, Decl(literalTypeWidening.ts, 76, 22)) +>FAILURE : Symbol(FAILURE, Decl(literalTypeWidening.ts, 59, 1), Decl(literalTypeWidening.ts, 64, 5)) +} + +function increment(x: number): number { +>increment : Symbol(increment, Decl(literalTypeWidening.ts, 78, 1)) +>x : Symbol(x, Decl(literalTypeWidening.ts, 80, 19)) + + return x + 1; +>x : Symbol(x, Decl(literalTypeWidening.ts, 80, 19)) +} + +let result = doWork(); +>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 3)) +>doWork : Symbol(doWork, Decl(literalTypeWidening.ts, 66, 29)) + +if (isSuccess(result)) { +>isSuccess : Symbol(isSuccess, Decl(literalTypeWidening.ts, 70, 1)) +>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 3)) + + increment(result); +>increment : Symbol(increment, Decl(literalTypeWidening.ts, 78, 1)) +>result : Symbol(result, Decl(literalTypeWidening.ts, 84, 3)) +} + +// Repro from #10898 + +type TestEvent = "onmouseover" | "onmouseout"; +>TestEvent : Symbol(TestEvent, Decl(literalTypeWidening.ts, 88, 1)) + +function onMouseOver(): TestEvent { return "onmouseover"; } +>onMouseOver : Symbol(onMouseOver, Decl(literalTypeWidening.ts, 92, 46)) +>TestEvent : Symbol(TestEvent, Decl(literalTypeWidening.ts, 88, 1)) + +let x = onMouseOver(); +>x : Symbol(x, Decl(literalTypeWidening.ts, 96, 3)) +>onMouseOver : Symbol(onMouseOver, Decl(literalTypeWidening.ts, 92, 46)) + diff --git a/tests/baselines/reference/literalTypeWidening.types b/tests/baselines/reference/literalTypeWidening.types new file mode 100644 index 00000000000..db5df6ba90c --- /dev/null +++ b/tests/baselines/reference/literalTypeWidening.types @@ -0,0 +1,318 @@ +=== tests/cases/conformance/types/literal/literalTypeWidening.ts === +// Widening vs. non-widening literal types + +function f1() { +>f1 : () => void + + const c1 = "hello"; // Widening type "hello" +>c1 : "hello" +>"hello" : "hello" + + let v1 = c1; // Type string +>v1 : string +>c1 : "hello" + + const c2 = c1; // Widening type "hello" +>c2 : "hello" +>c1 : "hello" + + let v2 = c2; // Type string +>v2 : string +>c2 : "hello" + + const c3: "hello" = "hello"; // Type "hello" +>c3 : "hello" +>"hello" : "hello" + + let v3 = c3; // Type "hello" +>v3 : "hello" +>c3 : "hello" + + const c4: "hello" = c1; // Type "hello" +>c4 : "hello" +>c1 : "hello" + + let v4 = c4; // Type "hello" +>v4 : "hello" +>c4 : "hello" +} + +function f2(cond: boolean) { +>f2 : (cond: boolean) => void +>cond : boolean + + const c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar" +>c1 : "foo" | "bar" +>cond ? "foo" : "bar" : "foo" | "bar" +>cond : boolean +>"foo" : "foo" +>"bar" : "bar" + + const c2: "foo" | "bar" = c1; // "foo" | "bar" +>c2 : "foo" | "bar" +>c1 : "foo" | "bar" + + const c3 = cond ? c1 : c2; // "foo" | "bar" +>c3 : "foo" | "bar" +>cond ? c1 : c2 : "foo" | "bar" +>cond : boolean +>c1 : "foo" | "bar" +>c2 : "foo" | "bar" + + const c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz" +>c4 : "foo" | "bar" | "baz" +>cond ? c3 : "baz" : "foo" | "bar" | "baz" +>cond : boolean +>c3 : "foo" | "bar" +>"baz" : "baz" + + const c5: "foo" | "bar" | "baz" = c4; // "foo" | "bar" | "baz" +>c5 : "foo" | "bar" | "baz" +>c4 : "foo" | "bar" | "baz" + + let v1 = c1; // string +>v1 : string +>c1 : "foo" | "bar" + + let v2 = c2; // "foo" | "bar" +>v2 : "foo" | "bar" +>c2 : "foo" | "bar" + + let v3 = c3; // "foo" | "bar" +>v3 : "foo" | "bar" +>c3 : "foo" | "bar" + + let v4 = c4; // string +>v4 : string +>c4 : "foo" | "bar" | "baz" + + let v5 = c5; // "foo" | "bar" | "baz" +>v5 : "foo" | "bar" | "baz" +>c5 : "foo" | "bar" | "baz" +} + +function f3() { +>f3 : () => void + + const c1 = 123; // Widening type 123 +>c1 : 123 +>123 : 123 + + let v1 = c1; // Type number +>v1 : number +>c1 : 123 + + const c2 = c1; // Widening type 123 +>c2 : 123 +>c1 : 123 + + let v2 = c2; // Type number +>v2 : number +>c2 : 123 + + const c3: 123 = 123; // Type 123 +>c3 : 123 +>123 : 123 + + let v3 = c3; // Type 123 +>v3 : 123 +>c3 : 123 + + const c4: 123 = c1; // Type 123 +>c4 : 123 +>c1 : 123 + + let v4 = c4; // Type 123 +>v4 : 123 +>c4 : 123 +} + +function f4(cond: boolean) { +>f4 : (cond: boolean) => void +>cond : boolean + + const c1 = cond ? 123 : 456; // widening 123 | widening 456 +>c1 : 123 | 456 +>cond ? 123 : 456 : 123 | 456 +>cond : boolean +>123 : 123 +>456 : 456 + + const c2: 123 | 456 = c1; // 123 | 456 +>c2 : 123 | 456 +>c1 : 123 | 456 + + const c3 = cond ? c1 : c2; // 123 | 456 +>c3 : 123 | 456 +>cond ? c1 : c2 : 123 | 456 +>cond : boolean +>c1 : 123 | 456 +>c2 : 123 | 456 + + const c4 = cond ? c3 : 789; // 123 | 456 | widening 789 +>c4 : 123 | 456 | 789 +>cond ? c3 : 789 : 123 | 456 | 789 +>cond : boolean +>c3 : 123 | 456 +>789 : 789 + + const c5: 123 | 456 | 789 = c4; // 123 | 456 | 789 +>c5 : 123 | 456 | 789 +>c4 : 123 | 456 | 789 + + let v1 = c1; // number +>v1 : number +>c1 : 123 | 456 + + let v2 = c2; // 123 | 456 +>v2 : 123 | 456 +>c2 : 123 | 456 + + let v3 = c3; // 123 | 456 +>v3 : 123 | 456 +>c3 : 123 | 456 + + let v4 = c4; // number +>v4 : number +>c4 : 123 | 456 | 789 + + let v5 = c5; // 123 | 456 | 789 +>v5 : 123 | 456 | 789 +>c5 : 123 | 456 | 789 +} + +function f5() { +>f5 : () => void + + const c1 = "foo"; +>c1 : "foo" +>"foo" : "foo" + + let v1 = c1; +>v1 : string +>c1 : "foo" + + const c2: "foo" = "foo"; +>c2 : "foo" +>"foo" : "foo" + + let v2 = c2; +>v2 : "foo" +>c2 : "foo" + + const c3 = "foo" as "foo"; +>c3 : "foo" +>"foo" as "foo" : "foo" +>"foo" : "foo" + + let v3 = c3; +>v3 : "foo" +>c3 : "foo" + + const c4 = <"foo">"foo"; +>c4 : "foo" +><"foo">"foo" : "foo" +>"foo" : "foo" + + let v4 = c4; +>v4 : "foo" +>c4 : "foo" +} + +// Repro from #10898 + +type FAILURE = "FAILURE"; +>FAILURE : "FAILURE" + +const FAILURE = "FAILURE"; +>FAILURE : "FAILURE" +>"FAILURE" : "FAILURE" + +type Result = T | FAILURE; +>Result : Result +>T : T +>T : T +>FAILURE : "FAILURE" + +function doWork(): Result { +>doWork : () => Result +>T : T +>Result : Result +>T : T + + return FAILURE; +>FAILURE : "FAILURE" +} + +function isSuccess(result: Result): result is T { +>isSuccess : (result: Result) => result is T +>T : T +>result : Result +>Result : Result +>T : T +>result : any +>T : T + + return !isFailure(result); +>!isFailure(result) : boolean +>isFailure(result) : boolean +>isFailure : (result: Result) => result is "FAILURE" +>result : Result +} + +function isFailure(result: Result): result is FAILURE { +>isFailure : (result: Result) => result is "FAILURE" +>T : T +>result : Result +>Result : Result +>T : T +>result : any +>FAILURE : "FAILURE" + + return result === FAILURE; +>result === FAILURE : boolean +>result : Result +>FAILURE : "FAILURE" +} + +function increment(x: number): number { +>increment : (x: number) => number +>x : number + + return x + 1; +>x + 1 : number +>x : number +>1 : 1 +} + +let result = doWork(); +>result : Result +>doWork() : Result +>doWork : () => Result + +if (isSuccess(result)) { +>isSuccess(result) : boolean +>isSuccess : (result: Result) => result is T +>result : Result + + increment(result); +>increment(result) : number +>increment : (x: number) => number +>result : number +} + +// Repro from #10898 + +type TestEvent = "onmouseover" | "onmouseout"; +>TestEvent : TestEvent + +function onMouseOver(): TestEvent { return "onmouseover"; } +>onMouseOver : () => TestEvent +>TestEvent : TestEvent +>"onmouseover" : "onmouseover" + +let x = onMouseOver(); +>x : TestEvent +>onMouseOver() : TestEvent +>onMouseOver : () => TestEvent + diff --git a/tests/baselines/reference/literalTypes2.types b/tests/baselines/reference/literalTypes2.types index ba12ada644b..716b016f64e 100644 --- a/tests/baselines/reference/literalTypes2.types +++ b/tests/baselines/reference/literalTypes2.types @@ -482,7 +482,7 @@ function f6() { const { c1 = true, c2 = 0, c3 = "foo" } = { c1: false, c2: 1, c3: "bar" }; >c1 : boolean >true : true ->c2 : 0 | 1 +>c2 : 1 | 0 >0 : 0 >c3 : "foo" | "bar" >"foo" : "foo" @@ -552,10 +552,10 @@ class C2 { >0 : 0 } bar() { ->bar : () => 0 | 1 +>bar : () => 1 | 0 return cond ? 0 : 1; ->cond ? 0 : 1 : 0 | 1 +>cond ? 0 : 1 : 1 | 0 >cond : boolean >0 : 0 >1 : 1 diff --git a/tests/baselines/reference/modularizeLibrary_Dom.iterable.js b/tests/baselines/reference/modularizeLibrary_Dom.iterable.js new file mode 100644 index 00000000000..a448e8359a5 --- /dev/null +++ b/tests/baselines/reference/modularizeLibrary_Dom.iterable.js @@ -0,0 +1,10 @@ +//// [modularizeLibrary_Dom.iterable.ts] + +for (const element of document.getElementsByTagName("a")) { + element.href; +} + +//// [modularizeLibrary_Dom.iterable.js] +for (const element of document.getElementsByTagName("a")) { + element.href; +} diff --git a/tests/baselines/reference/modularizeLibrary_Dom.iterable.symbols b/tests/baselines/reference/modularizeLibrary_Dom.iterable.symbols new file mode 100644 index 00000000000..a487763582b --- /dev/null +++ b/tests/baselines/reference/modularizeLibrary_Dom.iterable.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/modularizeLibrary_Dom.iterable.ts === + +for (const element of document.getElementsByTagName("a")) { +>element : Symbol(element, Decl(modularizeLibrary_Dom.iterable.ts, 1, 10)) +>document.getElementsByTagName : Symbol(Document.getElementsByTagName, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>document : Symbol(document, Decl(lib.dom.d.ts, --, --)) +>getElementsByTagName : Symbol(Document.getElementsByTagName, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) + + element.href; +>element.href : Symbol(HTMLAnchorElement.href, Decl(lib.dom.d.ts, --, --)) +>element : Symbol(element, Decl(modularizeLibrary_Dom.iterable.ts, 1, 10)) +>href : Symbol(HTMLAnchorElement.href, Decl(lib.dom.d.ts, --, --)) +} diff --git a/tests/baselines/reference/modularizeLibrary_Dom.iterable.types b/tests/baselines/reference/modularizeLibrary_Dom.iterable.types new file mode 100644 index 00000000000..dbce5e17ae2 --- /dev/null +++ b/tests/baselines/reference/modularizeLibrary_Dom.iterable.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/modularizeLibrary_Dom.iterable.ts === + +for (const element of document.getElementsByTagName("a")) { +>element : HTMLAnchorElement +>document.getElementsByTagName("a") : NodeListOf +>document.getElementsByTagName : { (tagname: "a"): NodeListOf; (tagname: "abbr"): NodeListOf; (tagname: "acronym"): NodeListOf; (tagname: "address"): NodeListOf; (tagname: "applet"): NodeListOf; (tagname: "area"): NodeListOf; (tagname: "article"): NodeListOf; (tagname: "aside"): NodeListOf; (tagname: "audio"): NodeListOf; (tagname: "b"): NodeListOf; (tagname: "base"): NodeListOf; (tagname: "basefont"): NodeListOf; (tagname: "bdo"): NodeListOf; (tagname: "big"): NodeListOf; (tagname: "blockquote"): NodeListOf; (tagname: "body"): NodeListOf; (tagname: "br"): NodeListOf; (tagname: "button"): NodeListOf; (tagname: "canvas"): NodeListOf; (tagname: "caption"): NodeListOf; (tagname: "center"): NodeListOf; (tagname: "circle"): NodeListOf; (tagname: "cite"): NodeListOf; (tagname: "clippath"): NodeListOf; (tagname: "code"): NodeListOf; (tagname: "col"): NodeListOf; (tagname: "colgroup"): NodeListOf; (tagname: "datalist"): NodeListOf; (tagname: "dd"): NodeListOf; (tagname: "defs"): NodeListOf; (tagname: "del"): NodeListOf; (tagname: "desc"): NodeListOf; (tagname: "dfn"): NodeListOf; (tagname: "dir"): NodeListOf; (tagname: "div"): NodeListOf; (tagname: "dl"): NodeListOf; (tagname: "dt"): NodeListOf; (tagname: "ellipse"): NodeListOf; (tagname: "em"): NodeListOf; (tagname: "embed"): NodeListOf; (tagname: "feblend"): NodeListOf; (tagname: "fecolormatrix"): NodeListOf; (tagname: "fecomponenttransfer"): NodeListOf; (tagname: "fecomposite"): NodeListOf; (tagname: "feconvolvematrix"): NodeListOf; (tagname: "fediffuselighting"): NodeListOf; (tagname: "fedisplacementmap"): NodeListOf; (tagname: "fedistantlight"): NodeListOf; (tagname: "feflood"): NodeListOf; (tagname: "fefunca"): NodeListOf; (tagname: "fefuncb"): NodeListOf; (tagname: "fefuncg"): NodeListOf; (tagname: "fefuncr"): NodeListOf; (tagname: "fegaussianblur"): NodeListOf; (tagname: "feimage"): NodeListOf; (tagname: "femerge"): NodeListOf; (tagname: "femergenode"): NodeListOf; (tagname: "femorphology"): NodeListOf; (tagname: "feoffset"): NodeListOf; (tagname: "fepointlight"): NodeListOf; (tagname: "fespecularlighting"): NodeListOf; (tagname: "fespotlight"): NodeListOf; (tagname: "fetile"): NodeListOf; (tagname: "feturbulence"): NodeListOf; (tagname: "fieldset"): NodeListOf; (tagname: "figcaption"): NodeListOf; (tagname: "figure"): NodeListOf; (tagname: "filter"): NodeListOf; (tagname: "font"): NodeListOf; (tagname: "footer"): NodeListOf; (tagname: "foreignobject"): NodeListOf; (tagname: "form"): NodeListOf; (tagname: "frame"): NodeListOf; (tagname: "frameset"): NodeListOf; (tagname: "g"): NodeListOf; (tagname: "h1"): NodeListOf; (tagname: "h2"): NodeListOf; (tagname: "h3"): NodeListOf; (tagname: "h4"): NodeListOf; (tagname: "h5"): NodeListOf; (tagname: "h6"): NodeListOf; (tagname: "head"): NodeListOf; (tagname: "header"): NodeListOf; (tagname: "hgroup"): NodeListOf; (tagname: "hr"): NodeListOf; (tagname: "html"): NodeListOf; (tagname: "i"): NodeListOf; (tagname: "iframe"): NodeListOf; (tagname: "image"): NodeListOf; (tagname: "img"): NodeListOf; (tagname: "input"): NodeListOf; (tagname: "ins"): NodeListOf; (tagname: "isindex"): NodeListOf; (tagname: "kbd"): NodeListOf; (tagname: "keygen"): NodeListOf; (tagname: "label"): NodeListOf; (tagname: "legend"): NodeListOf; (tagname: "li"): NodeListOf; (tagname: "line"): NodeListOf; (tagname: "lineargradient"): NodeListOf; (tagname: "link"): NodeListOf; (tagname: "listing"): NodeListOf; (tagname: "map"): NodeListOf; (tagname: "mark"): NodeListOf; (tagname: "marker"): NodeListOf; (tagname: "marquee"): NodeListOf; (tagname: "mask"): NodeListOf; (tagname: "menu"): NodeListOf; (tagname: "meta"): NodeListOf; (tagname: "metadata"): NodeListOf; (tagname: "meter"): NodeListOf; (tagname: "nav"): NodeListOf; (tagname: "nextid"): NodeListOf; (tagname: "nobr"): NodeListOf; (tagname: "noframes"): NodeListOf; (tagname: "noscript"): NodeListOf; (tagname: "object"): NodeListOf; (tagname: "ol"): NodeListOf; (tagname: "optgroup"): NodeListOf; (tagname: "option"): NodeListOf; (tagname: "p"): NodeListOf; (tagname: "param"): NodeListOf; (tagname: "path"): NodeListOf; (tagname: "pattern"): NodeListOf; (tagname: "picture"): NodeListOf; (tagname: "plaintext"): NodeListOf; (tagname: "polygon"): NodeListOf; (tagname: "polyline"): NodeListOf; (tagname: "pre"): NodeListOf; (tagname: "progress"): NodeListOf; (tagname: "q"): NodeListOf; (tagname: "radialgradient"): NodeListOf; (tagname: "rect"): NodeListOf; (tagname: "rt"): NodeListOf; (tagname: "ruby"): NodeListOf; (tagname: "s"): NodeListOf; (tagname: "samp"): NodeListOf; (tagname: "script"): NodeListOf; (tagname: "section"): NodeListOf; (tagname: "select"): NodeListOf; (tagname: "small"): NodeListOf; (tagname: "source"): NodeListOf; (tagname: "span"): NodeListOf; (tagname: "stop"): NodeListOf; (tagname: "strike"): NodeListOf; (tagname: "strong"): NodeListOf; (tagname: "style"): NodeListOf; (tagname: "sub"): NodeListOf; (tagname: "sup"): NodeListOf; (tagname: "svg"): NodeListOf; (tagname: "switch"): NodeListOf; (tagname: "symbol"): NodeListOf; (tagname: "table"): NodeListOf; (tagname: "tbody"): NodeListOf; (tagname: "td"): NodeListOf; (tagname: "template"): NodeListOf; (tagname: "text"): NodeListOf; (tagname: "textpath"): NodeListOf; (tagname: "textarea"): NodeListOf; (tagname: "tfoot"): NodeListOf; (tagname: "th"): NodeListOf; (tagname: "thead"): NodeListOf; (tagname: "title"): NodeListOf; (tagname: "tr"): NodeListOf; (tagname: "track"): NodeListOf; (tagname: "tspan"): NodeListOf; (tagname: "tt"): NodeListOf; (tagname: "u"): NodeListOf; (tagname: "ul"): NodeListOf; (tagname: "use"): NodeListOf; (tagname: "var"): NodeListOf; (tagname: "video"): NodeListOf; (tagname: "view"): NodeListOf; (tagname: "wbr"): NodeListOf; (tagname: "x-ms-webview"): NodeListOf; (tagname: "xmp"): NodeListOf; (tagname: string): NodeListOf; } +>document : Document +>getElementsByTagName : { (tagname: "a"): NodeListOf; (tagname: "abbr"): NodeListOf; (tagname: "acronym"): NodeListOf; (tagname: "address"): NodeListOf; (tagname: "applet"): NodeListOf; (tagname: "area"): NodeListOf; (tagname: "article"): NodeListOf; (tagname: "aside"): NodeListOf; (tagname: "audio"): NodeListOf; (tagname: "b"): NodeListOf; (tagname: "base"): NodeListOf; (tagname: "basefont"): NodeListOf; (tagname: "bdo"): NodeListOf; (tagname: "big"): NodeListOf; (tagname: "blockquote"): NodeListOf; (tagname: "body"): NodeListOf; (tagname: "br"): NodeListOf; (tagname: "button"): NodeListOf; (tagname: "canvas"): NodeListOf; (tagname: "caption"): NodeListOf; (tagname: "center"): NodeListOf; (tagname: "circle"): NodeListOf; (tagname: "cite"): NodeListOf; (tagname: "clippath"): NodeListOf; (tagname: "code"): NodeListOf; (tagname: "col"): NodeListOf; (tagname: "colgroup"): NodeListOf; (tagname: "datalist"): NodeListOf; (tagname: "dd"): NodeListOf; (tagname: "defs"): NodeListOf; (tagname: "del"): NodeListOf; (tagname: "desc"): NodeListOf; (tagname: "dfn"): NodeListOf; (tagname: "dir"): NodeListOf; (tagname: "div"): NodeListOf; (tagname: "dl"): NodeListOf; (tagname: "dt"): NodeListOf; (tagname: "ellipse"): NodeListOf; (tagname: "em"): NodeListOf; (tagname: "embed"): NodeListOf; (tagname: "feblend"): NodeListOf; (tagname: "fecolormatrix"): NodeListOf; (tagname: "fecomponenttransfer"): NodeListOf; (tagname: "fecomposite"): NodeListOf; (tagname: "feconvolvematrix"): NodeListOf; (tagname: "fediffuselighting"): NodeListOf; (tagname: "fedisplacementmap"): NodeListOf; (tagname: "fedistantlight"): NodeListOf; (tagname: "feflood"): NodeListOf; (tagname: "fefunca"): NodeListOf; (tagname: "fefuncb"): NodeListOf; (tagname: "fefuncg"): NodeListOf; (tagname: "fefuncr"): NodeListOf; (tagname: "fegaussianblur"): NodeListOf; (tagname: "feimage"): NodeListOf; (tagname: "femerge"): NodeListOf; (tagname: "femergenode"): NodeListOf; (tagname: "femorphology"): NodeListOf; (tagname: "feoffset"): NodeListOf; (tagname: "fepointlight"): NodeListOf; (tagname: "fespecularlighting"): NodeListOf; (tagname: "fespotlight"): NodeListOf; (tagname: "fetile"): NodeListOf; (tagname: "feturbulence"): NodeListOf; (tagname: "fieldset"): NodeListOf; (tagname: "figcaption"): NodeListOf; (tagname: "figure"): NodeListOf; (tagname: "filter"): NodeListOf; (tagname: "font"): NodeListOf; (tagname: "footer"): NodeListOf; (tagname: "foreignobject"): NodeListOf; (tagname: "form"): NodeListOf; (tagname: "frame"): NodeListOf; (tagname: "frameset"): NodeListOf; (tagname: "g"): NodeListOf; (tagname: "h1"): NodeListOf; (tagname: "h2"): NodeListOf; (tagname: "h3"): NodeListOf; (tagname: "h4"): NodeListOf; (tagname: "h5"): NodeListOf; (tagname: "h6"): NodeListOf; (tagname: "head"): NodeListOf; (tagname: "header"): NodeListOf; (tagname: "hgroup"): NodeListOf; (tagname: "hr"): NodeListOf; (tagname: "html"): NodeListOf; (tagname: "i"): NodeListOf; (tagname: "iframe"): NodeListOf; (tagname: "image"): NodeListOf; (tagname: "img"): NodeListOf; (tagname: "input"): NodeListOf; (tagname: "ins"): NodeListOf; (tagname: "isindex"): NodeListOf; (tagname: "kbd"): NodeListOf; (tagname: "keygen"): NodeListOf; (tagname: "label"): NodeListOf; (tagname: "legend"): NodeListOf; (tagname: "li"): NodeListOf; (tagname: "line"): NodeListOf; (tagname: "lineargradient"): NodeListOf; (tagname: "link"): NodeListOf; (tagname: "listing"): NodeListOf; (tagname: "map"): NodeListOf; (tagname: "mark"): NodeListOf; (tagname: "marker"): NodeListOf; (tagname: "marquee"): NodeListOf; (tagname: "mask"): NodeListOf; (tagname: "menu"): NodeListOf; (tagname: "meta"): NodeListOf; (tagname: "metadata"): NodeListOf; (tagname: "meter"): NodeListOf; (tagname: "nav"): NodeListOf; (tagname: "nextid"): NodeListOf; (tagname: "nobr"): NodeListOf; (tagname: "noframes"): NodeListOf; (tagname: "noscript"): NodeListOf; (tagname: "object"): NodeListOf; (tagname: "ol"): NodeListOf; (tagname: "optgroup"): NodeListOf; (tagname: "option"): NodeListOf; (tagname: "p"): NodeListOf; (tagname: "param"): NodeListOf; (tagname: "path"): NodeListOf; (tagname: "pattern"): NodeListOf; (tagname: "picture"): NodeListOf; (tagname: "plaintext"): NodeListOf; (tagname: "polygon"): NodeListOf; (tagname: "polyline"): NodeListOf; (tagname: "pre"): NodeListOf; (tagname: "progress"): NodeListOf; (tagname: "q"): NodeListOf; (tagname: "radialgradient"): NodeListOf; (tagname: "rect"): NodeListOf; (tagname: "rt"): NodeListOf; (tagname: "ruby"): NodeListOf; (tagname: "s"): NodeListOf; (tagname: "samp"): NodeListOf; (tagname: "script"): NodeListOf; (tagname: "section"): NodeListOf; (tagname: "select"): NodeListOf; (tagname: "small"): NodeListOf; (tagname: "source"): NodeListOf; (tagname: "span"): NodeListOf; (tagname: "stop"): NodeListOf; (tagname: "strike"): NodeListOf; (tagname: "strong"): NodeListOf; (tagname: "style"): NodeListOf; (tagname: "sub"): NodeListOf; (tagname: "sup"): NodeListOf; (tagname: "svg"): NodeListOf; (tagname: "switch"): NodeListOf; (tagname: "symbol"): NodeListOf; (tagname: "table"): NodeListOf; (tagname: "tbody"): NodeListOf; (tagname: "td"): NodeListOf; (tagname: "template"): NodeListOf; (tagname: "text"): NodeListOf; (tagname: "textpath"): NodeListOf; (tagname: "textarea"): NodeListOf; (tagname: "tfoot"): NodeListOf; (tagname: "th"): NodeListOf; (tagname: "thead"): NodeListOf; (tagname: "title"): NodeListOf; (tagname: "tr"): NodeListOf; (tagname: "track"): NodeListOf; (tagname: "tspan"): NodeListOf; (tagname: "tt"): NodeListOf; (tagname: "u"): NodeListOf; (tagname: "ul"): NodeListOf; (tagname: "use"): NodeListOf; (tagname: "var"): NodeListOf; (tagname: "video"): NodeListOf; (tagname: "view"): NodeListOf; (tagname: "wbr"): NodeListOf; (tagname: "x-ms-webview"): NodeListOf; (tagname: "xmp"): NodeListOf; (tagname: string): NodeListOf; } +>"a" : "a" + + element.href; +>element.href : string +>element : HTMLAnchorElement +>href : string +} diff --git a/tests/baselines/reference/moduleElementsInWrongContext.js b/tests/baselines/reference/moduleElementsInWrongContext.js index cd440bd6017..b8c7ae25730 100644 --- a/tests/baselines/reference/moduleElementsInWrongContext.js +++ b/tests/baselines/reference/moduleElementsInWrongContext.js @@ -45,7 +45,7 @@ return C; }()); export default C; - function bee() { } + export function bee() { } import I2 = require("foo"); import * as Foo from "ambient"; import bar from "ambient"; diff --git a/tests/baselines/reference/moduleElementsInWrongContext2.js b/tests/baselines/reference/moduleElementsInWrongContext2.js index cc4aca0dec0..8582213a6ae 100644 --- a/tests/baselines/reference/moduleElementsInWrongContext2.js +++ b/tests/baselines/reference/moduleElementsInWrongContext2.js @@ -45,7 +45,7 @@ function blah() { return C; }()); export default C; - function bee() { } + export function bee() { } import I2 = require("foo"); import * as Foo from "ambient"; import bar from "ambient"; diff --git a/tests/baselines/reference/numericLiteralTypes1.types b/tests/baselines/reference/numericLiteralTypes1.types index f091dd99d60..56e4bcc0f3f 100644 --- a/tests/baselines/reference/numericLiteralTypes1.types +++ b/tests/baselines/reference/numericLiteralTypes1.types @@ -370,7 +370,7 @@ function f14(x: 0 | 1 | 2, y: string) { >y : string var b = x || y; ->b : string | number +>b : string | 1 | 2 >x || y : string | 1 | 2 >x : 0 | 1 | 2 >y : string @@ -383,25 +383,25 @@ function f15(x: 0 | false, y: 1 | "one") { >y : 1 | "one" var a = x && y; ->a : number | boolean +>a : boolean | 0 >x && y : false | 0 >x : false | 0 >y : 1 | "one" var b = y && x; ->b : number | boolean +>b : boolean | 0 >y && x : false | 0 >y : 1 | "one" >x : false | 0 var c = x || y; ->c : string | number +>c : 1 | "one" >x || y : 1 | "one" >x : false | 0 >y : 1 | "one" var d = y || x; ->d : string | number | boolean +>d : boolean | 0 | 1 | "one" >y || x : false | 0 | 1 | "one" >y : 1 | "one" >x : false | 0 diff --git a/tests/baselines/reference/numericLiteralTypes2.types b/tests/baselines/reference/numericLiteralTypes2.types index a5744de2a34..b8e2526a221 100644 --- a/tests/baselines/reference/numericLiteralTypes2.types +++ b/tests/baselines/reference/numericLiteralTypes2.types @@ -365,13 +365,13 @@ function f14(x: 0 | 1 | 2, y: string) { >y : string var a = x && y; ->a : string | number +>a : string | 0 >x && y : string | 0 >x : 0 | 1 | 2 >y : string var b = x || y; ->b : string | number +>b : string | 1 | 2 >x || y : string | 1 | 2 >x : 0 | 1 | 2 >y : string @@ -384,25 +384,25 @@ function f15(x: 0 | false, y: 1 | "one") { >y : 1 | "one" var a = x && y; ->a : number | boolean +>a : boolean | 0 >x && y : false | 0 >x : false | 0 >y : 1 | "one" var b = y && x; ->b : number | boolean +>b : boolean | 0 >y && x : false | 0 >y : 1 | "one" >x : false | 0 var c = x || y; ->c : string | number +>c : 1 | "one" >x || y : 1 | "one" >x : false | 0 >y : 1 | "one" var d = y || x; ->d : string | number +>d : 1 | "one" >y || x : 1 | "one" >y : 1 | "one" >x : false | 0 diff --git a/tests/baselines/reference/objectTypeHidingMembersOfObjectAssignmentCompat2.errors.txt b/tests/baselines/reference/objectTypeHidingMembersOfObjectAssignmentCompat2.errors.txt index a88796b390e..3e27b22240e 100644 --- a/tests/baselines/reference/objectTypeHidingMembersOfObjectAssignmentCompat2.errors.txt +++ b/tests/baselines/reference/objectTypeHidingMembersOfObjectAssignmentCompat2.errors.txt @@ -3,17 +3,19 @@ tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentC Type '() => number' is not assignable to type '() => string'. Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentCompat2.ts(8,1): error TS2322: Type 'Object' is not assignable to type 'I'. - Types of property 'toString' are incompatible. - Type '() => string' is not assignable to type '() => number'. - Type 'string' is not assignable to type 'number'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Types of property 'toString' are incompatible. + Type '() => string' is not assignable to type '() => number'. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentCompat2.ts(14,1): error TS2322: Type 'C' is not assignable to type 'Object'. Types of property 'toString' are incompatible. Type '() => number' is not assignable to type '() => string'. Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentCompat2.ts(15,1): error TS2322: Type 'Object' is not assignable to type 'C'. - Types of property 'toString' are incompatible. - Type '() => string' is not assignable to type '() => number'. - Type 'string' is not assignable to type 'number'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Types of property 'toString' are incompatible. + Type '() => string' is not assignable to type '() => number'. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentCompat2.ts(20,1): error TS2322: Type '{ toString: () => void; }' is not assignable to type 'Object'. Types of property 'toString' are incompatible. Type '() => void' is not assignable to type '() => string'. @@ -36,9 +38,10 @@ tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentC i = o; // error ~ !!! error TS2322: Type 'Object' is not assignable to type 'I'. -!!! error TS2322: Types of property 'toString' are incompatible. -!!! error TS2322: Type '() => string' is not assignable to type '() => number'. -!!! error TS2322: Type 'string' is not assignable to type 'number'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Types of property 'toString' are incompatible. +!!! error TS2322: Type '() => string' is not assignable to type '() => number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. class C { toString(): number { return 1; } @@ -53,9 +56,10 @@ tests/cases/conformance/types/members/objectTypeHidingMembersOfObjectAssignmentC c = o; // error ~ !!! error TS2322: Type 'Object' is not assignable to type 'C'. -!!! error TS2322: Types of property 'toString' are incompatible. -!!! error TS2322: Type '() => string' is not assignable to type '() => number'. -!!! error TS2322: Type 'string' is not assignable to type 'number'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Types of property 'toString' are incompatible. +!!! error TS2322: Type '() => string' is not assignable to type '() => number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. var a = { toString: () => { } diff --git a/tests/baselines/reference/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt b/tests/baselines/reference/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt index e296f2113fb..caeca11edf8 100644 --- a/tests/baselines/reference/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt +++ b/tests/baselines/reference/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt @@ -1,7 +1,9 @@ tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.ts(8,1): error TS2322: Type 'Object' is not assignable to type 'I'. - Type 'Object' provides no match for the signature '(): void' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature '(): void' tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.ts(14,1): error TS2322: Type 'Object' is not assignable to type '() => void'. - Type 'Object' provides no match for the signature '(): void' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature '(): void' ==== tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOfFunctionAssignmentCompat.ts (2 errors) ==== @@ -15,7 +17,8 @@ tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOf i = f; ~ !!! error TS2322: Type 'Object' is not assignable to type 'I'. -!!! error TS2322: Type 'Object' provides no match for the signature '(): void' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature '(): void' var a: { (): void @@ -24,4 +27,5 @@ tests/cases/conformance/types/members/objectTypeWithCallSignatureHidingMembersOf a = f; ~ !!! error TS2322: Type 'Object' is not assignable to type '() => void'. -!!! error TS2322: Type 'Object' provides no match for the signature '(): void' \ No newline at end of file +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature '(): void' \ No newline at end of file diff --git a/tests/baselines/reference/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt b/tests/baselines/reference/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt index 227ccc99603..ad0e801e435 100644 --- a/tests/baselines/reference/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt +++ b/tests/baselines/reference/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.errors.txt @@ -1,7 +1,9 @@ tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.ts(8,1): error TS2322: Type 'Object' is not assignable to type 'I'. - Type 'Object' provides no match for the signature 'new (): any' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature 'new (): any' tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.ts(14,1): error TS2322: Type 'Object' is not assignable to type 'new () => any'. - Type 'Object' provides no match for the signature 'new (): any' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature 'new (): any' ==== tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMembersOfFunctionAssignmentCompat.ts (2 errors) ==== @@ -15,7 +17,8 @@ tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMemb i = f; ~ !!! error TS2322: Type 'Object' is not assignable to type 'I'. -!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' var a: { new(): any @@ -24,4 +27,5 @@ tests/cases/conformance/types/members/objectTypeWithConstructSignatureHidingMemb a = f; ~ !!! error TS2322: Type 'Object' is not assignable to type 'new () => any'. -!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' \ No newline at end of file +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature 'new (): any' \ No newline at end of file diff --git a/tests/baselines/reference/parserAutomaticSemicolonInsertion1.errors.txt b/tests/baselines/reference/parserAutomaticSemicolonInsertion1.errors.txt index 9ffdc614ab1..a2bbb98fbf4 100644 --- a/tests/baselines/reference/parserAutomaticSemicolonInsertion1.errors.txt +++ b/tests/baselines/reference/parserAutomaticSemicolonInsertion1.errors.txt @@ -1,7 +1,9 @@ tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAutomaticSemicolonInsertion1.ts(8,1): error TS2322: Type 'Object' is not assignable to type 'I'. - Type 'Object' provides no match for the signature '(): void' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature '(): void' tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAutomaticSemicolonInsertion1.ts(14,1): error TS2322: Type 'Object' is not assignable to type '() => void'. - Type 'Object' provides no match for the signature '(): void' + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? + Type 'Object' provides no match for the signature '(): void' ==== tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAutomaticSemicolonInsertion1.ts (2 errors) ==== @@ -15,7 +17,8 @@ tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAut i = o; ~ !!! error TS2322: Type 'Object' is not assignable to type 'I'. -!!! error TS2322: Type 'Object' provides no match for the signature '(): void' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature '(): void' var a: { (): void @@ -24,5 +27,6 @@ tests/cases/conformance/parser/ecmascript5/AutomaticSemicolonInsertion/parserAut a = o; ~ !!! error TS2322: Type 'Object' is not assignable to type '() => void'. -!!! error TS2322: Type 'Object' provides no match for the signature '(): void' +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? +!!! error TS2322: Type 'Object' provides no match for the signature '(): void' \ No newline at end of file diff --git a/tests/baselines/reference/parserModifierOnStatementInBlock3.js b/tests/baselines/reference/parserModifierOnStatementInBlock3.js index 2815af43708..9f2cdf6850f 100644 --- a/tests/baselines/reference/parserModifierOnStatementInBlock3.js +++ b/tests/baselines/reference/parserModifierOnStatementInBlock3.js @@ -8,7 +8,7 @@ export function foo() { //// [parserModifierOnStatementInBlock3.js] "use strict"; function foo() { - function bar() { + export function bar() { } } exports.foo = foo; diff --git a/tests/baselines/reference/parserModifierOnStatementInBlock4.js b/tests/baselines/reference/parserModifierOnStatementInBlock4.js index 34b390468eb..ba2d256aeb9 100644 --- a/tests/baselines/reference/parserModifierOnStatementInBlock4.js +++ b/tests/baselines/reference/parserModifierOnStatementInBlock4.js @@ -7,6 +7,6 @@ //// [parserModifierOnStatementInBlock4.js] { - function bar() { + export function bar() { } } diff --git a/tests/baselines/reference/project/declarationsExportNamespace/amd/declarationsExportNamespace.json b/tests/baselines/reference/project/declarationsExportNamespace/amd/declarationsExportNamespace.json new file mode 100644 index 00000000000..b9b27b6c02e --- /dev/null +++ b/tests/baselines/reference/project/declarationsExportNamespace/amd/declarationsExportNamespace.json @@ -0,0 +1,19 @@ +{ + "scenario": "declarations_ExportNamespace", + "projectRoot": "tests/cases/projects/declarations_ExportNamespace", + "inputFiles": [ + "decl.d.ts", + "useModule.ts" + ], + "declaration": true, + "baselineCheck": true, + "emittedFiles": [ + "useModule.js", + "useModule.d.ts" + ], + "resolvedInputFiles": [ + "lib.d.ts", + "decl.d.ts", + "useModule.ts" + ] +} \ No newline at end of file diff --git a/tests/baselines/reference/project/declarationsExportNamespace/amd/useModule.d.ts b/tests/baselines/reference/project/declarationsExportNamespace/amd/useModule.d.ts new file mode 100644 index 00000000000..40fb7f35522 --- /dev/null +++ b/tests/baselines/reference/project/declarationsExportNamespace/amd/useModule.d.ts @@ -0,0 +1,5 @@ +declare module moduleB { + interface IUseModuleA { + a: moduleA.A; + } +} diff --git a/tests/baselines/reference/project/declarationsExportNamespace/amd/useModule.js b/tests/baselines/reference/project/declarationsExportNamespace/amd/useModule.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/baselines/reference/project/declarationsExportNamespace/node/declarationsExportNamespace.json b/tests/baselines/reference/project/declarationsExportNamespace/node/declarationsExportNamespace.json new file mode 100644 index 00000000000..b9b27b6c02e --- /dev/null +++ b/tests/baselines/reference/project/declarationsExportNamespace/node/declarationsExportNamespace.json @@ -0,0 +1,19 @@ +{ + "scenario": "declarations_ExportNamespace", + "projectRoot": "tests/cases/projects/declarations_ExportNamespace", + "inputFiles": [ + "decl.d.ts", + "useModule.ts" + ], + "declaration": true, + "baselineCheck": true, + "emittedFiles": [ + "useModule.js", + "useModule.d.ts" + ], + "resolvedInputFiles": [ + "lib.d.ts", + "decl.d.ts", + "useModule.ts" + ] +} \ No newline at end of file diff --git a/tests/baselines/reference/project/declarationsExportNamespace/node/useModule.d.ts b/tests/baselines/reference/project/declarationsExportNamespace/node/useModule.d.ts new file mode 100644 index 00000000000..40fb7f35522 --- /dev/null +++ b/tests/baselines/reference/project/declarationsExportNamespace/node/useModule.d.ts @@ -0,0 +1,5 @@ +declare module moduleB { + interface IUseModuleA { + a: moduleA.A; + } +} diff --git a/tests/baselines/reference/project/declarationsExportNamespace/node/useModule.js b/tests/baselines/reference/project/declarationsExportNamespace/node/useModule.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js index df23dba8776..c1728d68e9b 100644 --- a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js +++ b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js @@ -17,5 +17,5 @@ exports.foo = foo; //// [shorthandOfExportedEntity01_targetES2015_CommonJS.d.ts] -export declare const test: "test"; +export declare const test = "test"; export declare function foo(): void; diff --git a/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.js b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.js index a594a1b6de5..e89a413463e 100644 --- a/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.js +++ b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.js @@ -17,5 +17,5 @@ exports.foo = foo; //// [shorthandOfExportedEntity02_targetES5_CommonJS.d.ts] -export declare const test: "test"; +export declare const test = "test"; export declare function foo(): void; diff --git a/tests/baselines/reference/stringLiteralTypesAndLogicalOrExpressions01.errors.txt b/tests/baselines/reference/stringLiteralTypesAndLogicalOrExpressions01.errors.txt index 3a884d2d1c4..1596d74281a 100644 --- a/tests/baselines/reference/stringLiteralTypesAndLogicalOrExpressions01.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesAndLogicalOrExpressions01.errors.txt @@ -1,16 +1,13 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndLogicalOrExpressions01.ts(6,5): error TS2322: Type 'string' is not assignable to type '"foo"'. tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndLogicalOrExpressions01.ts(8,5): error TS2322: Type 'string' is not assignable to type '"foo" | "bar"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndLogicalOrExpressions01.ts (2 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAndLogicalOrExpressions01.ts (1 errors) ==== declare function myRandBool(): boolean; let a: "foo" = "foo"; let b = a || "foo"; let c: "foo" = b; - ~ -!!! error TS2322: Type 'string' is not assignable to type '"foo"'. let d = b || "bar"; let e: "foo" | "bar" = d; ~ diff --git a/tests/baselines/reference/stringLiteralTypesAndLogicalOrExpressions01.js b/tests/baselines/reference/stringLiteralTypesAndLogicalOrExpressions01.js index b6bcaf7c887..33dce2041e3 100644 --- a/tests/baselines/reference/stringLiteralTypesAndLogicalOrExpressions01.js +++ b/tests/baselines/reference/stringLiteralTypesAndLogicalOrExpressions01.js @@ -20,7 +20,7 @@ var e = d; //// [stringLiteralTypesAndLogicalOrExpressions01.d.ts] declare function myRandBool(): boolean; declare let a: "foo"; -declare let b: string; +declare let b: "foo"; declare let c: "foo"; declare let d: string; declare let e: "foo" | "bar"; diff --git a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint01.js b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint01.js index 805f16228ba..4f49d326ec0 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint01.js +++ b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint01.js @@ -38,8 +38,8 @@ hResult = h("bar"); declare function foo(f: (x: T) => T): (x: T) => T; declare function bar(f: (x: T) => T): (x: T) => T; declare let f: (x: "foo") => "foo"; -declare let fResult: string; +declare let fResult: "foo"; declare let g: (x: "foo") => "foo"; -declare let gResult: string; +declare let gResult: "foo"; declare let h: (x: "foo" | "bar") => "foo" | "bar"; -declare let hResult: string; +declare let hResult: "foo" | "bar"; diff --git a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint01.types b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint01.types index e213faf3b69..fe9163fc819 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint01.types +++ b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint01.types @@ -33,7 +33,7 @@ let f = foo(x => x); >x : "foo" let fResult = f("foo"); ->fResult : string +>fResult : "foo" >f("foo") : "foo" >f : (x: "foo") => "foo" >"foo" : "foo" @@ -48,7 +48,7 @@ let g = foo((x => x)); >x : "foo" let gResult = g("foo"); ->gResult : string +>gResult : "foo" >g("foo") : "foo" >g : (x: "foo") => "foo" >"foo" : "foo" @@ -62,14 +62,14 @@ let h = bar(x => x); >x : "foo" | "bar" let hResult = h("foo"); ->hResult : string +>hResult : "foo" | "bar" >h("foo") : "foo" | "bar" >h : (x: "foo" | "bar") => "foo" | "bar" >"foo" : "foo" hResult = h("bar"); >hResult = h("bar") : "foo" | "bar" ->hResult : string +>hResult : "foo" | "bar" >h("bar") : "foo" | "bar" >h : (x: "foo" | "bar") => "foo" | "bar" >"bar" : "bar" diff --git a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.js b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.js index 06ee42b68ad..173e74a6eef 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.js +++ b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.js @@ -18,4 +18,4 @@ var fResult = f("foo"); //// [stringLiteralTypesAsTypeParameterConstraint02.d.ts] declare function foo(f: (x: T) => T): (x: T) => T; declare let f: (x: "foo") => "foo"; -declare let fResult: string; +declare let fResult: "foo"; diff --git a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.types b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.types index 75ba54cf6c2..3a1b8fdc05c 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.types +++ b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.types @@ -26,7 +26,7 @@ let f = foo((y: "foo" | "bar") => y === "foo" ? y : "foo"); >"foo" : "foo" let fResult = f("foo"); ->fResult : string +>fResult : "foo" >f("foo") : "foo" >f : (x: "foo") => "foo" >"foo" : "foo" diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.errors.txt b/tests/baselines/reference/stringLiteralTypesInUnionTypes01.errors.txt deleted file mode 100644 index 39b2b154cc8..00000000000 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.errors.txt +++ /dev/null @@ -1,26 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts(16,9): error TS2322: Type 'string' is not assignable to type '"foo" | "bar" | "baz"'. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes01.ts (1 errors) ==== - - type T = "foo" | "bar" | "baz"; - - var x: "foo" | "bar" | "baz" = undefined; - var y: T = undefined; - - if (x === "foo") { - let a = x; - } - else if (x !== "bar") { - let b = x || y; - } - else { - let c = x; - let d = y; - let e: (typeof x) | (typeof y) = c || d; - ~ -!!! error TS2322: Type 'string' is not assignable to type '"foo" | "bar" | "baz"'. - } - - x = y; - y = x; \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types index 40b34796e72..0be891ade44 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types @@ -1,62 +1,62 @@ === tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes02.ts === type T = string | "foo" | "bar" | "baz"; ->T : string | "foo" | "bar" | "baz" +>T : string var x: "foo" | "bar" | "baz" | string = undefined; ->x : string | "foo" | "bar" | "baz" +>x : string >undefined : undefined var y: T = undefined; ->y : string | "foo" | "bar" | "baz" ->T : string | "foo" | "bar" | "baz" +>y : string +>T : string >undefined : undefined if (x === "foo") { >x === "foo" : boolean ->x : string | "foo" | "bar" | "baz" +>x : string >"foo" : "foo" let a = x; >a : string ->x : string | "foo" +>x : string } else if (x !== "bar") { >x !== "bar" : boolean ->x : string | "bar" | "baz" +>x : string >"bar" : "bar" let b = x || y; >b : string >x || y : string ->x : string | "baz" ->y : string | "foo" | "bar" | "baz" +>x : string +>y : string } else { let c = x; >c : string ->x : string | "bar" +>x : string let d = y; >d : string ->y : string | "foo" | "bar" | "baz" +>y : string let e: (typeof x) | (typeof y) = c || d; ->e : string | "foo" | "bar" | "baz" ->x : string | "bar" ->y : string | "foo" | "bar" | "baz" +>e : string +>x : string +>y : string >c || d : string >c : string >d : string } x = y; ->x = y : string | "foo" | "bar" | "baz" ->x : string | "foo" | "bar" | "baz" ->y : string | "foo" | "bar" | "baz" +>x = y : string +>x : string +>y : string y = x; ->y = x : string | "foo" | "bar" | "baz" ->y : string | "foo" | "bar" | "baz" ->x : string | "foo" | "bar" | "baz" +>y = x : string +>y : string +>x : string diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.errors.txt b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.errors.txt deleted file mode 100644 index 784f368c164..00000000000 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.errors.txt +++ /dev/null @@ -1,28 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts(16,9): error TS2322: Type 'string | number' is not assignable to type 'number | "foo" | "bar"'. - Type 'string' is not assignable to type 'number | "foo" | "bar"'. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes03.ts (1 errors) ==== - - type T = number | "foo" | "bar"; - - var x: "foo" | "bar" | number; - var y: T = undefined; - - if (x === "foo") { - let a = x; - } - else if (x !== "bar") { - let b = x || y; - } - else { - let c = x; - let d = y; - let e: (typeof x) | (typeof y) = c || d; - ~ -!!! error TS2322: Type 'string | number' is not assignable to type 'number | "foo" | "bar"'. -!!! error TS2322: Type 'string' is not assignable to type 'number | "foo" | "bar"'. - } - - x = y; - y = x; \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types index 3d2a41ec5c9..05b6b9b9b7a 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types @@ -19,7 +19,7 @@ if (x === "") { >"" : "" let a = x; ->a : string +>a : "" >x : "" } @@ -29,7 +29,7 @@ if (x !== "") { >"" : "" let b = x; ->b : string +>b : "foo" >x : "foo" } @@ -39,7 +39,7 @@ if (x == "") { >"" : "" let c = x; ->c : string +>c : "" >x : "" } @@ -49,7 +49,7 @@ if (x != "") { >"" : "" let d = x; ->d : string +>d : "foo" >x : "foo" } @@ -57,7 +57,7 @@ if (x) { >x : T let e = x; ->e : string +>e : "foo" >x : "foo" } @@ -66,7 +66,7 @@ if (!x) { >x : T let f = x; ->f : string +>f : T >x : T } @@ -76,7 +76,7 @@ if (!!x) { >x : T let g = x; ->g : string +>g : "foo" >x : "foo" } @@ -87,6 +87,6 @@ if (!!!x) { >x : T let h = x; ->h : string +>h : T >x : T } diff --git a/tests/baselines/reference/stringLiteralTypesOverloads02.js b/tests/baselines/reference/stringLiteralTypesOverloads02.js index 0e7bd8c82c8..c0a7622075a 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads02.js +++ b/tests/baselines/reference/stringLiteralTypesOverloads02.js @@ -100,12 +100,12 @@ declare function getFalsyPrimitive(x: "number" | "string"): number | string; declare function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; declare namespace Consts1 { } -declare const string: "string"; -declare const number: "number"; -declare const boolean: "boolean"; -declare const stringOrNumber: "string" | "number"; -declare const stringOrBoolean: "string" | "boolean"; -declare const booleanOrNumber: "number" | "boolean"; -declare const stringOrBooleanOrNumber: "string" | "number" | "boolean"; +declare const string = "string"; +declare const number = "number"; +declare const boolean = "boolean"; +declare const stringOrNumber: string; +declare const stringOrBoolean: string; +declare const booleanOrNumber: string; +declare const stringOrBooleanOrNumber: string; declare namespace Consts2 { } diff --git a/tests/baselines/reference/stringLiteralTypesTypePredicates01.types b/tests/baselines/reference/stringLiteralTypesTypePredicates01.types index 0a87ffad865..822103b86f5 100644 --- a/tests/baselines/reference/stringLiteralTypesTypePredicates01.types +++ b/tests/baselines/reference/stringLiteralTypesTypePredicates01.types @@ -42,12 +42,12 @@ if (kindIs(x, "A")) { >"A" : "A" let a = x; ->a : string +>a : "A" >x : "A" } else { let b = x; ->b : string +>b : "B" >x : "B" } @@ -59,11 +59,11 @@ if (!kindIs(x, "B")) { >"B" : "B" let c = x; ->c : string +>c : "A" >x : "A" } else { let d = x; ->d : string +>d : "B" >x : "B" } diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.types b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.types index 99aef9e95f6..23ac78ec013 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.types +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.types @@ -259,14 +259,14 @@ function f6(x: T) { var r2 = true ? '' : x; // ok >r2 : string | T ->true ? '' : x : "" | T +>true ? '' : x : T | "" >true : true >'' : "" >x : T var r2 = true ? x : ''; // ok >r2 : string | T ->true ? x : '' : "" | T +>true ? x : '' : T | "" >true : true >x : T >'' : "" diff --git a/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.errors.txt b/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.errors.txt index 2876390758f..48c7efb37e8 100644 --- a/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.errors.txt +++ b/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.errors.txt @@ -11,17 +11,21 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0 tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(55,43): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(57,52): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(58,43): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(68,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(70,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(75,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(77,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(61,5): error TS2322: Type 'string' is not assignable to type '"Hello"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(63,5): error TS2322: Type 'string' is not assignable to type '"Hello"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(75,5): error TS2322: Type '"Hello" | "World"' is not assignable to type '"Hello"'. + Type '"World"' is not assignable to type '"Hello"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(77,5): error TS2322: Type '"Hello" | "World"' is not assignable to type '"Hello"'. + Type '"World"' is not assignable to type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(87,43): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(88,43): error TS2345: Argument of type '"Hello"' is not assignable to parameter of type '"World"'. tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(89,52): error TS2345: Argument of type '"World"' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(100,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(104,25): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(107,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. -tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(111,30): error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(93,5): error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(97,5): error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(100,25): error TS2345: Argument of type '"Hello" | "World"' is not assignable to parameter of type '"Hello"'. + Type '"World"' is not assignable to type '"Hello"'. +tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts(104,25): error TS2345: Argument of type '"Hello" | "World"' is not assignable to parameter of type '"Hello"'. + Type '"World"' is not assignable to type '"Hello"'. ==== tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes01.ts (24 errors) ==== @@ -112,30 +116,32 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0 // Assignment from the returned value should cause an error. a = takeReturnString(a); + ~ +!!! error TS2322: Type 'string' is not assignable to type '"Hello"'. b = takeReturnString(b); c = takeReturnString(c); + ~ +!!! error TS2322: Type 'string' is not assignable to type '"Hello"'. d = takeReturnString(d); e = takeReturnString(e); // Should be valid a = takeReturnHello(a); - ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. b = takeReturnHello(b); c = takeReturnHello(c); - ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. d = takeReturnHello(d); e = takeReturnHello(e); // Assignment from the returned value should cause an error. a = takeReturnHelloWorld(a); - ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. + ~ +!!! error TS2322: Type '"Hello" | "World"' is not assignable to type '"Hello"'. +!!! error TS2322: Type '"World"' is not assignable to type '"Hello"'. b = takeReturnHelloWorld(b); c = takeReturnHelloWorld(c); - ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. + ~ +!!! error TS2322: Type '"Hello" | "World"' is not assignable to type '"Hello"'. +!!! error TS2322: Type '"World"' is not assignable to type '"Hello"'. d = takeReturnHelloWorld(d); e = takeReturnHelloWorld(e); } @@ -158,30 +164,32 @@ tests/cases/conformance/types/stringLiteral/typeArgumentsWithStringLiteralTypes0 // Assignment from the returned value should cause an error. a = takeReturnString(a); + ~ +!!! error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'. b = takeReturnString(b); c = takeReturnString(c); d = takeReturnString(d); e = takeReturnString(e); + ~ +!!! error TS2322: Type 'string' is not assignable to type '"Hello" | "World"'. // Passing these as arguments should cause an error. a = takeReturnHello(a); ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type '"Hello" | "World"' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Type '"World"' is not assignable to type '"Hello"'. b = takeReturnHello(b); c = takeReturnHello(c); d = takeReturnHello(d); e = takeReturnHello(e); ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Argument of type '"Hello" | "World"' is not assignable to parameter of type '"Hello"'. +!!! error TS2345: Type '"World"' is not assignable to type '"Hello"'. // Both should be valid. a = takeReturnHelloWorld(a); - ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. b = takeReturnHelloWorld(b); c = takeReturnHelloWorld(c); d = takeReturnHelloWorld(d); e = takeReturnHelloWorld(e); - ~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type '"Hello" | "World"'. } \ No newline at end of file diff --git a/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.js b/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.js index ca67e358705..c07dd225396 100644 --- a/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.js +++ b/tests/baselines/reference/typeArgumentsWithStringLiteralTypes01.js @@ -229,16 +229,16 @@ declare namespace n1 { let e: string; } declare namespace n2 { - let a: string; + let a: "Hello"; let b: any; - let c: string; + let c: "Hello"; let d: any; let e: any; } declare namespace n3 { - let a: string; + let a: "Hello" | "World"; let b: any; let c: any; let d: any; - let e: string; + let e: "Hello" | "World"; } diff --git a/tests/baselines/reference/typeParametersShouldNotBeEqual.errors.txt b/tests/baselines/reference/typeParametersShouldNotBeEqual.errors.txt index 6f5e2766c8c..b5c9fd60206 100644 --- a/tests/baselines/reference/typeParametersShouldNotBeEqual.errors.txt +++ b/tests/baselines/reference/typeParametersShouldNotBeEqual.errors.txt @@ -1,5 +1,6 @@ tests/cases/compiler/typeParametersShouldNotBeEqual.ts(4,5): error TS2322: Type 'U' is not assignable to type 'T'. tests/cases/compiler/typeParametersShouldNotBeEqual.ts(5,5): error TS2322: Type 'Object' is not assignable to type 'T'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? ==== tests/cases/compiler/typeParametersShouldNotBeEqual.ts (2 errors) ==== @@ -12,6 +13,7 @@ tests/cases/compiler/typeParametersShouldNotBeEqual.ts(5,5): error TS2322: Type x = z; // Error ~ !!! error TS2322: Type 'Object' is not assignable to type 'T'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? z = x; // Ok } \ No newline at end of file diff --git a/tests/baselines/reference/typeParametersShouldNotBeEqual2.errors.txt b/tests/baselines/reference/typeParametersShouldNotBeEqual2.errors.txt index 27ac1e07eab..d452b997980 100644 --- a/tests/baselines/reference/typeParametersShouldNotBeEqual2.errors.txt +++ b/tests/baselines/reference/typeParametersShouldNotBeEqual2.errors.txt @@ -7,6 +7,7 @@ tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(7,5): error TS2322: Type tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(8,5): error TS2322: Type 'U' is not assignable to type 'V'. Type 'Date' is not assignable to type 'V'. tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(9,5): error TS2322: Type 'Object' is not assignable to type 'T'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? ==== tests/cases/compiler/typeParametersShouldNotBeEqual2.ts (6 errors) ==== @@ -34,6 +35,7 @@ tests/cases/compiler/typeParametersShouldNotBeEqual2.ts(9,5): error TS2322: Type x = zz; // Error ~ !!! error TS2322: Type 'Object' is not assignable to type 'T'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? zz = x; // Ok } \ No newline at end of file diff --git a/tests/baselines/reference/typeParametersShouldNotBeEqual3.errors.txt b/tests/baselines/reference/typeParametersShouldNotBeEqual3.errors.txt index 0169f57c06f..816db440a4c 100644 --- a/tests/baselines/reference/typeParametersShouldNotBeEqual3.errors.txt +++ b/tests/baselines/reference/typeParametersShouldNotBeEqual3.errors.txt @@ -1,6 +1,8 @@ tests/cases/compiler/typeParametersShouldNotBeEqual3.ts(4,5): error TS2322: Type 'U' is not assignable to type 'T'. Type 'Object' is not assignable to type 'T'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? tests/cases/compiler/typeParametersShouldNotBeEqual3.ts(5,5): error TS2322: Type 'Object' is not assignable to type 'T'. + The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? ==== tests/cases/compiler/typeParametersShouldNotBeEqual3.ts (2 errors) ==== @@ -11,9 +13,11 @@ tests/cases/compiler/typeParametersShouldNotBeEqual3.ts(5,5): error TS2322: Type ~ !!! error TS2322: Type 'U' is not assignable to type 'T'. !!! error TS2322: Type 'Object' is not assignable to type 'T'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? x = z; // Ok ~ !!! error TS2322: Type 'Object' is not assignable to type 'T'. +!!! error TS2322: The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead? z = x; // Ok } \ No newline at end of file diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index d4898d43bed..97e064fb12c 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -512,7 +512,7 @@ _.compact([0, 1, false, 2, '', 3]); >_.compact : (list: T[]) => T[] >_ : Underscore.Static >compact : (list: T[]) => T[] ->[0, 1, false, 2, '', 3] : (false | "" | 0 | 1 | 2 | 3)[] +>[0, 1, false, 2, '', 3] : (false | 1 | 2 | 3 | 0 | "")[] >0 : 0 >1 : 1 >false : false diff --git a/tests/baselines/reference/useSharedArrayBuffer4.types b/tests/baselines/reference/useSharedArrayBuffer4.types index d070150c95b..27b99acd231 100644 --- a/tests/baselines/reference/useSharedArrayBuffer4.types +++ b/tests/baselines/reference/useSharedArrayBuffer4.types @@ -24,7 +24,7 @@ var species = foge[Symbol.species]; >species : symbol var stringTag = foge[Symbol.toStringTag]; ->stringTag : string +>stringTag : "SharedArrayBuffer" >foge[Symbol.toStringTag] : "SharedArrayBuffer" >foge : SharedArrayBuffer >Symbol.toStringTag : symbol diff --git a/tests/baselines/reference/useSharedArrayBuffer5.types b/tests/baselines/reference/useSharedArrayBuffer5.types index 848a1596591..44d41d52477 100644 --- a/tests/baselines/reference/useSharedArrayBuffer5.types +++ b/tests/baselines/reference/useSharedArrayBuffer5.types @@ -15,7 +15,7 @@ var species = foge[Symbol.species]; >species : symbol var stringTag = foge[Symbol.toStringTag]; ->stringTag : string +>stringTag : "SharedArrayBuffer" >foge[Symbol.toStringTag] : "SharedArrayBuffer" >foge : SharedArrayBuffer >Symbol.toStringTag : symbol diff --git a/tests/baselines/reference/useSharedArrayBuffer6.types b/tests/baselines/reference/useSharedArrayBuffer6.types index 4cf07e49320..d4d831e68fb 100644 --- a/tests/baselines/reference/useSharedArrayBuffer6.types +++ b/tests/baselines/reference/useSharedArrayBuffer6.types @@ -15,7 +15,7 @@ var species = foge[Symbol.species]; >species : symbol var stringTag = foge[Symbol.toStringTag]; ->stringTag : string +>stringTag : "SharedArrayBuffer" >foge[Symbol.toStringTag] : "SharedArrayBuffer" >foge : SharedArrayBuffer >Symbol.toStringTag : symbol diff --git a/tests/cases/compiler/ambientConstLiterals.ts b/tests/cases/compiler/ambientConstLiterals.ts new file mode 100644 index 00000000000..040b739bf93 --- /dev/null +++ b/tests/cases/compiler/ambientConstLiterals.ts @@ -0,0 +1,22 @@ +// @declaration: true + +function f(x: T): T { + return x; +} + +enum E { A, B, C } + +const c1 = "abc"; +const c2 = 123; +const c3 = c1; +const c4 = c2; +const c5 = f(123); +const c6 = f(-123); +const c7 = true; +const c8 = E.A; +const c9 = { x: "abc" }; +const c10 = [123]; +const c11 = "abc" + "def"; +const c12 = 123 + 456; +const c13 = Math.random() > 0.5 ? "abc" : "def"; +const c14 = Math.random() > 0.5 ? 123 : 456; \ No newline at end of file diff --git a/tests/cases/compiler/assigningFromObjectToAnythingElse.ts b/tests/cases/compiler/assigningFromObjectToAnythingElse.ts new file mode 100644 index 00000000000..ebf1a0a8763 --- /dev/null +++ b/tests/cases/compiler/assigningFromObjectToAnythingElse.ts @@ -0,0 +1,8 @@ +var x: Object; +var y: RegExp; +y = x; + +var a: String = Object.create(""); +var c: String = Object.create(1); + +var w: Error = new Object(); diff --git a/tests/cases/compiler/blockScopedBindingCaptureThisInFunction.ts b/tests/cases/compiler/blockScopedBindingCaptureThisInFunction.ts new file mode 100644 index 00000000000..7c054a0e0ea --- /dev/null +++ b/tests/cases/compiler/blockScopedBindingCaptureThisInFunction.ts @@ -0,0 +1,7 @@ +// https://github.com/Microsoft/TypeScript/issues/11038 +() => function () { + for (let someKey in {}) { + this.helloWorld(); + () => someKey; + } +}; \ No newline at end of file diff --git a/tests/cases/compiler/controlFlowWithIncompleteTypes.ts b/tests/cases/compiler/controlFlowWithIncompleteTypes.ts new file mode 100644 index 00000000000..a851e6652c8 --- /dev/null +++ b/tests/cases/compiler/controlFlowWithIncompleteTypes.ts @@ -0,0 +1,27 @@ +// Repro from #11000 + +declare var cond: boolean; + +function foo1() { + let x: string | number | boolean = 0; + while (cond) { + if (typeof x === "string") { + x = x.slice(); + } + else { + x = "abc"; + } + } +} + +function foo2() { + let x: string | number | boolean = 0; + while (cond) { + if (typeof x === "number") { + x = "abc"; + } + else { + x = x.slice(); + } + } +} \ No newline at end of file diff --git a/tests/cases/compiler/forOfTransformsExpression.ts b/tests/cases/compiler/forOfTransformsExpression.ts new file mode 100644 index 00000000000..e91bec012b1 --- /dev/null +++ b/tests/cases/compiler/forOfTransformsExpression.ts @@ -0,0 +1,5 @@ +// https://github.com/Microsoft/TypeScript/issues/11024 +let items = [{ name: "A" }, { name: "C" }, { name: "B" }]; +for (var item of items.sort((a, b) => a.name.localeCompare(b.name))) { + +} \ No newline at end of file diff --git a/tests/cases/compiler/modularizeLibrary_Dom.iterable.ts b/tests/cases/compiler/modularizeLibrary_Dom.iterable.ts new file mode 100644 index 00000000000..3488d255eaa --- /dev/null +++ b/tests/cases/compiler/modularizeLibrary_Dom.iterable.ts @@ -0,0 +1,6 @@ +// @lib: es6,dom,dom.iterable +// @target: es6 + +for (const element of document.getElementsByTagName("a")) { + element.href; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/literalTypeWidening.ts b/tests/cases/conformance/types/literal/literalTypeWidening.ts new file mode 100644 index 00000000000..98ed328f0d2 --- /dev/null +++ b/tests/cases/conformance/types/literal/literalTypeWidening.ts @@ -0,0 +1,97 @@ +// Widening vs. non-widening literal types + +function f1() { + const c1 = "hello"; // Widening type "hello" + let v1 = c1; // Type string + const c2 = c1; // Widening type "hello" + let v2 = c2; // Type string + const c3: "hello" = "hello"; // Type "hello" + let v3 = c3; // Type "hello" + const c4: "hello" = c1; // Type "hello" + let v4 = c4; // Type "hello" +} + +function f2(cond: boolean) { + const c1 = cond ? "foo" : "bar"; // widening "foo" | widening "bar" + const c2: "foo" | "bar" = c1; // "foo" | "bar" + const c3 = cond ? c1 : c2; // "foo" | "bar" + const c4 = cond ? c3 : "baz"; // "foo" | "bar" | widening "baz" + const c5: "foo" | "bar" | "baz" = c4; // "foo" | "bar" | "baz" + let v1 = c1; // string + let v2 = c2; // "foo" | "bar" + let v3 = c3; // "foo" | "bar" + let v4 = c4; // string + let v5 = c5; // "foo" | "bar" | "baz" +} + +function f3() { + const c1 = 123; // Widening type 123 + let v1 = c1; // Type number + const c2 = c1; // Widening type 123 + let v2 = c2; // Type number + const c3: 123 = 123; // Type 123 + let v3 = c3; // Type 123 + const c4: 123 = c1; // Type 123 + let v4 = c4; // Type 123 +} + +function f4(cond: boolean) { + const c1 = cond ? 123 : 456; // widening 123 | widening 456 + const c2: 123 | 456 = c1; // 123 | 456 + const c3 = cond ? c1 : c2; // 123 | 456 + const c4 = cond ? c3 : 789; // 123 | 456 | widening 789 + const c5: 123 | 456 | 789 = c4; // 123 | 456 | 789 + let v1 = c1; // number + let v2 = c2; // 123 | 456 + let v3 = c3; // 123 | 456 + let v4 = c4; // number + let v5 = c5; // 123 | 456 | 789 +} + +function f5() { + const c1 = "foo"; + let v1 = c1; + const c2: "foo" = "foo"; + let v2 = c2; + const c3 = "foo" as "foo"; + let v3 = c3; + const c4 = <"foo">"foo"; + let v4 = c4; +} + +// Repro from #10898 + +type FAILURE = "FAILURE"; +const FAILURE = "FAILURE"; + +type Result = T | FAILURE; + +function doWork(): Result { + return FAILURE; +} + +function isSuccess(result: Result): result is T { + return !isFailure(result); +} + +function isFailure(result: Result): result is FAILURE { + return result === FAILURE; +} + +function increment(x: number): number { + return x + 1; +} + +let result = doWork(); + +if (isSuccess(result)) { + increment(result); +} + +// Repro from #10898 + +type TestEvent = "onmouseover" | "onmouseout"; + +function onMouseOver(): TestEvent { return "onmouseover"; } + +let x = onMouseOver(); \ No newline at end of file diff --git a/tests/cases/project/declarationsExportNamespace.json b/tests/cases/project/declarationsExportNamespace.json new file mode 100644 index 00000000000..550326efcaa --- /dev/null +++ b/tests/cases/project/declarationsExportNamespace.json @@ -0,0 +1,14 @@ +{ + "scenario": "declarations_ExportNamespace", + "projectRoot": "tests/cases/projects/declarations_ExportNamespace", + "inputFiles": [ + "decl.d.ts", + "useModule.ts" + ], + "declaration": true, + "baselineCheck": true, + "emittedFiles": [ + "useModule.js", + "useModule.d.ts" + ] +} \ No newline at end of file diff --git a/tests/cases/projects/declarations_ExportNamespace/decl.d.ts b/tests/cases/projects/declarations_ExportNamespace/decl.d.ts new file mode 100644 index 00000000000..62b83defaed --- /dev/null +++ b/tests/cases/projects/declarations_ExportNamespace/decl.d.ts @@ -0,0 +1,4 @@ +export interface A { + b: number; +} +export as namespace moduleA; \ No newline at end of file diff --git a/tests/cases/projects/declarations_ExportNamespace/useModule.ts b/tests/cases/projects/declarations_ExportNamespace/useModule.ts new file mode 100644 index 00000000000..dc297a5a0ae --- /dev/null +++ b/tests/cases/projects/declarations_ExportNamespace/useModule.ts @@ -0,0 +1,5 @@ +module moduleB { + export interface IUseModuleA { + a: moduleA.A; + } +} \ No newline at end of file