From 89596cb73b946c50b91ba434160bacbda92f3575 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 18 Jun 2016 07:21:23 -0700 Subject: [PATCH 01/55] Numeric and boolean literal types --- src/compiler/checker.ts | 156 ++++++++++++++++++----------- src/compiler/declarationEmitter.ts | 2 +- src/compiler/emitter.ts | 2 +- src/compiler/parser.ts | 29 +++++- src/compiler/types.ts | 75 +++++++------- src/services/services.ts | 17 ++-- src/services/utilities.ts | 4 +- 7 files changed, 170 insertions(+), 115 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e53600f2acef3..973a1a79cc549 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -114,6 +114,8 @@ namespace ts { const stringType = createIntrinsicType(TypeFlags.String, "string"); const numberType = createIntrinsicType(TypeFlags.Number, "number"); const booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean"); + const trueType = createIntrinsicType(TypeFlags.BooleanLiteral, "true"); + const falseType = createIntrinsicType(TypeFlags.BooleanLiteral, "false"); const esSymbolType = createIntrinsicType(TypeFlags.ESSymbol, "symbol"); const voidType = createIntrinsicType(TypeFlags.Void, "void"); const undefinedType = createIntrinsicType(TypeFlags.Undefined, "undefined"); @@ -134,8 +136,8 @@ namespace ts { const noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); - const anySignature = createSignature(undefined, undefined, undefined, emptyArray, anyType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); - const unknownSignature = createSignature(undefined, undefined, undefined, emptyArray, unknownType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false); + 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 enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true); @@ -195,7 +197,8 @@ namespace ts { const tupleTypes: Map = {}; const unionTypes: Map = {}; const intersectionTypes: Map = {}; - const stringLiteralTypes: Map = {}; + const stringLiteralTypes: Map = {}; + const numericLiteralTypes: Map = {}; const resolutionTargets: TypeSystemEntity[] = []; const resolutionResults: boolean[] = []; @@ -2060,7 +2063,10 @@ namespace ts { writeAnonymousType(type, flags); } else if (type.flags & TypeFlags.StringLiteral) { - writer.writeStringLiteral(`"${escapeString((type).text)}"`); + writer.writeStringLiteral(`"${escapeString((type).text)}"`); + } + else if (type.flags & TypeFlags.NumberLiteral) { + writer.writeStringLiteral((type).text); } else { // Should never get here @@ -3718,7 +3724,7 @@ namespace ts { case SyntaxKind.UndefinedKeyword: case SyntaxKind.NullKeyword: case SyntaxKind.NeverKeyword: - case SyntaxKind.StringLiteralType: + case SyntaxKind.LiteralType: return true; case SyntaxKind.ArrayType: return isIndependentType((node).elementType); @@ -3863,7 +3869,7 @@ namespace ts { } function createSignature(declaration: SignatureDeclaration, typeParameters: TypeParameter[], thisType: Type, parameters: Symbol[], - resolvedReturnType: Type, typePredicate: TypePredicate, minArgumentCount: number, hasRestParameter: boolean, hasStringLiterals: boolean): Signature { + resolvedReturnType: Type, typePredicate: TypePredicate, minArgumentCount: number, hasRestParameter: boolean, hasLiteralTypes: boolean): Signature { const sig = new Signature(checker); sig.declaration = declaration; sig.typeParameters = typeParameters; @@ -3873,20 +3879,20 @@ namespace ts { sig.typePredicate = typePredicate; sig.minArgumentCount = minArgumentCount; sig.hasRestParameter = hasRestParameter; - sig.hasStringLiterals = hasStringLiterals; + sig.hasLiteralTypes = hasLiteralTypes; return sig; } function cloneSignature(sig: Signature): Signature { return createSignature(sig.declaration, sig.typeParameters, sig.thisType, sig.parameters, sig.resolvedReturnType, - sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); + sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasLiteralTypes); } function getDefaultConstructSignatures(classType: InterfaceType): Signature[] { const baseConstructorType = getBaseConstructorTypeOfClass(classType); const baseSignatures = getSignaturesOfType(baseConstructorType, SignatureKind.Construct); if (baseSignatures.length === 0) { - return [createSignature(undefined, classType.localTypeParameters, undefined, emptyArray, classType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasStringLiterals*/ false)]; + return [createSignature(undefined, classType.localTypeParameters, undefined, emptyArray, classType, /*typePredicate*/ undefined, 0, /*hasRestParameter*/ false, /*hasLiteralTypes*/ false)]; } const baseTypeNode = getBaseTypeNodeOfClass(classType); const typeArguments = map(baseTypeNode.typeArguments, getTypeFromTypeNode); @@ -4184,7 +4190,7 @@ namespace ts { else if (type.flags & TypeFlags.NumberLike) { type = globalNumberType; } - else if (type.flags & TypeFlags.Boolean) { + else if (type.flags & TypeFlags.BooleanLike) { type = globalBooleanType; } else if (type.flags & TypeFlags.ESSymbol) { @@ -4426,7 +4432,7 @@ namespace ts { const links = getNodeLinks(declaration); if (!links.resolvedSignature) { const parameters: Symbol[] = []; - let hasStringLiterals = false; + let hasLiteralTypes = false; let minArgumentCount = -1; let thisType: Type = undefined; let hasThisParameter: boolean; @@ -4452,8 +4458,8 @@ namespace ts { parameters.push(paramSymbol); } - if (param.type && param.type.kind === SyntaxKind.StringLiteralType) { - hasStringLiterals = true; + if (param.type && param.type.kind === SyntaxKind.LiteralType) { + hasLiteralTypes = true; } if (param.initializer || param.questionToken || param.dotDotDotToken) { @@ -4494,7 +4500,7 @@ namespace ts { createTypePredicateFromTypePredicateNode(declaration.type as TypePredicateNode) : undefined; - links.resolvedSignature = createSignature(declaration, typeParameters, thisType, parameters, returnType, typePredicate, minArgumentCount, hasRestParameter(declaration), hasStringLiterals); + links.resolvedSignature = createSignature(declaration, typeParameters, thisType, parameters, returnType, typePredicate, minArgumentCount, hasRestParameter(declaration), hasLiteralTypes); } return links.resolvedSignature; } @@ -5182,19 +5188,53 @@ namespace ts { return links.resolvedType; } - function getStringLiteralTypeForText(text: string): StringLiteralType { + function getStringLiteralTypeForText(text: string): LiteralType { if (hasProperty(stringLiteralTypes, text)) { return stringLiteralTypes[text]; } - const type = stringLiteralTypes[text] = createType(TypeFlags.StringLiteral); + const type = stringLiteralTypes[text] = createType(TypeFlags.StringLiteral); + type.text = text; + return type; + } + + function createLiteralType(flags: TypeFlags, text: string) { + const type = createType(flags); type.text = text; return type; } - function getTypeFromStringLiteralTypeNode(node: StringLiteralTypeNode): Type { + function getLiteralTypeForText(flags: TypeFlags, text: string) { + const map = flags & TypeFlags.StringLiteral ? stringLiteralTypes : numericLiteralTypes; + return hasProperty(map, text) ? map[text] : map[text] = createLiteralType(flags, text); + } + + function getTypeFromLiteralExpression(node: Expression): Type { + switch (node.kind) { + case SyntaxKind.StringLiteral: + return getLiteralTypeForText(TypeFlags.StringLiteral, (node).text); + case SyntaxKind.NumericLiteral: + return getLiteralTypeForText(TypeFlags.NumberLiteral, (node).text); + case SyntaxKind.TrueKeyword: + return trueType; + case SyntaxKind.FalseKeyword: + return falseType; + case SyntaxKind.PrefixUnaryExpression: + if ((node).operator === SyntaxKind.MinusToken && + (node).operand.kind === SyntaxKind.NumericLiteral) { + return getLiteralTypeForText(TypeFlags.NumberLiteral, "" + -((node).operand).text); + } + } + return undefined; + } + + function getTypeOfLiteralOrExpression(node: Expression): Type { + return getTypeFromLiteralExpression(node) || checkExpression(node); + } + + function getTypeFromLiteralTypeNode(node: LiteralTypeNode): Type { const links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = getStringLiteralTypeForText(unescapeIdentifier(node.text)); + links.resolvedType = getTypeFromLiteralExpression(node.literal); } return links.resolvedType; } @@ -5263,8 +5303,8 @@ namespace ts { case SyntaxKind.ThisType: case SyntaxKind.ThisKeyword: return getTypeFromThisTypeNode(node); - case SyntaxKind.StringLiteralType: - return getTypeFromStringLiteralTypeNode(node); + case SyntaxKind.LiteralType: + return getTypeFromLiteralTypeNode(node); case SyntaxKind.TypeReference: case SyntaxKind.JSDocTypeReference: return getTypeFromTypeReference(node); @@ -5431,7 +5471,7 @@ namespace ts { instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, - signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); + signature.minArgumentCount, signature.hasRestParameter, signature.hasLiteralTypes); result.target = signature; result.mapper = mapper; return result; @@ -5918,18 +5958,18 @@ namespace ts { if (source.flags & TypeFlags.Null) { if (!strictNullChecks || target.flags & TypeFlags.Null) return Ternary.True; } - if (source.flags & TypeFlags.Enum && target === numberType) return Ternary.True; + if (source.flags & TypeFlags.NumberLike && target === numberType) return Ternary.True; if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum) { if (result = enumRelatedTo(source, target, reportErrors)) { return result; } } - if (source.flags & TypeFlags.StringLiteral && target === stringType) return Ternary.True; + if (source.flags & TypeFlags.StringLike && target === stringType) return Ternary.True; if (relation === assignableRelation || relation === comparableRelation) { if (source.flags & TypeFlags.Any) return Ternary.True; if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True; } - if (source.flags & TypeFlags.Boolean && target.flags & TypeFlags.Boolean) { + if (source.flags & TypeFlags.BooleanLike && target.flags & TypeFlags.Boolean) { return Ternary.True; } } @@ -6834,9 +6874,9 @@ namespace ts { return !!getPropertyOfType(type, "0"); } - function isStringLiteralUnionType(type: Type): boolean { - return type.flags & TypeFlags.StringLiteral ? true : - type.flags & TypeFlags.Union ? forEach((type).types, isStringLiteralUnionType) : + function isLiteralUnionType(type: Type): boolean { + return type.flags & TypeFlags.Literal ? true : + type.flags & TypeFlags.Union ? forEach((type).types, isLiteralUnionType) : false; } @@ -7528,7 +7568,7 @@ namespace ts { if (flags & TypeFlags.NumberLike) { return strictNullChecks ? TypeFacts.NumberStrictFacts : TypeFacts.NumberFacts; } - if (flags & TypeFlags.Boolean) { + if (flags & TypeFlags.BooleanLike) { return strictNullChecks ? TypeFacts.BooleanStrictFacts : TypeFacts.BooleanFacts; } if (flags & TypeFlags.ObjectType) { @@ -7703,11 +7743,7 @@ namespace ts { } function getTypeOfSwitchClause(clause: CaseClause | DefaultClause) { - if (clause.kind === SyntaxKind.CaseClause) { - const expr = (clause).expression; - return expr.kind === SyntaxKind.StringLiteral ? getStringLiteralTypeForText((expr).text) : checkExpression(expr); - } - return undefined; + return clause.kind === SyntaxKind.CaseClause ? getTypeOfLiteralOrExpression((clause).expression) : undefined; } function getSwitchClauseTypes(switchStatement: SwitchStatement): Type[] { @@ -8021,11 +8057,11 @@ namespace ts { } const propName = propAccess.name.text; const propType = getTypeOfPropertyOfType(type, propName); - if (!propType || !isStringLiteralUnionType(propType)) { + if (!propType || !isLiteralUnionType(propType)) { return type; } - const discriminantType = value.kind === SyntaxKind.StringLiteral ? getStringLiteralTypeForText((value).text) : checkExpression(value); - if (!isStringLiteralUnionType(discriminantType)) { + const discriminantType = getTypeOfLiteralOrExpression(value); + if (!isLiteralUnionType(discriminantType)) { return type; } if (operator === SyntaxKind.ExclamationEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) { @@ -8047,7 +8083,7 @@ namespace ts { } const propName = (switchStatement.expression).name.text; const propType = getTypeOfPropertyOfType(type, propName); - if (!propType || !isStringLiteralUnionType(propType)) { + if (!propType || !isLiteralUnionType(propType)) { return type; } const switchTypes = getSwitchClauseTypes(switchStatement); @@ -10446,7 +10482,7 @@ namespace ts { // specialized signatures always need to be placed before non-specialized signatures regardless // of the cutoff position; see GH#1133 - if (signature.hasStringLiterals) { + if (signature.hasLiteralTypes) { specializedIndex++; spliceIndex = specializedIndex; // The cutoff index always needs to be greater than or equal to the specialized signature index @@ -10705,7 +10741,7 @@ namespace ts { // for the argument. In that case, we should check the argument. if (argType === undefined) { argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors - ? getStringLiteralTypeForText((arg).text) + ? getTypeFromLiteralExpression(arg) : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); } @@ -11877,7 +11913,7 @@ namespace ts { } const propName = (expr).name.text; const propType = getTypeOfPropertyOfType(type, propName); - if (!propType || !isStringLiteralUnionType(propType)) { + if (!propType || !isLiteralUnionType(propType)) { return false; } const switchTypes = getSwitchClauseTypes(node); @@ -12217,6 +12253,9 @@ namespace ts { function checkPrefixUnaryExpression(node: PrefixUnaryExpression): Type { const operandType = checkExpression(node.operand); + if (node.operator === SyntaxKind.MinusToken && node.operand.kind === SyntaxKind.NumericLiteral && hasLiteralContextualType(node)) { + return getTypeFromLiteralExpression(node); + } switch (node.operator) { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: @@ -12520,8 +12559,8 @@ namespace ts { let suggestedOperator: SyntaxKind; // if a user tries to apply a bitwise operator to 2 boolean operands // try and return them a helpful suggestion - if ((leftType.flags & TypeFlags.Boolean) && - (rightType.flags & TypeFlags.Boolean) && + if ((leftType.flags & TypeFlags.BooleanLike) && + (rightType.flags & TypeFlags.BooleanLike) && (suggestedOperator = getSuggestedBooleanOperator(operatorToken.kind)) !== undefined) { error(errorNode || operatorToken, Diagnostics.The_0_operator_is_not_allowed_for_boolean_types_Consider_using_1_instead, tokenToString(operatorToken.kind), tokenToString(suggestedOperator)); } @@ -12734,13 +12773,18 @@ namespace ts { return getUnionType([type1, type2]); } - function checkStringLiteralExpression(node: StringLiteral): Type { - const contextualType = getContextualType(node); - if (contextualType && isStringLiteralUnionType(contextualType)) { - return getStringLiteralTypeForText(node.text); - } + function hasLiteralContextualType(node: Expression) { + return isLiteralUnionType(getContextualType(node) || unknownType); + } - return stringType; + function checkLiteralExpression(node: Expression): Type { + const type = node.kind === SyntaxKind.StringLiteral ? stringType : + node.kind === SyntaxKind.TrueKeyword || node.kind === SyntaxKind.FalseKeyword ? booleanType : + numberType; + if (type === numberType) { + checkGrammarNumericLiteral(node); + } + return hasLiteralContextualType(node) ? getTypeFromLiteralExpression(node) : type; } function checkTemplateExpression(node: TemplateExpression): Type { @@ -12855,12 +12899,6 @@ namespace ts { return type; } - function checkNumericLiteral(node: LiteralExpression): Type { - // Grammar checking - checkGrammarNumericLiteral(node); - return numberType; - } - function checkExpressionWorker(node: Expression, contextualMapper: TypeMapper): Type { switch (node.kind) { case SyntaxKind.Identifier: @@ -12871,15 +12909,13 @@ namespace ts { return checkSuperExpression(node); case SyntaxKind.NullKeyword: return nullWideningType; + case SyntaxKind.StringLiteral: + case SyntaxKind.NumericLiteral: case SyntaxKind.TrueKeyword: case SyntaxKind.FalseKeyword: - return booleanType; - case SyntaxKind.NumericLiteral: - return checkNumericLiteral(node); + return checkLiteralExpression(node); case SyntaxKind.TemplateExpression: return checkTemplateExpression(node); - case SyntaxKind.StringLiteral: - return checkStringLiteralExpression(node); case SyntaxKind.NoSubstitutionTemplateLiteral: return stringType; case SyntaxKind.RegularExpressionLiteral: @@ -17605,7 +17641,7 @@ namespace ts { else if (isTypeOfKind(type, TypeFlags.Void)) { return TypeReferenceSerializationKind.VoidType; } - else if (isTypeOfKind(type, TypeFlags.Boolean)) { + else if (isTypeOfKind(type, TypeFlags.BooleanLike)) { return TypeReferenceSerializationKind.BooleanType; } else if (isTypeOfKind(type, TypeFlags.NumberLike)) { diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 2708833a13f3c..d93a8a0aed027 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -397,7 +397,7 @@ namespace ts { case SyntaxKind.NullKeyword: case SyntaxKind.NeverKeyword: case SyntaxKind.ThisType: - case SyntaxKind.StringLiteralType: + case SyntaxKind.LiteralType: return writeTextOfNode(currentText, type); case SyntaxKind.ExpressionWithTypeArguments: return emitExpressionWithTypeArguments(type); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 101778e732223..057cbecb0a411 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6009,7 +6009,7 @@ const _super = (function (geti, seti) { return; case SyntaxKind.StringKeyword: - case SyntaxKind.StringLiteralType: + case SyntaxKind.LiteralType: write("String"); return; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index b2f3755ec46be..c206b66645f16 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -128,6 +128,8 @@ namespace ts { return visitNodes(cbNodes, (node).types); case SyntaxKind.ParenthesizedType: return visitNode(cbNode, (node).type); + case SyntaxKind.LiteralType: + return visitNode(cbNode, (node).literal); case SyntaxKind.ObjectBindingPattern: case SyntaxKind.ArrayBindingPattern: return visitNodes(cbNodes, (node).elements); @@ -1918,10 +1920,6 @@ namespace ts { return finishNode(span); } - function parseStringLiteralTypeNode(): StringLiteralTypeNode { - return parseLiteralLikeNode(SyntaxKind.StringLiteralType, /*internName*/ true); - } - function parseLiteralNode(internName?: boolean): LiteralExpression { return parseLiteralLikeNode(token, internName); } @@ -2387,6 +2385,17 @@ namespace ts { return token === SyntaxKind.DotToken ? undefined : node; } + function parseLiteralTypeNode(): LiteralTypeNode { + const node = createNode(SyntaxKind.LiteralType); + node.literal = parseSimpleUnaryExpression(); + finishNode(node); + return node; + } + + function nextTokenIsNumericLiteral() { + return nextToken() === SyntaxKind.NumericLiteral; + } + function parseNonArrayType(): TypeNode { switch (token) { case SyntaxKind.AnyKeyword: @@ -2400,7 +2409,12 @@ namespace ts { const node = tryParse(parseKeywordAndNoDot); return node || parseTypeReference(); case SyntaxKind.StringLiteral: - return parseStringLiteralTypeNode(); + case SyntaxKind.NumericLiteral: + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: + return parseLiteralTypeNode(); + case SyntaxKind.MinusToken: + return lookAhead(nextTokenIsNumericLiteral) ? parseLiteralTypeNode() : parseTypeReference(); case SyntaxKind.VoidKeyword: case SyntaxKind.NullKeyword: return parseTokenNode(); @@ -2444,7 +2458,12 @@ namespace ts { case SyntaxKind.LessThanToken: case SyntaxKind.NewKeyword: case SyntaxKind.StringLiteral: + case SyntaxKind.NumericLiteral: + case SyntaxKind.TrueKeyword: + case SyntaxKind.FalseKeyword: return true; + case SyntaxKind.MinusToken: + return lookAhead(nextTokenIsNumericLiteral); case SyntaxKind.OpenParenToken: // Only consider '(' the start of a type if followed by ')', '...', an identifier, a modifier, // or something that starts a type. We don't want to consider things like '(1)' a type. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 22861f04c5e02..04027042c2dfd 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -210,7 +210,7 @@ namespace ts { IntersectionType, ParenthesizedType, ThisType, - StringLiteralType, + LiteralType, // Binding patterns ObjectBindingPattern, ArrayBindingPattern, @@ -361,7 +361,7 @@ namespace ts { FirstFutureReservedWord = ImplementsKeyword, LastFutureReservedWord = YieldKeyword, FirstTypeNode = TypePredicate, - LastTypeNode = StringLiteralType, + LastTypeNode = LiteralType, FirstPunctuation = OpenBraceToken, LastPunctuation = CaretEqualsToken, FirstToken = Unknown, @@ -790,8 +790,9 @@ namespace ts { } // @kind(SyntaxKind.StringLiteralType) - export interface StringLiteralTypeNode extends LiteralLikeNode, TypeNode { + export interface LiteralTypeNode extends TypeNode { _stringLiteralTypeBrand: any; + literal: Expression; } // @kind(SyntaxKind.StringLiteral) @@ -2197,50 +2198,54 @@ namespace ts { } export const enum TypeFlags { - Any = 0x00000001, - String = 0x00000002, - Number = 0x00000004, - Boolean = 0x00000008, - Void = 0x00000010, - Undefined = 0x00000020, - Null = 0x00000040, - Enum = 0x00000080, // Enum type - StringLiteral = 0x00000100, // String literal type - TypeParameter = 0x00000200, // Type parameter - Class = 0x00000400, // Class - Interface = 0x00000800, // Interface - Reference = 0x00001000, // Generic type reference - Tuple = 0x00002000, // Tuple - Union = 0x00004000, // Union (T | U) - Intersection = 0x00008000, // Intersection (T & U) - Anonymous = 0x00010000, // Anonymous - Instantiated = 0x00020000, // Instantiated anonymous type + Any = 1 << 0, + String = 1 << 1, + Number = 1 << 2, + Boolean = 1 << 3, + StringLiteral = 1 << 4, // String literal type + NumberLiteral = 1 << 5, + BooleanLiteral = 1 << 6, + ESSymbol = 1 << 7, // Type of symbol primitive introduced in ES6 + Void = 1 << 8, + Undefined = 1 << 9, + Null = 1 << 10, + Never = 1 << 11, // Never type + Enum = 1 << 12, // Enum type + TypeParameter = 1 << 13, // Type parameter + Class = 1 << 14, // Class + Interface = 1 << 15, // Interface + Reference = 1 << 16, // Generic type reference + Tuple = 1 << 17, // Tuple + Union = 1 << 18, // Union (T | U) + Intersection = 1 << 19, // Intersection (T & U) + Anonymous = 1 << 20, // Anonymous + Instantiated = 1 << 21, // Instantiated anonymous type /* @internal */ - FromSignature = 0x00040000, // Created for signature assignment check - ObjectLiteral = 0x00080000, // Originates in an object literal + FromSignature = 1 << 22, // Created for signature assignment check + ObjectLiteral = 1 << 23, // Originates in an object literal /* @internal */ - FreshObjectLiteral = 0x00100000, // Fresh object literal type + FreshObjectLiteral = 1 << 24, // Fresh object literal type /* @internal */ - ContainsWideningType = 0x00200000, // Type is or contains undefined or null widening type + ContainsWideningType = 1 << 25, // Type is or contains undefined or null widening type /* @internal */ - ContainsObjectLiteral = 0x00400000, // Type is or contains object literal type + ContainsObjectLiteral = 1 << 26, // Type is or contains object literal type /* @internal */ - ContainsAnyFunctionType = 0x00800000, // Type is or contains object literal type - ESSymbol = 0x01000000, // Type of symbol primitive introduced in ES6 - ThisType = 0x02000000, // This type - ObjectLiteralPatternWithComputedProperties = 0x04000000, // Object literal type implied by binding pattern has computed properties - Never = 0x08000000, // Never type + ContainsAnyFunctionType = 1 << 27, // Type is or contains object literal type + ThisType = 1 << 28, // This type + ObjectLiteralPatternWithComputedProperties = 1 << 29, // Object literal type implied by binding pattern has computed properties /* @internal */ Nullable = Undefined | Null, + Literal = StringLiteral | NumberLiteral | BooleanLiteral, /* @internal */ Falsy = Void | Undefined | Null, // TODO: Add false, 0, and "" /* @internal */ - Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null | Never, + Intrinsic = Any | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never, /* @internal */ Primitive = String | Number | Boolean | ESSymbol | Void | Undefined | Null | StringLiteral | Enum, StringLike = String | StringLiteral, - NumberLike = Number | Enum, + NumberLike = Number | NumberLiteral | Enum, + BooleanLike = Boolean | BooleanLiteral, ObjectType = Class | Interface | Reference | Tuple | Anonymous, UnionOrIntersection = Union | Intersection, StructuredType = ObjectType | Union | Intersection, @@ -2271,7 +2276,7 @@ namespace ts { } // String literal types (TypeFlags.StringLiteral) - export interface StringLiteralType extends Type { + export interface LiteralType extends Type { text: string; // Text of string literal } @@ -2394,7 +2399,7 @@ namespace ts { /* @internal */ hasRestParameter: boolean; // True if last parameter is rest parameter /* @internal */ - hasStringLiterals: boolean; // True if specialized + hasLiteralTypes: boolean; // True if specialized /* @internal */ target?: Signature; // Instantiation target /* @internal */ diff --git a/src/services/services.ts b/src/services/services.ts index 983ddfbf250f6..1e205bb393fd5 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -783,7 +783,7 @@ namespace ts { resolvedReturnType: Type; minArgumentCount: number; hasRestParameter: boolean; - hasStringLiterals: boolean; + hasLiteralTypes: boolean; // Undefined is used to indicate the value has not been computed. If, after computing, the // symbol has no doc comment, then the empty string will be returned. @@ -3633,7 +3633,6 @@ namespace ts { function isInStringOrRegularExpressionOrTemplateLiteral(contextToken: Node): boolean { if (contextToken.kind === SyntaxKind.StringLiteral - || contextToken.kind === SyntaxKind.StringLiteralType || contextToken.kind === SyntaxKind.RegularExpressionLiteral || isTemplateLiteralKind(contextToken.kind)) { const start = contextToken.getStart(); @@ -4298,7 +4297,7 @@ namespace ts { else { if (type.flags & TypeFlags.StringLiteral) { result.push({ - name: (type).text, + name: (type).text, kindModifiers: ScriptElementKindModifier.none, kind: ScriptElementKind.variableElement, sortText: "0" @@ -6985,7 +6984,6 @@ namespace ts { case SyntaxKind.PropertyAccessExpression: case SyntaxKind.QualifiedName: case SyntaxKind.StringLiteral: - case SyntaxKind.StringLiteralType: case SyntaxKind.FalseKeyword: case SyntaxKind.TrueKeyword: case SyntaxKind.NullKeyword: @@ -7489,7 +7487,7 @@ namespace ts { else if (tokenKind === SyntaxKind.NumericLiteral) { return ClassificationType.numericLiteral; } - else if (tokenKind === SyntaxKind.StringLiteral || tokenKind === SyntaxKind.StringLiteralType) { + else if (tokenKind === SyntaxKind.StringLiteral) { return token.parent.kind === SyntaxKind.JsxAttribute ? ClassificationType.jsxAttributeStringLiteralValue : ClassificationType.stringLiteral; } else if (tokenKind === SyntaxKind.RegularExpressionLiteral) { @@ -7983,11 +7981,11 @@ namespace ts { } } - function getStringLiteralTypeForNode(node: StringLiteral | StringLiteralTypeNode, typeChecker: TypeChecker): StringLiteralType { - const searchNode = node.parent.kind === SyntaxKind.StringLiteralType ? node.parent : node; + function getStringLiteralTypeForNode(node: StringLiteral | LiteralTypeNode, typeChecker: TypeChecker): LiteralType { + const searchNode = node.parent.kind === SyntaxKind.LiteralType ? node.parent : node; const type = typeChecker.getTypeAtLocation(searchNode); if (type && type.flags & TypeFlags.StringLiteral) { - return type; + return type; } return undefined; } @@ -8474,7 +8472,7 @@ namespace ts { addResult(start, end, classFromKind(token)); if (end >= text.length) { - if (token === SyntaxKind.StringLiteral || token === SyntaxKind.StringLiteralType) { + if (token === SyntaxKind.StringLiteral) { // Check to see if we finished up on a multiline string literal. const tokenText = scanner.getTokenText(); if (scanner.isUnterminated()) { @@ -8624,7 +8622,6 @@ namespace ts { case SyntaxKind.NumericLiteral: return ClassificationType.numericLiteral; case SyntaxKind.StringLiteral: - case SyntaxKind.StringLiteralType: return ClassificationType.stringLiteral; case SyntaxKind.RegularExpressionLiteral: return ClassificationType.regularExpressionLiteral; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index d49fa39043571..ce2b30c839f86 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -428,8 +428,7 @@ namespace ts { export function isInString(sourceFile: SourceFile, position: number): boolean { const previousToken = findPrecedingToken(position, sourceFile); - if (previousToken && - (previousToken.kind === SyntaxKind.StringLiteral || previousToken.kind === SyntaxKind.StringLiteralType)) { + if (previousToken && previousToken.kind === SyntaxKind.StringLiteral) { const start = previousToken.getStart(); const end = previousToken.getEnd(); @@ -627,7 +626,6 @@ namespace ts { export function isStringOrRegularExpressionOrTemplateLiteral(kind: SyntaxKind): boolean { if (kind === SyntaxKind.StringLiteral - || kind === SyntaxKind.StringLiteralType || kind === SyntaxKind.RegularExpressionLiteral || isTemplateLiteralKind(kind)) { return true; From a204622ec6e58befcba0f346ee5ecc35b1566477 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 20 Jun 2016 12:05:58 -0700 Subject: [PATCH 02/55] Accept new baselines --- .../discriminatedUnionTypes1.errors.txt | 148 ++++++ .../discriminatedUnionTypes1.symbols | 402 --------------- .../reference/discriminatedUnionTypes1.types | 465 ------------------ .../typeParameterConstraints1.errors.txt | 8 +- 4 files changed, 149 insertions(+), 874 deletions(-) create mode 100644 tests/baselines/reference/discriminatedUnionTypes1.errors.txt delete mode 100644 tests/baselines/reference/discriminatedUnionTypes1.symbols delete mode 100644 tests/baselines/reference/discriminatedUnionTypes1.types diff --git a/tests/baselines/reference/discriminatedUnionTypes1.errors.txt b/tests/baselines/reference/discriminatedUnionTypes1.errors.txt new file mode 100644 index 0000000000000..ac2bd4d3b1973 --- /dev/null +++ b/tests/baselines/reference/discriminatedUnionTypes1.errors.txt @@ -0,0 +1,148 @@ +tests/cases/conformance/types/union/discriminatedUnionTypes1.ts(89,9): error TS2365: Operator '===' cannot be applied to types '"A" | "B" | "C" | "D"' and '"X"'. + + +==== tests/cases/conformance/types/union/discriminatedUnionTypes1.ts (1 errors) ==== + interface Square { + kind: "square"; + size: number; + } + + interface Rectangle { + kind: "rectangle"; + width: number; + height: number; + } + + interface Circle { + kind: "circle"; + radius: number; + } + + type Shape = Square | Rectangle | Circle; + + function area1(s: Shape) { + if (s.kind === "square") { + return s.size * s.size; + } + else if (s.kind === "circle") { + return Math.PI * s.radius * s.radius; + } + else if (s.kind === "rectangle") { + return s.width * s.height; + } + else { + return 0; + } + } + + function area2(s: Shape) { + switch (s.kind) { + case "square": return s.size * s.size; + case "rectangle": return s.width * s.height; + case "circle": return Math.PI * s.radius * s.radius; + } + } + + function assertNever(x: never): never { + throw new Error("Unexpected object: " + x); + } + + function area3(s: Shape) { + switch (s.kind) { + case "square": return s.size * s.size; + case "rectangle": return s.width * s.height; + case "circle": return Math.PI * s.radius * s.radius; + default: return assertNever(s); + } + } + + function area4(s: Shape) { + switch (s.kind) { + case "square": return s.size * s.size; + case "rectangle": return s.width * s.height; + case "circle": return Math.PI * s.radius * s.radius; + } + return assertNever(s); + } + + type Message = + { kind: "A", x: string } | + { kind: "B" | "C", y: number } | + { kind: "D" }; + + function f1(m: Message) { + if (m.kind === "A") { + m; // { kind: "A", x: string } + } + else if (m.kind === "D") { + m; // { kind: "D" } + } + else { + m; // { kind: "B" | "C", y: number } + } + } + + function f2(m: Message) { + if (m.kind === "A") { + return; + } + m; // { kind: "B" | "C", y: number } | { kind: "D" } + } + + function f3(m: Message) { + if (m.kind === "X") { + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"A" | "B" | "C" | "D"' and '"X"'. + m; // never + } + } + + function f4(m: Message, x: "A" | "D") { + if (m.kind == x) { + m; // { kind: "A", x: string } | { kind: "D" } + } + } + + function f5(m: Message) { + switch (m.kind) { + case "A": + m; // { kind: "A", x: string } + break; + case "D": + m; // { kind: "D" } + break; + default: + m; // { kind: "B" | "C", y: number } + } + } + + function f6(m: Message) { + switch (m.kind) { + case "A": + m; // { kind: "A", x: string } + case "D": + m; // { kind: "A", x: string } | { kind: "D" } + break; + default: + m; // { kind: "B" | "C", y: number } + } + } + + function f7(m: Message) { + switch (m.kind) { + case "A": + case "B": + return; + } + m; // { kind: "B" | "C", y: number } | { kind: "D" } + } + + function f8(m: Message) { + switch (m.kind) { + case "A": + return; + case "D": + throw new Error(); + } + m; // { kind: "B" | "C", y: number } + } \ No newline at end of file diff --git a/tests/baselines/reference/discriminatedUnionTypes1.symbols b/tests/baselines/reference/discriminatedUnionTypes1.symbols deleted file mode 100644 index 380694474239a..0000000000000 --- a/tests/baselines/reference/discriminatedUnionTypes1.symbols +++ /dev/null @@ -1,402 +0,0 @@ -=== tests/cases/conformance/types/union/discriminatedUnionTypes1.ts === -interface Square { ->Square : Symbol(Square, Decl(discriminatedUnionTypes1.ts, 0, 0)) - - kind: "square"; ->kind : Symbol(Square.kind, Decl(discriminatedUnionTypes1.ts, 0, 18)) - - size: number; ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) -} - -interface Rectangle { ->Rectangle : Symbol(Rectangle, Decl(discriminatedUnionTypes1.ts, 3, 1)) - - kind: "rectangle"; ->kind : Symbol(Rectangle.kind, Decl(discriminatedUnionTypes1.ts, 5, 21)) - - width: number; ->width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) - - height: number; ->height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) -} - -interface Circle { ->Circle : Symbol(Circle, Decl(discriminatedUnionTypes1.ts, 9, 1)) - - kind: "circle"; ->kind : Symbol(Circle.kind, Decl(discriminatedUnionTypes1.ts, 11, 18)) - - radius: number; ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) -} - -type Shape = Square | Rectangle | Circle; ->Shape : Symbol(Shape, Decl(discriminatedUnionTypes1.ts, 14, 1)) ->Square : Symbol(Square, Decl(discriminatedUnionTypes1.ts, 0, 0)) ->Rectangle : Symbol(Rectangle, Decl(discriminatedUnionTypes1.ts, 3, 1)) ->Circle : Symbol(Circle, Decl(discriminatedUnionTypes1.ts, 9, 1)) - -function area1(s: Shape) { ->area1 : Symbol(area1, Decl(discriminatedUnionTypes1.ts, 16, 41)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->Shape : Symbol(Shape, Decl(discriminatedUnionTypes1.ts, 14, 1)) - - if (s.kind === "square") { ->s.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) - - return s.size * s.size; ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) - } - else if (s.kind === "circle") { ->s.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) - - return Math.PI * s.radius * s.radius; ->Math.PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) - } - else if (s.kind === "rectangle") { ->s.kind : Symbol(Rectangle.kind, Decl(discriminatedUnionTypes1.ts, 5, 21)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->kind : Symbol(Rectangle.kind, Decl(discriminatedUnionTypes1.ts, 5, 21)) - - return s.width * s.height; ->s.width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s.height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 18, 15)) ->height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) - } - else { - return 0; - } -} - -function area2(s: Shape) { ->area2 : Symbol(area2, Decl(discriminatedUnionTypes1.ts, 31, 1)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->Shape : Symbol(Shape, Decl(discriminatedUnionTypes1.ts, 14, 1)) - - switch (s.kind) { ->s.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) - - case "square": return s.size * s.size; ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) - - case "rectangle": return s.width * s.height; ->s.width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s.height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) - - case "circle": return Math.PI * s.radius * s.radius; ->Math.PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 33, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) - } -} - -function assertNever(x: never): never { ->assertNever : Symbol(assertNever, Decl(discriminatedUnionTypes1.ts, 39, 1)) ->x : Symbol(x, Decl(discriminatedUnionTypes1.ts, 41, 21)) - - throw new Error("Unexpected object: " + x); ->Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->x : Symbol(x, Decl(discriminatedUnionTypes1.ts, 41, 21)) -} - -function area3(s: Shape) { ->area3 : Symbol(area3, Decl(discriminatedUnionTypes1.ts, 43, 1)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->Shape : Symbol(Shape, Decl(discriminatedUnionTypes1.ts, 14, 1)) - - switch (s.kind) { ->s.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) - - case "square": return s.size * s.size; ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) - - case "rectangle": return s.width * s.height; ->s.width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s.height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) - - case "circle": return Math.PI * s.radius * s.radius; ->Math.PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) - - default: return assertNever(s); ->assertNever : Symbol(assertNever, Decl(discriminatedUnionTypes1.ts, 39, 1)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 45, 15)) - } -} - -function area4(s: Shape) { ->area4 : Symbol(area4, Decl(discriminatedUnionTypes1.ts, 52, 1)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->Shape : Symbol(Shape, Decl(discriminatedUnionTypes1.ts, 14, 1)) - - switch (s.kind) { ->s.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 0, 18), Decl(discriminatedUnionTypes1.ts, 5, 21), Decl(discriminatedUnionTypes1.ts, 11, 18)) - - case "square": return s.size * s.size; ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s.size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->size : Symbol(Square.size, Decl(discriminatedUnionTypes1.ts, 1, 19)) - - case "rectangle": return s.width * s.height; ->s.width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->width : Symbol(Rectangle.width, Decl(discriminatedUnionTypes1.ts, 6, 22)) ->s.height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->height : Symbol(Rectangle.height, Decl(discriminatedUnionTypes1.ts, 7, 18)) - - case "circle": return Math.PI * s.radius * s.radius; ->Math.PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) ->PI : Symbol(Math.PI, Decl(lib.d.ts, --, --)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s.radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) ->radius : Symbol(Circle.radius, Decl(discriminatedUnionTypes1.ts, 12, 19)) - } - return assertNever(s); ->assertNever : Symbol(assertNever, Decl(discriminatedUnionTypes1.ts, 39, 1)) ->s : Symbol(s, Decl(discriminatedUnionTypes1.ts, 54, 15)) -} - -type Message = ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - { kind: "A", x: string } | ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5)) ->x : Symbol(x, Decl(discriminatedUnionTypes1.ts, 64, 16)) - - { kind: "B" | "C", y: number } | ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 65, 5)) ->y : Symbol(y, Decl(discriminatedUnionTypes1.ts, 65, 22)) - - { kind: "D" }; ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 66, 5)) - -function f1(m: Message) { ->f1 : Symbol(f1, Decl(discriminatedUnionTypes1.ts, 66, 18)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 68, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - if (m.kind === "A") { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 68, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - m; // { kind: "A", x: string } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 68, 12)) - } - else if (m.kind === "D") { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 68, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - m; // { kind: "D" } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 68, 12)) - } - else { - m; // { kind: "B" | "C", y: number } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 68, 12)) - } -} - -function f2(m: Message) { ->f2 : Symbol(f2, Decl(discriminatedUnionTypes1.ts, 78, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 80, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - if (m.kind === "A") { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 80, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - return; - } - m; // { kind: "B" | "C", y: number } | { kind: "D" } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 80, 12)) -} - -function f3(m: Message) { ->f3 : Symbol(f3, Decl(discriminatedUnionTypes1.ts, 85, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 87, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - if (m.kind === "X") { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 87, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - m; // never ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 87, 12)) - } -} - -function f4(m: Message, x: "A" | "D") { ->f4 : Symbol(f4, Decl(discriminatedUnionTypes1.ts, 91, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 93, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) ->x : Symbol(x, Decl(discriminatedUnionTypes1.ts, 93, 23)) - - if (m.kind == x) { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 93, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->x : Symbol(x, Decl(discriminatedUnionTypes1.ts, 93, 23)) - - m; // { kind: "A", x: string } | { kind: "D" } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 93, 12)) - } -} - -function f5(m: Message) { ->f5 : Symbol(f5, Decl(discriminatedUnionTypes1.ts, 97, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 99, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - switch (m.kind) { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 99, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - case "A": - m; // { kind: "A", x: string } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 99, 12)) - - break; - case "D": - m; // { kind: "D" } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 99, 12)) - - break; - default: - m; // { kind: "B" | "C", y: number } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 99, 12)) - } -} - -function f6(m: Message) { ->f6 : Symbol(f6, Decl(discriminatedUnionTypes1.ts, 110, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 112, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - switch (m.kind) { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 112, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - case "A": - m; // { kind: "A", x: string } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 112, 12)) - - case "D": - m; // { kind: "A", x: string } | { kind: "D" } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 112, 12)) - - break; - default: - m; // { kind: "B" | "C", y: number } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 112, 12)) - } -} - -function f7(m: Message) { ->f7 : Symbol(f7, Decl(discriminatedUnionTypes1.ts, 122, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 124, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - switch (m.kind) { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 124, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - case "A": - case "B": - return; - } - m; // { kind: "B" | "C", y: number } | { kind: "D" } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 124, 12)) -} - -function f8(m: Message) { ->f8 : Symbol(f8, Decl(discriminatedUnionTypes1.ts, 131, 1)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 133, 12)) ->Message : Symbol(Message, Decl(discriminatedUnionTypes1.ts, 61, 1)) - - switch (m.kind) { ->m.kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 133, 12)) ->kind : Symbol(kind, Decl(discriminatedUnionTypes1.ts, 64, 5), Decl(discriminatedUnionTypes1.ts, 65, 5), Decl(discriminatedUnionTypes1.ts, 66, 5)) - - case "A": - return; - case "D": - throw new Error(); ->Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) - } - m; // { kind: "B" | "C", y: number } ->m : Symbol(m, Decl(discriminatedUnionTypes1.ts, 133, 12)) -} diff --git a/tests/baselines/reference/discriminatedUnionTypes1.types b/tests/baselines/reference/discriminatedUnionTypes1.types deleted file mode 100644 index 234de28eabae5..0000000000000 --- a/tests/baselines/reference/discriminatedUnionTypes1.types +++ /dev/null @@ -1,465 +0,0 @@ -=== tests/cases/conformance/types/union/discriminatedUnionTypes1.ts === -interface Square { ->Square : Square - - kind: "square"; ->kind : "square" - - size: number; ->size : number -} - -interface Rectangle { ->Rectangle : Rectangle - - kind: "rectangle"; ->kind : "rectangle" - - width: number; ->width : number - - height: number; ->height : number -} - -interface Circle { ->Circle : Circle - - kind: "circle"; ->kind : "circle" - - radius: number; ->radius : number -} - -type Shape = Square | Rectangle | Circle; ->Shape : Square | Rectangle | Circle ->Square : Square ->Rectangle : Rectangle ->Circle : Circle - -function area1(s: Shape) { ->area1 : (s: Square | Rectangle | Circle) => number ->s : Square | Rectangle | Circle ->Shape : Square | Rectangle | Circle - - if (s.kind === "square") { ->s.kind === "square" : boolean ->s.kind : "square" | "rectangle" | "circle" ->s : Square | Rectangle | Circle ->kind : "square" | "rectangle" | "circle" ->"square" : string - - return s.size * s.size; ->s.size * s.size : number ->s.size : number ->s : Square ->size : number ->s.size : number ->s : Square ->size : number - } - else if (s.kind === "circle") { ->s.kind === "circle" : boolean ->s.kind : "rectangle" | "circle" ->s : Rectangle | Circle ->kind : "rectangle" | "circle" ->"circle" : string - - return Math.PI * s.radius * s.radius; ->Math.PI * s.radius * s.radius : number ->Math.PI * s.radius : number ->Math.PI : number ->Math : Math ->PI : number ->s.radius : number ->s : Circle ->radius : number ->s.radius : number ->s : Circle ->radius : number - } - else if (s.kind === "rectangle") { ->s.kind === "rectangle" : boolean ->s.kind : "rectangle" ->s : Rectangle ->kind : "rectangle" ->"rectangle" : string - - return s.width * s.height; ->s.width * s.height : number ->s.width : number ->s : Rectangle ->width : number ->s.height : number ->s : Rectangle ->height : number - } - else { - return 0; ->0 : number - } -} - -function area2(s: Shape) { ->area2 : (s: Square | Rectangle | Circle) => number ->s : Square | Rectangle | Circle ->Shape : Square | Rectangle | Circle - - switch (s.kind) { ->s.kind : "square" | "rectangle" | "circle" ->s : Square | Rectangle | Circle ->kind : "square" | "rectangle" | "circle" - - case "square": return s.size * s.size; ->"square" : string ->s.size * s.size : number ->s.size : number ->s : Square ->size : number ->s.size : number ->s : Square ->size : number - - case "rectangle": return s.width * s.height; ->"rectangle" : string ->s.width * s.height : number ->s.width : number ->s : Rectangle ->width : number ->s.height : number ->s : Rectangle ->height : number - - case "circle": return Math.PI * s.radius * s.radius; ->"circle" : string ->Math.PI * s.radius * s.radius : number ->Math.PI * s.radius : number ->Math.PI : number ->Math : Math ->PI : number ->s.radius : number ->s : Circle ->radius : number ->s.radius : number ->s : Circle ->radius : number - } -} - -function assertNever(x: never): never { ->assertNever : (x: never) => never ->x : never - - throw new Error("Unexpected object: " + x); ->new Error("Unexpected object: " + x) : Error ->Error : ErrorConstructor ->"Unexpected object: " + x : string ->"Unexpected object: " : string ->x : never -} - -function area3(s: Shape) { ->area3 : (s: Square | Rectangle | Circle) => number ->s : Square | Rectangle | Circle ->Shape : Square | Rectangle | Circle - - switch (s.kind) { ->s.kind : "square" | "rectangle" | "circle" ->s : Square | Rectangle | Circle ->kind : "square" | "rectangle" | "circle" - - case "square": return s.size * s.size; ->"square" : string ->s.size * s.size : number ->s.size : number ->s : Square ->size : number ->s.size : number ->s : Square ->size : number - - case "rectangle": return s.width * s.height; ->"rectangle" : string ->s.width * s.height : number ->s.width : number ->s : Rectangle ->width : number ->s.height : number ->s : Rectangle ->height : number - - case "circle": return Math.PI * s.radius * s.radius; ->"circle" : string ->Math.PI * s.radius * s.radius : number ->Math.PI * s.radius : number ->Math.PI : number ->Math : Math ->PI : number ->s.radius : number ->s : Circle ->radius : number ->s.radius : number ->s : Circle ->radius : number - - default: return assertNever(s); ->assertNever(s) : never ->assertNever : (x: never) => never ->s : never - } -} - -function area4(s: Shape) { ->area4 : (s: Square | Rectangle | Circle) => number ->s : Square | Rectangle | Circle ->Shape : Square | Rectangle | Circle - - switch (s.kind) { ->s.kind : "square" | "rectangle" | "circle" ->s : Square | Rectangle | Circle ->kind : "square" | "rectangle" | "circle" - - case "square": return s.size * s.size; ->"square" : string ->s.size * s.size : number ->s.size : number ->s : Square ->size : number ->s.size : number ->s : Square ->size : number - - case "rectangle": return s.width * s.height; ->"rectangle" : string ->s.width * s.height : number ->s.width : number ->s : Rectangle ->width : number ->s.height : number ->s : Rectangle ->height : number - - case "circle": return Math.PI * s.radius * s.radius; ->"circle" : string ->Math.PI * s.radius * s.radius : number ->Math.PI * s.radius : number ->Math.PI : number ->Math : Math ->PI : number ->s.radius : number ->s : Circle ->radius : number ->s.radius : number ->s : Circle ->radius : number - } - return assertNever(s); ->assertNever(s) : never ->assertNever : (x: never) => never ->s : never -} - -type Message = ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - { kind: "A", x: string } | ->kind : "A" ->x : string - - { kind: "B" | "C", y: number } | ->kind : "B" | "C" ->y : number - - { kind: "D" }; ->kind : "D" - -function f1(m: Message) { ->f1 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - if (m.kind === "A") { ->m.kind === "A" : boolean ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" ->"A" : string - - m; // { kind: "A", x: string } ->m : { kind: "A"; x: string; } - } - else if (m.kind === "D") { ->m.kind === "D" : boolean ->m.kind : "B" | "C" | "D" ->m : { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "B" | "C" | "D" ->"D" : string - - m; // { kind: "D" } ->m : { kind: "D"; } - } - else { - m; // { kind: "B" | "C", y: number } ->m : { kind: "B" | "C"; y: number; } - } -} - -function f2(m: Message) { ->f2 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - if (m.kind === "A") { ->m.kind === "A" : boolean ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" ->"A" : string - - return; - } - m; // { kind: "B" | "C", y: number } | { kind: "D" } ->m : { kind: "B" | "C"; y: number; } | { kind: "D"; } -} - -function f3(m: Message) { ->f3 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - if (m.kind === "X") { ->m.kind === "X" : boolean ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" ->"X" : string - - m; // never ->m : never - } -} - -function f4(m: Message, x: "A" | "D") { ->f4 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }, x: "A" | "D") => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->x : "A" | "D" - - if (m.kind == x) { ->m.kind == x : boolean ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" ->x : "A" | "D" - - m; // { kind: "A", x: string } | { kind: "D" } ->m : { kind: "A"; x: string; } | { kind: "D"; } - } -} - -function f5(m: Message) { ->f5 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - switch (m.kind) { ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" - - case "A": ->"A" : string - - m; // { kind: "A", x: string } ->m : { kind: "A"; x: string; } - - break; - case "D": ->"D" : string - - m; // { kind: "D" } ->m : { kind: "D"; } - - break; - default: - m; // { kind: "B" | "C", y: number } ->m : { kind: "B" | "C"; y: number; } - } -} - -function f6(m: Message) { ->f6 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - switch (m.kind) { ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" - - case "A": ->"A" : string - - m; // { kind: "A", x: string } ->m : { kind: "A"; x: string; } - - case "D": ->"D" : string - - m; // { kind: "A", x: string } | { kind: "D" } ->m : { kind: "D"; } | { kind: "A"; x: string; } - - break; - default: - m; // { kind: "B" | "C", y: number } ->m : { kind: "B" | "C"; y: number; } - } -} - -function f7(m: Message) { ->f7 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - switch (m.kind) { ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" - - case "A": ->"A" : string - - case "B": ->"B" : string - - return; - } - m; // { kind: "B" | "C", y: number } | { kind: "D" } ->m : { kind: "B" | "C"; y: number; } | { kind: "D"; } -} - -function f8(m: Message) { ->f8 : (m: { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; }) => void ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->Message : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } - - switch (m.kind) { ->m.kind : "A" | "B" | "C" | "D" ->m : { kind: "A"; x: string; } | { kind: "B" | "C"; y: number; } | { kind: "D"; } ->kind : "A" | "B" | "C" | "D" - - case "A": ->"A" : string - - return; - case "D": ->"D" : string - - throw new Error(); ->new Error() : Error ->Error : ErrorConstructor - } - m; // { kind: "B" | "C", y: number } ->m : { kind: "B" | "C"; y: number; } -} diff --git a/tests/baselines/reference/typeParameterConstraints1.errors.txt b/tests/baselines/reference/typeParameterConstraints1.errors.txt index 97bc816575138..bba4bd1878ea4 100644 --- a/tests/baselines/reference/typeParameterConstraints1.errors.txt +++ b/tests/baselines/reference/typeParameterConstraints1.errors.txt @@ -1,9 +1,7 @@ tests/cases/compiler/typeParameterConstraints1.ts(6,25): error TS2304: Cannot find name 'hm'. -tests/cases/compiler/typeParameterConstraints1.ts(9,25): error TS1110: Type expected. -tests/cases/compiler/typeParameterConstraints1.ts(10,26): error TS1110: Type expected. -==== tests/cases/compiler/typeParameterConstraints1.ts (3 errors) ==== +==== tests/cases/compiler/typeParameterConstraints1.ts (1 errors) ==== function foo1(test: T) { } function foo2(test: T) { } function foo3(test: T) { } @@ -15,11 +13,7 @@ tests/cases/compiler/typeParameterConstraints1.ts(10,26): error TS1110: Type exp function foo7(test: T) { } // valid function foo8(test: T) { } function foo9 (test: T) { } - ~ -!!! error TS1110: Type expected. function foo10 (test: T) { } - ~ -!!! error TS1110: Type expected. function foo11 (test: T) { } function foo12(test: T) { } function foo13(test: T) { } \ No newline at end of file From a9309178c4371a874b2f82b4cb70adfd7ecb5794 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 20 Jun 2016 12:14:42 -0700 Subject: [PATCH 03/55] Introduce literal type locations --- src/compiler/checker.ts | 108 ++++++++++++++++++++++------------------ 1 file changed, 60 insertions(+), 48 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 973a1a79cc549..e2515c1e3866e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5188,15 +5188,6 @@ namespace ts { return links.resolvedType; } - function getStringLiteralTypeForText(text: string): LiteralType { - if (hasProperty(stringLiteralTypes, text)) { - return stringLiteralTypes[text]; - } - const type = stringLiteralTypes[text] = createType(TypeFlags.StringLiteral); - type.text = text; - return type; - } - function createLiteralType(flags: TypeFlags, text: string) { const type = createType(flags); type.text = text; @@ -5208,33 +5199,10 @@ namespace ts { return hasProperty(map, text) ? map[text] : map[text] = createLiteralType(flags, text); } - function getTypeFromLiteralExpression(node: Expression): Type { - switch (node.kind) { - case SyntaxKind.StringLiteral: - return getLiteralTypeForText(TypeFlags.StringLiteral, (node).text); - case SyntaxKind.NumericLiteral: - return getLiteralTypeForText(TypeFlags.NumberLiteral, (node).text); - case SyntaxKind.TrueKeyword: - return trueType; - case SyntaxKind.FalseKeyword: - return falseType; - case SyntaxKind.PrefixUnaryExpression: - if ((node).operator === SyntaxKind.MinusToken && - (node).operand.kind === SyntaxKind.NumericLiteral) { - return getLiteralTypeForText(TypeFlags.NumberLiteral, "" + -((node).operand).text); - } - } - return undefined; - } - - function getTypeOfLiteralOrExpression(node: Expression): Type { - return getTypeFromLiteralExpression(node) || checkExpression(node); - } - function getTypeFromLiteralTypeNode(node: LiteralTypeNode): Type { const links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = getTypeFromLiteralExpression(node.literal); + links.resolvedType = checkExpression(node.literal); } return links.resolvedType; } @@ -6880,6 +6848,14 @@ namespace ts { false; } + function getBaseTypeOfLiteralType(type: Type): Type { + return type.flags & TypeFlags.StringLiteral ? stringType : + type.flags & TypeFlags.NumberLiteral ? numberType : + type.flags & TypeFlags.BooleanLiteral ? booleanType : + type.flags & TypeFlags.Union ? getUnionType(map((type).types, getBaseTypeOfLiteralType)) : + type; + } + /** * Check if a Type was written as a tuple type literal. * Prefer using isTupleLikeType() unless the use of `elementTypes` is required. @@ -7743,7 +7719,7 @@ namespace ts { } function getTypeOfSwitchClause(clause: CaseClause | DefaultClause) { - return clause.kind === SyntaxKind.CaseClause ? getTypeOfLiteralOrExpression((clause).expression) : undefined; + return clause.kind === SyntaxKind.CaseClause ? checkExpression((clause).expression) : undefined; } function getSwitchClauseTypes(switchStatement: SwitchStatement): Type[] { @@ -8060,7 +8036,7 @@ namespace ts { if (!propType || !isLiteralUnionType(propType)) { return type; } - const discriminantType = getTypeOfLiteralOrExpression(value); + const discriminantType = checkExpression(value); if (!isLiteralUnionType(discriminantType)) { return type; } @@ -9225,6 +9201,31 @@ namespace ts { return undefined; } + function isLiteralTypeLocation(node: Node): boolean { + const parent = node.parent; + switch (parent.kind) { + case SyntaxKind.BinaryExpression: + switch ((parent).operatorToken.kind) { + case SyntaxKind.EqualsEqualsEqualsToken: + case SyntaxKind.ExclamationEqualsEqualsToken: + case SyntaxKind.EqualsEqualsToken: + case SyntaxKind.ExclamationEqualsToken: + return true; + } + break; + case SyntaxKind.ConditionalExpression: + return (node === (parent).whenTrue || + node === (parent).whenFalse) && + isLiteralTypeLocation(parent); + case SyntaxKind.ParenthesizedExpression: + return isLiteralTypeLocation(parent); + case SyntaxKind.CaseClause: + case SyntaxKind.LiteralType: + return true; + } + return false; + } + // If the given type is an object or union type, if that type has a single signature, and if // that signature is non-generic, return the signature. Otherwise return undefined. function getNonGenericSignature(type: Type): Signature { @@ -10740,9 +10741,7 @@ namespace ts { // If the effective argument type is 'undefined', there is no synthetic type // for the argument. In that case, we should check the argument. if (argType === undefined) { - argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors - ? getTypeFromLiteralExpression(arg) - : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); + argType = checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined); } // Use argument expression as error location when reporting errors @@ -10950,7 +10949,7 @@ namespace ts { case SyntaxKind.Identifier: case SyntaxKind.NumericLiteral: case SyntaxKind.StringLiteral: - return getStringLiteralTypeForText((element.name).text); + return getLiteralTypeForText(TypeFlags.StringLiteral, (element.name).text); case SyntaxKind.ComputedPropertyName: const nameType = checkComputedPropertyName(element.name); @@ -12253,8 +12252,8 @@ namespace ts { function checkPrefixUnaryExpression(node: PrefixUnaryExpression): Type { const operandType = checkExpression(node.operand); - if (node.operator === SyntaxKind.MinusToken && node.operand.kind === SyntaxKind.NumericLiteral && hasLiteralContextualType(node)) { - return getTypeFromLiteralExpression(node); + if (node.operator === SyntaxKind.MinusToken && node.operand.kind === SyntaxKind.NumericLiteral && isLiteralTypeContext(node)) { + return getLiteralTypeForText(TypeFlags.NumberLiteral, "" + -(node.operand).text); } switch (node.operator) { case SyntaxKind.PlusToken: @@ -12633,6 +12632,12 @@ namespace ts { case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: case SyntaxKind.ExclamationEqualsEqualsToken: + const leftIsLiteral = isLiteralUnionType(leftType); + const rightIsLiteral = isLiteralUnionType(rightType); + if (!leftIsLiteral || !rightIsLiteral) { + leftType = leftIsLiteral ? getBaseTypeOfLiteralType(leftType) : leftType; + rightType = rightIsLiteral ? getBaseTypeOfLiteralType(rightType) : rightType; + } if (!isTypeEqualityComparableTo(leftType, rightType) && !isTypeEqualityComparableTo(rightType, leftType)) { reportOperatorError(); } @@ -12773,18 +12778,25 @@ namespace ts { return getUnionType([type1, type2]); } - function hasLiteralContextualType(node: Expression) { - return isLiteralUnionType(getContextualType(node) || unknownType); + function isLiteralTypeContext(node: Expression) { + return isLiteralTypeLocation(node) || isLiteralUnionType(getContextualType(node) || unknownType); } function checkLiteralExpression(node: Expression): Type { - const type = node.kind === SyntaxKind.StringLiteral ? stringType : - node.kind === SyntaxKind.TrueKeyword || node.kind === SyntaxKind.FalseKeyword ? booleanType : - numberType; - if (type === numberType) { + if (node.kind === SyntaxKind.NumericLiteral) { checkGrammarNumericLiteral(node); } - return hasLiteralContextualType(node) ? getTypeFromLiteralExpression(node) : type; + const hasLiteralType = isLiteralTypeContext(node); + switch (node.kind) { + case SyntaxKind.StringLiteral: + return hasLiteralType ? getLiteralTypeForText(TypeFlags.StringLiteral, (node).text) : stringType; + case SyntaxKind.NumericLiteral: + return hasLiteralType ? getLiteralTypeForText(TypeFlags.NumberLiteral, (node).text) : numberType; + case SyntaxKind.TrueKeyword: + return hasLiteralType ? trueType : booleanType; + case SyntaxKind.FalseKeyword: + return hasLiteralType ? falseType : booleanType; + } } function checkTemplateExpression(node: TemplateExpression): Type { From 3ccd68bbe40c7080e755722251fd903706fc572d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 20 Jun 2016 12:16:43 -0700 Subject: [PATCH 04/55] Accept new baselines --- tests/baselines/reference/ES5for-of32.types | 2 +- .../reference/TypeGuardWithEnumUnion.types | 8 +- .../amdImportAsPrimaryExpression.types | 2 +- .../reference/anonymousClassExpression1.types | 2 +- ...blockScopedBindingsReassignedInLoop2.types | 8 +- ...blockScopedBindingsReassignedInLoop3.types | 8 +- ...blockScopedBindingsReassignedInLoop4.types | 2 +- ...blockScopedBindingsReassignedInLoop5.types | 2 +- ...blockScopedBindingsReassignedInLoop6.types | 8 +- .../reference/capturedLetConstInLoop1.types | 32 +-- .../reference/capturedLetConstInLoop11.types | 2 +- .../capturedLetConstInLoop11_ES6.types | 2 +- .../capturedLetConstInLoop1_ES6.types | 32 +-- .../reference/capturedLetConstInLoop2.types | 32 +-- .../capturedLetConstInLoop2_ES6.types | 32 +-- .../reference/capturedLetConstInLoop3.types | 32 +-- .../capturedLetConstInLoop3_ES6.types | 32 +-- .../reference/capturedLetConstInLoop4.types | 32 +-- .../capturedLetConstInLoop4_ES6.types | 32 +-- .../reference/capturedLetConstInLoop5.types | 72 +++---- .../capturedLetConstInLoop5_ES6.types | 72 +++---- .../reference/capturedLetConstInLoop6.types | 112 +++++----- .../capturedLetConstInLoop6_ES6.types | 112 +++++----- .../reference/capturedLetConstInLoop7.types | 192 +++++++++--------- .../capturedLetConstInLoop7_ES6.types | 192 +++++++++--------- .../reference/capturedLetConstInLoop8.types | 64 +++--- .../capturedLetConstInLoop8_ES6.types | 64 +++--- .../reference/capturedLetConstInLoop9.types | 36 ++-- .../capturedLetConstInLoop9_ES6.types | 36 ++-- ...eckSwitchStatementIfCaseTypeIsString.types | 2 +- .../classDoesNotDependOnBaseTypes.types | 2 +- ...isonOperatorWithSubtypeEnumAndNumber.types | 16 +- ...tionalOperatorConditionIsBooleanType.types | 6 +- .../constLocalsInFunctionExpressions.types | 10 +- ...oopsWithCapturedBlockScopedBindings1.types | 2 +- .../reference/controlFlowCaching.types | 12 +- .../reference/controlFlowCommaOperator.types | 4 +- .../controlFlowDoWhileStatement.types | 2 +- .../reference/controlFlowForStatement.types | 8 +- .../baselines/reference/controlFlowIIFE.types | 6 +- .../controlFlowPropertyDeclarations.types | 6 +- .../reference/controlFlowWhileStatement.types | 2 +- .../declFileTypeAnnotationStringLiteral.types | 2 +- ...eclarationEmitIdentifierPredicates01.types | 2 +- ...orInstantiateModulesInFunctionBodies.types | 2 +- .../reference/emptyThenWithoutWarning.types | 6 +- .../reference/es3defaultAliasIsQuoted.types | 2 +- .../exportAssignmentTopLevelClodule.types | 2 +- .../exportAssignmentTopLevelFundule.types | 2 +- .../exportAssignmentTopLevelIdentifier.types | 2 +- .../reference/fallFromLastCase1.types | 6 +- .../reference/fatarrowfunctions.types | 2 +- .../genericArrayPropertyAssignment.types | 2 +- .../reference/implicitAnyInCatch.types | 2 +- .../interfaceDoesNotDependOnBaseTypes.types | 2 +- .../invalidSwitchBreakStatement.types | 2 +- ...ileCompilationRestParamJsDocFunction.types | 8 +- .../memberAccessOnConstructorType.types | 2 +- .../nestedBlockScopedBindings1.types | 4 +- .../nestedBlockScopedBindings10.types | 2 +- .../nestedBlockScopedBindings11.types | 2 +- .../nestedBlockScopedBindings12.types | 2 +- .../nestedBlockScopedBindings2.types | 22 +- .../nestedBlockScopedBindings3.types | 6 +- .../nestedBlockScopedBindings6.types | 8 +- .../nestedBlockScopedBindings9.types | 2 +- tests/baselines/reference/neverType.types | 12 +- .../reference/noImplicitReturnsInAsync1.types | 2 +- .../objectLiteralArraySpecialization.types | 2 +- .../operatorsAndIntersectionTypes.types | 4 +- .../overloadResolutionOverNonCTLambdas.types | 2 +- .../reference/overloadReturnTypes.types | 2 +- .../reachabilityCheckWithEmptyDefault.types | 2 +- .../reference/recursiveReturns.types | 2 +- .../reference/sourceMap-Comments.types | 6 +- .../reference/sourceMapValidationIfElse.types | 8 +- .../reference/sourceMapValidationSwitch.types | 8 +- .../reference/sourceMapValidationWhile.types | 4 +- ...ymousTypeNotReferencingTypeParameter.types | 8 +- .../stringLiteralCheckedInIf01.types | 4 +- .../stringLiteralCheckedInIf02.types | 4 +- .../stringLiteralMatchedInSwitch01.types | 4 +- .../stringLiteralTypesAndTuples01.types | 4 +- .../stringLiteralTypesInUnionTypes01.types | 4 +- .../stringLiteralTypesInUnionTypes02.types | 4 +- .../stringLiteralTypesInUnionTypes03.types | 4 +- .../stringLiteralTypesInUnionTypes04.types | 8 +- .../stringLiteralTypesOverloads01.types | 6 +- ...ngLiteralTypesWithVariousOperators01.types | 4 +- .../reference/switchBreakStatements.types | 22 +- tests/baselines/reference/switchCases.types | 2 +- ...itchCasesExpressionTypeMismatch.errors.txt | 8 +- .../reference/switchFallThroughs.types | 12 +- tests/baselines/reference/symbolType17.types | 2 +- tests/baselines/reference/symbolType18.types | 2 +- tests/baselines/reference/symbolType19.types | 2 +- ...ingsWithManyCallAndMemberExpressions.types | 2 +- ...sWithManyCallAndMemberExpressionsES6.types | 2 +- .../templateStringInEqualityChecks.types | 4 +- .../templateStringInEqualityChecksES6.types | 4 +- .../throwInEnclosingStatements.types | 2 +- .../baselines/reference/typeGuardEnums.types | 4 +- .../typeGuardIntersectionTypes.types | 6 +- .../reference/typeGuardNesting.types | 24 +-- .../typeGuardOfFormExpr1AndExpr2.types | 18 +- .../typeGuardOfFormExpr1OrExpr2.types | 18 +- .../reference/typeGuardOfFormNotExpr.types | 20 +- .../typeGuardOfFormTypeOfBoolean.types | 20 +- ...eGuardOfFormTypeOfIsOrderIndependent.types | 8 +- .../typeGuardOfFormTypeOfNumber.types | 20 +- .../typeGuardOfFormTypeOfOther.types | 16 +- ...ypeGuardOfFormTypeOfPrimitiveSubtype.types | 12 +- .../typeGuardOfFormTypeOfString.types | 20 +- .../reference/typeGuardRedundancy.types | 16 +- .../typeGuardTautologicalConsistiency.types | 8 +- .../reference/typeGuardTypeOfUndefined.types | 64 +++--- .../reference/typeGuardsAsAssertions.types | 12 +- .../typeGuardsInClassAccessors.types | 40 ++-- .../reference/typeGuardsInClassMethods.types | 30 +-- .../typeGuardsInConditionalExpression.types | 46 ++--- .../reference/typeGuardsInDoStatement.types | 6 +- .../typeGuardsInExternalModule.types | 4 +- .../reference/typeGuardsInForStatement.types | 6 +- .../reference/typeGuardsInFunction.types | 38 ++-- .../typeGuardsInFunctionAndModuleBlock.types | 26 +-- .../reference/typeGuardsInGlobal.types | 2 +- .../reference/typeGuardsInModule.types | 22 +- .../reference/typeGuardsInProperties.types | 12 +- ...GuardsInRightOperandOfAndAndOperator.types | 26 +-- ...peGuardsInRightOperandOfOrOrOperator.types | 26 +-- .../typeGuardsInWhileStatement.types | 6 +- .../typeGuardsNestedAssignments.types | 2 +- .../reference/typeGuardsObjectMethods.types | 20 +- .../reference/typeGuardsOnClassProperty.types | 8 +- .../reference/uncaughtCompilerError1.types | 10 +- .../baselines/reference/underscoreTest1.types | 10 +- .../reference/unionTypeInference.types | 4 +- .../baselines/reference/voidAsOperator.types | 4 +- 138 files changed, 1116 insertions(+), 1116 deletions(-) diff --git a/tests/baselines/reference/ES5for-of32.types b/tests/baselines/reference/ES5for-of32.types index 6fe5ba2008b82..034d7a3b1eaba 100644 --- a/tests/baselines/reference/ES5for-of32.types +++ b/tests/baselines/reference/ES5for-of32.types @@ -18,7 +18,7 @@ for (let num of array) { if (sum === 0) { >sum === 0 : boolean >sum : number ->0 : number +>0 : 0 array = [4,5,6] >array = [4,5,6] : number[] diff --git a/tests/baselines/reference/TypeGuardWithEnumUnion.types b/tests/baselines/reference/TypeGuardWithEnumUnion.types index 05d55cb0dbba1..bf5625e0c991e 100644 --- a/tests/baselines/reference/TypeGuardWithEnumUnion.types +++ b/tests/baselines/reference/TypeGuardWithEnumUnion.types @@ -14,7 +14,7 @@ function f1(x: Color | string) { >typeof x === "number" : boolean >typeof x : string >x : Color | string ->"number" : string +>"number" : "number" var y = x; >y : Color @@ -43,7 +43,7 @@ function f2(x: Color | string | string[]) { >typeof x === "object" : boolean >typeof x : string >x : Color | string | string[] ->"object" : string +>"object" : "object" var y = x; >y : string[] @@ -56,7 +56,7 @@ function f2(x: Color | string | string[]) { >typeof x === "number" : boolean >typeof x : string >x : string[] | Color | string ->"number" : string +>"number" : "number" var z = x; >z : Color @@ -78,7 +78,7 @@ function f2(x: Color | string | string[]) { >typeof x === "string" : boolean >typeof x : string >x : Color | string[] | string ->"string" : string +>"string" : "string" var a = x; >a : string diff --git a/tests/baselines/reference/amdImportAsPrimaryExpression.types b/tests/baselines/reference/amdImportAsPrimaryExpression.types index eab0b168f445e..4c2f47f4d59d6 100644 --- a/tests/baselines/reference/amdImportAsPrimaryExpression.types +++ b/tests/baselines/reference/amdImportAsPrimaryExpression.types @@ -9,7 +9,7 @@ if(foo.E1.A === 0){ >foo : typeof foo >E1 : typeof foo.E1 >A : foo.E1 ->0 : number +>0 : 0 // Should cause runtime import - interesting optimization possibility, as gets inlined to 0. } diff --git a/tests/baselines/reference/anonymousClassExpression1.types b/tests/baselines/reference/anonymousClassExpression1.types index 1e38399f01ed7..0fbffffdf4b82 100644 --- a/tests/baselines/reference/anonymousClassExpression1.types +++ b/tests/baselines/reference/anonymousClassExpression1.types @@ -6,5 +6,5 @@ function f() { >typeof class {} === "function" : boolean >typeof class {} : string >class {} : typeof (Anonymous class) ->"function" : string +>"function" : "function" } diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.types index 244160dcc6b38..477d36982f44c 100644 --- a/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.types +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop2.types @@ -25,7 +25,7 @@ for (let x = 1, y = 2; x < y; ++x, --y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } @@ -63,7 +63,7 @@ for (let x = 1, y = 2; x < y; ++x, --y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 continue; } @@ -104,7 +104,7 @@ for (let x = 1, y = 2; x < y; ++x, --y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break loop; >loop : any @@ -146,7 +146,7 @@ for (let x = 1, y = 2; x < y; ++x, --y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 continue loop; >loop : any diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.types index 0753391d5c225..ee69f9a5a9f62 100644 --- a/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.types +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop3.types @@ -26,7 +26,7 @@ for (let x = 1, y = 2; x < y; ++x, --y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } @@ -96,7 +96,7 @@ for (let x = 1, y = 2; x < y; ++x, --y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 continue; } @@ -168,7 +168,7 @@ for (let x = 1, y = 2; x < y; ++x, --y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break loop2; >loop2 : any @@ -248,7 +248,7 @@ for (let x = 1, y = 2; x < y; ++x, --y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 continue loop2; >loop2 : any diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.types index 006f536ccca4e..c3576bbccd264 100644 --- a/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.types +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop4.types @@ -28,7 +28,7 @@ function f1() { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return 1; >1 : number diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.types index 530978dc722ed..47a0fd5289125 100644 --- a/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.types +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop5.types @@ -25,7 +25,7 @@ for (let x = 1, y = 2; x < y; ++x, --y) { if (x == 1) >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; else diff --git a/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.types b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.types index 673c0788a033b..c4287869ec0a3 100644 --- a/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.types +++ b/tests/baselines/reference/blockScopedBindingsReassignedInLoop6.types @@ -29,13 +29,13 @@ function f1() { if (x == 1) >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; else if (y == 2) >y == 2 : boolean >y : number ->2 : number +>2 : 2 y = 5; >y = 5 : number @@ -85,13 +85,13 @@ function f2() { if (x == 1) >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; else if (y == 2) >y == 2 : boolean >y : number ->2 : number +>2 : 2 y = 5; >y = 5 : number diff --git a/tests/baselines/reference/capturedLetConstInLoop1.types b/tests/baselines/reference/capturedLetConstInLoop1.types index bed3db55d7cf2..c60ac25ce1fd8 100644 --- a/tests/baselines/reference/capturedLetConstInLoop1.types +++ b/tests/baselines/reference/capturedLetConstInLoop1.types @@ -52,8 +52,8 @@ for (let x = 0; x < 1; ++x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x; >x : any @@ -85,8 +85,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (let y = 0; y < 1; ++y) { >y : number @@ -140,8 +140,8 @@ for (let x = 0, y = 1; x < 1; ++x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -183,8 +183,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (let y = 0; y < 1; ++y) { >y : number @@ -265,8 +265,8 @@ for (const x = 0; x < 1;) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1; >x : number @@ -300,8 +300,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (const y = 0; y < 1;) { >y : number @@ -351,8 +351,8 @@ for (const x = 0, y = 1; x < 1;) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y = 1; >x : number @@ -398,8 +398,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (const y = 0; y < 1;) { >y : number diff --git a/tests/baselines/reference/capturedLetConstInLoop11.types b/tests/baselines/reference/capturedLetConstInLoop11.types index 93e18f2cb27ba..09fad9f202308 100644 --- a/tests/baselines/reference/capturedLetConstInLoop11.types +++ b/tests/baselines/reference/capturedLetConstInLoop11.types @@ -21,7 +21,7 @@ function foo() { >a : number case 0: return () => a; ->0 : number +>0 : 0 >() => a : () => number >a : number } diff --git a/tests/baselines/reference/capturedLetConstInLoop11_ES6.types b/tests/baselines/reference/capturedLetConstInLoop11_ES6.types index de75d5d15118b..d6fd971202c54 100644 --- a/tests/baselines/reference/capturedLetConstInLoop11_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop11_ES6.types @@ -21,7 +21,7 @@ function foo() { >a : number case 0: return () => a; ->0 : number +>0 : 0 >() => a : () => number >a : number } diff --git a/tests/baselines/reference/capturedLetConstInLoop1_ES6.types b/tests/baselines/reference/capturedLetConstInLoop1_ES6.types index 47b125866849c..cee71c0d5cd3c 100644 --- a/tests/baselines/reference/capturedLetConstInLoop1_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop1_ES6.types @@ -52,8 +52,8 @@ for (let x = 0; x < 1; ++x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x; >x : any @@ -85,8 +85,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (let y = 0; y < 1; ++y) { >y : number @@ -140,8 +140,8 @@ for (let x = 0, y = 1; x < 1; ++x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -183,8 +183,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (let y = 0; y < 1; ++y) { >y : number @@ -265,8 +265,8 @@ for (const x = 0; x < 1;) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1; >x : number @@ -300,8 +300,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (const y = 0; y < 1;) { >y : number @@ -351,8 +351,8 @@ for (const x = 0, y = 1; x < 1;) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y = 1; >x : number @@ -398,8 +398,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (const y = 0; y < 1;) { >y : number diff --git a/tests/baselines/reference/capturedLetConstInLoop2.types b/tests/baselines/reference/capturedLetConstInLoop2.types index 2872eb4c763f8..f4f7a926f8946 100644 --- a/tests/baselines/reference/capturedLetConstInLoop2.types +++ b/tests/baselines/reference/capturedLetConstInLoop2.types @@ -103,8 +103,8 @@ function foo2(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let a = arguments.length; >a : number @@ -158,8 +158,8 @@ function foo3(x) { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 } function foo4(x) { @@ -249,8 +249,8 @@ function foo6(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -317,8 +317,8 @@ function foo7(x) { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 } @@ -464,8 +464,8 @@ function foo2_c(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const a = arguments.length; >a : number @@ -520,8 +520,8 @@ function foo3_c(x) { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 } function foo4_c(x) { @@ -607,8 +607,8 @@ function foo6_c(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y =1 ; >x : number @@ -679,8 +679,8 @@ function foo7_c(x) { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 } diff --git a/tests/baselines/reference/capturedLetConstInLoop2_ES6.types b/tests/baselines/reference/capturedLetConstInLoop2_ES6.types index 8a4d9c826285e..80e455e44cefe 100644 --- a/tests/baselines/reference/capturedLetConstInLoop2_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop2_ES6.types @@ -102,8 +102,8 @@ function foo2(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let a = arguments.length; >a : number @@ -157,8 +157,8 @@ function foo3(x) { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 } function foo4(x) { @@ -248,8 +248,8 @@ function foo6(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -316,8 +316,8 @@ function foo7(x) { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 } @@ -463,8 +463,8 @@ function foo2_c(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const a = arguments.length; >a : number @@ -519,8 +519,8 @@ function foo3_c(x) { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 } function foo4_c(x) { @@ -606,8 +606,8 @@ function foo6_c(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y =1 ; >x : number @@ -678,8 +678,8 @@ function foo7_c(x) { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 } diff --git a/tests/baselines/reference/capturedLetConstInLoop3.types b/tests/baselines/reference/capturedLetConstInLoop3.types index 9c0c188b7272b..3f35072fdb2cd 100644 --- a/tests/baselines/reference/capturedLetConstInLoop3.types +++ b/tests/baselines/reference/capturedLetConstInLoop3.types @@ -114,8 +114,8 @@ function foo2(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x = 1; >x : number @@ -173,8 +173,8 @@ function foo3(x) { } while (1 === 1); >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -275,8 +275,8 @@ function foo6(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -344,8 +344,8 @@ function foo7(x) { } while (1 === 1); >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -508,8 +508,8 @@ function foo2_c(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1; >x : number @@ -568,8 +568,8 @@ function foo3_c(x) { } while (1 === 1); >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -666,8 +666,8 @@ function foo6_c(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y = 1; >x : number @@ -739,8 +739,8 @@ function foo7_c(x) { } while (1 === 1); >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any diff --git a/tests/baselines/reference/capturedLetConstInLoop3_ES6.types b/tests/baselines/reference/capturedLetConstInLoop3_ES6.types index 03377d913c967..3c7776a665119 100644 --- a/tests/baselines/reference/capturedLetConstInLoop3_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop3_ES6.types @@ -115,8 +115,8 @@ function foo2(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x = 1; >x : number @@ -174,8 +174,8 @@ function foo3(x) { } while (1 === 1); >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -276,8 +276,8 @@ function foo6(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -345,8 +345,8 @@ function foo7(x) { } while (1 === 1); >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -509,8 +509,8 @@ function foo2_c(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1; >x : number @@ -569,8 +569,8 @@ function foo3_c(x) { } while (1 === 1); >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -667,8 +667,8 @@ function foo6_c(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y = 1; >x : number @@ -740,8 +740,8 @@ function foo7_c(x) { } while (1 === 1); >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any diff --git a/tests/baselines/reference/capturedLetConstInLoop4.types b/tests/baselines/reference/capturedLetConstInLoop4.types index 1bc928cefe447..16226243c53a3 100644 --- a/tests/baselines/reference/capturedLetConstInLoop4.types +++ b/tests/baselines/reference/capturedLetConstInLoop4.types @@ -96,8 +96,8 @@ for (let x = 0; x < 1; ++x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x; >x : any @@ -141,8 +141,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (let y = 0; y < 1; ++y) { >y : number @@ -208,8 +208,8 @@ for (let x = 0, y = 1; x < 1; ++x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -263,8 +263,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (let y = 0; y < 1; ++y) { >y : number @@ -394,8 +394,8 @@ for (const x = 0; x < 1;) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x =1; >x : number @@ -441,8 +441,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (const y = 0; y < 1;) { >y : number @@ -504,8 +504,8 @@ for (const x = 0, y = 1; x < 1;) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y = 1; >x : number @@ -563,8 +563,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (const y = 0; y < 1;) { >y : number diff --git a/tests/baselines/reference/capturedLetConstInLoop4_ES6.types b/tests/baselines/reference/capturedLetConstInLoop4_ES6.types index cf44c7b69819e..fba7d88ec488f 100644 --- a/tests/baselines/reference/capturedLetConstInLoop4_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop4_ES6.types @@ -96,8 +96,8 @@ for (let x = 0; x < 1; ++x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x; >x : any @@ -141,8 +141,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (let y = 0; y < 1; ++y) { >y : number @@ -208,8 +208,8 @@ for (let x = 0, y = 1; x < 1; ++x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -263,8 +263,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (let y = 0; y < 1; ++y) { >y : number @@ -394,8 +394,8 @@ for (const x = 0; x < 1;) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x =1; >x : number @@ -441,8 +441,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (const y = 0; y < 1;) { >y : number @@ -504,8 +504,8 @@ for (const x = 0, y = 1; x < 1;) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y = 1; >x : number @@ -563,8 +563,8 @@ do { } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (const y = 0; y < 1;) { >y : number diff --git a/tests/baselines/reference/capturedLetConstInLoop5.types b/tests/baselines/reference/capturedLetConstInLoop5.types index b7b4b880dc4c1..098a1ce70a474 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5.types +++ b/tests/baselines/reference/capturedLetConstInLoop5.types @@ -33,7 +33,7 @@ function foo0(x) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 return; } @@ -74,7 +74,7 @@ function foo00(x) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" return; } @@ -120,7 +120,7 @@ function foo1(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -138,8 +138,8 @@ function foo2(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x = 1; >x : number @@ -166,7 +166,7 @@ function foo2(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -206,14 +206,14 @@ function foo3(x) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 return; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -259,7 +259,7 @@ function foo4(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -311,7 +311,7 @@ function foo5(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -330,8 +330,8 @@ function foo6(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -362,7 +362,7 @@ function foo6(x) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 return; } @@ -408,14 +408,14 @@ function foo7(x) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 return; } } while (1 === 1); >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -466,7 +466,7 @@ function foo8(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -508,7 +508,7 @@ function foo0_c(x) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 return; } @@ -549,7 +549,7 @@ function foo00_c(x) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" return; } @@ -593,7 +593,7 @@ function foo1_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -611,8 +611,8 @@ function foo2_c(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1; >x : number @@ -639,7 +639,7 @@ function foo2_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -680,14 +680,14 @@ function foo3_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -731,7 +731,7 @@ function foo4_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -781,7 +781,7 @@ function foo5_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -800,8 +800,8 @@ function foo6_c(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y = 1; >x : number @@ -834,7 +834,7 @@ function foo6_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -882,14 +882,14 @@ function foo7_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -938,7 +938,7 @@ function foo8_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } diff --git a/tests/baselines/reference/capturedLetConstInLoop5_ES6.types b/tests/baselines/reference/capturedLetConstInLoop5_ES6.types index 855bbfc63086a..78b41d7cdf354 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop5_ES6.types @@ -34,7 +34,7 @@ function foo0(x) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 return; } @@ -75,7 +75,7 @@ function foo00(x) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" return; } @@ -121,7 +121,7 @@ function foo1(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -139,8 +139,8 @@ function foo2(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x = 1; >x : number @@ -167,7 +167,7 @@ function foo2(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -207,14 +207,14 @@ function foo3(x) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 return; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -260,7 +260,7 @@ function foo4(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -312,7 +312,7 @@ function foo5(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -331,8 +331,8 @@ function foo6(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -363,7 +363,7 @@ function foo6(x) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 return; } @@ -409,14 +409,14 @@ function foo7(x) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 return; } } while (1 === 1); >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -467,7 +467,7 @@ function foo8(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -509,7 +509,7 @@ function foo0_c(x) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 return; } @@ -550,7 +550,7 @@ function foo00_c(x) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" return; } @@ -594,7 +594,7 @@ function foo1_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -612,8 +612,8 @@ function foo2_c(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1; >x : number @@ -640,7 +640,7 @@ function foo2_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -681,14 +681,14 @@ function foo3_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -732,7 +732,7 @@ function foo4_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -782,7 +782,7 @@ function foo5_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -801,8 +801,8 @@ function foo6_c(x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y = 1; >x : number @@ -835,7 +835,7 @@ function foo6_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } @@ -883,14 +883,14 @@ function foo7_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 use(v); >use(v) : any @@ -939,7 +939,7 @@ function foo8_c(x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 return; } diff --git a/tests/baselines/reference/capturedLetConstInLoop6.types b/tests/baselines/reference/capturedLetConstInLoop6.types index f2b1103305fb8..a7d28222bb09f 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6.types +++ b/tests/baselines/reference/capturedLetConstInLoop6.types @@ -17,14 +17,14 @@ for (let x of []) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } @@ -47,14 +47,14 @@ for (let x in []) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" break; } if (x == "2") { >x == "2" : boolean >x : string ->"2" : string +>"2" : "2" continue; } @@ -83,14 +83,14 @@ for (let x = 0; x < 1; ++x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -98,8 +98,8 @@ for (let x = 0; x < 1; ++x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x; >x : any @@ -117,14 +117,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } @@ -147,21 +147,21 @@ do { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (let y = 0; y < 1; ++y) { >y : number @@ -189,14 +189,14 @@ for (let y = 0; y < 1; ++y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -230,14 +230,14 @@ for (let x = 0, y = 1; x < 1; ++x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -245,8 +245,8 @@ for (let x = 0, y = 1; x < 1; ++x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -269,14 +269,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } @@ -304,21 +304,21 @@ do { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (let y = 0; y < 1; ++y) { >y : number @@ -350,14 +350,14 @@ for (let y = 0; y < 1; ++y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -382,14 +382,14 @@ for (const x of []) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } @@ -412,14 +412,14 @@ for (const x in []) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" break; } if (x == "2") { >x == "2" : boolean >x : string ->"2" : string +>"2" : "2" continue; } @@ -446,14 +446,14 @@ for (const x = 0; x < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -461,8 +461,8 @@ for (const x = 0; x < 1;) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1; >x : number @@ -481,14 +481,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -512,21 +512,21 @@ do { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (const y = 0; y < 1;) { >y : number @@ -552,14 +552,14 @@ for (const y = 0; y < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -591,14 +591,14 @@ for (const x = 0, y = 1; x < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -606,8 +606,8 @@ for (const x = 0, y = 1; x < 1;) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y = 1; >x : number @@ -632,14 +632,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -669,21 +669,21 @@ do { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (const y = 0; y < 1;) { >y : number @@ -713,14 +713,14 @@ for (const y = 0; y < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } diff --git a/tests/baselines/reference/capturedLetConstInLoop6_ES6.types b/tests/baselines/reference/capturedLetConstInLoop6_ES6.types index cfd55a63aaab2..14635c0cd1c8a 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop6_ES6.types @@ -17,14 +17,14 @@ for (let x of []) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } @@ -47,14 +47,14 @@ for (let x in []) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" break; } if (x == "2") { >x == "2" : boolean >x : string ->"2" : string +>"2" : "2" continue; } @@ -83,14 +83,14 @@ for (let x = 0; x < 1; ++x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -98,8 +98,8 @@ for (let x = 0; x < 1; ++x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x; >x : any @@ -117,14 +117,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } @@ -147,21 +147,21 @@ do { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (let y = 0; y < 1; ++y) { >y : number @@ -189,14 +189,14 @@ for (let y = 0; y < 1; ++y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -230,14 +230,14 @@ for (let x = 0, y = 1; x < 1; ++x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -245,8 +245,8 @@ for (let x = 0, y = 1; x < 1; ++x) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -269,14 +269,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } @@ -304,21 +304,21 @@ do { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (let y = 0; y < 1; ++y) { >y : number @@ -350,14 +350,14 @@ for (let y = 0; y < 1; ++y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -382,14 +382,14 @@ for (const x of []) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } @@ -412,14 +412,14 @@ for (const x in []) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" break; } if (x == "2") { >x == "2" : boolean >x : string ->"2" : string +>"2" : "2" continue; } @@ -446,14 +446,14 @@ for (const x = 0; x < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -461,8 +461,8 @@ for (const x = 0; x < 1;) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1; >x : number @@ -481,14 +481,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -512,21 +512,21 @@ do { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (const y = 0; y < 1;) { >y : number @@ -552,14 +552,14 @@ for (const y = 0; y < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -591,14 +591,14 @@ for (const x = 0, y = 1; x < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -606,8 +606,8 @@ for (const x = 0, y = 1; x < 1;) { while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y = 1; >x : number @@ -632,14 +632,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } @@ -669,21 +669,21 @@ do { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 for (const y = 0; y < 1;) { >y : number @@ -713,14 +713,14 @@ for (const y = 0; y < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } diff --git a/tests/baselines/reference/capturedLetConstInLoop7.types b/tests/baselines/reference/capturedLetConstInLoop7.types index 29ea34e39a16b..641ccb9dbeacb 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7.types +++ b/tests/baselines/reference/capturedLetConstInLoop7.types @@ -20,14 +20,14 @@ for (let x of []) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break l0; >l0 : any @@ -35,14 +35,14 @@ for (let x of []) { if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue l0; >l0 : any @@ -69,14 +69,14 @@ for (let x in []) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" break; } if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" break l00; >l00 : any @@ -84,14 +84,14 @@ for (let x in []) { if (x == "2") { >x == "2" : boolean >x : string ->"2" : string +>"2" : "2" continue; } if (x == "2") { >x == "2" : boolean >x : string ->"2" : string +>"2" : "2" continue l00; >l00 : any @@ -123,14 +123,14 @@ for (let x = 0; x < 1; ++x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l1; >l1 : any @@ -138,14 +138,14 @@ for (let x = 0; x < 1; ++x) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l1; >l1 : any @@ -157,8 +157,8 @@ l2: while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x; >x : any @@ -176,14 +176,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break l2; >l2 : any @@ -191,14 +191,14 @@ while (1 === 1) { if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue l2; >l2 : any @@ -225,14 +225,14 @@ do { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break l3; >l3 : any @@ -240,22 +240,22 @@ do { if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue l3; >l3 : any } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 l4: >l4 : any @@ -286,14 +286,14 @@ for (let y = 0; y < 1; ++y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l4; >l4 : any @@ -301,14 +301,14 @@ for (let y = 0; y < 1; ++y) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l4; >l4 : any @@ -346,14 +346,14 @@ for (let x = 0, y = 1; x < 1; ++x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l5; >l5 : any @@ -361,14 +361,14 @@ for (let x = 0, y = 1; x < 1; ++x) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l5; >l5 : any @@ -380,8 +380,8 @@ l6: while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -404,14 +404,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break l6; >l6 : any @@ -419,14 +419,14 @@ while (1 === 1) { if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue l6; >l6 : any @@ -459,14 +459,14 @@ do { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break l7; >l7 : any @@ -474,22 +474,22 @@ do { if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue l7; >l7 : any } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 l8: >l8 : any @@ -524,14 +524,14 @@ for (let y = 0; y < 1; ++y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l8; >l8 : any @@ -539,14 +539,14 @@ for (let y = 0; y < 1; ++y) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l8; >l8 : any @@ -574,14 +574,14 @@ for (const x of []) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break l0_c; >l0_c : any @@ -589,14 +589,14 @@ for (const x of []) { if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue l0_c; >l0_c : any @@ -623,14 +623,14 @@ for (const x in []) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" break; } if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" break l00_c; >l00_c : any @@ -638,14 +638,14 @@ for (const x in []) { if (x == "2") { >x == "2" : boolean >x : string ->"2" : string +>"2" : "2" continue; } if (x == "2") { >x == "2" : boolean >x : string ->"2" : string +>"2" : "2" continue l00_c; >l00_c : any @@ -675,14 +675,14 @@ for (const x = 0; x < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l1_c; >l1_c : any @@ -690,14 +690,14 @@ for (const x = 0; x < 1;) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l1_c; >l1_c : any @@ -709,8 +709,8 @@ l2_c: while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1; >x : number @@ -729,14 +729,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l2_c; >l2_c : any @@ -744,14 +744,14 @@ while (1 === 1) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l2_c; >l2_c : any @@ -779,14 +779,14 @@ do { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l3_c; >l3_c : any @@ -794,22 +794,22 @@ do { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l3_c; >l3_c : any } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 l4_c: >l4_c : any @@ -838,14 +838,14 @@ for (const y = 0; y < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l4_c; >l4_c : any @@ -853,14 +853,14 @@ for (const y = 0; y < 1;) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l4_c; >l4_c : any @@ -896,14 +896,14 @@ for (const x = 0, y = 1; x < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l5_c; >l5_c : any @@ -911,14 +911,14 @@ for (const x = 0, y = 1; x < 1;) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l5_c; >l5_c : any @@ -930,8 +930,8 @@ l6_c: while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y = 1; >x : number @@ -956,14 +956,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l6_c; >l6_c : any @@ -971,14 +971,14 @@ while (1 === 1) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l6_c; >l6_c : any @@ -1013,14 +1013,14 @@ do { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l7_c; >l7_c : any @@ -1028,22 +1028,22 @@ do { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l7_c; >l7_c : any } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 l8_c: >l8_c : any @@ -1076,14 +1076,14 @@ for (const y = 0; y < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l8_c; >l8_c : any @@ -1091,14 +1091,14 @@ for (const y = 0; y < 1;) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l8_c; >l8_c : any diff --git a/tests/baselines/reference/capturedLetConstInLoop7_ES6.types b/tests/baselines/reference/capturedLetConstInLoop7_ES6.types index c72afb4194200..666f3e33e0f2c 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop7_ES6.types @@ -20,14 +20,14 @@ for (let x of []) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break l0; >l0 : any @@ -35,14 +35,14 @@ for (let x of []) { if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue l0; >l0 : any @@ -69,14 +69,14 @@ for (let x in []) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" break; } if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" break l00; >l00 : any @@ -84,14 +84,14 @@ for (let x in []) { if (x == "2") { >x == "2" : boolean >x : string ->"2" : string +>"2" : "2" continue; } if (x == "2") { >x == "2" : boolean >x : string ->"2" : string +>"2" : "2" continue l00; >l00 : any @@ -123,14 +123,14 @@ for (let x = 0; x < 1; ++x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l1; >l1 : any @@ -138,14 +138,14 @@ for (let x = 0; x < 1; ++x) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l1; >l1 : any @@ -157,8 +157,8 @@ l2: while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x; >x : any @@ -176,14 +176,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break l2; >l2 : any @@ -191,14 +191,14 @@ while (1 === 1) { if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue l2; >l2 : any @@ -225,14 +225,14 @@ do { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break l3; >l3 : any @@ -240,22 +240,22 @@ do { if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue l3; >l3 : any } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 l4: >l4 : any @@ -286,14 +286,14 @@ for (let y = 0; y < 1; ++y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l4; >l4 : any @@ -301,14 +301,14 @@ for (let y = 0; y < 1; ++y) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l4; >l4 : any @@ -346,14 +346,14 @@ for (let x = 0, y = 1; x < 1; ++x) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l5; >l5 : any @@ -361,14 +361,14 @@ for (let x = 0, y = 1; x < 1; ++x) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l5; >l5 : any @@ -380,8 +380,8 @@ l6: while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x, y; >x : any @@ -404,14 +404,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break l6; >l6 : any @@ -419,14 +419,14 @@ while (1 === 1) { if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue l6; >l6 : any @@ -459,14 +459,14 @@ do { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break l7; >l7 : any @@ -474,22 +474,22 @@ do { if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue l7; >l7 : any } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 l8: >l8 : any @@ -524,14 +524,14 @@ for (let y = 0; y < 1; ++y) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l8; >l8 : any @@ -539,14 +539,14 @@ for (let y = 0; y < 1; ++y) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l8; >l8 : any @@ -574,14 +574,14 @@ for (const x of []) { if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : any ->1 : number +>1 : 1 break l0_c; >l0_c : any @@ -589,14 +589,14 @@ for (const x of []) { if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : any ->2 : number +>2 : 2 continue l0_c; >l0_c : any @@ -623,14 +623,14 @@ for (const x in []) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" break; } if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" break l00_c; >l00_c : any @@ -638,14 +638,14 @@ for (const x in []) { if (x == "2") { >x == "2" : boolean >x : string ->"2" : string +>"2" : "2" continue; } if (x == "2") { >x == "2" : boolean >x : string ->"2" : string +>"2" : "2" continue l00_c; >l00_c : any @@ -675,14 +675,14 @@ for (const x = 0; x < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l1_c; >l1_c : any @@ -690,14 +690,14 @@ for (const x = 0; x < 1;) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l1_c; >l1_c : any @@ -709,8 +709,8 @@ l2_c: while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1; >x : number @@ -729,14 +729,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l2_c; >l2_c : any @@ -744,14 +744,14 @@ while (1 === 1) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l2_c; >l2_c : any @@ -779,14 +779,14 @@ do { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l3_c; >l3_c : any @@ -794,22 +794,22 @@ do { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l3_c; >l3_c : any } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 l4_c: >l4_c : any @@ -838,14 +838,14 @@ for (const y = 0; y < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l4_c; >l4_c : any @@ -853,14 +853,14 @@ for (const y = 0; y < 1;) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l4_c; >l4_c : any @@ -896,14 +896,14 @@ for (const x = 0, y = 1; x < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l5_c; >l5_c : any @@ -911,14 +911,14 @@ for (const x = 0, y = 1; x < 1;) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l5_c; >l5_c : any @@ -930,8 +930,8 @@ l6_c: while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 const x = 1, y = 1; >x : number @@ -956,14 +956,14 @@ while (1 === 1) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l6_c; >l6_c : any @@ -971,14 +971,14 @@ while (1 === 1) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l6_c; >l6_c : any @@ -1013,14 +1013,14 @@ do { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l7_c; >l7_c : any @@ -1028,22 +1028,22 @@ do { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l7_c; >l7_c : any } } while (1 === 1) >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 l8_c: >l8_c : any @@ -1076,14 +1076,14 @@ for (const y = 0; y < 1;) { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l8_c; >l8_c : any @@ -1091,14 +1091,14 @@ for (const y = 0; y < 1;) { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l8_c; >l8_c : any diff --git a/tests/baselines/reference/capturedLetConstInLoop8.types b/tests/baselines/reference/capturedLetConstInLoop8.types index 9c3db88535c86..618e71038ffd6 100644 --- a/tests/baselines/reference/capturedLetConstInLoop8.types +++ b/tests/baselines/reference/capturedLetConstInLoop8.types @@ -55,14 +55,14 @@ function foo() { if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 break; } if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 break l1; >l1 : any @@ -70,7 +70,7 @@ function foo() { if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 break ll1; >ll1 : any @@ -78,7 +78,7 @@ function foo() { if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 continue l0; >l0 : any @@ -87,14 +87,14 @@ function foo() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l1; >l1 : any @@ -102,7 +102,7 @@ function foo() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue ll1; >ll1 : any @@ -110,7 +110,7 @@ function foo() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 return "123" >"123" : string @@ -118,7 +118,7 @@ function foo() { if (x == 3) { >x == 3 : boolean >x : number ->3 : number +>3 : 3 return; } @@ -126,14 +126,14 @@ function foo() { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l1; >l1 : any @@ -141,14 +141,14 @@ function foo() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l1; >l1 : any @@ -156,7 +156,7 @@ function foo() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l0; >l0 : any @@ -164,7 +164,7 @@ function foo() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 return "456"; >"456" : string @@ -172,7 +172,7 @@ function foo() { if (x == 3) { >x == 3 : boolean >x : number ->3 : number +>3 : 3 return; } @@ -230,14 +230,14 @@ function foo_c() { if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 break; } if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 break l1; >l1 : any @@ -245,7 +245,7 @@ function foo_c() { if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 break ll1; >ll1 : any @@ -253,7 +253,7 @@ function foo_c() { if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 continue l0; >l0 : any @@ -262,14 +262,14 @@ function foo_c() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l1; >l1 : any @@ -277,7 +277,7 @@ function foo_c() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue ll1; >ll1 : any @@ -285,7 +285,7 @@ function foo_c() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 return "123" >"123" : string @@ -293,7 +293,7 @@ function foo_c() { if (x == 3) { >x == 3 : boolean >x : number ->3 : number +>3 : 3 return; } @@ -301,14 +301,14 @@ function foo_c() { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l1; >l1 : any @@ -316,14 +316,14 @@ function foo_c() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l1; >l1 : any @@ -331,7 +331,7 @@ function foo_c() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l0; >l0 : any @@ -339,7 +339,7 @@ function foo_c() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 return "456"; >"456" : string @@ -347,7 +347,7 @@ function foo_c() { if (x == 3) { >x == 3 : boolean >x : number ->3 : number +>3 : 3 return; } diff --git a/tests/baselines/reference/capturedLetConstInLoop8_ES6.types b/tests/baselines/reference/capturedLetConstInLoop8_ES6.types index 7911e9b63a259..0b877d27a4632 100644 --- a/tests/baselines/reference/capturedLetConstInLoop8_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop8_ES6.types @@ -55,14 +55,14 @@ function foo() { if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 break; } if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 break l1; >l1 : any @@ -70,7 +70,7 @@ function foo() { if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 break ll1; >ll1 : any @@ -78,7 +78,7 @@ function foo() { if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 continue l0; >l0 : any @@ -87,14 +87,14 @@ function foo() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l1; >l1 : any @@ -102,7 +102,7 @@ function foo() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue ll1; >ll1 : any @@ -110,7 +110,7 @@ function foo() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 return "123" >"123" : string @@ -118,7 +118,7 @@ function foo() { if (x == 3) { >x == 3 : boolean >x : number ->3 : number +>3 : 3 return; } @@ -126,14 +126,14 @@ function foo() { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l1; >l1 : any @@ -141,14 +141,14 @@ function foo() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l1; >l1 : any @@ -156,7 +156,7 @@ function foo() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l0; >l0 : any @@ -164,7 +164,7 @@ function foo() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 return "456"; >"456" : string @@ -172,7 +172,7 @@ function foo() { if (x == 3) { >x == 3 : boolean >x : number ->3 : number +>3 : 3 return; } @@ -230,14 +230,14 @@ function foo_c() { if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 break; } if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 break l1; >l1 : any @@ -245,7 +245,7 @@ function foo_c() { if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 break ll1; >ll1 : any @@ -253,7 +253,7 @@ function foo_c() { if (y == 1) { >y == 1 : boolean >y : number ->1 : number +>1 : 1 continue l0; >l0 : any @@ -262,14 +262,14 @@ function foo_c() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l1; >l1 : any @@ -277,7 +277,7 @@ function foo_c() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue ll1; >ll1 : any @@ -285,7 +285,7 @@ function foo_c() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 return "123" >"123" : string @@ -293,7 +293,7 @@ function foo_c() { if (x == 3) { >x == 3 : boolean >x : number ->3 : number +>3 : 3 return; } @@ -301,14 +301,14 @@ function foo_c() { if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break; } if (x == 1) { >x == 1 : boolean >x : number ->1 : number +>1 : 1 break l1; >l1 : any @@ -316,14 +316,14 @@ function foo_c() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue; } if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l1; >l1 : any @@ -331,7 +331,7 @@ function foo_c() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 continue l0; >l0 : any @@ -339,7 +339,7 @@ function foo_c() { if (x == 2) { >x == 2 : boolean >x : number ->2 : number +>2 : 2 return "456"; >"456" : string @@ -347,7 +347,7 @@ function foo_c() { if (x == 3) { >x == 3 : boolean >x : number ->3 : number +>3 : 3 return; } diff --git a/tests/baselines/reference/capturedLetConstInLoop9.types b/tests/baselines/reference/capturedLetConstInLoop9.types index 7f793ab66016d..9f1bab2014871 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9.types +++ b/tests/baselines/reference/capturedLetConstInLoop9.types @@ -42,7 +42,7 @@ for (let x = 0; x < 1; ++x) { >x : any case 1: ->1 : number +>1 : 1 let x; >x : any @@ -57,8 +57,8 @@ for (let x = 0; x < 1; ++x) { while (1 == 1) { >1 == 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x; >x : any @@ -100,7 +100,7 @@ function foo() { if (a === 1) { >a === 1 : boolean >a : any ->1 : number +>1 : 1 break; } @@ -108,7 +108,7 @@ function foo() { if (a === 2) { >a === 2 : boolean >a : any ->2 : number +>2 : 2 break l0; >l0 : any @@ -132,7 +132,7 @@ function foo() { if (b === 1) { >b === 1 : boolean >b : any ->1 : number +>1 : 1 break; } @@ -141,7 +141,7 @@ function foo() { if (b === 2) { >b === 2 : boolean >b : any ->2 : number +>2 : 2 break l0; >l0 : any @@ -153,7 +153,7 @@ function foo() { if (b === 3) { >b === 3 : boolean >b : any ->3 : number +>3 : 3 break l1; >l1 : any @@ -183,7 +183,7 @@ function foo() { if (b === 1) { >b === 1 : boolean >b : any ->1 : number +>1 : 1 break; } @@ -191,7 +191,7 @@ function foo() { if (b === 2) { >b === 2 : boolean >b : any ->2 : number +>2 : 2 break l0; >l0 : any @@ -242,22 +242,22 @@ function foo2() { if (x === 1) { >x === 1 : boolean >x : any ->1 : number +>1 : 1 break; } else if (x === 2) { >x === 2 : boolean >x : any ->2 : number +>2 : 2 continue; } while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 if (x) { >x : any @@ -273,10 +273,10 @@ function foo2() { >x : any case 1: break; ->1 : number +>1 : 1 case 2: continue; ->2 : number +>2 : 2 } for (let y of []) { @@ -287,10 +287,10 @@ function foo2() { >y : any case 1: break; ->1 : number +>1 : 1 case 2: continue; ->2 : number +>2 : 2 } } } diff --git a/tests/baselines/reference/capturedLetConstInLoop9_ES6.types b/tests/baselines/reference/capturedLetConstInLoop9_ES6.types index dfbfa387ed409..8a4adafe34069 100644 --- a/tests/baselines/reference/capturedLetConstInLoop9_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop9_ES6.types @@ -43,7 +43,7 @@ for (let x = 0; x < 1; ++x) { >x : any case 1: ->1 : number +>1 : 1 let x; >x : any @@ -58,8 +58,8 @@ for (let x = 0; x < 1; ++x) { while (1 == 1) { >1 == 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 let x; >x : any @@ -101,7 +101,7 @@ function foo() { if (a === 1) { >a === 1 : boolean >a : any ->1 : number +>1 : 1 break; } @@ -109,7 +109,7 @@ function foo() { if (a === 2) { >a === 2 : boolean >a : any ->2 : number +>2 : 2 break l0; >l0 : any @@ -133,7 +133,7 @@ function foo() { if (b === 1) { >b === 1 : boolean >b : any ->1 : number +>1 : 1 break; } @@ -142,7 +142,7 @@ function foo() { if (b === 2) { >b === 2 : boolean >b : any ->2 : number +>2 : 2 break l0; >l0 : any @@ -154,7 +154,7 @@ function foo() { if (b === 3) { >b === 3 : boolean >b : any ->3 : number +>3 : 3 break l1; >l1 : any @@ -184,7 +184,7 @@ function foo() { if (b === 1) { >b === 1 : boolean >b : any ->1 : number +>1 : 1 break; } @@ -192,7 +192,7 @@ function foo() { if (b === 2) { >b === 2 : boolean >b : any ->2 : number +>2 : 2 break l0; >l0 : any @@ -242,22 +242,22 @@ function foo2() { if (x === 1) { >x === 1 : boolean >x : any ->1 : number +>1 : 1 break; } else if (x === 2) { >x === 2 : boolean >x : any ->2 : number +>2 : 2 continue; } while (1 === 1) { >1 === 1 : boolean ->1 : number ->1 : number +>1 : 1 +>1 : 1 if (x) { >x : any @@ -273,10 +273,10 @@ function foo2() { >x : any case 1: break; ->1 : number +>1 : 1 case 2: continue; ->2 : number +>2 : 2 } for (let y of []) { @@ -287,10 +287,10 @@ function foo2() { >y : any case 1: break; ->1 : number +>1 : 1 case 2: continue; ->2 : number +>2 : 2 } } } diff --git a/tests/baselines/reference/checkSwitchStatementIfCaseTypeIsString.types b/tests/baselines/reference/checkSwitchStatementIfCaseTypeIsString.types index fa394b4e0bd32..30f584894fcc3 100644 --- a/tests/baselines/reference/checkSwitchStatementIfCaseTypeIsString.types +++ b/tests/baselines/reference/checkSwitchStatementIfCaseTypeIsString.types @@ -23,7 +23,7 @@ class A { >v : string case "test": use(this); ->"test" : string +>"test" : "test" >use(this) : void >use : (a: any) => void >this : this diff --git a/tests/baselines/reference/classDoesNotDependOnBaseTypes.types b/tests/baselines/reference/classDoesNotDependOnBaseTypes.types index c342f0ea002cd..f8e510230e2ca 100644 --- a/tests/baselines/reference/classDoesNotDependOnBaseTypes.types +++ b/tests/baselines/reference/classDoesNotDependOnBaseTypes.types @@ -7,7 +7,7 @@ if (typeof x !== "string") { >typeof x !== "string" : boolean >typeof x : string >x : string | StringTreeCollection ->"string" : string +>"string" : "string" x[0] = ""; >x[0] = "" : string diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.types b/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.types index 67077683d8733..fa804eada4449 100644 --- a/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.types +++ b/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.types @@ -227,12 +227,12 @@ var re5 = E.a == 0; >E.a : E >E : typeof E >a : E ->0 : number +>0 : 0 var re6 = 0 == E.a; >re6 : boolean >0 == E.a : boolean ->0 : number +>0 : 0 >E.a : E >E : typeof E >a : E @@ -272,12 +272,12 @@ var rf5 = E.a != 0; >E.a : E >E : typeof E >a : E ->0 : number +>0 : 0 var rf6 = 0 != E.a; >rf6 : boolean >0 != E.a : boolean ->0 : number +>0 : 0 >E.a : E >E : typeof E >a : E @@ -317,12 +317,12 @@ var rg5 = E.a === 0; >E.a : E >E : typeof E >a : E ->0 : number +>0 : 0 var rg6 = 0 === E.a; >rg6 : boolean >0 === E.a : boolean ->0 : number +>0 : 0 >E.a : E >E : typeof E >a : E @@ -362,12 +362,12 @@ var rh5 = E.a !== 0; >E.a : E >E : typeof E >a : E ->0 : number +>0 : 0 var rh6 = 0 !== E.a; >rh6 : boolean >0 !== E.a : boolean ->0 : number +>0 : 0 >E.a : E >E : typeof E >a : E diff --git a/tests/baselines/reference/conditionalOperatorConditionIsBooleanType.types b/tests/baselines/reference/conditionalOperatorConditionIsBooleanType.types index 4d28939b696ae..ec3bd526e9e4b 100644 --- a/tests/baselines/reference/conditionalOperatorConditionIsBooleanType.types +++ b/tests/baselines/reference/conditionalOperatorConditionIsBooleanType.types @@ -122,7 +122,7 @@ typeof "123" == "string" ? exprBoolean1 : exprBoolean2; >typeof "123" == "string" : boolean >typeof "123" : string >"123" : string ->"string" : string +>"string" : "string" >exprBoolean1 : boolean >exprBoolean2 : boolean @@ -264,7 +264,7 @@ var resultIsBoolean3 = typeof "123" == "string" ? exprBoolean1 : exprBoolean2; >typeof "123" == "string" : boolean >typeof "123" : string >"123" : string ->"string" : string +>"string" : "string" >exprBoolean1 : boolean >exprBoolean2 : boolean @@ -301,7 +301,7 @@ var resultIsStringOrBoolean4 = typeof "123" === "string" ? exprString1 : exprBoo >typeof "123" === "string" : boolean >typeof "123" : string >"123" : string ->"string" : string +>"string" : "string" >exprString1 : string >exprBoolean1 : boolean diff --git a/tests/baselines/reference/constLocalsInFunctionExpressions.types b/tests/baselines/reference/constLocalsInFunctionExpressions.types index e9f0086f6b1b5..db1da04e0ca1e 100644 --- a/tests/baselines/reference/constLocalsInFunctionExpressions.types +++ b/tests/baselines/reference/constLocalsInFunctionExpressions.types @@ -14,7 +14,7 @@ function f1() { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" const f = () => x.length; >f : () => number @@ -37,7 +37,7 @@ function f2() { >typeof x !== "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" return; } @@ -61,7 +61,7 @@ function f3() { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" const f = function() { return x.length; }; >f : () => number @@ -84,7 +84,7 @@ function f4() { >typeof x !== "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" return; } @@ -108,7 +108,7 @@ function f5() { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" const f = () => () => x.length; >f : () => () => number diff --git a/tests/baselines/reference/continueInLoopsWithCapturedBlockScopedBindings1.types b/tests/baselines/reference/continueInLoopsWithCapturedBlockScopedBindings1.types index 2aeb286d60490..885b67d414046 100644 --- a/tests/baselines/reference/continueInLoopsWithCapturedBlockScopedBindings1.types +++ b/tests/baselines/reference/continueInLoopsWithCapturedBlockScopedBindings1.types @@ -11,7 +11,7 @@ function foo() { if (i === 0) { >i === 0 : boolean >i : number ->0 : number +>0 : 0 continue; } diff --git a/tests/baselines/reference/controlFlowCaching.types b/tests/baselines/reference/controlFlowCaching.types index cd603b274d139..137fbc3d19c53 100644 --- a/tests/baselines/reference/controlFlowCaching.types +++ b/tests/baselines/reference/controlFlowCaching.types @@ -43,7 +43,7 @@ function f(dim, offsets, arr, acommon, centerAnchorLimit, g, has, lin) { >leftBottom : boolean >position !== "rightOrTop" : boolean >position : any ->"rightOrTop" : string +>"rightOrTop" : "rightOrTop" >rotation : number >o.rotation % 360 : number >o.rotation : any @@ -180,7 +180,7 @@ function f(dim, offsets, arr, acommon, centerAnchorLimit, g, has, lin) { >o.titleGap : any >o : any >titleGap : any ->0 : number +>0 : 0 >0 : number >o.titleGap || (ta.title && ta.title.gap) || 15 : any >o.titleGap || (ta.title && ta.title.gap) : any @@ -545,7 +545,7 @@ function f(dim, offsets, arr, acommon, centerAnchorLimit, g, has, lin) { >taTitleOrientation : any >taTitleOrientation == "away" : boolean >taTitleOrientation : any ->"away" : string +>"away" : "away" >180 : number >0 : number @@ -570,7 +570,7 @@ function f(dim, offsets, arr, acommon, centerAnchorLimit, g, has, lin) { >labelAlign : any case "start": ->"start" : string +>"start" : "start" labelAlign = "end"; >labelAlign = "end" : string @@ -579,7 +579,7 @@ function f(dim, offsets, arr, acommon, centerAnchorLimit, g, has, lin) { break; case "end": ->"end" : string +>"end" : "end" labelAlign = "start"; >labelAlign = "start" : string @@ -588,7 +588,7 @@ function f(dim, offsets, arr, acommon, centerAnchorLimit, g, has, lin) { break; case "middle": ->"middle" : string +>"middle" : "middle" labelOffset.y -= size; >labelOffset.y -= size : number diff --git a/tests/baselines/reference/controlFlowCommaOperator.types b/tests/baselines/reference/controlFlowCommaOperator.types index 53014ceafa7b0..328bffc42ab05 100644 --- a/tests/baselines/reference/controlFlowCommaOperator.types +++ b/tests/baselines/reference/controlFlowCommaOperator.types @@ -19,7 +19,7 @@ function f(x: string | number | boolean) { >typeof x === "string" : boolean >typeof x : string >x : string | number | boolean ->"string" : string +>"string" : "string" x; // string >x : string @@ -38,7 +38,7 @@ function f(x: string | number | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" x; // number >x : number diff --git a/tests/baselines/reference/controlFlowDoWhileStatement.types b/tests/baselines/reference/controlFlowDoWhileStatement.types index a82ae1b716efe..ffd9f03096f52 100644 --- a/tests/baselines/reference/controlFlowDoWhileStatement.types +++ b/tests/baselines/reference/controlFlowDoWhileStatement.types @@ -68,7 +68,7 @@ function c() { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" break; } while (cond) diff --git a/tests/baselines/reference/controlFlowForStatement.types b/tests/baselines/reference/controlFlowForStatement.types index cdf049b32d6ab..d0b0a2e6b8a11 100644 --- a/tests/baselines/reference/controlFlowForStatement.types +++ b/tests/baselines/reference/controlFlowForStatement.types @@ -84,7 +84,7 @@ function d() { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" >x = 5 : number >x : string | number | boolean >5 : number @@ -109,7 +109,7 @@ function e() { >typeof x !== "string" : boolean >typeof x : string >x : string | number | boolean ->"string" : string +>"string" : "string" >x = "" || true : string | boolean >x : string | number | boolean | RegExp >"" || true : string | boolean @@ -130,7 +130,7 @@ function f() { >typeof x !== "string" : boolean >typeof x : string >x : string | number | boolean ->"string" : string +>"string" : "string" x; // number | boolean >x : number | boolean @@ -139,7 +139,7 @@ function f() { >typeof x === "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" x = undefined; >x = undefined : undefined diff --git a/tests/baselines/reference/controlFlowIIFE.types b/tests/baselines/reference/controlFlowIIFE.types index c041de04bc724..dd1fbacc42425 100644 --- a/tests/baselines/reference/controlFlowIIFE.types +++ b/tests/baselines/reference/controlFlowIIFE.types @@ -15,7 +15,7 @@ function f1() { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" let n = function() { >n : number @@ -43,7 +43,7 @@ function f2() { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" let n = (function() { >n : number @@ -75,7 +75,7 @@ function f3() { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" let n = (z => x.length + y + z)(y = 1); >n : number diff --git a/tests/baselines/reference/controlFlowPropertyDeclarations.types b/tests/baselines/reference/controlFlowPropertyDeclarations.types index 81c86e8625d04..38f05122d69d1 100644 --- a/tests/baselines/reference/controlFlowPropertyDeclarations.types +++ b/tests/baselines/reference/controlFlowPropertyDeclarations.types @@ -62,7 +62,7 @@ function repeatString(string, times) { if (times === 1) { >times === 1 : boolean >times : any ->1 : number +>1 : 1 return string; >string : any @@ -269,10 +269,10 @@ export class HTMLtoJSX { >parentTag === 'textarea' || parentTag === 'style' : boolean >parentTag === 'textarea' : boolean >parentTag : any ->'textarea' : string +>'textarea' : "textarea" >parentTag === 'style' : boolean >parentTag : any ->'style' : string +>'style' : "style" // Ignore text content of textareas and styles, as it will have already been moved // to a "defaultValue" attribute and "dangerouslySetInnerHTML" attribute respectively. diff --git a/tests/baselines/reference/controlFlowWhileStatement.types b/tests/baselines/reference/controlFlowWhileStatement.types index a17c084228bd3..33f5d455f9beb 100644 --- a/tests/baselines/reference/controlFlowWhileStatement.types +++ b/tests/baselines/reference/controlFlowWhileStatement.types @@ -71,7 +71,7 @@ function c() { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" break; } diff --git a/tests/baselines/reference/declFileTypeAnnotationStringLiteral.types b/tests/baselines/reference/declFileTypeAnnotationStringLiteral.types index 3041b92cf6dc7..6d9c17b4ab907 100644 --- a/tests/baselines/reference/declFileTypeAnnotationStringLiteral.types +++ b/tests/baselines/reference/declFileTypeAnnotationStringLiteral.types @@ -19,7 +19,7 @@ function foo(a: string): string | number { if (a === "hello") { >a === "hello" : boolean >a : string ->"hello" : string +>"hello" : "hello" return a.length; >a.length : number diff --git a/tests/baselines/reference/declarationEmitIdentifierPredicates01.types b/tests/baselines/reference/declarationEmitIdentifierPredicates01.types index 7d8a56682651d..1129012a80a9c 100644 --- a/tests/baselines/reference/declarationEmitIdentifierPredicates01.types +++ b/tests/baselines/reference/declarationEmitIdentifierPredicates01.types @@ -9,5 +9,5 @@ export function f(x: any): x is number { >typeof x === "number" : boolean >typeof x : string >x : any ->"number" : string +>"number" : "number" } diff --git a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types index d0f930b7ad43d..17b37c7937805 100644 --- a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types +++ b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types @@ -31,7 +31,7 @@ class Wat { >() => test == 'abc' : () => boolean >test == 'abc' : boolean >test : string ->'abc' : string +>'abc' : "abc" static whatever() { >whatever : () => void diff --git a/tests/baselines/reference/emptyThenWithoutWarning.types b/tests/baselines/reference/emptyThenWithoutWarning.types index 2dca405966931..5da827deb2ca6 100644 --- a/tests/baselines/reference/emptyThenWithoutWarning.types +++ b/tests/baselines/reference/emptyThenWithoutWarning.types @@ -8,13 +8,13 @@ if(a === 1 || a === 2 || a === 3) { >a === 1 || a === 2 : boolean >a === 1 : boolean >a : number ->1 : number +>1 : 1 >a === 2 : boolean >a : number ->2 : number +>2 : 2 >a === 3 : boolean >a : number ->3 : number +>3 : 3 } else { let message = "Ooops"; diff --git a/tests/baselines/reference/es3defaultAliasIsQuoted.types b/tests/baselines/reference/es3defaultAliasIsQuoted.types index d3b1ebf105b84..59ce62dff1e75 100644 --- a/tests/baselines/reference/es3defaultAliasIsQuoted.types +++ b/tests/baselines/reference/es3defaultAliasIsQuoted.types @@ -33,5 +33,5 @@ assert(Foo.CONSTANT === "Foo"); >Foo.CONSTANT : string >Foo : typeof Foo >CONSTANT : string ->"Foo" : string +>"Foo" : "Foo" diff --git a/tests/baselines/reference/exportAssignmentTopLevelClodule.types b/tests/baselines/reference/exportAssignmentTopLevelClodule.types index 93ce39c3b6079..a8a827ba9c3f6 100644 --- a/tests/baselines/reference/exportAssignmentTopLevelClodule.types +++ b/tests/baselines/reference/exportAssignmentTopLevelClodule.types @@ -7,7 +7,7 @@ if(foo.answer === 42){ >foo.answer : number >foo : typeof foo >answer : number ->42 : number +>42 : 42 var x = new foo(); >x : foo diff --git a/tests/baselines/reference/exportAssignmentTopLevelFundule.types b/tests/baselines/reference/exportAssignmentTopLevelFundule.types index 3464f4294a035..950693dcc62b5 100644 --- a/tests/baselines/reference/exportAssignmentTopLevelFundule.types +++ b/tests/baselines/reference/exportAssignmentTopLevelFundule.types @@ -7,7 +7,7 @@ if(foo.answer === 42){ >foo.answer : number >foo : typeof foo >answer : number ->42 : number +>42 : 42 var x = foo(); >x : string diff --git a/tests/baselines/reference/exportAssignmentTopLevelIdentifier.types b/tests/baselines/reference/exportAssignmentTopLevelIdentifier.types index 34971ca9cd6ba..9851eab189808 100644 --- a/tests/baselines/reference/exportAssignmentTopLevelIdentifier.types +++ b/tests/baselines/reference/exportAssignmentTopLevelIdentifier.types @@ -7,7 +7,7 @@ if(foo.answer === 42){ >foo.answer : number >foo : typeof foo >answer : number ->42 : number +>42 : 42 } diff --git a/tests/baselines/reference/fallFromLastCase1.types b/tests/baselines/reference/fallFromLastCase1.types index 47e444ee17df0..1a21727e7a1b2 100644 --- a/tests/baselines/reference/fallFromLastCase1.types +++ b/tests/baselines/reference/fallFromLastCase1.types @@ -12,7 +12,7 @@ function foo1(a: number) { >a : number case 1: ->1 : number +>1 : 1 use("1"); >use("1") : any @@ -21,7 +21,7 @@ function foo1(a: number) { break; case 2: ->2 : number +>2 : 2 use("2"); >use("2") : any @@ -39,7 +39,7 @@ function foo2(a: number) { >a : number case 1: ->1 : number +>1 : 1 use("1"); >use("1") : any diff --git a/tests/baselines/reference/fatarrowfunctions.types b/tests/baselines/reference/fatarrowfunctions.types index e48b63e50ee2d..7fd15ee29a794 100644 --- a/tests/baselines/reference/fatarrowfunctions.types +++ b/tests/baselines/reference/fatarrowfunctions.types @@ -208,7 +208,7 @@ function ternaryTest(isWhile:boolean) { >n : any >n === 0 : boolean >n : any ->0 : number +>0 : 0 } diff --git a/tests/baselines/reference/genericArrayPropertyAssignment.types b/tests/baselines/reference/genericArrayPropertyAssignment.types index 6db56dde38142..9552d0ac2c922 100644 --- a/tests/baselines/reference/genericArrayPropertyAssignment.types +++ b/tests/baselines/reference/genericArrayPropertyAssignment.types @@ -9,7 +9,7 @@ return list.length ===0; >list.length : number >list : { length: number; } >length : number ->0 : number +>0 : 0 } isEmpty([]); // error diff --git a/tests/baselines/reference/implicitAnyInCatch.types b/tests/baselines/reference/implicitAnyInCatch.types index 015d41b123f68..6dda46fd3ca84 100644 --- a/tests/baselines/reference/implicitAnyInCatch.types +++ b/tests/baselines/reference/implicitAnyInCatch.types @@ -8,7 +8,7 @@ try { } catch (error) { >error.number : any >error : any >number : any ->-2147024809 : number +>-2147024809 : -2147024809 >2147024809 : number } for (var key in this) { } diff --git a/tests/baselines/reference/interfaceDoesNotDependOnBaseTypes.types b/tests/baselines/reference/interfaceDoesNotDependOnBaseTypes.types index 7b5d60a526137..cdfa40910127e 100644 --- a/tests/baselines/reference/interfaceDoesNotDependOnBaseTypes.types +++ b/tests/baselines/reference/interfaceDoesNotDependOnBaseTypes.types @@ -7,7 +7,7 @@ if (typeof x !== "string") { >typeof x !== "string" : boolean >typeof x : string >x : string | StringTreeArray ->"string" : string +>"string" : "string" x.push(""); >x.push("") : number diff --git a/tests/baselines/reference/invalidSwitchBreakStatement.types b/tests/baselines/reference/invalidSwitchBreakStatement.types index 3544da72489db..fd0ad2699a075 100644 --- a/tests/baselines/reference/invalidSwitchBreakStatement.types +++ b/tests/baselines/reference/invalidSwitchBreakStatement.types @@ -5,7 +5,7 @@ switch (12) { >12 : number case 5: ->5 : number +>5 : 5 break; } diff --git a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types index fbfe9d3edae29..443ed7398286e 100644 --- a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types +++ b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types @@ -26,7 +26,7 @@ function apply(func, thisArg, args) { >length : number case 0: return func.call(thisArg); ->0 : number +>0 : 0 >func.call(thisArg) : any >func.call : (this: Function, thisArg: any, ...argArray: any[]) => any >func : Function @@ -34,7 +34,7 @@ function apply(func, thisArg, args) { >thisArg : any case 1: return func.call(thisArg, args[0]); ->1 : number +>1 : 1 >func.call(thisArg, args[0]) : any >func.call : (this: Function, thisArg: any, ...argArray: any[]) => any >func : Function @@ -45,7 +45,7 @@ function apply(func, thisArg, args) { >0 : number case 2: return func.call(thisArg, args[0], args[1]); ->2 : number +>2 : 2 >func.call(thisArg, args[0], args[1]) : any >func.call : (this: Function, thisArg: any, ...argArray: any[]) => any >func : Function @@ -59,7 +59,7 @@ function apply(func, thisArg, args) { >1 : number case 3: return func.call(thisArg, args[0], args[1], args[2]); ->3 : number +>3 : 3 >func.call(thisArg, args[0], args[1], args[2]) : any >func.call : (this: Function, thisArg: any, ...argArray: any[]) => any >func : Function diff --git a/tests/baselines/reference/memberAccessOnConstructorType.types b/tests/baselines/reference/memberAccessOnConstructorType.types index a767336ec12c5..9b8436d631144 100644 --- a/tests/baselines/reference/memberAccessOnConstructorType.types +++ b/tests/baselines/reference/memberAccessOnConstructorType.types @@ -7,5 +7,5 @@ f.arguments == 0; >f.arguments : any >f : new () => void >arguments : any ->0 : number +>0 : 0 diff --git a/tests/baselines/reference/nestedBlockScopedBindings1.types b/tests/baselines/reference/nestedBlockScopedBindings1.types index 6d5b47a348b64..e192b0748a55c 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings1.types +++ b/tests/baselines/reference/nestedBlockScopedBindings1.types @@ -50,7 +50,7 @@ function a3() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -70,7 +70,7 @@ function a4() { >1 : number case 1: ->1 : number +>1 : 1 let x = 1; >x : number diff --git a/tests/baselines/reference/nestedBlockScopedBindings10.types b/tests/baselines/reference/nestedBlockScopedBindings10.types index ee2701cdcf13c..747f2ef1f2b2d 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings10.types +++ b/tests/baselines/reference/nestedBlockScopedBindings10.types @@ -13,7 +13,7 @@ switch (1) { >1 : number case 1: ->1 : number +>1 : 1 let y; >y : any diff --git a/tests/baselines/reference/nestedBlockScopedBindings11.types b/tests/baselines/reference/nestedBlockScopedBindings11.types index ab7b4228278df..4d1914d6f1a79 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings11.types +++ b/tests/baselines/reference/nestedBlockScopedBindings11.types @@ -17,7 +17,7 @@ switch (1) { >1 : number case 1: ->1 : number +>1 : 1 let y; >y : any diff --git a/tests/baselines/reference/nestedBlockScopedBindings12.types b/tests/baselines/reference/nestedBlockScopedBindings12.types index 8c1fdda0ce0fc..ec75d16a37fe2 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings12.types +++ b/tests/baselines/reference/nestedBlockScopedBindings12.types @@ -18,7 +18,7 @@ switch (1) { >1 : number case 1: ->1 : number +>1 : 1 let y; >y : any diff --git a/tests/baselines/reference/nestedBlockScopedBindings2.types b/tests/baselines/reference/nestedBlockScopedBindings2.types index adb33b4dc7685..3e7dbe4b75765 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings2.types +++ b/tests/baselines/reference/nestedBlockScopedBindings2.types @@ -71,7 +71,7 @@ function a3() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -95,7 +95,7 @@ function a4() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -123,7 +123,7 @@ function a5() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -139,7 +139,7 @@ function a6() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -150,7 +150,7 @@ function a6() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -166,7 +166,7 @@ function a7() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -181,7 +181,7 @@ function a7() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -197,7 +197,7 @@ function a8() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -208,7 +208,7 @@ function a8() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -228,7 +228,7 @@ function a9() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -243,7 +243,7 @@ function a9() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any diff --git a/tests/baselines/reference/nestedBlockScopedBindings3.types b/tests/baselines/reference/nestedBlockScopedBindings3.types index 37b89242f3e2c..e10cffb71232d 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings3.types +++ b/tests/baselines/reference/nestedBlockScopedBindings3.types @@ -96,7 +96,7 @@ function a3() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -129,7 +129,7 @@ function a4() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -163,7 +163,7 @@ function a5() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any diff --git a/tests/baselines/reference/nestedBlockScopedBindings6.types b/tests/baselines/reference/nestedBlockScopedBindings6.types index 5c8c1fa68fadc..fa4fa5ec6957e 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings6.types +++ b/tests/baselines/reference/nestedBlockScopedBindings6.types @@ -146,7 +146,7 @@ function a4() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -175,7 +175,7 @@ function a5() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -207,7 +207,7 @@ function a6() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any @@ -239,7 +239,7 @@ function a7() { >1 : number case 1: ->1 : number +>1 : 1 let x; >x : any diff --git a/tests/baselines/reference/nestedBlockScopedBindings9.types b/tests/baselines/reference/nestedBlockScopedBindings9.types index b889421e7dd61..e27254717fa9e 100644 --- a/tests/baselines/reference/nestedBlockScopedBindings9.types +++ b/tests/baselines/reference/nestedBlockScopedBindings9.types @@ -12,7 +12,7 @@ switch (1) { >1 : number case 1: ->1 : number +>1 : 1 let y; >y : any diff --git a/tests/baselines/reference/neverType.types b/tests/baselines/reference/neverType.types index 5424f61d1ede5..5cd6f419a9da0 100644 --- a/tests/baselines/reference/neverType.types +++ b/tests/baselines/reference/neverType.types @@ -70,13 +70,13 @@ function move1(direction: "up" | "down") { >direction : "up" | "down" case "up": ->"up" : string +>"up" : "up" return 1; >1 : number case "down": ->"down" : string +>"down" : "down" return -1; >-1 : number @@ -96,14 +96,14 @@ function move2(direction: "up" | "down") { >direction === "up" ? 1 : direction === "down" ? -1 : error("Should never get here") : number >direction === "up" : boolean >direction : "up" | "down" ->"up" : string +>"up" : "up" >1 : number direction === "down" ? -1 : >direction === "down" ? -1 : error("Should never get here") : number >direction === "down" : boolean >direction : "up" | "down" ->"down" : string +>"down" : "down" >-1 : number >1 : number @@ -166,7 +166,7 @@ function f1(x: string | number) { >typeof x === "boolean" : boolean >typeof x : string >x : string | number ->"boolean" : string +>"boolean" : "boolean" x; // never >x : never @@ -184,7 +184,7 @@ function f2(x: string | number) { >typeof x === "boolean" : boolean >typeof x : string >x : string | number ->"boolean" : string +>"boolean" : "boolean" return x; // never >x : never diff --git a/tests/baselines/reference/noImplicitReturnsInAsync1.types b/tests/baselines/reference/noImplicitReturnsInAsync1.types index 23f0892f30edc..1dfc098675c4e 100644 --- a/tests/baselines/reference/noImplicitReturnsInAsync1.types +++ b/tests/baselines/reference/noImplicitReturnsInAsync1.types @@ -8,7 +8,7 @@ async function test(isError: boolean = false) { if (isError === true) { >isError === true : boolean >isError : boolean ->true : boolean +>true : true return; } diff --git a/tests/baselines/reference/objectLiteralArraySpecialization.types b/tests/baselines/reference/objectLiteralArraySpecialization.types index b32eaa0441e18..405d8bff47225 100644 --- a/tests/baselines/reference/objectLiteralArraySpecialization.types +++ b/tests/baselines/reference/objectLiteralArraySpecialization.types @@ -52,5 +52,5 @@ thing.doSomething((x, y) => x.name === "bob"); // should not error >x.name : string >x : { name: string; id: number; } >name : string ->"bob" : string +>"bob" : "bob" diff --git a/tests/baselines/reference/operatorsAndIntersectionTypes.types b/tests/baselines/reference/operatorsAndIntersectionTypes.types index 6b5987d3a69da..2cf04c6549c7b 100644 --- a/tests/baselines/reference/operatorsAndIntersectionTypes.types +++ b/tests/baselines/reference/operatorsAndIntersectionTypes.types @@ -110,7 +110,7 @@ const b1 = guid === ""; >b1 : boolean >guid === "" : boolean >guid : string & { $Guid: any; } ->"" : string +>"" : "" const b2 = guid === guid; >b2 : boolean @@ -122,7 +122,7 @@ const b3 = serialNo === 0; >b3 : boolean >serialNo === 0 : boolean >serialNo : number & { $SerialNo: any; } ->0 : number +>0 : 0 const b4 = serialNo === serialNo; >b4 : boolean diff --git a/tests/baselines/reference/overloadResolutionOverNonCTLambdas.types b/tests/baselines/reference/overloadResolutionOverNonCTLambdas.types index 066015389d220..4cf7b0b086fb1 100644 --- a/tests/baselines/reference/overloadResolutionOverNonCTLambdas.types +++ b/tests/baselines/reference/overloadResolutionOverNonCTLambdas.types @@ -36,7 +36,7 @@ module Bugs { >args[index] : any >args : any[] >index : any ->'undefined' : string +>'undefined' : "undefined" ? args[index] >args[index] : any diff --git a/tests/baselines/reference/overloadReturnTypes.types b/tests/baselines/reference/overloadReturnTypes.types index 3de1aec1196c6..e8d1b7905dc48 100644 --- a/tests/baselines/reference/overloadReturnTypes.types +++ b/tests/baselines/reference/overloadReturnTypes.types @@ -28,7 +28,7 @@ function attr(nameOrMap: any, value?: string): any { >typeof nameOrMap === "object" : boolean >typeof nameOrMap : string >nameOrMap : any ->"object" : string +>"object" : "object" // handle map case return new Accessor; diff --git a/tests/baselines/reference/reachabilityCheckWithEmptyDefault.types b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.types index 3d01b8764735d..37a6d11b598f9 100644 --- a/tests/baselines/reference/reachabilityCheckWithEmptyDefault.types +++ b/tests/baselines/reference/reachabilityCheckWithEmptyDefault.types @@ -11,7 +11,7 @@ function foo(x: any) { >x : any case 1: return; ->1 : number +>1 : 1 default: } diff --git a/tests/baselines/reference/recursiveReturns.types b/tests/baselines/reference/recursiveReturns.types index c4d9fd31981bd..b1fdd125ecc5b 100644 --- a/tests/baselines/reference/recursiveReturns.types +++ b/tests/baselines/reference/recursiveReturns.types @@ -21,7 +21,7 @@ function R3(n:number) { if (n == 0) { >n == 0 : boolean >n : number ->0 : number +>0 : 0 //return; } diff --git a/tests/baselines/reference/sourceMap-Comments.types b/tests/baselines/reference/sourceMap-Comments.types index cbb58b6799459..b1681c05aad0d 100644 --- a/tests/baselines/reference/sourceMap-Comments.types +++ b/tests/baselines/reference/sourceMap-Comments.types @@ -17,17 +17,17 @@ module sas.tools { >f : number case 1: ->1 : number +>1 : 1 break; case 2: ->2 : number +>2 : 2 //line comment 1 //line comment 2 break; case 3: ->3 : number +>3 : 3 //a comment break; diff --git a/tests/baselines/reference/sourceMapValidationIfElse.types b/tests/baselines/reference/sourceMapValidationIfElse.types index 30de2f11450d3..2b195983f217b 100644 --- a/tests/baselines/reference/sourceMapValidationIfElse.types +++ b/tests/baselines/reference/sourceMapValidationIfElse.types @@ -6,7 +6,7 @@ var i = 10; if (i == 10) { >i == 10 : boolean >i : number ->10 : number +>10 : 10 i++; >i++ : number @@ -18,7 +18,7 @@ if (i == 10) { if (i == 10) >i == 10 : boolean >i : number ->10 : number +>10 : 10 { i++; >i++ : number @@ -27,7 +27,7 @@ if (i == 10) else if (i == 20) { >i == 20 : boolean >i : number ->20 : number +>20 : 20 i--; >i-- : number @@ -36,7 +36,7 @@ else if (i == 20) { } else if (i == 30) { >i == 30 : boolean >i : number ->30 : number +>30 : 30 i += 70; >i += 70 : number diff --git a/tests/baselines/reference/sourceMapValidationSwitch.types b/tests/baselines/reference/sourceMapValidationSwitch.types index a594004a54812..1c0a73c1bbe11 100644 --- a/tests/baselines/reference/sourceMapValidationSwitch.types +++ b/tests/baselines/reference/sourceMapValidationSwitch.types @@ -7,7 +7,7 @@ switch (x) { >x : number case 5: ->5 : number +>5 : 5 x++; >x++ : number @@ -15,7 +15,7 @@ switch (x) { break; case 10: ->10 : number +>10 : 10 { x--; >x-- : number @@ -35,7 +35,7 @@ switch (x) >x : number { case 5: ->5 : number +>5 : 5 x++; >x++ : number @@ -43,7 +43,7 @@ switch (x) break; case 10: ->10 : number +>10 : 10 { x--; >x-- : number diff --git a/tests/baselines/reference/sourceMapValidationWhile.types b/tests/baselines/reference/sourceMapValidationWhile.types index 9225b93e08ce6..86cf021627694 100644 --- a/tests/baselines/reference/sourceMapValidationWhile.types +++ b/tests/baselines/reference/sourceMapValidationWhile.types @@ -6,7 +6,7 @@ var a = 10; while (a == 10) { >a == 10 : boolean >a : number ->10 : number +>10 : 10 a++; >a++ : number @@ -15,7 +15,7 @@ while (a == 10) { while (a == 10) >a == 10 : boolean >a : number ->10 : number +>10 : 10 { a++; >a++ : number diff --git a/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.types b/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.types index 8d35f32707af3..7140935cb913c 100644 --- a/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.types +++ b/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.types @@ -241,7 +241,7 @@ class ListWrapper { >array.length : number >array : T[] >length : number ->0 : number +>0 : 0 >null : null return array[array.length - 1]; @@ -288,7 +288,7 @@ class ListWrapper { >list : T[] >indexOf : (searchElement: T, fromIndex?: number) => number >el : T ->-1 : number +>-1 : -1 >1 : number static reversed(dit: typeof ListWrapper, array: T[]): T[] { @@ -496,7 +496,7 @@ class ListWrapper { >list.length : number >list : any[] >length : number ->0 : number +>0 : 0 static fill(dit: typeof ListWrapper, list: any[], value: any, start: number = 0, end: number = null) { >fill : (dit: typeof ListWrapper, list: any[], value: any, start?: number, end?: number) => void @@ -684,7 +684,7 @@ class ListWrapper { >list.length : number >list : T[] >length : number ->0 : number +>0 : 0 return null; >null : null diff --git a/tests/baselines/reference/stringLiteralCheckedInIf01.types b/tests/baselines/reference/stringLiteralCheckedInIf01.types index 75b7eadbc19b4..be25df63f209b 100644 --- a/tests/baselines/reference/stringLiteralCheckedInIf01.types +++ b/tests/baselines/reference/stringLiteralCheckedInIf01.types @@ -16,7 +16,7 @@ function f(foo: T) { if (foo === "a") { >foo === "a" : boolean >foo : ("a" | "b")[] | "a" | "b" ->"a" : string +>"a" : "a" return foo; >foo : ("a" | "b")[] | "a" | "b" @@ -24,7 +24,7 @@ function f(foo: T) { else if (foo === "b") { >foo === "b" : boolean >foo : ("a" | "b")[] | "a" | "b" ->"b" : string +>"b" : "b" return foo; >foo : ("a" | "b")[] | "a" | "b" diff --git a/tests/baselines/reference/stringLiteralCheckedInIf02.types b/tests/baselines/reference/stringLiteralCheckedInIf02.types index 79f4c6a223a71..ae0e370e33b94 100644 --- a/tests/baselines/reference/stringLiteralCheckedInIf02.types +++ b/tests/baselines/reference/stringLiteralCheckedInIf02.types @@ -19,10 +19,10 @@ function isS(t: T): t is S { >t === "a" || t === "b" : boolean >t === "a" : boolean >t : ("a" | "b")[] | "a" | "b" ->"a" : string +>"a" : "a" >t === "b" : boolean >t : ("a" | "b")[] | "a" | "b" ->"b" : string +>"b" : "b" } function f(foo: T) { diff --git a/tests/baselines/reference/stringLiteralMatchedInSwitch01.types b/tests/baselines/reference/stringLiteralMatchedInSwitch01.types index cfbb77e07e0a3..ded50d120fd74 100644 --- a/tests/baselines/reference/stringLiteralMatchedInSwitch01.types +++ b/tests/baselines/reference/stringLiteralMatchedInSwitch01.types @@ -16,10 +16,10 @@ switch (foo) { >foo : ("a" | "b")[] | "a" | "b" case "a": ->"a" : string +>"a" : "a" case "b": ->"b" : string +>"b" : "b" break; default: diff --git a/tests/baselines/reference/stringLiteralTypesAndTuples01.types b/tests/baselines/reference/stringLiteralTypesAndTuples01.types index e8b5b37a2dda8..b15656835b281 100644 --- a/tests/baselines/reference/stringLiteralTypesAndTuples01.types +++ b/tests/baselines/reference/stringLiteralTypesAndTuples01.types @@ -38,7 +38,7 @@ function rawr(dino: RexOrRaptor) { if (dino === "t-rex") { >dino === "t-rex" : boolean >dino : "t-rex" | "raptor" ->"t-rex" : string +>"t-rex" : "t-rex" return "ROAAAAR!"; >"ROAAAAR!" : string @@ -46,7 +46,7 @@ function rawr(dino: RexOrRaptor) { if (dino === "raptor") { >dino === "raptor" : boolean >dino : "t-rex" | "raptor" ->"raptor" : string +>"raptor" : "raptor" return "yip yip!"; >"yip yip!" : string diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types index 7201aaa91cab1..aac177224b115 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types @@ -15,7 +15,7 @@ var y: T = undefined; if (x === "foo") { >x === "foo" : boolean >x : "foo" | "bar" | "baz" ->"foo" : string +>"foo" : "foo" let a = x; >a : "foo" | "bar" | "baz" @@ -24,7 +24,7 @@ if (x === "foo") { else if (x !== "bar") { >x !== "bar" : boolean >x : "foo" | "bar" | "baz" ->"bar" : string +>"bar" : "bar" let b = x || y; >b : "foo" | "bar" | "baz" diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types index 242248617e0d4..7b61b7e26fb11 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types @@ -15,7 +15,7 @@ var y: T = undefined; if (x === "foo") { >x === "foo" : boolean >x : string ->"foo" : string +>"foo" : "foo" let a = x; >a : string @@ -24,7 +24,7 @@ if (x === "foo") { else if (x !== "bar") { >x !== "bar" : boolean >x : string ->"bar" : string +>"bar" : "bar" let b = x || y; >b : string diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types index 920f7e1a71ccb..c877bfffe3c86 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types @@ -14,7 +14,7 @@ var y: T = undefined; if (x === "foo") { >x === "foo" : boolean >x : "foo" | "bar" | number ->"foo" : string +>"foo" : "foo" let a = x; >a : "foo" | "bar" | number @@ -23,7 +23,7 @@ if (x === "foo") { else if (x !== "bar") { >x !== "bar" : boolean >x : "foo" | "bar" | number ->"bar" : string +>"bar" : "bar" let b = x || y; >b : "foo" | "bar" | number diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types index fdaaa21b6cbb2..eb96d02217e1a 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types @@ -16,7 +16,7 @@ let y: T = undefined; if (x === "") { >x === "" : boolean >x : "" | "foo" ->"" : string +>"" : "" let a = x; >a : "" | "foo" @@ -26,7 +26,7 @@ if (x === "") { if (x !== "") { >x !== "" : boolean >x : "" | "foo" ->"" : string +>"" : "" let b = x; >b : "" | "foo" @@ -36,7 +36,7 @@ if (x !== "") { if (x == "") { >x == "" : boolean >x : "" | "foo" ->"" : string +>"" : "" let c = x; >c : "" | "foo" @@ -46,7 +46,7 @@ if (x == "") { if (x != "") { >x != "" : boolean >x : "" | "foo" ->"" : string +>"" : "" let d = x; >d : "" | "foo" diff --git a/tests/baselines/reference/stringLiteralTypesOverloads01.types b/tests/baselines/reference/stringLiteralTypesOverloads01.types index 6ba8d482117c6..21c9831e9e770 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads01.types +++ b/tests/baselines/reference/stringLiteralTypesOverloads01.types @@ -39,7 +39,7 @@ function getFalsyPrimitive(x: PrimitiveName): number | string | boolean { if (x === "string") { >x === "string" : boolean >x : "string" | "number" | "boolean" ->"string" : string +>"string" : "string" return ""; >"" : string @@ -47,7 +47,7 @@ function getFalsyPrimitive(x: PrimitiveName): number | string | boolean { if (x === "number") { >x === "number" : boolean >x : "string" | "number" | "boolean" ->"number" : string +>"number" : "number" return 0; >0 : number @@ -55,7 +55,7 @@ function getFalsyPrimitive(x: PrimitiveName): number | string | boolean { if (x === "boolean") { >x === "boolean" : boolean >x : "string" | "number" | "boolean" ->"boolean" : string +>"boolean" : "boolean" return false; >false : boolean diff --git a/tests/baselines/reference/stringLiteralTypesWithVariousOperators01.types b/tests/baselines/reference/stringLiteralTypesWithVariousOperators01.types index 90cb538b800d1..46442d75ad4ac 100644 --- a/tests/baselines/reference/stringLiteralTypesWithVariousOperators01.types +++ b/tests/baselines/reference/stringLiteralTypesWithVariousOperators01.types @@ -16,9 +16,9 @@ let abcOrXyz: "ABC" | "XYZ" = abc || xyz; let abcOrXyzOrNumber: "ABC" | "XYZ" | number = abcOrXyz || 100; >abcOrXyzOrNumber : "ABC" | "XYZ" | number ->abcOrXyz || 100 : "ABC" | "XYZ" | number +>abcOrXyz || 100 : "ABC" | "XYZ" | 100 >abcOrXyz : "ABC" | "XYZ" ->100 : number +>100 : 100 let a = "" + abc; >a : string diff --git a/tests/baselines/reference/switchBreakStatements.types b/tests/baselines/reference/switchBreakStatements.types index 0364d878d5ab4..c69c20a33064a 100644 --- a/tests/baselines/reference/switchBreakStatements.types +++ b/tests/baselines/reference/switchBreakStatements.types @@ -4,7 +4,7 @@ switch ('') { >'' : string case 'a': ->'a' : string +>'a' : "a" break; } @@ -16,7 +16,7 @@ switch ('') { >'' : string case 'a': ->'a' : string +>'a' : "a" break ONE; >ONE : any @@ -32,7 +32,7 @@ switch ('') { >'' : string case 'a': ->'a' : string +>'a' : "a" break THREE; >THREE : any @@ -45,7 +45,7 @@ switch ('') { >'' : string case 'a': ->'a' : string +>'a' : "a" FIVE: >FIVE : any @@ -54,7 +54,7 @@ switch ('') { >'' : string case 'a': ->'a' : string +>'a' : "a" break FOUR; >FOUR : any @@ -65,7 +65,7 @@ switch ('') { >'' : string case 'a': ->'a' : string +>'a' : "a" SIX: >SIX : any @@ -74,7 +74,7 @@ switch ('') { >'' : string case 'a': ->'a' : string +>'a' : "a" break SIX; >SIX : any @@ -88,19 +88,19 @@ switch ('') { >'' : string case 'a': ->'a' : string +>'a' : "a" switch ('') { >'' : string case 'a': ->'a' : string +>'a' : "a" switch ('') { >'' : string case 'a': ->'a' : string +>'a' : "a" break SEVEN; >SEVEN : any @@ -112,7 +112,7 @@ switch ('') { >'' : string case 'a': ->'a' : string +>'a' : "a" var fn = function () { } >fn : () => void diff --git a/tests/baselines/reference/switchCases.types b/tests/baselines/reference/switchCases.types index 154ea011cdeff..0f10e7029076d 100644 --- a/tests/baselines/reference/switchCases.types +++ b/tests/baselines/reference/switchCases.types @@ -3,7 +3,7 @@ switch(0) { >0 : number case 1: ->1 : number +>1 : 1 break; } diff --git a/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt b/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt index 26d39efef48ec..e430b33097c0a 100644 --- a/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt +++ b/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(4,10): error TS2678: Type 'typeof Foo' is not comparable to type 'number'. -tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2678: Type 'string' is not comparable to type 'number'. -tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2678: Type 'boolean' is not comparable to type 'number'. +tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2678: Type '"sss"' is not comparable to type 'number'. +tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2678: Type 'true' is not comparable to type 'number'. ==== tests/cases/compiler/switchCasesExpressionTypeMismatch.ts (3 errors) ==== @@ -12,11 +12,11 @@ tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2678: T !!! error TS2678: Type 'typeof Foo' is not comparable to type 'number'. case "sss": break; // Error ~~~~~ -!!! error TS2678: Type 'string' is not comparable to type 'number'. +!!! error TS2678: Type '"sss"' is not comparable to type 'number'. case 123: break; // No Error case true: break; // Error ~~~~ -!!! error TS2678: Type 'boolean' is not comparable to type 'number'. +!!! error TS2678: Type 'true' is not comparable to type 'number'. } var s: any = 0; diff --git a/tests/baselines/reference/switchFallThroughs.types b/tests/baselines/reference/switchFallThroughs.types index 7a88985741c9c..cd0af6693ebf8 100644 --- a/tests/baselines/reference/switchFallThroughs.types +++ b/tests/baselines/reference/switchFallThroughs.types @@ -7,13 +7,13 @@ function R1(index: number) { >index : number case 0: ->0 : number +>0 : 0 case 1: ->1 : number +>1 : 1 case 2: ->2 : number +>2 : 2 var a = 'a'; >a : string @@ -23,16 +23,16 @@ function R1(index: number) { >a : string case 3: ->3 : number +>3 : 3 case 4: { ->4 : number +>4 : 4 return 'b'; >'b' : string } case 5: ->5 : number +>5 : 5 default: return 'c'; diff --git a/tests/baselines/reference/symbolType17.types b/tests/baselines/reference/symbolType17.types index a6174f7a3aeb2..c186f915cd0ac 100644 --- a/tests/baselines/reference/symbolType17.types +++ b/tests/baselines/reference/symbolType17.types @@ -14,7 +14,7 @@ if (typeof x === "symbol") { >typeof x === "symbol" : boolean >typeof x : string >x : symbol | Foo ->"symbol" : string +>"symbol" : "symbol" x; >x : symbol diff --git a/tests/baselines/reference/symbolType18.types b/tests/baselines/reference/symbolType18.types index 68c43215136fa..8f0012f4f118b 100644 --- a/tests/baselines/reference/symbolType18.types +++ b/tests/baselines/reference/symbolType18.types @@ -14,7 +14,7 @@ if (typeof x === "object") { >typeof x === "object" : boolean >typeof x : string >x : symbol | Foo ->"object" : string +>"object" : "object" x; >x : Foo diff --git a/tests/baselines/reference/symbolType19.types b/tests/baselines/reference/symbolType19.types index 33c4f5ac07c65..18daa27fd00d7 100644 --- a/tests/baselines/reference/symbolType19.types +++ b/tests/baselines/reference/symbolType19.types @@ -13,7 +13,7 @@ if (typeof x === "number") { >typeof x === "number" : boolean >typeof x : string >x : symbol | E ->"number" : string +>"number" : "number" x; >x : E diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.types b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.types index 83a0f2cf9f417..8ebab064029e9 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.types +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressions.types @@ -39,6 +39,6 @@ var x = new new new f `abc${ 0 }def`.member("hello")(42) === true; >member : new (s: string) => new (n: number) => new () => boolean >"hello" : string >42 : number ->true : boolean +>true : true diff --git a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.types b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.types index c240b7ced11f6..ec335b8120788 100644 --- a/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.types +++ b/tests/baselines/reference/taggedTemplateStringsWithManyCallAndMemberExpressionsES6.types @@ -39,6 +39,6 @@ var x = new new new f `abc${ 0 }def`.member("hello")(42) === true; >member : new (s: string) => new (n: number) => new () => boolean >"hello" : string >42 : number ->true : boolean +>true : true diff --git a/tests/baselines/reference/templateStringInEqualityChecks.types b/tests/baselines/reference/templateStringInEqualityChecks.types index 51a450e5245fa..2f1b2cf987b00 100644 --- a/tests/baselines/reference/templateStringInEqualityChecks.types +++ b/tests/baselines/reference/templateStringInEqualityChecks.types @@ -19,11 +19,11 @@ var x = `abc${0}abc` === `abc` || >`abc${0}abc` == "abc0abc" : boolean >`abc${0}abc` : string >0 : number ->"abc0abc" : string +>"abc0abc" : "abc0abc" "abc0abc" !== `abc${0}abc`; >"abc0abc" !== `abc${0}abc` : boolean ->"abc0abc" : string +>"abc0abc" : "abc0abc" >`abc${0}abc` : string >0 : number diff --git a/tests/baselines/reference/templateStringInEqualityChecksES6.types b/tests/baselines/reference/templateStringInEqualityChecksES6.types index 37e5e4a8c283a..ce552da09eaa9 100644 --- a/tests/baselines/reference/templateStringInEqualityChecksES6.types +++ b/tests/baselines/reference/templateStringInEqualityChecksES6.types @@ -19,11 +19,11 @@ var x = `abc${0}abc` === `abc` || >`abc${0}abc` == "abc0abc" : boolean >`abc${0}abc` : string >0 : number ->"abc0abc" : string +>"abc0abc" : "abc0abc" "abc0abc" !== `abc${0}abc`; >"abc0abc" !== `abc${0}abc` : boolean ->"abc0abc" : string +>"abc0abc" : "abc0abc" >`abc${0}abc` : string >0 : number diff --git a/tests/baselines/reference/throwInEnclosingStatements.types b/tests/baselines/reference/throwInEnclosingStatements.types index c0a43ca38f548..eb127cf28bd93 100644 --- a/tests/baselines/reference/throwInEnclosingStatements.types +++ b/tests/baselines/reference/throwInEnclosingStatements.types @@ -22,7 +22,7 @@ switch (y) { >y : string case 'a': ->'a' : string +>'a' : "a" throw y; >y : string diff --git a/tests/baselines/reference/typeGuardEnums.types b/tests/baselines/reference/typeGuardEnums.types index 2bef691504606..255326e66d26e 100644 --- a/tests/baselines/reference/typeGuardEnums.types +++ b/tests/baselines/reference/typeGuardEnums.types @@ -14,7 +14,7 @@ if (typeof x === "number") { >typeof x === "number" : boolean >typeof x : string >x : number | string | E | V ->"number" : string +>"number" : "number" x; // number|E|V >x : number | E | V @@ -28,7 +28,7 @@ if (typeof x !== "number") { >typeof x !== "number" : boolean >typeof x : string >x : number | string ->"number" : string +>"number" : "number" x; // string >x : string diff --git a/tests/baselines/reference/typeGuardIntersectionTypes.types b/tests/baselines/reference/typeGuardIntersectionTypes.types index 8be50453572b6..6b6dbae8ca27e 100644 --- a/tests/baselines/reference/typeGuardIntersectionTypes.types +++ b/tests/baselines/reference/typeGuardIntersectionTypes.types @@ -167,7 +167,7 @@ function hasLegs(x: Beast): x is Legged { return x && typeof x.legs === 'number' >x.legs : number | undefined >x : Beast >legs : number | undefined ->'number' : string +>'number' : "number" function hasWings(x: Beast): x is Winged { return x && !!x.wings; } >hasWings : (x: Beast) => x is Winged @@ -206,7 +206,7 @@ function identifyBeast(beast: Beast) { >beast.legs : number >beast : Legged & Winged >legs : number ->4 : number +>4 : 4 log(`pegasus - 4 legs, wings`); >log(`pegasus - 4 legs, wings`) : void @@ -218,7 +218,7 @@ function identifyBeast(beast: Beast) { >beast.legs : number >beast : Legged & Winged >legs : number ->2 : number +>2 : 2 log(`bird - 2 legs, wings`); >log(`bird - 2 legs, wings`) : void diff --git a/tests/baselines/reference/typeGuardNesting.types b/tests/baselines/reference/typeGuardNesting.types index 2b18e232412e9..cb06d457a3097 100644 --- a/tests/baselines/reference/typeGuardNesting.types +++ b/tests/baselines/reference/typeGuardNesting.types @@ -9,13 +9,13 @@ if ((typeof strOrBool === 'boolean' && !strOrBool) || typeof strOrBool === 'stri >typeof strOrBool === 'boolean' : boolean >typeof strOrBool : string >strOrBool : string | boolean ->'boolean' : string +>'boolean' : "boolean" >!strOrBool : boolean >strOrBool : boolean >typeof strOrBool === 'string' : boolean >typeof strOrBool : string >strOrBool : string | boolean ->'string' : string +>'string' : "string" let label: string = (typeof strOrBool === 'string') ? strOrBool : "string"; >label : string @@ -24,7 +24,7 @@ if ((typeof strOrBool === 'boolean' && !strOrBool) || typeof strOrBool === 'stri >typeof strOrBool === 'string' : boolean >typeof strOrBool : string >strOrBool : boolean | string ->'string' : string +>'string' : "string" >strOrBool : string >"string" : string @@ -35,7 +35,7 @@ if ((typeof strOrBool === 'boolean' && !strOrBool) || typeof strOrBool === 'stri >typeof strOrBool === 'boolean' : boolean >typeof strOrBool : string >strOrBool : string | boolean ->'boolean' : string +>'boolean' : "boolean" >strOrBool : boolean >false : boolean @@ -46,7 +46,7 @@ if ((typeof strOrBool === 'boolean' && !strOrBool) || typeof strOrBool === 'stri >typeof strOrBool !== 'boolean' : boolean >typeof strOrBool : string >strOrBool : boolean | string ->'boolean' : string +>'boolean' : "boolean" >strOrBool : string >"string" : string @@ -57,7 +57,7 @@ if ((typeof strOrBool === 'boolean' && !strOrBool) || typeof strOrBool === 'stri >typeof strOrBool !== 'string' : boolean >typeof strOrBool : string >strOrBool : string | boolean ->'string' : string +>'string' : "string" >strOrBool : boolean >false : boolean } @@ -69,13 +69,13 @@ if ((typeof strOrBool !== 'string' && !strOrBool) || typeof strOrBool !== 'boole >typeof strOrBool !== 'string' : boolean >typeof strOrBool : string >strOrBool : boolean | string ->'string' : string +>'string' : "string" >!strOrBool : boolean >strOrBool : boolean >typeof strOrBool !== 'boolean' : boolean >typeof strOrBool : string >strOrBool : string | boolean ->'boolean' : string +>'boolean' : "boolean" let label: string = (typeof strOrBool === 'string') ? strOrBool : "string"; >label : string @@ -84,7 +84,7 @@ if ((typeof strOrBool !== 'string' && !strOrBool) || typeof strOrBool !== 'boole >typeof strOrBool === 'string' : boolean >typeof strOrBool : string >strOrBool : boolean | string ->'string' : string +>'string' : "string" >strOrBool : string >"string" : string @@ -95,7 +95,7 @@ if ((typeof strOrBool !== 'string' && !strOrBool) || typeof strOrBool !== 'boole >typeof strOrBool === 'boolean' : boolean >typeof strOrBool : string >strOrBool : string | boolean ->'boolean' : string +>'boolean' : "boolean" >strOrBool : boolean >false : boolean @@ -106,7 +106,7 @@ if ((typeof strOrBool !== 'string' && !strOrBool) || typeof strOrBool !== 'boole >typeof strOrBool !== 'boolean' : boolean >typeof strOrBool : string >strOrBool : boolean | string ->'boolean' : string +>'boolean' : "boolean" >strOrBool : string >"string" : string @@ -117,7 +117,7 @@ if ((typeof strOrBool !== 'string' && !strOrBool) || typeof strOrBool !== 'boole >typeof strOrBool !== 'string' : boolean >typeof strOrBool : string >strOrBool : string | boolean ->'string' : string +>'string' : "string" >strOrBool : boolean >false : boolean } diff --git a/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types b/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types index a10d398988fd9..0b1661820d5f1 100644 --- a/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types +++ b/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types @@ -44,11 +44,11 @@ if (typeof strOrNumOrBool !== "string" && typeof strOrNumOrBool !== "number") { >typeof strOrNumOrBool !== "string" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"string" : string +>"string" : "string" >typeof strOrNumOrBool !== "number" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : number | boolean ->"number" : string +>"number" : "number" bool = strOrNumOrBool; // boolean >bool = strOrNumOrBool : boolean @@ -68,15 +68,15 @@ if (typeof strOrNumOrBoolOrC !== "string" && typeof strOrNumOrBoolOrC !== "numbe >typeof strOrNumOrBoolOrC !== "string" : boolean >typeof strOrNumOrBoolOrC : string >strOrNumOrBoolOrC : string | number | boolean | C ->"string" : string +>"string" : "string" >typeof strOrNumOrBoolOrC !== "number" : boolean >typeof strOrNumOrBoolOrC : string >strOrNumOrBoolOrC : number | boolean | C ->"number" : string +>"number" : "number" >typeof strOrNumOrBoolOrC !== "boolean" : boolean >typeof strOrNumOrBoolOrC : string >strOrNumOrBoolOrC : boolean | C ->"boolean" : string +>"boolean" : "boolean" c = strOrNumOrBoolOrC; // C >c = strOrNumOrBoolOrC : C @@ -96,15 +96,15 @@ if (typeof strOrNumOrBoolOrC !== "string" && typeof strOrNumOrBoolOrC !== "numbe >typeof strOrNumOrBoolOrC !== "string" : boolean >typeof strOrNumOrBoolOrC : string >strOrNumOrBoolOrC : C | string | number | boolean ->"string" : string +>"string" : "string" >typeof strOrNumOrBoolOrC !== "number" : boolean >typeof strOrNumOrBoolOrC : string >strOrNumOrBoolOrC : C | number | boolean ->"number" : string +>"number" : "number" >typeof strOrNumOrBool === "boolean" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"boolean" : string +>"boolean" : "boolean" cOrBool = strOrNumOrBoolOrC; // C | boolean >cOrBool = strOrNumOrBoolOrC : C | boolean @@ -132,7 +132,7 @@ if (typeof strOrNumOrBool !== "string" && numOrBool !== strOrNumOrBool) { >typeof strOrNumOrBool !== "string" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"string" : string +>"string" : "string" >numOrBool !== strOrNumOrBool : boolean >numOrBool : number | boolean >strOrNumOrBool : number | boolean diff --git a/tests/baselines/reference/typeGuardOfFormExpr1OrExpr2.types b/tests/baselines/reference/typeGuardOfFormExpr1OrExpr2.types index acd929a7ca118..b576630c1cf16 100644 --- a/tests/baselines/reference/typeGuardOfFormExpr1OrExpr2.types +++ b/tests/baselines/reference/typeGuardOfFormExpr1OrExpr2.types @@ -44,11 +44,11 @@ if (typeof strOrNumOrBool === "string" || typeof strOrNumOrBool === "number") { >typeof strOrNumOrBool === "string" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"string" : string +>"string" : "string" >typeof strOrNumOrBool === "number" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : number | boolean ->"number" : string +>"number" : "number" strOrNum = strOrNumOrBool; // string | number >strOrNum = strOrNumOrBool : string | number @@ -68,15 +68,15 @@ if (typeof strOrNumOrBoolOrC === "string" || typeof strOrNumOrBoolOrC === "numbe >typeof strOrNumOrBoolOrC === "string" : boolean >typeof strOrNumOrBoolOrC : string >strOrNumOrBoolOrC : string | number | boolean | C ->"string" : string +>"string" : "string" >typeof strOrNumOrBoolOrC === "number" : boolean >typeof strOrNumOrBoolOrC : string >strOrNumOrBoolOrC : number | boolean | C ->"number" : string +>"number" : "number" >typeof strOrNumOrBoolOrC === "boolean" : boolean >typeof strOrNumOrBoolOrC : string >strOrNumOrBoolOrC : boolean | C ->"boolean" : string +>"boolean" : "boolean" strOrNumOrBool = strOrNumOrBoolOrC; // string | number | boolean >strOrNumOrBool = strOrNumOrBoolOrC : string | number | boolean @@ -96,15 +96,15 @@ if (typeof strOrNumOrBoolOrC === "string" || typeof strOrNumOrBoolOrC === "numbe >typeof strOrNumOrBoolOrC === "string" : boolean >typeof strOrNumOrBoolOrC : string >strOrNumOrBoolOrC : string | number | boolean | C ->"string" : string +>"string" : "string" >typeof strOrNumOrBoolOrC === "number" : boolean >typeof strOrNumOrBoolOrC : string >strOrNumOrBoolOrC : number | boolean | C ->"number" : string +>"number" : "number" >typeof strOrNumOrBool !== "boolean" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"boolean" : string +>"boolean" : "boolean" var r1: string | number | boolean | C = strOrNumOrBoolOrC; // string | number | boolean | C >r1 : string | number | boolean | C @@ -132,7 +132,7 @@ if (typeof strOrNumOrBool === "string" || numOrBool !== strOrNumOrBool) { >typeof strOrNumOrBool === "string" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"string" : string +>"string" : "string" >numOrBool !== strOrNumOrBool : boolean >numOrBool : number | boolean >strOrNumOrBool : number | boolean diff --git a/tests/baselines/reference/typeGuardOfFormNotExpr.types b/tests/baselines/reference/typeGuardOfFormNotExpr.types index e7cfd6a0dce0f..6989fa663c841 100644 --- a/tests/baselines/reference/typeGuardOfFormNotExpr.types +++ b/tests/baselines/reference/typeGuardOfFormNotExpr.types @@ -28,7 +28,7 @@ if (!(typeof strOrNum === "string")) { >typeof strOrNum === "string" : boolean >typeof strOrNum : string >strOrNum : string | number ->"string" : string +>"string" : "string" num === strOrNum; // number >num === strOrNum : boolean @@ -49,11 +49,11 @@ if (!(typeof strOrNumOrBool === "string" || typeof strOrNumOrBool === "number")) >typeof strOrNumOrBool === "string" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"string" : string +>"string" : "string" >typeof strOrNumOrBool === "number" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : number | boolean ->"number" : string +>"number" : "number" bool = strOrNumOrBool; // boolean >bool = strOrNumOrBool : boolean @@ -74,13 +74,13 @@ if (!(typeof strOrNumOrBool !== "string") || !(typeof strOrNumOrBool !== "number >typeof strOrNumOrBool !== "string" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : boolean | string | number ->"string" : string +>"string" : "string" >!(typeof strOrNumOrBool !== "number") : boolean >(typeof strOrNumOrBool !== "number") : boolean >typeof strOrNumOrBool !== "number" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : boolean | number ->"number" : string +>"number" : "number" strOrNum = strOrNumOrBool; // string | number >strOrNum = strOrNumOrBool : string | number @@ -101,11 +101,11 @@ if (!(typeof strOrNumOrBool !== "string" && typeof strOrNumOrBool !== "number")) >typeof strOrNumOrBool !== "string" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"string" : string +>"string" : "string" >typeof strOrNumOrBool !== "number" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : number | boolean ->"number" : string +>"number" : "number" strOrNum = strOrNumOrBool; // string | number >strOrNum = strOrNumOrBool : string | number @@ -126,13 +126,13 @@ if (!(typeof strOrNumOrBool === "string") && !(typeof strOrNumOrBool === "number >typeof strOrNumOrBool === "string" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"string" : string +>"string" : "string" >!(typeof strOrNumOrBool === "number") : boolean >(typeof strOrNumOrBool === "number") : boolean >typeof strOrNumOrBool === "number" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : number | boolean ->"number" : string +>"number" : "number" bool = strOrNumOrBool; // boolean >bool = strOrNumOrBool : boolean @@ -153,7 +153,7 @@ if (!(typeof strOrNumOrBool === "string") && numOrBool !== strOrNumOrBool) { >typeof strOrNumOrBool === "string" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : boolean | string | number ->"string" : string +>"string" : "string" >numOrBool !== strOrNumOrBool : boolean >numOrBool : number | boolean >strOrNumOrBool : boolean | number diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types b/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types index 7a4b279b57254..9166b00386ac3 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types @@ -48,7 +48,7 @@ if (typeof strOrBool === "boolean") { >typeof strOrBool === "boolean" : boolean >typeof strOrBool : string >strOrBool : string | boolean ->"boolean" : string +>"boolean" : "boolean" bool = strOrBool; // boolean >bool = strOrBool : boolean @@ -65,7 +65,7 @@ if (typeof numOrBool === "boolean") { >typeof numOrBool === "boolean" : boolean >typeof numOrBool : string >numOrBool : number | boolean ->"boolean" : string +>"boolean" : "boolean" bool = numOrBool; // boolean >bool = numOrBool : boolean @@ -82,7 +82,7 @@ if (typeof strOrNumOrBool === "boolean") { >typeof strOrNumOrBool === "boolean" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"boolean" : string +>"boolean" : "boolean" bool = strOrNumOrBool; // boolean >bool = strOrNumOrBool : boolean @@ -99,7 +99,7 @@ if (typeof boolOrC === "boolean") { >typeof boolOrC === "boolean" : boolean >typeof boolOrC : string >boolOrC : boolean | C ->"boolean" : string +>"boolean" : "boolean" bool = boolOrC; // boolean >bool = boolOrC : boolean @@ -117,7 +117,7 @@ if (typeof strOrNum === "boolean") { >typeof strOrNum === "boolean" : boolean >typeof strOrNum : string >strOrNum : string | number ->"boolean" : string +>"boolean" : "boolean" let z1: {} = strOrNum; // {} >z1 : {} @@ -137,7 +137,7 @@ if (typeof strOrBool !== "boolean") { >typeof strOrBool !== "boolean" : boolean >typeof strOrBool : string >strOrBool : boolean | string ->"boolean" : string +>"boolean" : "boolean" str = strOrBool; // string >str = strOrBool : string @@ -154,7 +154,7 @@ if (typeof numOrBool !== "boolean") { >typeof numOrBool !== "boolean" : boolean >typeof numOrBool : string >numOrBool : boolean | number ->"boolean" : string +>"boolean" : "boolean" num = numOrBool; // number >num = numOrBool : number @@ -171,7 +171,7 @@ if (typeof strOrNumOrBool !== "boolean") { >typeof strOrNumOrBool !== "boolean" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : boolean | string | number ->"boolean" : string +>"boolean" : "boolean" strOrNum = strOrNumOrBool; // string | number >strOrNum = strOrNumOrBool : string | number @@ -188,7 +188,7 @@ if (typeof boolOrC !== "boolean") { >typeof boolOrC !== "boolean" : boolean >typeof boolOrC : string >boolOrC : boolean | C ->"boolean" : string +>"boolean" : "boolean" c = boolOrC; // C >c = boolOrC : C @@ -206,7 +206,7 @@ if (typeof strOrNum !== "boolean") { >typeof strOrNum !== "boolean" : boolean >typeof strOrNum : string >strOrNum : string | number ->"boolean" : string +>"boolean" : "boolean" let z1: string | number = strOrNum; // string | number >z1 : string | number diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.types b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.types index 2d91abb9613ac..43cc37f98e837 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.types @@ -25,7 +25,7 @@ var func: () => void; if ("string" === typeof strOrNum) { >"string" === typeof strOrNum : boolean ->"string" : string +>"string" : "string" >typeof strOrNum : string >strOrNum : string | number @@ -42,7 +42,7 @@ else { } if ("function" === typeof strOrFunc) { >"function" === typeof strOrFunc : boolean ->"function" : string +>"function" : "function" >typeof strOrFunc : string >strOrFunc : string | (() => void) @@ -59,7 +59,7 @@ else { } if ("number" === typeof numOrBool) { >"number" === typeof numOrBool : boolean ->"number" : string +>"number" : "number" >typeof numOrBool : string >numOrBool : number | boolean @@ -76,7 +76,7 @@ else { } if ("boolean" === typeof strOrBool) { >"boolean" === typeof strOrBool : boolean ->"boolean" : string +>"boolean" : "boolean" >typeof strOrBool : string >strOrBool : string | boolean diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types b/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types index c6a5615e75a8c..736cd14e88e8e 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types @@ -48,7 +48,7 @@ if (typeof strOrNum === "number") { >typeof strOrNum === "number" : boolean >typeof strOrNum : string >strOrNum : string | number ->"number" : string +>"number" : "number" num = strOrNum; // number >num = strOrNum : number @@ -65,7 +65,7 @@ if (typeof numOrBool === "number") { >typeof numOrBool === "number" : boolean >typeof numOrBool : string >numOrBool : number | boolean ->"number" : string +>"number" : "number" num = numOrBool; // number >num = numOrBool : number @@ -81,7 +81,7 @@ if (typeof strOrNumOrBool === "number") { >typeof strOrNumOrBool === "number" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"number" : string +>"number" : "number" num = strOrNumOrBool; // number >num = strOrNumOrBool : number @@ -98,7 +98,7 @@ if (typeof numOrC === "number") { >typeof numOrC === "number" : boolean >typeof numOrC : string >numOrC : number | C ->"number" : string +>"number" : "number" num = numOrC; // number >num = numOrC : number @@ -116,7 +116,7 @@ if (typeof strOrBool === "number") { >typeof strOrBool === "number" : boolean >typeof strOrBool : string >strOrBool : string | boolean ->"number" : string +>"number" : "number" let y1: {} = strOrBool; // {} >y1 : {} @@ -135,7 +135,7 @@ if (typeof strOrNum !== "number") { >typeof strOrNum !== "number" : boolean >typeof strOrNum : string >strOrNum : number | string ->"number" : string +>"number" : "number" str === strOrNum; // string >str === strOrNum : boolean @@ -152,7 +152,7 @@ if (typeof numOrBool !== "number") { >typeof numOrBool !== "number" : boolean >typeof numOrBool : string >numOrBool : number | boolean ->"number" : string +>"number" : "number" var x: number | boolean = numOrBool; // number | boolean >x : number | boolean @@ -168,7 +168,7 @@ if (typeof strOrNumOrBool !== "number") { >typeof strOrNumOrBool !== "number" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : number | string | boolean ->"number" : string +>"number" : "number" strOrBool = strOrNumOrBool; // string | boolean >strOrBool = strOrNumOrBool : string | boolean @@ -185,7 +185,7 @@ if (typeof numOrC !== "number") { >typeof numOrC !== "number" : boolean >typeof numOrC : string >numOrC : number | C ->"number" : string +>"number" : "number" c = numOrC; // C >c = numOrC : C @@ -203,7 +203,7 @@ if (typeof strOrBool !== "number") { >typeof strOrBool !== "number" : boolean >typeof strOrBool : string >strOrBool : string | boolean ->"number" : string +>"number" : "number" let y1: string | boolean = strOrBool; // string | boolean >y1 : string | boolean diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfOther.types b/tests/baselines/reference/typeGuardOfFormTypeOfOther.types index 8e42a8e0d8e26..3dfb720d88016 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfOther.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfOther.types @@ -52,7 +52,7 @@ if (typeof strOrC === "Object") { >typeof strOrC === "Object" : boolean >typeof strOrC : string >strOrC : string | C ->"Object" : string +>"Object" : "Object" c = strOrC; // C >c = strOrC : C @@ -68,7 +68,7 @@ if (typeof numOrC === "Object") { >typeof numOrC === "Object" : boolean >typeof numOrC : string >numOrC : number | C ->"Object" : string +>"Object" : "Object" c = numOrC; // C >c = numOrC : C @@ -84,7 +84,7 @@ if (typeof boolOrC === "Object") { >typeof boolOrC === "Object" : boolean >typeof boolOrC : string >boolOrC : boolean | C ->"Object" : string +>"Object" : "Object" c = boolOrC; // C >c = boolOrC : C @@ -101,7 +101,7 @@ if (typeof strOrNumOrBool === "Object") { >typeof strOrNumOrBool === "Object" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"Object" : string +>"Object" : "Object" let q1: {} = strOrNumOrBool; // {} >q1 : {} @@ -120,7 +120,7 @@ if (typeof strOrC !== "Object") { >typeof strOrC !== "Object" : boolean >typeof strOrC : string >strOrC : C | string ->"Object" : string +>"Object" : "Object" var r2: string = strOrC; // string >r2 : string @@ -136,7 +136,7 @@ if (typeof numOrC !== "Object") { >typeof numOrC !== "Object" : boolean >typeof numOrC : string >numOrC : C | number ->"Object" : string +>"Object" : "Object" var r3: number = numOrC; // number >r3 : number @@ -152,7 +152,7 @@ if (typeof boolOrC !== "Object") { >typeof boolOrC !== "Object" : boolean >typeof boolOrC : string >boolOrC : C | boolean ->"Object" : string +>"Object" : "Object" var r4: boolean = boolOrC; // boolean >r4 : boolean @@ -169,7 +169,7 @@ if (typeof strOrNumOrBool !== "Object") { >typeof strOrNumOrBool !== "Object" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"Object" : string +>"Object" : "Object" let q1: string | number | boolean = strOrNumOrBool; // string | number | boolean >q1 : string | number | boolean diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfPrimitiveSubtype.types b/tests/baselines/reference/typeGuardOfFormTypeOfPrimitiveSubtype.types index 7e88ca5cb94e5..6302ef58005c9 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfPrimitiveSubtype.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfPrimitiveSubtype.types @@ -10,7 +10,7 @@ if (typeof a === "number") { >typeof a === "number" : boolean >typeof a : string >a : {} ->"number" : string +>"number" : "number" let c: number = a; >c : number @@ -20,7 +20,7 @@ if (typeof a === "string") { >typeof a === "string" : boolean >typeof a : string >a : {} ->"string" : string +>"string" : "string" let c: string = a; >c : string @@ -30,7 +30,7 @@ if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string >a : {} ->"boolean" : string +>"boolean" : "boolean" let c: boolean = a; >c : boolean @@ -41,7 +41,7 @@ if (typeof b === "number") { >typeof b === "number" : boolean >typeof b : string >b : { toString(): string; } ->"number" : string +>"number" : "number" let c: number = b; >c : number @@ -51,7 +51,7 @@ if (typeof b === "string") { >typeof b === "string" : boolean >typeof b : string >b : { toString(): string; } ->"string" : string +>"string" : "string" let c: string = b; >c : string @@ -61,7 +61,7 @@ if (typeof b === "boolean") { >typeof b === "boolean" : boolean >typeof b : string >b : { toString(): string; } ->"boolean" : string +>"boolean" : "boolean" let c: boolean = b; >c : boolean diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfString.types b/tests/baselines/reference/typeGuardOfFormTypeOfString.types index 971109215f785..e9960ac3019db 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfString.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfString.types @@ -48,7 +48,7 @@ if (typeof strOrNum === "string") { >typeof strOrNum === "string" : boolean >typeof strOrNum : string >strOrNum : string | number ->"string" : string +>"string" : "string" str = strOrNum; // string >str = strOrNum : string @@ -65,7 +65,7 @@ if (typeof strOrBool === "string") { >typeof strOrBool === "string" : boolean >typeof strOrBool : string >strOrBool : string | boolean ->"string" : string +>"string" : "string" str = strOrBool; // string >str = strOrBool : string @@ -82,7 +82,7 @@ if (typeof strOrNumOrBool === "string") { >typeof strOrNumOrBool === "string" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"string" : string +>"string" : "string" str = strOrNumOrBool; // string >str = strOrNumOrBool : string @@ -99,7 +99,7 @@ if (typeof strOrC === "string") { >typeof strOrC === "string" : boolean >typeof strOrC : string >strOrC : string | C ->"string" : string +>"string" : "string" str = strOrC; // string >str = strOrC : string @@ -117,7 +117,7 @@ if (typeof numOrBool === "string") { >typeof numOrBool === "string" : boolean >typeof numOrBool : string >numOrBool : number | boolean ->"string" : string +>"string" : "string" let x1: {} = numOrBool; // {} >x1 : {} @@ -136,7 +136,7 @@ if (typeof strOrNum !== "string") { >typeof strOrNum !== "string" : boolean >typeof strOrNum : string >strOrNum : string | number ->"string" : string +>"string" : "string" num === strOrNum; // number >num === strOrNum : boolean @@ -153,7 +153,7 @@ if (typeof strOrBool !== "string") { >typeof strOrBool !== "string" : boolean >typeof strOrBool : string >strOrBool : string | boolean ->"string" : string +>"string" : "string" bool = strOrBool; // boolean >bool = strOrBool : boolean @@ -170,7 +170,7 @@ if (typeof strOrNumOrBool !== "string") { >typeof strOrNumOrBool !== "string" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"string" : string +>"string" : "string" numOrBool = strOrNumOrBool; // number | boolean >numOrBool = strOrNumOrBool : number | boolean @@ -187,7 +187,7 @@ if (typeof strOrC !== "string") { >typeof strOrC !== "string" : boolean >typeof strOrC : string >strOrC : string | C ->"string" : string +>"string" : "string" c = strOrC; // C >c = strOrC : C @@ -205,7 +205,7 @@ if (typeof numOrBool !== "string") { >typeof numOrBool !== "string" : boolean >typeof numOrBool : string >numOrBool : number | boolean ->"string" : string +>"string" : "string" let x1: number | boolean = numOrBool; // number | boolean >x1 : number | boolean diff --git a/tests/baselines/reference/typeGuardRedundancy.types b/tests/baselines/reference/typeGuardRedundancy.types index 754019de7ed7a..e028b4d11eb37 100644 --- a/tests/baselines/reference/typeGuardRedundancy.types +++ b/tests/baselines/reference/typeGuardRedundancy.types @@ -9,11 +9,11 @@ var r1 = typeof x === "string" && typeof x === "string" ? x.substr : x.toFixed; >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" >typeof x === "string" : boolean >typeof x : string >x : string ->"string" : string +>"string" : "string" >x.substr : (from: number, length?: number) => string >x : string >substr : (from: number, length?: number) => string @@ -30,11 +30,11 @@ var r2 = !(typeof x === "string" && typeof x === "string") ? x.toFixed : x.subst >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" >typeof x === "string" : boolean >typeof x : string >x : string ->"string" : string +>"string" : "string" >x.toFixed : (fractionDigits?: number) => string >x : number >toFixed : (fractionDigits?: number) => string @@ -49,11 +49,11 @@ var r3 = typeof x === "string" || typeof x === "string" ? x.substr : x.toFixed; >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" >typeof x === "string" : boolean >typeof x : string >x : number ->"string" : string +>"string" : "string" >x.substr : (from: number, length?: number) => string >x : string >substr : (from: number, length?: number) => string @@ -70,11 +70,11 @@ var r4 = !(typeof x === "string" || typeof x === "string") ? x.toFixed : x.subst >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" >typeof x === "string" : boolean >typeof x : string >x : number ->"string" : string +>"string" : "string" >x.toFixed : (fractionDigits?: number) => string >x : number >toFixed : (fractionDigits?: number) => string diff --git a/tests/baselines/reference/typeGuardTautologicalConsistiency.types b/tests/baselines/reference/typeGuardTautologicalConsistiency.types index 8e681deb07369..f86a9e66fa285 100644 --- a/tests/baselines/reference/typeGuardTautologicalConsistiency.types +++ b/tests/baselines/reference/typeGuardTautologicalConsistiency.types @@ -6,13 +6,13 @@ if (typeof stringOrNumber === "number") { >typeof stringOrNumber === "number" : boolean >typeof stringOrNumber : string >stringOrNumber : string | number ->"number" : string +>"number" : "number" if (typeof stringOrNumber !== "number") { >typeof stringOrNumber !== "number" : boolean >typeof stringOrNumber : string >stringOrNumber : number ->"number" : string +>"number" : "number" stringOrNumber; >stringOrNumber : string @@ -24,11 +24,11 @@ if (typeof stringOrNumber === "number" && typeof stringOrNumber !== "number") { >typeof stringOrNumber === "number" : boolean >typeof stringOrNumber : string >stringOrNumber : string | number ->"number" : string +>"number" : "number" >typeof stringOrNumber !== "number" : boolean >typeof stringOrNumber : string >stringOrNumber : number ->"number" : string +>"number" : "number" stringOrNumber; >stringOrNumber : string diff --git a/tests/baselines/reference/typeGuardTypeOfUndefined.types b/tests/baselines/reference/typeGuardTypeOfUndefined.types index 167d6204a9898..d20eca99ca17a 100644 --- a/tests/baselines/reference/typeGuardTypeOfUndefined.types +++ b/tests/baselines/reference/typeGuardTypeOfUndefined.types @@ -8,13 +8,13 @@ function test1(a: any) { >typeof a !== "undefined" : boolean >typeof a : string >a : any ->"undefined" : string +>"undefined" : "undefined" if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string >a : any ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean @@ -38,13 +38,13 @@ function test2(a: any) { >typeof a === "undefined" : boolean >typeof a : string >a : any ->"undefined" : string +>"undefined" : "undefined" if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string >a : undefined ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean @@ -69,11 +69,11 @@ function test3(a: any) { >typeof a === "undefined" : boolean >typeof a : string >a : any ->"undefined" : string +>"undefined" : "undefined" >typeof a === "boolean" : boolean >typeof a : string >a : any ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean @@ -93,11 +93,11 @@ function test4(a: any) { >typeof a !== "undefined" : boolean >typeof a : string >a : any ->"undefined" : string +>"undefined" : "undefined" >typeof a === "boolean" : boolean >typeof a : string >a : any ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean @@ -116,13 +116,13 @@ function test5(a: boolean | void) { >typeof a !== "undefined" : boolean >typeof a : string >a : boolean | void ->"undefined" : string +>"undefined" : "undefined" if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string >a : boolean ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean @@ -146,13 +146,13 @@ function test6(a: boolean | void) { >typeof a === "undefined" : boolean >typeof a : string >a : boolean | void ->"undefined" : string +>"undefined" : "undefined" if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string >a : boolean | void ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean @@ -177,11 +177,11 @@ function test7(a: boolean | void) { >typeof a === "undefined" : boolean >typeof a : string >a : boolean | void ->"undefined" : string +>"undefined" : "undefined" >typeof a === "boolean" : boolean >typeof a : string >a : boolean ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean | void @@ -201,11 +201,11 @@ function test8(a: boolean | void) { >typeof a !== "undefined" : boolean >typeof a : string >a : boolean | void ->"undefined" : string +>"undefined" : "undefined" >typeof a === "boolean" : boolean >typeof a : string >a : boolean ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean @@ -224,13 +224,13 @@ function test9(a: boolean | number) { >typeof a !== "undefined" : boolean >typeof a : string >a : boolean | number ->"undefined" : string +>"undefined" : "undefined" if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string >a : boolean | number ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean @@ -254,13 +254,13 @@ function test10(a: boolean | number) { >typeof a === "undefined" : boolean >typeof a : string >a : boolean | number ->"undefined" : string +>"undefined" : "undefined" if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string >a : boolean | number ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean @@ -285,11 +285,11 @@ function test11(a: boolean | number) { >typeof a === "undefined" : boolean >typeof a : string >a : boolean | number ->"undefined" : string +>"undefined" : "undefined" >typeof a === "boolean" : boolean >typeof a : string >a : boolean | number ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean | number @@ -309,11 +309,11 @@ function test12(a: boolean | number) { >typeof a !== "undefined" : boolean >typeof a : string >a : boolean | number ->"undefined" : string +>"undefined" : "undefined" >typeof a === "boolean" : boolean >typeof a : string >a : boolean | number ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean @@ -332,13 +332,13 @@ function test13(a: boolean | number | void) { >typeof a !== "undefined" : boolean >typeof a : string >a : boolean | number | void ->"undefined" : string +>"undefined" : "undefined" if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string >a : boolean | number ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean @@ -362,13 +362,13 @@ function test14(a: boolean | number | void) { >typeof a === "undefined" : boolean >typeof a : string >a : boolean | number | void ->"undefined" : string +>"undefined" : "undefined" if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string >a : boolean | number | void ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean @@ -393,11 +393,11 @@ function test15(a: boolean | number | void) { >typeof a === "undefined" : boolean >typeof a : string >a : boolean | number | void ->"undefined" : string +>"undefined" : "undefined" >typeof a === "boolean" : boolean >typeof a : string >a : boolean | number ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean | number | void @@ -417,11 +417,11 @@ function test16(a: boolean | number | void) { >typeof a !== "undefined" : boolean >typeof a : string >a : boolean | number | void ->"undefined" : string +>"undefined" : "undefined" >typeof a === "boolean" : boolean >typeof a : string >a : boolean | number ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean diff --git a/tests/baselines/reference/typeGuardsAsAssertions.types b/tests/baselines/reference/typeGuardsAsAssertions.types index 82e92a72d8d08..37018c654a897 100644 --- a/tests/baselines/reference/typeGuardsAsAssertions.types +++ b/tests/baselines/reference/typeGuardsAsAssertions.types @@ -120,7 +120,7 @@ function foo1() { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" >x.slice() : string >x.slice : (start?: number | undefined, end?: number | undefined) => string >x : string @@ -154,7 +154,7 @@ function foo2() { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" x = x.slice(); >x = x.slice() : string @@ -213,7 +213,7 @@ function f2() { >typeof x === "string" : boolean >typeof x : string >x : undefined ->"string" : string +>"string" : "string" x; // string (guard as assertion) >x : string @@ -256,7 +256,7 @@ function f4() { >typeof x === "boolean" : boolean >typeof x : string >x : undefined ->"boolean" : string +>"boolean" : "boolean" x; // nothing (boolean not in declared type) >x : never @@ -274,11 +274,11 @@ function f5(x: string | number) { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" >typeof x === "number" : boolean >typeof x : string >x : string ->"number" : string +>"number" : "number" x; // number (guard as assertion) >x : number diff --git a/tests/baselines/reference/typeGuardsInClassAccessors.types b/tests/baselines/reference/typeGuardsInClassAccessors.types index bdba5e9c116a3..2250657e453a9 100644 --- a/tests/baselines/reference/typeGuardsInClassAccessors.types +++ b/tests/baselines/reference/typeGuardsInClassAccessors.types @@ -28,7 +28,7 @@ class ClassWithAccessors { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -44,7 +44,7 @@ class ClassWithAccessors { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -65,7 +65,7 @@ class ClassWithAccessors { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -78,7 +78,7 @@ class ClassWithAccessors { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -94,7 +94,7 @@ class ClassWithAccessors { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -111,7 +111,7 @@ class ClassWithAccessors { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -127,7 +127,7 @@ class ClassWithAccessors { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -148,7 +148,7 @@ class ClassWithAccessors { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -161,7 +161,7 @@ class ClassWithAccessors { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -177,7 +177,7 @@ class ClassWithAccessors { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -194,7 +194,7 @@ class ClassWithAccessors { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -210,7 +210,7 @@ class ClassWithAccessors { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -231,7 +231,7 @@ class ClassWithAccessors { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -244,7 +244,7 @@ class ClassWithAccessors { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -260,7 +260,7 @@ class ClassWithAccessors { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -277,7 +277,7 @@ class ClassWithAccessors { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -293,7 +293,7 @@ class ClassWithAccessors { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -314,7 +314,7 @@ class ClassWithAccessors { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -327,7 +327,7 @@ class ClassWithAccessors { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -343,7 +343,7 @@ class ClassWithAccessors { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number diff --git a/tests/baselines/reference/typeGuardsInClassMethods.types b/tests/baselines/reference/typeGuardsInClassMethods.types index b3e20c88ed381..600e3e36ab0f2 100644 --- a/tests/baselines/reference/typeGuardsInClassMethods.types +++ b/tests/baselines/reference/typeGuardsInClassMethods.types @@ -23,7 +23,7 @@ class C1 { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -39,7 +39,7 @@ class C1 { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -52,7 +52,7 @@ class C1 { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -70,7 +70,7 @@ class C1 { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -86,7 +86,7 @@ class C1 { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -99,7 +99,7 @@ class C1 { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -117,7 +117,7 @@ class C1 { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -133,7 +133,7 @@ class C1 { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -146,7 +146,7 @@ class C1 { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -164,7 +164,7 @@ class C1 { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -180,7 +180,7 @@ class C1 { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -193,7 +193,7 @@ class C1 { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -211,7 +211,7 @@ class C1 { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -227,7 +227,7 @@ class C1 { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -240,7 +240,7 @@ class C1 { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number diff --git a/tests/baselines/reference/typeGuardsInConditionalExpression.types b/tests/baselines/reference/typeGuardsInConditionalExpression.types index cc1459738e4d8..3224dc48b5b3b 100644 --- a/tests/baselines/reference/typeGuardsInConditionalExpression.types +++ b/tests/baselines/reference/typeGuardsInConditionalExpression.types @@ -15,7 +15,7 @@ function foo(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" ? x.length // string >x.length : number @@ -35,7 +35,7 @@ function foo2(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" ? ((x = "hello") && x) // string >((x = "hello") && x) : string @@ -58,7 +58,7 @@ function foo3(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" ? ((x = 10) && x) // number >((x = 10) && x) : number @@ -81,7 +81,7 @@ function foo4(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" ? x // string >x : string @@ -104,7 +104,7 @@ function foo5(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" ? x // string >x : string @@ -128,7 +128,7 @@ function foo6(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" ? ((x = 10) && x) // number >((x = 10) && x) : number @@ -157,19 +157,19 @@ function foo7(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" ? x === "hello" // boolean >x === "hello" : boolean >x : string ->"hello" : string +>"hello" : "hello" : typeof x === "boolean" >typeof x === "boolean" ? x // boolean : x == 10 : boolean >typeof x === "boolean" : boolean >typeof x : string >x : number | boolean ->"boolean" : string +>"boolean" : "boolean" ? x // boolean >x : boolean @@ -177,7 +177,7 @@ function foo7(x: number | string | boolean) { : x == 10; // boolean >x == 10 : boolean >x : number ->10 : number +>10 : 10 } function foo8(x: number | string | boolean) { >foo8 : (x: number | string | boolean) => boolean @@ -191,12 +191,12 @@ function foo8(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" ? x === "hello" >x === "hello" : boolean >x : string ->"hello" : string +>"hello" : "hello" : ((b = x) && // number | boolean >((b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10)) : boolean @@ -212,7 +212,7 @@ function foo8(x: number | string | boolean) { >typeof x === "boolean" : boolean >typeof x : string >x : number | boolean ->"boolean" : string +>"boolean" : "boolean" ? x // boolean >x : boolean @@ -220,7 +220,7 @@ function foo8(x: number | string | boolean) { : x == 10)); // boolean >x == 10 : boolean >x : number ->10 : number +>10 : 10 } function foo9(x: number | string) { >foo9 : (x: number | string) => boolean @@ -236,7 +236,7 @@ function foo9(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" ? ((y = x.length) && x === "hello") // boolean >((y = x.length) && x === "hello") : boolean @@ -249,12 +249,12 @@ function foo9(x: number | string) { >length : number >x === "hello" : boolean >x : string ->"hello" : string +>"hello" : "hello" : x === 10; // boolean >x === 10 : boolean >x : number ->10 : number +>10 : 10 } function foo10(x: number | string | boolean) { >foo10 : (x: number | string | boolean) => string @@ -269,7 +269,7 @@ function foo10(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" ? x // string >x : string @@ -287,7 +287,7 @@ function foo10(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" && x.toString()); // x is number >x.toString() : string @@ -308,7 +308,7 @@ function foo11(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" ? x // string >x : string @@ -327,7 +327,7 @@ function foo11(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" && (x = 10) // assignment to x >(x = 10) : number @@ -351,7 +351,7 @@ function foo12(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" ? ((x = 10) && x.toString().length) // number >((x = 10) && x.toString().length) : number @@ -380,7 +380,7 @@ function foo12(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" && x); // x is number >x : number diff --git a/tests/baselines/reference/typeGuardsInDoStatement.types b/tests/baselines/reference/typeGuardsInDoStatement.types index 79183e7d6c8d4..3000764051dc2 100644 --- a/tests/baselines/reference/typeGuardsInDoStatement.types +++ b/tests/baselines/reference/typeGuardsInDoStatement.types @@ -24,7 +24,7 @@ function a(x: string | number | boolean) { >typeof x === "string" : boolean >typeof x : string >x : string | number | boolean ->"string" : string +>"string" : "string" x; // number | boolean >x : number | boolean @@ -54,7 +54,7 @@ function b(x: string | number | boolean) { >typeof x === "string" : boolean >typeof x : string >x : string | number | boolean ->"string" : string +>"string" : "string" x; // number | boolean >x : number | boolean @@ -84,7 +84,7 @@ function c(x: string | number) { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" x; // string | number >x : string | number diff --git a/tests/baselines/reference/typeGuardsInExternalModule.types b/tests/baselines/reference/typeGuardsInExternalModule.types index 940e7db831adf..a0c33af455742 100644 --- a/tests/baselines/reference/typeGuardsInExternalModule.types +++ b/tests/baselines/reference/typeGuardsInExternalModule.types @@ -13,7 +13,7 @@ if (typeof var1 === "string") { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" num = var1.length; // string >num = var1.length : number @@ -40,7 +40,7 @@ if (typeof var2 === "string") { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" // export makes the var property and not variable strOrNum = var2; // string | number diff --git a/tests/baselines/reference/typeGuardsInForStatement.types b/tests/baselines/reference/typeGuardsInForStatement.types index 5ebdea53c31d2..6a7561bb436a6 100644 --- a/tests/baselines/reference/typeGuardsInForStatement.types +++ b/tests/baselines/reference/typeGuardsInForStatement.types @@ -13,7 +13,7 @@ function a(x: string | number) { >typeof x !== "number" : boolean >typeof x : string >x : string | number ->"number" : string +>"number" : "number" >x = undefined : undefined >x : string | number >undefined : undefined @@ -35,7 +35,7 @@ function b(x: string | number) { >typeof x !== "number" : boolean >typeof x : string >x : string | number ->"number" : string +>"number" : "number" >x = undefined : undefined >x : string | number >undefined : undefined @@ -60,7 +60,7 @@ function c(x: string | number) { >typeof x !== "number" : boolean >typeof x : string >x : string | number ->"number" : string +>"number" : "number" >x = undefined : undefined >x : string | number >undefined : undefined diff --git a/tests/baselines/reference/typeGuardsInFunction.types b/tests/baselines/reference/typeGuardsInFunction.types index 5ae489ce48a8e..6a007dd7c955e 100644 --- a/tests/baselines/reference/typeGuardsInFunction.types +++ b/tests/baselines/reference/typeGuardsInFunction.types @@ -22,7 +22,7 @@ function f(param: string | number) { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -38,7 +38,7 @@ function f(param: string | number) { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -51,7 +51,7 @@ function f(param: string | number) { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -76,7 +76,7 @@ function f1(param: string | number) { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -89,7 +89,7 @@ function f1(param: string | number) { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -102,7 +102,7 @@ function f1(param: string | number) { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -118,7 +118,7 @@ function f1(param: string | number) { >typeof var3 === "string" : boolean >typeof var3 : string >var3 : string | number ->"string" : string +>"string" : "string" >var3.length : number >var3 : string >length : number @@ -130,7 +130,7 @@ function f1(param: string | number) { >typeof param1 === "string" : boolean >typeof param1 : string >param1 : string | number ->"string" : string +>"string" : "string" >param1.length : number >param1 : string >length : number @@ -160,7 +160,7 @@ function f2(param: string | number) { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -173,7 +173,7 @@ function f2(param: string | number) { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -186,7 +186,7 @@ function f2(param: string | number) { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -202,7 +202,7 @@ function f2(param: string | number) { >typeof var3 === "string" : boolean >typeof var3 : string >var3 : string | number ->"string" : string +>"string" : "string" >var3.length : number >var3 : string >length : number @@ -214,7 +214,7 @@ function f2(param: string | number) { >typeof param1 === "string" : boolean >typeof param1 : string >param1 : string | number ->"string" : string +>"string" : "string" >param1.length : number >param1 : string >length : number @@ -247,7 +247,7 @@ function f3(param: string | number) { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -260,7 +260,7 @@ function f3(param: string | number) { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -273,7 +273,7 @@ function f3(param: string | number) { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -289,7 +289,7 @@ function f3(param: string | number) { >typeof var3 === "string" : boolean >typeof var3 : string >var3 : string | number ->"string" : string +>"string" : "string" >var3.length : number >var3 : string >length : number @@ -301,7 +301,7 @@ function f3(param: string | number) { >typeof param1 === "string" : boolean >typeof param1 : string >param1 : string | number ->"string" : string +>"string" : "string" >param1.length : number >param1 : string >length : number @@ -332,7 +332,7 @@ strOrNum = typeof f4() === "string" && f4(); // string | number >typeof f4() : string >f4() : string | number >f4 : () => string | number ->"string" : string +>"string" : "string" >f4() : string | number >f4 : () => string | number diff --git a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types index cc9553b976728..946ac9d71ed72 100644 --- a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types +++ b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types @@ -10,7 +10,7 @@ function foo(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" ? x >x : string @@ -29,7 +29,7 @@ function foo(x: number | string | boolean) { >typeof x === "boolean" : boolean >typeof x : string >x : number | boolean ->"boolean" : string +>"boolean" : "boolean" ? x.toString() // boolean >x.toString() : string @@ -54,7 +54,7 @@ function foo2(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" ? x >x : string @@ -74,7 +74,7 @@ function foo2(x: number | string | boolean) { >typeof x === "boolean" : boolean >typeof x : string >x : number | boolean ->"boolean" : string +>"boolean" : "boolean" ? x.toString() // boolean >x.toString() : string @@ -100,7 +100,7 @@ function foo3(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" ? x >x : string @@ -119,7 +119,7 @@ function foo3(x: number | string | boolean) { >typeof x === "boolean" : boolean >typeof x : string >x : number | boolean ->"boolean" : string +>"boolean" : "boolean" ? x.toString() // boolean >x.toString() : string @@ -144,7 +144,7 @@ function foo4(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" ? x >x : string @@ -164,7 +164,7 @@ function foo4(x: number | string | boolean) { >typeof x === "boolean" : boolean >typeof x : string >x : number | boolean ->"boolean" : string +>"boolean" : "boolean" ? x.toString() // boolean >x.toString() : string @@ -190,7 +190,7 @@ function foo5(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" var y = x; // string; >y : string @@ -225,7 +225,7 @@ module m { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" y = x // string; >y = x : string @@ -240,7 +240,7 @@ module m { >typeof x === "boolean" : boolean >typeof x : string >x : number | boolean ->"boolean" : string +>"boolean" : "boolean" ? x.toString() // boolean >x.toString() : string @@ -277,7 +277,7 @@ module m1 { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" y = x // string; >y = x : string @@ -292,7 +292,7 @@ module m1 { >typeof x === "boolean" : boolean >typeof x : string >x : number | boolean ->"boolean" : string +>"boolean" : "boolean" ? x.toString() // boolean >x.toString() : string diff --git a/tests/baselines/reference/typeGuardsInGlobal.types b/tests/baselines/reference/typeGuardsInGlobal.types index b64c1edcc1341..7935c05411e2e 100644 --- a/tests/baselines/reference/typeGuardsInGlobal.types +++ b/tests/baselines/reference/typeGuardsInGlobal.types @@ -13,7 +13,7 @@ if (typeof var1 === "string") { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" num = var1.length; // string >num = var1.length : number diff --git a/tests/baselines/reference/typeGuardsInModule.types b/tests/baselines/reference/typeGuardsInModule.types index 7d3753037ad38..f1efc45a2484f 100644 --- a/tests/baselines/reference/typeGuardsInModule.types +++ b/tests/baselines/reference/typeGuardsInModule.types @@ -24,7 +24,7 @@ module m1 { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -37,7 +37,7 @@ module m1 { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" num = var2.length; // string >num = var2.length : number @@ -61,7 +61,7 @@ module m1 { >typeof var3 === "string" : boolean >typeof var3 : string >var3 : string | number ->"string" : string +>"string" : "string" strOrNum = var3; // string | number >strOrNum = var3 : string @@ -96,7 +96,7 @@ module m2 { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -109,7 +109,7 @@ module m2 { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -122,7 +122,7 @@ module m2 { >typeof var3 === "string" : boolean >typeof var3 : string >var3 : string | number ->"string" : string +>"string" : "string" >var3 : string // variables in module declaration @@ -133,7 +133,7 @@ module m2 { >typeof var4 === "string" : boolean >typeof var4 : string >var4 : string | number ->"string" : string +>"string" : "string" num = var4.length; // string >num = var4.length : number @@ -157,7 +157,7 @@ module m2 { >typeof var5 === "string" : boolean >typeof var5 : string >var5 : string | number ->"string" : string +>"string" : "string" strOrNum = var5; // string | number >strOrNum = var5 : string @@ -185,7 +185,7 @@ module m3.m4 { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -198,7 +198,7 @@ module m3.m4 { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" num = var2.length; // string >num = var2.length : number @@ -222,7 +222,7 @@ module m3.m4 { >typeof var3 === "string" : boolean >typeof var3 : string >var3 : string | number ->"string" : string +>"string" : "string" strOrNum = var3; // string | number >strOrNum = var3 : string diff --git a/tests/baselines/reference/typeGuardsInProperties.types b/tests/baselines/reference/typeGuardsInProperties.types index 4ddf8af7a6768..1f8151dff7133 100644 --- a/tests/baselines/reference/typeGuardsInProperties.types +++ b/tests/baselines/reference/typeGuardsInProperties.types @@ -37,7 +37,7 @@ class C1 { >this.pp1 : string | number >this : this >pp1 : string | number ->"string" : string +>"string" : "string" >this.pp1 : string >this : this >pp1 : string @@ -51,7 +51,7 @@ class C1 { >this.pp2 : string | number >this : this >pp2 : string | number ->"string" : string +>"string" : "string" >this.pp2 : string >this : this >pp2 : string @@ -65,7 +65,7 @@ class C1 { >this.pp3 : string | number >this : this >pp3 : string | number ->"string" : string +>"string" : "string" >this.pp3 : string >this : this >pp3 : string @@ -84,7 +84,7 @@ strOrNum = typeof c1.pp2 === "string" && c1.pp2; // string | number >c1.pp2 : string | number >c1 : C1 >pp2 : string | number ->"string" : string +>"string" : "string" >c1.pp2 : string >c1 : C1 >pp2 : string @@ -98,7 +98,7 @@ strOrNum = typeof c1.pp3 === "string" && c1.pp3; // string | number >c1.pp3 : string | number >c1 : C1 >pp3 : string | number ->"string" : string +>"string" : "string" >c1.pp3 : string >c1 : C1 >pp3 : string @@ -119,7 +119,7 @@ strOrNum = typeof obj1.x === "string" && obj1.x; // string | number >obj1.x : string | number >obj1 : { x: string | number; } >x : string | number ->"string" : string +>"string" : "string" >obj1.x : string >obj1 : { x: string | number; } >x : string diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types index 2da52b8b1b8c7..379e26fbb7e9b 100644 --- a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types +++ b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types @@ -10,12 +10,12 @@ function foo(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" >x.length === 10 : boolean >x.length : number >x : string >length : number ->10 : number +>10 : 10 } function foo2(x: number | string) { >foo2 : (x: number | string) => number @@ -27,7 +27,7 @@ function foo2(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" >((x = 10) && x) : number >(x = 10) && x : number >(x = 10) : number @@ -46,7 +46,7 @@ function foo3(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" >((x = "hello") && x) : string >(x = "hello") && x : string >(x = "hello") : string @@ -65,13 +65,13 @@ function foo4(x: number | string | boolean) { >typeof x !== "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" && typeof x !== "number" // number | boolean >typeof x !== "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" && x; // boolean >x : boolean @@ -89,7 +89,7 @@ function foo5(x: number | string | boolean) { >typeof x !== "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" && ((b = x) && (typeof x !== "number" // number | boolean >((b = x) && (typeof x !== "number" // number | boolean && x)) : boolean @@ -103,7 +103,7 @@ function foo5(x: number | string | boolean) { >typeof x !== "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" && x)); // boolean >x : boolean @@ -118,7 +118,7 @@ function foo6(x: number | string | boolean) { >typeof x !== "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" && (typeof x !== "number" // number | boolean >(typeof x !== "number" // number | boolean ? x // boolean : x === 10) : boolean @@ -126,7 +126,7 @@ function foo6(x: number | string | boolean) { >typeof x !== "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" ? x // boolean >x : boolean @@ -134,7 +134,7 @@ function foo6(x: number | string | boolean) { : x === 10) // number >x === 10 : boolean >x : number ->10 : number +>10 : 10 } function foo7(x: number | string | boolean) { >foo7 : (x: number | string | boolean) => string @@ -152,7 +152,7 @@ function foo7(x: number | string | boolean) { >typeof x !== "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" && ((z = x) // number | boolean >((z = x) // number | boolean && (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // x is number // do not change value : ((y = x) && x.toString()))) : string @@ -168,7 +168,7 @@ function foo7(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" // change value of x ? ((x = 10) && x.toString()) // x is number diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types index 659182ab888cf..b251664e9ee2f 100644 --- a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types +++ b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types @@ -11,12 +11,12 @@ function foo(x: number | string) { >typeof x !== "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" >x.length === 10 : boolean >x.length : number >x : string >length : number ->10 : number +>10 : 10 } function foo2(x: number | string) { >foo2 : (x: number | string) => boolean | number @@ -28,7 +28,7 @@ function foo2(x: number | string) { >typeof x !== "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" >((x = 10) || x) : number >(x = 10) || x : number >(x = 10) : number @@ -47,7 +47,7 @@ function foo3(x: number | string) { >typeof x !== "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" >((x = "hello") || x) : string >(x = "hello") || x : string >(x = "hello") : string @@ -66,13 +66,13 @@ function foo4(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" || typeof x === "number" // number | boolean >typeof x === "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" || x; // boolean >x : boolean @@ -90,7 +90,7 @@ function foo5(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" || ((b = x) || (typeof x === "number" // number | boolean >((b = x) || (typeof x === "number" // number | boolean || x)) : number | boolean @@ -104,7 +104,7 @@ function foo5(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" || x)); // boolean >x : boolean @@ -119,7 +119,7 @@ function foo6(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" || (typeof x !== "number" // number | boolean >(typeof x !== "number" // number | boolean ? x // boolean : x === 10) : boolean @@ -127,7 +127,7 @@ function foo6(x: number | string | boolean) { >typeof x !== "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" ? x // boolean >x : boolean @@ -135,7 +135,7 @@ function foo6(x: number | string | boolean) { : x === 10) // number >x === 10 : boolean >x : number ->10 : number +>10 : 10 } function foo7(x: number | string | boolean) { >foo7 : (x: number | string | boolean) => boolean | number | string @@ -153,7 +153,7 @@ function foo7(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" || ((z = x) // number | boolean >((z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString()))) : number | boolean | string @@ -169,7 +169,7 @@ function foo7(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string diff --git a/tests/baselines/reference/typeGuardsInWhileStatement.types b/tests/baselines/reference/typeGuardsInWhileStatement.types index cde045cc621c3..1786871f814de 100644 --- a/tests/baselines/reference/typeGuardsInWhileStatement.types +++ b/tests/baselines/reference/typeGuardsInWhileStatement.types @@ -10,7 +10,7 @@ function a(x: string | number) { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" x; // string >x : string @@ -31,7 +31,7 @@ function b(x: string | number) { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" if (cond) continue; >cond : boolean @@ -55,7 +55,7 @@ function c(x: string | number) { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" if (cond) break; >cond : boolean diff --git a/tests/baselines/reference/typeGuardsNestedAssignments.types b/tests/baselines/reference/typeGuardsNestedAssignments.types index 566a39a9c23d1..3b125d4f32c1b 100644 --- a/tests/baselines/reference/typeGuardsNestedAssignments.types +++ b/tests/baselines/reference/typeGuardsNestedAssignments.types @@ -109,7 +109,7 @@ function f4() { >x : string | number | null >getStringOrNumberOrNull() : string | number | null >getStringOrNumberOrNull : () => string | number | null ->"number" : string +>"number" : "number" x; >x : number diff --git a/tests/baselines/reference/typeGuardsObjectMethods.types b/tests/baselines/reference/typeGuardsObjectMethods.types index f409bf5caf9bf..5a795c336e257 100644 --- a/tests/baselines/reference/typeGuardsObjectMethods.types +++ b/tests/baselines/reference/typeGuardsObjectMethods.types @@ -30,7 +30,7 @@ var obj1 = { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -46,7 +46,7 @@ var obj1 = { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -59,7 +59,7 @@ var obj1 = { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -79,7 +79,7 @@ var obj1 = { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -95,7 +95,7 @@ var obj1 = { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -116,7 +116,7 @@ var obj1 = { >typeof var1 === "string" : boolean >typeof var1 : string >var1 : string | number ->"string" : string +>"string" : "string" >var1.length : number >var1 : string >length : number @@ -132,7 +132,7 @@ var obj1 = { >typeof var2 === "string" : boolean >typeof var2 : string >var2 : string | number ->"string" : string +>"string" : "string" >var2.length : number >var2 : string >length : number @@ -145,7 +145,7 @@ var obj1 = { >typeof param === "string" : boolean >typeof param : string >param : string | number ->"string" : string +>"string" : "string" >param.length : number >param : string >length : number @@ -163,7 +163,7 @@ strOrNum = typeof obj1.method(strOrNum) === "string" && obj1.method(strOrNum); >obj1 : { method(param: string | number): string | number; prop: string | number; } >method : (param: string | number) => string | number >strOrNum : string | number ->"string" : string +>"string" : "string" >obj1.method(strOrNum) : string | number >obj1.method : (param: string | number) => string | number >obj1 : { method(param: string | number): string | number; prop: string | number; } @@ -180,7 +180,7 @@ strOrNum = typeof obj1.prop === "string" && obj1.prop; >obj1.prop : string | number >obj1 : { method(param: string | number): string | number; prop: string | number; } >prop : string | number ->"string" : string +>"string" : "string" >obj1.prop : string >obj1 : { method(param: string | number): string | number; prop: string | number; } >prop : string diff --git a/tests/baselines/reference/typeGuardsOnClassProperty.types b/tests/baselines/reference/typeGuardsOnClassProperty.types index 6d524ccf6744c..b4ca9c0b1221a 100644 --- a/tests/baselines/reference/typeGuardsOnClassProperty.types +++ b/tests/baselines/reference/typeGuardsOnClassProperty.types @@ -24,7 +24,7 @@ class D { >typeof data === "string" : boolean >typeof data : string >data : string | string[] ->"string" : string +>"string" : "string" >data : string >data.join(" ") : string >data.join : (separator?: string) => string @@ -43,7 +43,7 @@ class D { >this.data : string | string[] >this : this >data : string | string[] ->"string" : string +>"string" : "string" >this.data : string >this : this >data : string @@ -85,7 +85,7 @@ if (typeof o.prop1 === "string" && o.prop1.toLowerCase()) {} >o.prop1 : number | string >o : { prop1: number | string; prop2: boolean | string; } >prop1 : number | string ->"string" : string +>"string" : "string" >o.prop1.toLowerCase() : string >o.prop1.toLowerCase : () => string >o.prop1 : string @@ -104,7 +104,7 @@ if (typeof prop1 === "string" && prop1.toLocaleLowerCase()) { } >typeof prop1 === "string" : boolean >typeof prop1 : string >prop1 : number | string ->"string" : string +>"string" : "string" >prop1.toLocaleLowerCase() : string >prop1.toLocaleLowerCase : () => string >prop1 : string diff --git a/tests/baselines/reference/uncaughtCompilerError1.types b/tests/baselines/reference/uncaughtCompilerError1.types index 20a3f0fbedd87..83503195f713e 100644 --- a/tests/baselines/reference/uncaughtCompilerError1.types +++ b/tests/baselines/reference/uncaughtCompilerError1.types @@ -19,7 +19,7 @@ function f() { >lineTokens : any >index : any >trim : any ->'=' : string +>'=' : "=" >index > 0 : boolean >index : any >0 : number @@ -27,7 +27,7 @@ function f() { >token.type : any >token : any >type : any ->'' : string +>'' : "" >tokens[index - 1].type === 'attribute.name.html' : boolean >tokens[index - 1].type : any >tokens[index - 1] : any @@ -36,7 +36,7 @@ function f() { >index : any >1 : number >type : any ->'attribute.name.html' : string +>'attribute.name.html' : "attribute.name.html" if (index === (tokens.length - 1)) { >index === (tokens.length - 1) : boolean @@ -65,7 +65,7 @@ function f() { >index : any >1 : number >type : any ->'attribute.value.html' : string +>'attribute.value.html' : "attribute.value.html" >tokens[index + 1].type !== '' : boolean >tokens[index + 1].type : any >tokens[index + 1] : any @@ -74,7 +74,7 @@ function f() { >index : any >1 : number >type : any ->'' : string +>'' : "" return { appendText: '\"\"', advanceCount: 1 }; >{ appendText: '\"\"', advanceCount: 1 } : { appendText: string; advanceCount: number; } diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index 37f3bdb12ab13..fcb329193f29f 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -149,7 +149,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); >num % 2 : number >num : number >2 : number ->0 : number +>0 : 0 var evens = _.filter([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); >evens : number[] @@ -170,7 +170,7 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); >num % 2 : number >num : number >2 : number ->0 : number +>0 : 0 var listOfPlays = [{ title: "Cymbeline", author: "Shakespeare", year: 1611 }, { title: "The Tempest", author: "Shakespeare", year: 1611 }, { title: "Other", author: "Not Shakespeare", year: 2012 }]; >listOfPlays : { title: string; author: string; year: number; }[] @@ -228,7 +228,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], (num) => num % 2 == 0); >num % 2 : number >num : number >2 : number ->0 : number +>0 : 0 _.all([true, 1, null, 'yes'], _.identity); >_.all([true, 1, null, 'yes'], _.identity) : boolean @@ -425,7 +425,7 @@ _.countBy([1, 2, 3, 4, 5], (num) => num % 2 == 0 ? 'even' : 'odd'); >num % 2 : number >num : number >2 : number ->0 : number +>0 : 0 >'even' : string >'odd' : string @@ -1249,7 +1249,7 @@ _.chain([1, 2, 3, 200]) >num % 2 : number >num : number >2 : number ->0 : number +>0 : 0 .tap(alert) >tap : (interceptor: (object: number[]) => void) => Underscore.ChainedArray diff --git a/tests/baselines/reference/unionTypeInference.types b/tests/baselines/reference/unionTypeInference.types index 58aa450c81395..ff204cfdac9a9 100644 --- a/tests/baselines/reference/unionTypeInference.types +++ b/tests/baselines/reference/unionTypeInference.types @@ -94,11 +94,11 @@ function h(x: string|boolean|T): T { >typeof x === "string" : boolean >typeof x : string >x : string | boolean | T ->"string" : string +>"string" : "string" >typeof x === "boolean" : boolean >typeof x : string >x : boolean | T ->"boolean" : string +>"boolean" : "boolean" >undefined : undefined >x : T } diff --git a/tests/baselines/reference/voidAsOperator.types b/tests/baselines/reference/voidAsOperator.types index 8f2a2951fcabb..0394e767fd9cc 100644 --- a/tests/baselines/reference/voidAsOperator.types +++ b/tests/baselines/reference/voidAsOperator.types @@ -4,7 +4,7 @@ if (!void 0 !== true) { >!void 0 : boolean >void 0 : undefined >0 : number ->true : boolean +>true : true } @@ -13,7 +13,7 @@ if (!null !== true) { >!null !== true : boolean >!null : boolean >null : null ->true : boolean +>true : true } From a91f71488bb40b67f069ad1071e46367e5e9b507 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 20 Jun 2016 20:24:54 -0700 Subject: [PATCH 05/55] Literal types for const enum members --- src/compiler/checker.ts | 20 +++++++++++++------- src/compiler/types.ts | 21 ++++++++++----------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e2515c1e3866e..1bc9ef3e67c6c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3686,7 +3686,7 @@ namespace ts { if (symbol.flags & SymbolFlags.TypeAlias) { return getDeclaredTypeOfTypeAlias(symbol); } - if (symbol.flags & SymbolFlags.Enum) { + if (symbol.flags & (SymbolFlags.Enum | SymbolFlags.EnumMember)) { return getDeclaredTypeOfEnum(symbol); } if (symbol.flags & SymbolFlags.TypeParameter) { @@ -4643,7 +4643,7 @@ namespace ts { // will result in a different declaration kind. if (!signature.isolatedSignatureType) { const isConstructor = signature.declaration.kind === SyntaxKind.Constructor || signature.declaration.kind === SyntaxKind.ConstructSignature; - const type = createObjectType(TypeFlags.Anonymous | TypeFlags.FromSignature); + const type = createObjectType(TypeFlags.Anonymous); type.members = emptySymbols; type.properties = emptyArray; type.callSignatures = !isConstructor ? [signature] : emptyArray; @@ -6569,9 +6569,12 @@ namespace ts { } function enumRelatedTo(source: Type, target: Type, reportErrors?: boolean) { + if (source.symbol.flags & SymbolFlags.EnumMember && source.symbol.parent === target.symbol) { + return Ternary.True; + } if (source.symbol.name !== target.symbol.name || - source.symbol.flags & SymbolFlags.ConstEnum || - target.symbol.flags & SymbolFlags.ConstEnum) { + !(source.symbol.flags & SymbolFlags.RegularEnum) || + !(target.symbol.flags & SymbolFlags.RegularEnum)) { return Ternary.False; } const targetEnumType = getTypeOfSymbol(target.symbol); @@ -6844,6 +6847,7 @@ namespace ts { function isLiteralUnionType(type: Type): boolean { return type.flags & TypeFlags.Literal ? true : + type.flags & TypeFlags.Enum ? (type.symbol.flags & SymbolFlags.EnumMember) !== 0 : type.flags & TypeFlags.Union ? forEach((type).types, isLiteralUnionType) : false; } @@ -6852,6 +6856,7 @@ namespace ts { return type.flags & TypeFlags.StringLiteral ? stringType : type.flags & TypeFlags.NumberLiteral ? numberType : type.flags & TypeFlags.BooleanLiteral ? booleanType : + type.flags & TypeFlags.Enum && type.symbol.flags & SymbolFlags.EnumMember ? getDeclaredTypeOfSymbol(getParentOfSymbol(type.symbol)) : type.flags & TypeFlags.Union ? getUnionType(map((type).types, getBaseTypeOfLiteralType)) : type; } @@ -7728,7 +7733,7 @@ namespace ts { // If all case clauses specify expressions that have unit types, we return an array // of those unit types. Otherwise we return an empty array. const types = map(switchStatement.caseBlock.clauses, getTypeOfSwitchClause); - links.switchTypes = forEach(types, t => !t || t.flags & TypeFlags.StringLiteral) ? types : emptyArray; + links.switchTypes = forEach(types, t => !t || isLiteralUnionType(t)) ? types : emptyArray; } return links.switchTypes; } @@ -8046,7 +8051,7 @@ namespace ts { if (assumeTrue) { return filterType(type, t => areTypesComparable(getTypeOfPropertyOfType(t, propName), discriminantType)); } - if (discriminantType.flags & TypeFlags.StringLiteral) { + if (isLiteralUnionType(discriminantType) && !(discriminantType.flags & TypeFlags.Union)) { return filterType(type, t => getTypeOfPropertyOfType(t, propName) !== discriminantType); } return type; @@ -10186,7 +10191,8 @@ namespace ts { checkClassPropertyAccess(node, left, apparentType, prop); } - const propType = getTypeOfSymbol(prop); + const propType = prop.flags & SymbolFlags.EnumMember && getParentOfSymbol(prop).flags & SymbolFlags.ConstEnum && + isLiteralTypeContext(node) ? getDeclaredTypeOfSymbol(prop) : getTypeOfSymbol(prop); // Only compute control flow type if this is a property access expression that isn't an // assignment target, and the referenced property was declared as a variable, property, // accessor, or optional method. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 04027042c2dfd..dbd8939113286 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2056,8 +2056,8 @@ namespace ts { Enum = RegularEnum | ConstEnum, Variable = FunctionScopedVariable | BlockScopedVariable, Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor, - Type = Class | Interface | Enum | TypeLiteral | ObjectLiteral | TypeParameter | TypeAlias, - Namespace = ValueModule | NamespaceModule, + Type = Class | Interface | Enum | EnumMember | TypeLiteral | ObjectLiteral | TypeParameter | TypeAlias, + Namespace = ValueModule | NamespaceModule | ConstEnum, Module = ValueModule | NamespaceModule, Accessor = GetAccessor | SetAccessor, @@ -2071,7 +2071,7 @@ namespace ts { ParameterExcludes = Value, PropertyExcludes = None, - EnumMemberExcludes = Value, + EnumMemberExcludes = Value | Type, FunctionExcludes = Value & ~(Function | ValueModule), ClassExcludes = (Value | Type) & ~(ValueModule | Interface), // class-interface mergability done in checker.ts InterfaceExcludes = Type & ~(Interface | Class), @@ -2221,18 +2221,17 @@ namespace ts { Anonymous = 1 << 20, // Anonymous Instantiated = 1 << 21, // Instantiated anonymous type /* @internal */ - FromSignature = 1 << 22, // Created for signature assignment check - ObjectLiteral = 1 << 23, // Originates in an object literal + ObjectLiteral = 1 << 22, // Originates in an object literal /* @internal */ - FreshObjectLiteral = 1 << 24, // Fresh object literal type + FreshObjectLiteral = 1 << 23, // Fresh object literal type /* @internal */ - ContainsWideningType = 1 << 25, // Type is or contains undefined or null widening type + ContainsWideningType = 1 << 24, // Type is or contains undefined or null widening type /* @internal */ - ContainsObjectLiteral = 1 << 26, // Type is or contains object literal type + ContainsObjectLiteral = 1 << 25, // Type is or contains object literal type /* @internal */ - ContainsAnyFunctionType = 1 << 27, // Type is or contains object literal type - ThisType = 1 << 28, // This type - ObjectLiteralPatternWithComputedProperties = 1 << 29, // Object literal type implied by binding pattern has computed properties + ContainsAnyFunctionType = 1 << 26, // Type is or contains object literal type + ThisType = 1 << 27, // This type + ObjectLiteralPatternWithComputedProperties = 1 << 28, // Object literal type implied by binding pattern has computed properties /* @internal */ Nullable = Undefined | Null, From 8455143fed4da23b736e5d12eb191b21e999e81c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 20 Jun 2016 20:26:14 -0700 Subject: [PATCH 06/55] Accept new baselines --- tests/baselines/reference/constEnums.types | 140 ++++++++++----------- 1 file changed, 70 insertions(+), 70 deletions(-) diff --git a/tests/baselines/reference/constEnums.types b/tests/baselines/reference/constEnums.types index a59bd2d012a6d..b49c9215df0ec 100644 --- a/tests/baselines/reference/constEnums.types +++ b/tests/baselines/reference/constEnums.types @@ -314,16 +314,16 @@ function foo0(e: I): void { if (e === I.V1) { >e === I.V1 : boolean >e : I ->I.V1 : I +>I.V1 : I.V1 >I : typeof I ->V1 : I +>V1 : I.V1 } else if (e === I.V2) { >e === I.V2 : boolean >e : I ->I.V2 : I +>I.V2 : I.V2 >I : typeof I ->V2 : I +>V2 : I.V2 } } @@ -337,24 +337,24 @@ function foo1(e: I1.C.E): void { if (e === I1.C.E.V1) { >e === I1.C.E.V1 : boolean >e : I1.C.E ->I1.C.E.V1 : I1.C.E +>I1.C.E.V1 : I1.C.E.V1 >I1.C.E : typeof I1.C.E >I1.C : typeof I1.C >I1 : typeof I1 >C : typeof I1.C >E : typeof I1.C.E ->V1 : I1.C.E +>V1 : I1.C.E.V1 } else if (e === I1.C.E.V2) { >e === I1.C.E.V2 : boolean >e : I1.C.E ->I1.C.E.V2 : I1.C.E +>I1.C.E.V2 : I1.C.E.V2 >I1.C.E : typeof I1.C.E >I1.C : typeof I1.C >I1 : typeof I1 >C : typeof I1.C >E : typeof I1.C.E ->V2 : I1.C.E +>V2 : I1.C.E.V2 } } @@ -368,24 +368,24 @@ function foo2(e: I2.C.E): void { if (e === I2.C.E.V1) { >e === I2.C.E.V1 : boolean >e : I2.C.E ->I2.C.E.V1 : I2.C.E +>I2.C.E.V1 : I2.C.E.V1 >I2.C.E : typeof I2.C.E >I2.C : typeof I2.C >I2 : typeof I2 >C : typeof I2.C >E : typeof I2.C.E ->V1 : I2.C.E +>V1 : I2.C.E.V1 } else if (e === I2.C.E.V2) { >e === I2.C.E.V2 : boolean >e : I2.C.E ->I2.C.E.V2 : I2.C.E +>I2.C.E.V2 : I2.C.E.V2 >I2.C.E : typeof I2.C.E >I2.C : typeof I2.C >I2 : typeof I2 >C : typeof I2.C >E : typeof I2.C.E ->V2 : I2.C.E +>V2 : I2.C.E.V2 } } @@ -399,99 +399,99 @@ function foo(x: Enum1) { >x : Enum1 case Enum1.A: ->Enum1.A : Enum1 +>Enum1.A : Enum1.A >Enum1 : typeof Enum1 ->A : Enum1 +>A : Enum1.A case Enum1.B: ->Enum1.B : Enum1 +>Enum1.B : Enum1.B >Enum1 : typeof Enum1 ->B : Enum1 +>B : Enum1.B case Enum1.C: ->Enum1.C : Enum1 +>Enum1.C : Enum1.C >Enum1 : typeof Enum1 ->C : Enum1 +>C : Enum1.C case Enum1.D: ->Enum1.D : Enum1 +>Enum1.D : Enum1.D >Enum1 : typeof Enum1 ->D : Enum1 +>D : Enum1.D case Enum1.E: ->Enum1.E : Enum1 +>Enum1.E : Enum1.E >Enum1 : typeof Enum1 ->E : Enum1 +>E : Enum1.E case Enum1.F: ->Enum1.F : Enum1 +>Enum1.F : Enum1.F >Enum1 : typeof Enum1 ->F : Enum1 +>F : Enum1.F case Enum1.G: ->Enum1.G : Enum1 +>Enum1.G : Enum1.G >Enum1 : typeof Enum1 ->G : Enum1 +>G : Enum1.G case Enum1.H: ->Enum1.H : Enum1 +>Enum1.H : Enum1.H >Enum1 : typeof Enum1 ->H : Enum1 +>H : Enum1.H case Enum1.I: ->Enum1.I : Enum1 +>Enum1.I : Enum1.I >Enum1 : typeof Enum1 ->I : Enum1 +>I : Enum1.I case Enum1.J: ->Enum1.J : Enum1 +>Enum1.J : Enum1.J >Enum1 : typeof Enum1 ->J : Enum1 +>J : Enum1.J case Enum1.K: ->Enum1.K : Enum1 +>Enum1.K : Enum1.K >Enum1 : typeof Enum1 ->K : Enum1 +>K : Enum1.K case Enum1.L: ->Enum1.L : Enum1 +>Enum1.L : Enum1.L >Enum1 : typeof Enum1 ->L : Enum1 +>L : Enum1.L case Enum1.M: ->Enum1.M : Enum1 +>Enum1.M : Enum1.M >Enum1 : typeof Enum1 ->M : Enum1 +>M : Enum1.M case Enum1.N: ->Enum1.N : Enum1 +>Enum1.N : Enum1.N >Enum1 : typeof Enum1 ->N : Enum1 +>N : Enum1.N case Enum1.O: ->Enum1.O : Enum1 +>Enum1.O : Enum1.O >Enum1 : typeof Enum1 ->O : Enum1 +>O : Enum1.O case Enum1.P: ->Enum1.P : Enum1 +>Enum1.P : Enum1.P >Enum1 : typeof Enum1 ->P : Enum1 +>P : Enum1.P case Enum1.Q: ->Enum1.Q : Enum1 +>Enum1.Q : Enum1.Q >Enum1 : typeof Enum1 ->Q : Enum1 +>Q : Enum1.Q case Enum1.R: ->Enum1.R : Enum1 +>Enum1.R : Enum1.R >Enum1 : typeof Enum1 ->R : Enum1 +>R : Enum1.R case Enum1.S: ->Enum1.S : Enum1 +>Enum1.S : Enum1.S >Enum1 : typeof Enum1 ->S : Enum1 +>S : Enum1.S case Enum1["T"]: >Enum1["T"] : Enum1 @@ -499,39 +499,39 @@ function foo(x: Enum1) { >"T" : string case Enum1.U: ->Enum1.U : Enum1 +>Enum1.U : Enum1.U >Enum1 : typeof Enum1 ->U : Enum1 +>U : Enum1.U case Enum1.V: ->Enum1.V : Enum1 +>Enum1.V : Enum1.V >Enum1 : typeof Enum1 ->V : Enum1 +>V : Enum1.V case Enum1.W: ->Enum1.W : Enum1 +>Enum1.W : Enum1.W >Enum1 : typeof Enum1 ->W : Enum1 +>W : Enum1.W case Enum1.W1: ->Enum1.W1 : Enum1 +>Enum1.W1 : Enum1.W1 >Enum1 : typeof Enum1 ->W1 : Enum1 +>W1 : Enum1.W1 case Enum1.W2: ->Enum1.W2 : Enum1 +>Enum1.W2 : Enum1.W2 >Enum1 : typeof Enum1 ->W2 : Enum1 +>W2 : Enum1.W2 case Enum1.W3: ->Enum1.W3 : Enum1 +>Enum1.W3 : Enum1.W3 >Enum1 : typeof Enum1 ->W3 : Enum1 +>W3 : Enum1.W3 case Enum1.W4: ->Enum1.W4 : Enum1 +>Enum1.W4 : Enum1.W4 >Enum1 : typeof Enum1 ->W4 : Enum1 +>W4 : Enum1.W4 break; } @@ -549,7 +549,7 @@ function bar(e: A.B.C.E): number { >e : I case A.B.C.E.V1: return 1; ->A.B.C.E.V1 : I +>A.B.C.E.V1 : I.V1 >A.B.C.E : typeof I >A.B.C : typeof A.B.C >A.B : typeof A.B @@ -557,11 +557,11 @@ function bar(e: A.B.C.E): number { >B : typeof A.B >C : typeof A.B.C >E : typeof I ->V1 : I +>V1 : I.V1 >1 : number case A.B.C.E.V2: return 1; ->A.B.C.E.V2 : I +>A.B.C.E.V2 : I.V2 >A.B.C.E : typeof I >A.B.C : typeof A.B.C >A.B : typeof A.B @@ -569,11 +569,11 @@ function bar(e: A.B.C.E): number { >B : typeof A.B >C : typeof A.B.C >E : typeof I ->V2 : I +>V2 : I.V2 >1 : number case A.B.C.E.V3: return 1; ->A.B.C.E.V3 : I +>A.B.C.E.V3 : I.V3 >A.B.C.E : typeof I >A.B.C : typeof A.B.C >A.B : typeof A.B @@ -581,7 +581,7 @@ function bar(e: A.B.C.E): number { >B : typeof A.B >C : typeof A.B.C >E : typeof I ->V3 : I +>V3 : I.V3 >1 : number } } From 477489699caf9d0c928a019df7cad942099f72bb Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 24 Jun 2016 11:49:37 -0700 Subject: [PATCH 07/55] Correct handling of falsy types ("" | 0 | false) --- src/compiler/checker.ts | 119 +++++++++++++++++++++++++++------------- src/compiler/types.ts | 4 +- 2 files changed, 85 insertions(+), 38 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1bc9ef3e67c6c..b02918ddd28ca 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -199,6 +199,8 @@ namespace ts { const intersectionTypes: Map = {}; const stringLiteralTypes: Map = {}; const numericLiteralTypes: Map = {}; + const emptyStringType = getLiteralTypeForText(TypeFlags.StringLiteral, ""); + const zeroType = getLiteralTypeForText(TypeFlags.NumberLiteral, "0"); const resolutionTargets: TypeSystemEntity[] = []; const resolutionResults: boolean[] = []; @@ -246,12 +248,30 @@ namespace ts { // The following members encode facts about particular kinds of types for use in the getTypeFacts function. // The presence of a particular fact means that the given test is true for some (and possibly all) values // of that kind of type. - StringStrictFacts = TypeofEQString | TypeofNENumber | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull | Truthy | Falsy, - StringFacts = StringStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull, - NumberStrictFacts = TypeofEQNumber | TypeofNEString | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull | Truthy | Falsy, - NumberFacts = NumberStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull, - BooleanStrictFacts = TypeofEQBoolean | TypeofNEString | TypeofNENumber | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull | Truthy | Falsy, - BooleanFacts = BooleanStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull, + BaseStringStrictFacts = TypeofEQString | TypeofNENumber | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull, + BaseStringFacts = BaseStringStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull, + StringStrictFacts = BaseStringStrictFacts | Truthy | Falsy, + StringFacts = BaseStringFacts | Truthy | Falsy, + EmptyStringStrictFacts = BaseStringStrictFacts | Falsy, + EmptyStringFacts = BaseStringFacts | Falsy, + NonEmptyStringStrictFacts = BaseStringStrictFacts | Truthy, + NonEmptyStringFacts = BaseStringFacts | Truthy, + BaseNumberStrictFacts = TypeofEQNumber | TypeofNEString | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull, + BaseNumberFacts = BaseNumberStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull, + NumberStrictFacts = BaseNumberStrictFacts | Truthy | Falsy, + NumberFacts = BaseNumberFacts | Truthy | Falsy, + ZeroStrictFacts = BaseNumberStrictFacts | Falsy, + ZeroFacts = BaseNumberFacts | Falsy, + NonZeroStrictFacts = BaseNumberStrictFacts | Truthy, + NonZeroFacts = BaseNumberFacts | Truthy, + BaseBooleanStrictFacts = TypeofEQBoolean | TypeofNEString | TypeofNENumber | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull, + BaseBooleanFacts = BaseBooleanStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull, + BooleanStrictFacts = BaseBooleanStrictFacts | Truthy | Falsy, + BooleanFacts = BaseBooleanFacts | Truthy | Falsy, + FalseStrictFacts = BaseBooleanStrictFacts | Falsy, + FalseFacts = BaseBooleanFacts | Falsy, + TrueStrictFacts = BaseBooleanStrictFacts | Truthy, + TrueFacts = BaseBooleanFacts | Truthy, SymbolStrictFacts = TypeofEQSymbol | TypeofNEString | TypeofNENumber | TypeofNEBoolean | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull | Truthy, SymbolFacts = SymbolStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy, ObjectStrictFacts = TypeofEQObject | TypeofEQHostObject | TypeofNEString | TypeofNENumber | TypeofNEBoolean | TypeofNESymbol | TypeofNEFunction | NEUndefined | NENull | NEUndefinedOrNull | Truthy, @@ -2871,7 +2891,7 @@ namespace ts { } // In strict null checking mode, if a default value of a non-undefined type is specified, remove // undefined from the final type. - if (strictNullChecks && declaration.initializer && !(getCombinedTypeFlags(checkExpressionCached(declaration.initializer)) & TypeFlags.Undefined)) { + if (strictNullChecks && declaration.initializer && !(getFalsyFlags(checkExpressionCached(declaration.initializer)) & TypeFlags.Undefined)) { type = getTypeWithFacts(type, TypeFacts.NEUndefined); } return type; @@ -2914,7 +2934,7 @@ namespace ts { } function addOptionality(type: Type, optional: boolean): Type { - return strictNullChecks && optional ? addTypeKind(type, TypeFlags.Undefined) : type; + return strictNullChecks && optional ? includeFalsyTypes(type, TypeFlags.Undefined) : type; } // Return the inferred type for a variable, parameter, or property declaration @@ -3253,7 +3273,7 @@ namespace ts { else { const type = createObjectType(TypeFlags.Anonymous, symbol); links.type = strictNullChecks && symbol.flags & SymbolFlags.Optional ? - addTypeKind(type, TypeFlags.Undefined) : type; + includeFalsyTypes(type, TypeFlags.Undefined) : type; } } return links.type; @@ -6769,14 +6789,6 @@ namespace ts { return true; } - function getCombinedFlagsOfTypes(types: Type[]) { - let flags: TypeFlags = 0; - for (const t of types) { - flags |= t.flags; - } - return flags; - } - function getCommonSupertype(types: Type[]): Type { if (!strictNullChecks) { return forEach(types, t => isSupertypeOfEach(t, types) ? t : undefined); @@ -6786,7 +6798,7 @@ namespace ts { return getUnionType(types); } const supertype = forEach(primaryTypes, t => isSupertypeOfEach(t, primaryTypes) ? t : undefined); - return supertype && addTypeKind(supertype, getCombinedFlagsOfTypes(types) & TypeFlags.Nullable); + return supertype && includeFalsyTypes(supertype, getFalsyFlagsOfTypes(types) & TypeFlags.Nullable); } function reportNoCommonSupertypeError(types: Type[], errorLocation: Node, errorMessageChainHead: DiagnosticMessageChain): void { @@ -6869,24 +6881,42 @@ namespace ts { return !!(type.flags & TypeFlags.Tuple); } - function getCombinedTypeFlags(type: Type): TypeFlags { - return type.flags & TypeFlags.Union ? getCombinedFlagsOfTypes((type).types) : type.flags; + function getFalsyFlagsOfTypes(types: Type[]): TypeFlags { + let result: TypeFlags = 0; + for (const t of types) { + result |= getFalsyFlags(t); + } + return result; + } + + function getFalsyFlags(type: Type): TypeFlags { + return type === emptyStringType ? TypeFlags.StringLiteral : + type === zeroType ? TypeFlags.NumberLiteral : + type === falseType ? TypeFlags.BooleanLiteral : + type.flags & TypeFlags.Union ? getFalsyFlagsOfTypes((type).types) : + type.flags & TypeFlags.AlwaysPossiblyFalsy; } - function addTypeKind(type: Type, kind: TypeFlags) { - if ((getCombinedTypeFlags(type) & kind) === kind) { + function includeFalsyTypes(type: Type, flags: TypeFlags) { + if ((getFalsyFlags(type) & flags) === flags) { return type; } const types = [type]; - if (kind & TypeFlags.String) types.push(stringType); - if (kind & TypeFlags.Number) types.push(numberType); - if (kind & TypeFlags.Boolean) types.push(booleanType); - if (kind & TypeFlags.Void) types.push(voidType); - if (kind & TypeFlags.Undefined) types.push(undefinedType); - if (kind & TypeFlags.Null) types.push(nullType); + if (flags & TypeFlags.StringLike) types.push(emptyStringType); + if (flags & TypeFlags.NumberLike) types.push(zeroType); + if (flags & TypeFlags.BooleanLike) types.push(falseType); + if (flags & TypeFlags.Void) types.push(voidType); + if (flags & TypeFlags.Undefined) types.push(undefinedType); + if (flags & TypeFlags.Null) types.push(nullType); return getUnionType(types); } + function removeDefinitelyFalsyTypes(type: Type): Type { + return getFalsyFlags(type) & TypeFlags.DefinitelyFalsy ? + filterType(type, t => !(getFalsyFlags(t) & TypeFlags.DefinitelyFalsy)) : + type; + } + function getNonNullableType(type: Type): Type { return strictNullChecks ? getTypeWithFacts(type, TypeFacts.NEUndefinedOrNull) : type; } @@ -7543,15 +7573,30 @@ namespace ts { function getTypeFacts(type: Type): TypeFacts { const flags = type.flags; - if (flags & TypeFlags.StringLike) { + if (flags & TypeFlags.String) { return strictNullChecks ? TypeFacts.StringStrictFacts : TypeFacts.StringFacts; } - if (flags & TypeFlags.NumberLike) { + if (flags & TypeFlags.StringLiteral) { + return strictNullChecks ? + type === emptyStringType ? TypeFacts.EmptyStringStrictFacts : TypeFacts.NonEmptyStringStrictFacts : + type === emptyStringType ? TypeFacts.EmptyStringFacts : TypeFacts.NonEmptyStringFacts; + } + if (flags & TypeFlags.Number) { return strictNullChecks ? TypeFacts.NumberStrictFacts : TypeFacts.NumberFacts; } - if (flags & TypeFlags.BooleanLike) { + if (flags & TypeFlags.NumberLike) { + return strictNullChecks ? + type === zeroType ? TypeFacts.ZeroStrictFacts : TypeFacts.NonZeroStrictFacts : + type === zeroType ? TypeFacts.ZeroFacts : TypeFacts.NonZeroFacts; + } + if (flags & TypeFlags.Boolean) { return strictNullChecks ? TypeFacts.BooleanStrictFacts : TypeFacts.BooleanFacts; } + if (flags & TypeFlags.BooleanLike) { + return strictNullChecks ? + type === falseType ? TypeFacts.FalseStrictFacts : TypeFacts.TrueStrictFacts : + type === falseType ? TypeFacts.FalseFacts : TypeFacts.TrueFacts; + } if (flags & TypeFlags.ObjectType) { const resolved = resolveStructuredTypeMembers(type); return resolved.callSignatures.length || resolved.constructSignatures.length || isTypeSubtypeOf(type, globalFunctionType) ? @@ -7753,7 +7798,7 @@ namespace ts { if (!reference.flowNode || assumeInitialized && !(declaredType.flags & TypeFlags.Narrowable)) { return declaredType; } - const initialType = assumeInitialized ? declaredType : addTypeKind(declaredType, TypeFlags.Undefined); + const initialType = assumeInitialized ? declaredType : includeFalsyTypes(declaredType, TypeFlags.Undefined); const visitedFlowStart = visitedFlowCount; const result = getTypeAtFlowNode(reference.flowNode); visitedFlowCount = visitedFlowStart; @@ -8330,7 +8375,7 @@ namespace ts { getRootDeclaration(declaration).kind === SyntaxKind.Parameter || isInAmbientContext(declaration) || !isDeclarationIncludedInFlow(node, declaration, includeOuterFunctions); const flowType = getFlowTypeOfReference(node, type, assumeInitialized, includeOuterFunctions); - if (!assumeInitialized && !(getCombinedTypeFlags(type) & TypeFlags.Undefined) && getCombinedTypeFlags(flowType) & TypeFlags.Undefined) { + if (!assumeInitialized && !(getFalsyFlags(type) & TypeFlags.Undefined) && getFalsyFlags(flowType) & TypeFlags.Undefined) { error(node, Diagnostics.Variable_0_is_used_before_being_assigned, symbolToString(symbol)); // Return the declared type to reduce follow-on errors return type; @@ -10146,7 +10191,7 @@ namespace ts { function checkNonNullExpression(node: Expression | QualifiedName) { const type = checkExpression(node); if (strictNullChecks) { - const kind = getCombinedTypeFlags(type) & TypeFlags.Nullable; + const kind = getFalsyFlags(type) & TypeFlags.Nullable; if (kind) { error(node, kind & TypeFlags.Undefined ? kind & TypeFlags.Null ? Diagnostics.Object_is_possibly_null_or_undefined : @@ -11686,7 +11731,7 @@ namespace ts { if (strictNullChecks) { const declaration = symbol.valueDeclaration; if (declaration && (declaration).initializer) { - return addTypeKind(type, TypeFlags.Undefined); + return includeFalsyTypes(type, TypeFlags.Undefined); } } return type; @@ -12653,9 +12698,9 @@ namespace ts { case SyntaxKind.InKeyword: return checkInExpression(left, right, leftType, rightType); case SyntaxKind.AmpersandAmpersandToken: - return strictNullChecks ? addTypeKind(rightType, getCombinedTypeFlags(leftType) & TypeFlags.Falsy) : rightType; + return strictNullChecks ? includeFalsyTypes(rightType, getFalsyFlags(leftType)) : rightType; case SyntaxKind.BarBarToken: - return getUnionType([getNonNullableType(leftType), rightType]); + return getUnionType([strictNullChecks ? removeDefinitelyFalsyTypes(leftType) : leftType, rightType]); case SyntaxKind.EqualsToken: checkAssignmentOperator(rightType); return getRegularTypeOfObjectLiteral(rightType); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index dbd8939113286..c49b5578c8041 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2237,7 +2237,9 @@ namespace ts { Nullable = Undefined | Null, Literal = StringLiteral | NumberLiteral | BooleanLiteral, /* @internal */ - Falsy = Void | Undefined | Null, // TODO: Add false, 0, and "" + DefinitelyFalsy = StringLiteral | NumberLiteral | BooleanLiteral | Void | Undefined | Null, + PossiblyFalsy = DefinitelyFalsy | String | Number | Boolean, + AlwaysPossiblyFalsy = String | Number | Boolean | Void | Undefined | Null, /* @internal */ Intrinsic = Any | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never, /* @internal */ From 770f42377d69994428279e3e536fe86d519c6b55 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 24 Jun 2016 11:49:54 -0700 Subject: [PATCH 08/55] Accept new baselines --- .../logicalAndOperatorStrictMode.types | 104 +++++++++--------- .../logicalOrOperatorWithEveryType.types | 2 +- .../reference/strictNullLogicalAndOr.types | 6 +- .../stringLiteralTypesInUnionTypes04.types | 20 ++-- 4 files changed, 66 insertions(+), 66 deletions(-) diff --git a/tests/baselines/reference/logicalAndOperatorStrictMode.types b/tests/baselines/reference/logicalAndOperatorStrictMode.types index a824af2f81106..afbca253b598a 100644 --- a/tests/baselines/reference/logicalAndOperatorStrictMode.types +++ b/tests/baselines/reference/logicalAndOperatorStrictMode.types @@ -86,8 +86,8 @@ const a8 = a && z; >z : string | number | undefined const s1 = s && a; ->s1 : number[] ->s && a : number[] +>s1 : number[] | "" +>s && a : number[] | "" >s : string >a : number[] @@ -98,32 +98,32 @@ const s2 = s && s; >s : string const s3 = s && x; ->s3 : number ->s && x : number +>s3 : number | "" +>s && x : number | "" >s : string >x : number const s4 = s && b; ->s4 : boolean ->s && b : boolean +>s4 : boolean | "" +>s && b : boolean | "" >s : string >b : boolean const s5 = s && v; ->s5 : void ->s && v : void +>s5 : void | "" +>s && v : void | "" >s : string >v : void const s6 = s && u; ->s6 : undefined ->s && u : undefined +>s6 : "" | undefined +>s && u : "" | undefined >s : string >u : undefined const s7 = s && n; ->s7 : null ->s && n : null +>s7 : "" | null +>s && n : "" | null >s : string >n : null @@ -134,14 +134,14 @@ const s8 = s && z; >z : string | number | undefined const x1 = x && a; ->x1 : number[] ->x && a : number[] +>x1 : number[] | 0 +>x && a : number[] | 0 >x : number >a : number[] const x2 = x && s; ->x2 : string ->x && s : string +>x2 : string | 0 +>x && s : string | 0 >x : number >s : string @@ -152,26 +152,26 @@ const x3 = x && x; >x : number const x4 = x && b; ->x4 : boolean ->x && b : boolean +>x4 : boolean | 0 +>x && b : boolean | 0 >x : number >b : boolean const x5 = x && v; ->x5 : void ->x && v : void +>x5 : void | 0 +>x && v : void | 0 >x : number >v : void const x6 = x && u; ->x6 : undefined ->x && u : undefined +>x6 : 0 | undefined +>x && u : 0 | undefined >x : number >u : undefined const x7 = x && n; ->x7 : null ->x && n : null +>x7 : 0 | null +>x && n : 0 | null >x : number >n : null @@ -182,20 +182,20 @@ const x8 = x && z; >z : string | number | undefined const b1 = b && a; ->b1 : number[] ->b && a : number[] +>b1 : number[] | false +>b && a : number[] | false >b : boolean >a : number[] const b2 = b && s; ->b2 : string ->b && s : string +>b2 : string | false +>b && s : string | false >b : boolean >s : string const b3 = b && x; ->b3 : number ->b && x : number +>b3 : number | false +>b && x : number | false >b : boolean >x : number @@ -206,26 +206,26 @@ const b4 = b && b; >b : boolean const b5 = b && v; ->b5 : void ->b && v : void +>b5 : void | false +>b && v : void | false >b : boolean >v : void const b6 = b && u; ->b6 : undefined ->b && u : undefined +>b6 : false | undefined +>b && u : false | undefined >b : boolean >u : undefined const b7 = b && n; ->b7 : null ->b && n : null +>b7 : false | null +>b && n : false | null >b : boolean >n : null const b8 = b && z; ->b8 : string | number | undefined ->b && z : string | number | undefined +>b8 : string | number | false | undefined +>b && z : string | number | false | undefined >b : boolean >z : string | number | undefined @@ -374,44 +374,44 @@ const n8 = n && z; >z : string | number | undefined const z1 = z && a; ->z1 : number[] | undefined ->z && a : number[] | undefined +>z1 : number[] | "" | 0 | undefined +>z && a : number[] | "" | 0 | undefined >z : string | number | undefined >a : number[] const z2 = z && s; ->z2 : string | undefined ->z && s : string | undefined +>z2 : string | 0 | undefined +>z && s : string | 0 | undefined >z : string | number | undefined >s : string const z3 = z && x; ->z3 : number | undefined ->z && x : number | undefined +>z3 : number | "" | undefined +>z && x : number | "" | undefined >z : string | number | undefined >x : number const z4 = z && b; ->z4 : boolean | undefined ->z && b : boolean | undefined +>z4 : boolean | "" | 0 | undefined +>z && b : boolean | "" | 0 | undefined >z : string | number | undefined >b : boolean const z5 = z && v; ->z5 : void ->z && v : void +>z5 : void | "" | 0 +>z && v : void | "" | 0 >z : string | number | undefined >v : void const z6 = z && u; ->z6 : undefined ->z && u : undefined +>z6 : "" | 0 | undefined +>z && u : "" | 0 | undefined >z : string | number | undefined >u : undefined const z7 = z && n; ->z7 : null | undefined ->z && n : null | undefined +>z7 : "" | 0 | null | undefined +>z && n : "" | 0 | null | undefined >z : string | number | undefined >n : null diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.types b/tests/baselines/reference/logicalOrOperatorWithEveryType.types index 4540e35aaf459..91485cad78d10 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.types @@ -370,7 +370,7 @@ var rg6 = a6 || a6; // enum || enum is E >rg6 : E >a6 || a6 : E >a6 : E ->a6 : E +>a6 : never var rg7 = a7 || a6; // object || enum is object | enum >rg7 : { a: string; } | E diff --git a/tests/baselines/reference/strictNullLogicalAndOr.types b/tests/baselines/reference/strictNullLogicalAndOr.types index a11a7033fb6ac..b82496845b768 100644 --- a/tests/baselines/reference/strictNullLogicalAndOr.types +++ b/tests/baselines/reference/strictNullLogicalAndOr.types @@ -14,7 +14,7 @@ let sinOrCos = Math.random() < .5; let choice = sinOrCos && Math.sin || Math.cos; >choice : (x: number) => number >sinOrCos && Math.sin || Math.cos : (x: number) => number ->sinOrCos && Math.sin : (x: number) => number +>sinOrCos && Math.sin : ((x: number) => number) | false >sinOrCos : boolean >Math.sin : (x: number) => number >Math : Math @@ -37,14 +37,14 @@ function sq(n?: number): number { const r = n !== undefined && n*n || 0; >r : number >n !== undefined && n*n || 0 : number ->n !== undefined && n*n : number +>n !== undefined && n*n : number | false >n !== undefined : boolean >n : number | undefined >undefined : undefined >n*n : number >n : number >n : number ->0 : number +>0 : 0 return r; >r : number diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types index eb96d02217e1a..81e87b727a829 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types @@ -57,17 +57,17 @@ if (x) { >x : "" | "foo" let e = x; ->e : "" | "foo" ->x : "" | "foo" +>e : "foo" +>x : "foo" } if (!x) { >!x : boolean ->x : "" | "foo" +>x : "foo" | "" let f = x; ->f : "" | "foo" ->x : "" | "foo" +>f : "" +>x : "" } if (!!x) { @@ -76,17 +76,17 @@ if (!!x) { >x : "" | "foo" let g = x; ->g : "" | "foo" ->x : "" | "foo" +>g : "foo" +>x : "foo" } if (!!!x) { >!!!x : boolean >!!x : boolean >!x : boolean ->x : "" | "foo" +>x : "foo" | "" let h = x; ->h : "" | "foo" ->x : "" | "foo" +>h : "" +>x : "" } From e900ebf856c388a138befcd7a2e7445d88468981 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 24 Jun 2016 21:12:44 -0700 Subject: [PATCH 09/55] Make boolean assignable to union types containing both true and false --- src/compiler/checker.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b02918ddd28ca..ab5d4e9a5c47b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6026,6 +6026,9 @@ namespace ts { if (result = typeRelatedToSomeType(source, target, reportErrors && !(source.flags & TypeFlags.Primitive))) { return result; } + if (source === booleanType && contains((target).types, trueType) && contains((target).types, falseType)) { + return Ternary.True; + } } } From 85128e02dadddc5bd6294915a19d9096f4e8f5c9 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 28 Jun 2016 17:00:52 -0700 Subject: [PATCH 10/55] Narrow unions of literal types by equality and truthiness --- src/compiler/binder.ts | 12 +-- src/compiler/checker.ts | 182 ++++++++++++++++++++-------------------- src/compiler/types.ts | 5 +- 3 files changed, 99 insertions(+), 100 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b45af24d4d198..27bd3b71c5eef 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -637,9 +637,8 @@ namespace ts { case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: case SyntaxKind.ExclamationEqualsEqualsToken: - return isNarrowingNullCheckOperands(expr.right, expr.left) || isNarrowingNullCheckOperands(expr.left, expr.right) || - isNarrowingTypeofOperands(expr.right, expr.left) || isNarrowingTypeofOperands(expr.left, expr.right) || - isNarrowingDiscriminant(expr.left) || isNarrowingDiscriminant(expr.right); + return isNarrowableOperand(expr.left) || isNarrowableOperand(expr.right) || + isNarrowingTypeofOperands(expr.right, expr.left) || isNarrowingTypeofOperands(expr.left, expr.right); case SyntaxKind.InstanceOfKeyword: return isNarrowableOperand(expr.left); case SyntaxKind.CommaToken: @@ -663,11 +662,6 @@ namespace ts { return isNarrowableReference(expr); } - function isNarrowingSwitchStatement(switchStatement: SwitchStatement) { - const expr = switchStatement.expression; - return expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((expr).expression); - } - function createBranchLabel(): FlowLabel { return { flags: FlowFlags.BranchLabel, @@ -717,7 +711,7 @@ namespace ts { } function createFlowSwitchClause(antecedent: FlowNode, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number): FlowNode { - if (!isNarrowingSwitchStatement(switchStatement)) { + if (!isNarrowingExpression(switchStatement.expression)) { return antecedent; } setFlowNodeReferenced(antecedent); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ab5d4e9a5c47b..82c37b159ecf4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6860,6 +6860,11 @@ namespace ts { return !!getPropertyOfType(type, "0"); } + function isUnitType(type: Type): boolean { + return type.flags & (TypeFlags.Literal | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null) || + type.flags & TypeFlags.Enum && type.symbol.flags & SymbolFlags.EnumMember ? true : false; + } + function isLiteralUnionType(type: Type): boolean { return type.flags & TypeFlags.Literal ? true : type.flags & TypeFlags.Enum ? (type.symbol.flags & SymbolFlags.EnumMember) !== 0 : @@ -7481,11 +7486,6 @@ namespace ts { return undefined; } - function isNullOrUndefinedLiteral(node: Expression) { - return node.kind === SyntaxKind.NullKeyword || - node.kind === SyntaxKind.Identifier && getResolvedSymbol(node) === undefinedSymbol; - } - function getLeftmostIdentifierOrThis(node: Node): Node { switch (node.kind) { case SyntaxKind.Identifier: @@ -7584,13 +7584,16 @@ namespace ts { type === emptyStringType ? TypeFacts.EmptyStringStrictFacts : TypeFacts.NonEmptyStringStrictFacts : type === emptyStringType ? TypeFacts.EmptyStringFacts : TypeFacts.NonEmptyStringFacts; } - if (flags & TypeFlags.Number) { + if (flags & TypeFlags.Number || type.flags & TypeFlags.Enum && !(type.symbol.flags & SymbolFlags.EnumMember)) { return strictNullChecks ? TypeFacts.NumberStrictFacts : TypeFacts.NumberFacts; } if (flags & TypeFlags.NumberLike) { + const isZero = type === zeroType || + type.flags & TypeFlags.Enum && type.symbol.flags & SymbolFlags.EnumMember && + getEnumMemberValue(type.symbol.valueDeclaration) === 0; return strictNullChecks ? - type === zeroType ? TypeFacts.ZeroStrictFacts : TypeFacts.NonZeroStrictFacts : - type === zeroType ? TypeFacts.ZeroFacts : TypeFacts.NonZeroFacts; + isZero ? TypeFacts.ZeroStrictFacts : TypeFacts.NonZeroStrictFacts : + isZero ? TypeFacts.ZeroFacts : TypeFacts.NonZeroFacts; } if (flags & TypeFlags.Boolean) { return strictNullChecks ? TypeFacts.BooleanStrictFacts : TypeFacts.BooleanFacts; @@ -7756,23 +7759,27 @@ namespace ts { getInitialTypeOfBindingElement(node); } - function getReferenceFromExpression(node: Expression): Expression { + function getReferenceCandidate(node: Expression): Expression { switch (node.kind) { case SyntaxKind.ParenthesizedExpression: - return getReferenceFromExpression((node).expression); + return getReferenceCandidate((node).expression); case SyntaxKind.BinaryExpression: switch ((node).operatorToken.kind) { case SyntaxKind.EqualsToken: - return getReferenceFromExpression((node).left); + return getReferenceCandidate((node).left); case SyntaxKind.CommaToken: - return getReferenceFromExpression((node).right); + return getReferenceCandidate((node).right); } } return node; } function getTypeOfSwitchClause(clause: CaseClause | DefaultClause) { - return clause.kind === SyntaxKind.CaseClause ? checkExpression((clause).expression) : undefined; + if (clause.kind === SyntaxKind.CaseClause) { + const caseType = checkExpression((clause).expression); + return isUnitType(caseType) ? caseType : undefined; + } + return neverType; } function getSwitchClauseTypes(switchStatement: SwitchStatement): Type[] { @@ -7781,7 +7788,7 @@ namespace ts { // If all case clauses specify expressions that have unit types, we return an array // of those unit types. Otherwise we return an empty array. const types = map(switchStatement.caseBlock.clauses, getTypeOfSwitchClause); - links.switchTypes = forEach(types, t => !t || isLiteralUnionType(t)) ? types : emptyArray; + links.switchTypes = !contains(types, undefined) ? types : emptyArray; } return links.switchTypes; } @@ -7921,7 +7928,14 @@ namespace ts { function getTypeAtSwitchClause(flow: FlowSwitchClause) { const type = getTypeAtFlowNode(flow.antecedent); - return narrowTypeBySwitchOnDiscriminant(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd); + const expr = flow.switchStatement.expression; + if (isMatchingReference(reference, expr)) { + return narrowTypeBySwitchOnDiscriminant(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd); + } + if (isMatchingPropertyAccess(expr)) { + return narrowTypeByDiscriminant(type, expr, t => narrowTypeBySwitchOnDiscriminant(t, flow.switchStatement, flow.clauseStart, flow.clauseEnd)); + } + return type; } function getTypeAtFlowBranchLabel(flow: FlowLabel) { @@ -7991,8 +8005,27 @@ namespace ts { return cache[key] = getUnionType(antecedentTypes); } + function isMatchingPropertyAccess(expr: Expression) { + return expr.kind === SyntaxKind.PropertyAccessExpression && + isMatchingReference(reference, (expr).expression) && + (declaredType.flags & TypeFlags.Union) !== 0; + } + + function narrowTypeByDiscriminant(type: Type, propAccess: PropertyAccessExpression, narrowType: (t: Type) => Type): Type { + const propName = propAccess.name.text; + const propType = getTypeOfPropertyOfType(type, propName); + const narrowedPropType = propType && narrowType(propType); + return propType === narrowedPropType ? type : filterType(type, t => isTypeComparableTo(getTypeOfPropertyOfType(t, propName), narrowedPropType)); + } + function narrowTypeByTruthiness(type: Type, expr: Expression, assumeTrue: boolean): Type { - return isMatchingReference(reference, expr) ? getTypeWithFacts(type, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy) : type; + if (isMatchingReference(reference, expr)) { + return getTypeWithFacts(type, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy); + } + if (isMatchingPropertyAccess(expr)) { + return narrowTypeByDiscriminant(type, expr, t => getTypeWithFacts(t, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy)); + } + return type; } function narrowTypeByBinaryExpression(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { @@ -8003,26 +8036,26 @@ namespace ts { case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: case SyntaxKind.ExclamationEqualsEqualsToken: - const left = expr.left; const operator = expr.operatorToken.kind; - const right = expr.right; - if (isNullOrUndefinedLiteral(right)) { - return narrowTypeByNullCheck(type, left, operator, right, assumeTrue); - } - if (isNullOrUndefinedLiteral(left)) { - return narrowTypeByNullCheck(type, right, operator, left, assumeTrue); - } + const left = getReferenceCandidate(expr.left); + const right = getReferenceCandidate(expr.right); if (left.kind === SyntaxKind.TypeOfExpression && right.kind === SyntaxKind.StringLiteral) { return narrowTypeByTypeof(type, left, operator, right, assumeTrue); } if (right.kind === SyntaxKind.TypeOfExpression && left.kind === SyntaxKind.StringLiteral) { return narrowTypeByTypeof(type, right, operator, left, assumeTrue); } - if (left.kind === SyntaxKind.PropertyAccessExpression) { - return narrowTypeByDiscriminant(type, left, operator, right, assumeTrue); + if (isMatchingReference(reference, left)) { + return narrowTypeByEquality(type, operator, right, assumeTrue); + } + if (isMatchingReference(reference, right)) { + return narrowTypeByEquality(type, operator, left, assumeTrue); } - if (right.kind === SyntaxKind.PropertyAccessExpression) { - return narrowTypeByDiscriminant(type, right, operator, left, assumeTrue); + if (isMatchingPropertyAccess(left)) { + return narrowTypeByDiscriminant(type, left, t => narrowTypeByEquality(t, operator, right, assumeTrue)); + } + if (isMatchingPropertyAccess(right)) { + return narrowTypeByDiscriminant(type, right, t => narrowTypeByEquality(t, operator, left, assumeTrue)); } break; case SyntaxKind.InstanceOfKeyword: @@ -8033,26 +8066,36 @@ namespace ts { return type; } - function narrowTypeByNullCheck(type: Type, target: Expression, operator: SyntaxKind, literal: Expression, assumeTrue: boolean): Type { - // We have '==', '!=', '===', or '!==' operator with 'null' or 'undefined' as value + function narrowTypeByEquality(type: Type, operator: SyntaxKind, value: Expression, assumeTrue: boolean): Type { if (operator === SyntaxKind.ExclamationEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) { assumeTrue = !assumeTrue; } - if (!strictNullChecks || !isMatchingReference(reference, getReferenceFromExpression(target))) { + const valueType = checkExpression(value); + if (valueType.flags & TypeFlags.Nullable) { + if (!strictNullChecks) { + return type; + } + const doubleEquals = operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsToken; + const facts = doubleEquals ? + assumeTrue ? TypeFacts.EQUndefinedOrNull : TypeFacts.NEUndefinedOrNull : + value.kind === SyntaxKind.NullKeyword ? + assumeTrue ? TypeFacts.EQNull : TypeFacts.NENull : + assumeTrue ? TypeFacts.EQUndefined : TypeFacts.NEUndefined; + return getTypeWithFacts(type, facts); + } + if (type.flags & TypeFlags.NotUnionOrUnit) { return type; } - const doubleEquals = operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsToken; - const facts = doubleEquals ? - assumeTrue ? TypeFacts.EQUndefinedOrNull : TypeFacts.NEUndefinedOrNull : - literal.kind === SyntaxKind.NullKeyword ? - assumeTrue ? TypeFacts.EQNull : TypeFacts.NENull : - assumeTrue ? TypeFacts.EQUndefined : TypeFacts.NEUndefined; - return getTypeWithFacts(type, facts); + if (assumeTrue) { + const narrowedType = filterType(type, t => areTypesComparable(t, valueType)); + return narrowedType !== neverType ? narrowedType : type; + } + return isUnitType(valueType) ? filterType(type, t => t !== valueType) : type; } function narrowTypeByTypeof(type: Type, typeOfExpr: TypeOfExpression, operator: SyntaxKind, literal: LiteralExpression, assumeTrue: boolean): Type { // We have '==', '!=', '====', or !==' operator with 'typeof xxx' and string literal operands - const target = getReferenceFromExpression(typeOfExpr.expression); + const target = getReferenceCandidate(typeOfExpr.expression); if (!isMatchingReference(reference, target)) { // For a reference of the form 'x.y', a 'typeof x === ...' type guard resets the // narrowed type of 'y' to its declared type. @@ -8079,40 +8122,8 @@ namespace ts { return getTypeWithFacts(type, facts); } - function narrowTypeByDiscriminant(type: Type, propAccess: PropertyAccessExpression, operator: SyntaxKind, value: Expression, assumeTrue: boolean): Type { - // We have '==', '!=', '===', or '!==' operator with property access as target - if (!isMatchingReference(reference, propAccess.expression)) { - return type; - } - const propName = propAccess.name.text; - const propType = getTypeOfPropertyOfType(type, propName); - if (!propType || !isLiteralUnionType(propType)) { - return type; - } - const discriminantType = checkExpression(value); - if (!isLiteralUnionType(discriminantType)) { - return type; - } - if (operator === SyntaxKind.ExclamationEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) { - assumeTrue = !assumeTrue; - } - if (assumeTrue) { - return filterType(type, t => areTypesComparable(getTypeOfPropertyOfType(t, propName), discriminantType)); - } - if (isLiteralUnionType(discriminantType) && !(discriminantType.flags & TypeFlags.Union)) { - return filterType(type, t => getTypeOfPropertyOfType(t, propName) !== discriminantType); - } - return type; - } - function narrowTypeBySwitchOnDiscriminant(type: Type, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number) { - // We have switch statement with property access expression - if (!isMatchingReference(reference, (switchStatement.expression).expression)) { - return type; - } - const propName = (switchStatement.expression).name.text; - const propType = getTypeOfPropertyOfType(type, propName); - if (!propType || !isLiteralUnionType(propType)) { + if (!isLiteralUnionType(type)) { return type; } const switchTypes = getSwitchClauseTypes(switchStatement); @@ -8120,19 +8131,18 @@ namespace ts { return type; } const clauseTypes = switchTypes.slice(clauseStart, clauseEnd); - const hasDefaultClause = clauseStart === clauseEnd || contains(clauseTypes, undefined); - const caseTypes = hasDefaultClause ? filter(clauseTypes, t => !!t) : clauseTypes; - const discriminantType = caseTypes.length ? getUnionType(caseTypes) : undefined; - const caseType = discriminantType && filterType(type, t => isTypeComparableTo(discriminantType, getTypeOfPropertyOfType(t, propName))); + const hasDefaultClause = clauseStart === clauseEnd || contains(clauseTypes, neverType); + const discriminantType = getUnionType(clauseTypes); + const caseType = discriminantType === neverType ? neverType : filterType(type, t => isTypeComparableTo(discriminantType, t)); if (!hasDefaultClause) { return caseType; } - const defaultType = filterType(type, t => !eachTypeContainedIn(getTypeOfPropertyOfType(t, propName), switchTypes)); - return caseType ? getUnionType([caseType, defaultType]) : defaultType; + const defaultType = filterType(type, t => !eachTypeContainedIn(t, switchTypes)); + return caseType === neverType ? defaultType : getUnionType([caseType, defaultType]); } function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { - const left = getReferenceFromExpression(expr.left); + const left = getReferenceCandidate(expr.left); if (!isMatchingReference(reference, left)) { // For a reference of the form 'x.y', an 'x instanceof T' type guard resets the // narrowed type of 'y' to its declared type. @@ -11956,24 +11966,18 @@ namespace ts { } function isExhaustiveSwitchStatement(node: SwitchStatement): boolean { - const expr = node.expression; - if (!node.possiblyExhaustive || expr.kind !== SyntaxKind.PropertyAccessExpression) { - return false; - } - const type = checkExpression((expr).expression); - if (!(type.flags & TypeFlags.Union)) { + if (!node.possiblyExhaustive) { return false; } - const propName = (expr).name.text; - const propType = getTypeOfPropertyOfType(type, propName); - if (!propType || !isLiteralUnionType(propType)) { + const type = checkExpression(node.expression); + if (!isLiteralUnionType(type)) { return false; } const switchTypes = getSwitchClauseTypes(node); if (!switchTypes.length) { return false; } - return eachTypeContainedIn(propType, switchTypes); + return eachTypeContainedIn(type, switchTypes); } function functionHasImplicitReturn(func: FunctionLikeDeclaration) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c49b5578c8041..486f1e82a9755 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2243,7 +2243,7 @@ namespace ts { /* @internal */ Intrinsic = Any | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never, /* @internal */ - Primitive = String | Number | Boolean | ESSymbol | Void | Undefined | Null | StringLiteral | Enum, + Primitive = String | Number | Boolean | ESSymbol | Void | Undefined | Null | Literal | Enum, StringLike = String | StringLiteral, NumberLike = Number | NumberLiteral | Enum, BooleanLike = Boolean | BooleanLiteral, @@ -2253,7 +2253,8 @@ namespace ts { // 'Narrowable' types are types where narrowing actually narrows. // This *should* be every type other than null, undefined, void, and never - Narrowable = Any | StructuredType | TypeParameter | StringLike | NumberLike | Boolean | ESSymbol, + Narrowable = Any | StructuredType | TypeParameter | StringLike | NumberLike | BooleanLike | ESSymbol, + NotUnionOrUnit = Any | String | Number | Boolean | ESSymbol | ObjectType, /* @internal */ RequiresWidening = ContainsWideningType | ContainsObjectLiteral, /* @internal */ From a2a48964f55cb7f6c47a3f0b347cdbb5ceae1a25 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 28 Jun 2016 17:07:42 -0700 Subject: [PATCH 11/55] Accept new baselines --- .../logicalOrOperatorWithEveryType.types | 2 +- tests/baselines/reference/neverType.types | 2 +- .../stringLiteralCheckedInIf01.types | 10 ++++---- .../stringLiteralCheckedInIf02.types | 2 +- .../stringLiteralMatchedInSwitch01.types | 2 +- .../stringLiteralTypesAndTuples01.types | 4 ++-- .../stringLiteralTypesInUnionTypes01.types | 24 +++++++++---------- .../stringLiteralTypesInUnionTypes03.types | 24 +++++++++---------- .../stringLiteralTypesInUnionTypes04.types | 20 ++++++++-------- .../stringLiteralTypesOverloads01.types | 4 ++-- 10 files changed, 47 insertions(+), 47 deletions(-) diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.types b/tests/baselines/reference/logicalOrOperatorWithEveryType.types index 91485cad78d10..4540e35aaf459 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.types @@ -370,7 +370,7 @@ var rg6 = a6 || a6; // enum || enum is E >rg6 : E >a6 || a6 : E >a6 : E ->a6 : never +>a6 : E var rg7 = a7 || a6; // object || enum is object | enum >rg7 : { a: string; } | E diff --git a/tests/baselines/reference/neverType.types b/tests/baselines/reference/neverType.types index 5cd6f419a9da0..72d8eae6b3b61 100644 --- a/tests/baselines/reference/neverType.types +++ b/tests/baselines/reference/neverType.types @@ -102,7 +102,7 @@ function move2(direction: "up" | "down") { direction === "down" ? -1 : >direction === "down" ? -1 : error("Should never get here") : number >direction === "down" : boolean ->direction : "up" | "down" +>direction : "down" >"down" : "down" >-1 : number >1 : number diff --git a/tests/baselines/reference/stringLiteralCheckedInIf01.types b/tests/baselines/reference/stringLiteralCheckedInIf01.types index be25df63f209b..23db9900231c8 100644 --- a/tests/baselines/reference/stringLiteralCheckedInIf01.types +++ b/tests/baselines/reference/stringLiteralCheckedInIf01.types @@ -9,7 +9,7 @@ type T = S[] | S; >S : "a" | "b" function f(foo: T) { ->f : (foo: ("a" | "b")[] | "a" | "b") => ("a" | "b")[] | "a" | "b" +>f : (foo: ("a" | "b")[] | "a" | "b") => "a" | "b" >foo : ("a" | "b")[] | "a" | "b" >T : ("a" | "b")[] | "a" | "b" @@ -19,22 +19,22 @@ function f(foo: T) { >"a" : "a" return foo; ->foo : ("a" | "b")[] | "a" | "b" +>foo : "a" } else if (foo === "b") { >foo === "b" : boolean ->foo : ("a" | "b")[] | "a" | "b" +>foo : ("a" | "b")[] | "b" >"b" : "b" return foo; ->foo : ("a" | "b")[] | "a" | "b" +>foo : "b" } else { return (foo as S[])[0]; >(foo as S[])[0] : "a" | "b" >(foo as S[]) : ("a" | "b")[] >foo as S[] : ("a" | "b")[] ->foo : ("a" | "b")[] | "a" | "b" +>foo : ("a" | "b")[] >S : "a" | "b" >0 : number } diff --git a/tests/baselines/reference/stringLiteralCheckedInIf02.types b/tests/baselines/reference/stringLiteralCheckedInIf02.types index ae0e370e33b94..b287400b21dcd 100644 --- a/tests/baselines/reference/stringLiteralCheckedInIf02.types +++ b/tests/baselines/reference/stringLiteralCheckedInIf02.types @@ -21,7 +21,7 @@ function isS(t: T): t is S { >t : ("a" | "b")[] | "a" | "b" >"a" : "a" >t === "b" : boolean ->t : ("a" | "b")[] | "a" | "b" +>t : ("a" | "b")[] | "b" >"b" : "b" } diff --git a/tests/baselines/reference/stringLiteralMatchedInSwitch01.types b/tests/baselines/reference/stringLiteralMatchedInSwitch01.types index ded50d120fd74..21b7029eea653 100644 --- a/tests/baselines/reference/stringLiteralMatchedInSwitch01.types +++ b/tests/baselines/reference/stringLiteralMatchedInSwitch01.types @@ -29,7 +29,7 @@ switch (foo) { >(foo as S[])[0] : "a" | "b" >(foo as S[]) : ("a" | "b")[] >foo as S[] : ("a" | "b")[] ->foo : ("a" | "b")[] | "a" | "b" +>foo : ("a" | "b")[] >S : "a" | "b" >0 : number diff --git a/tests/baselines/reference/stringLiteralTypesAndTuples01.types b/tests/baselines/reference/stringLiteralTypesAndTuples01.types index b15656835b281..59057b85f54b1 100644 --- a/tests/baselines/reference/stringLiteralTypesAndTuples01.types +++ b/tests/baselines/reference/stringLiteralTypesAndTuples01.types @@ -45,7 +45,7 @@ function rawr(dino: RexOrRaptor) { } if (dino === "raptor") { >dino === "raptor" : boolean ->dino : "t-rex" | "raptor" +>dino : "raptor" >"raptor" : "raptor" return "yip yip!"; @@ -55,5 +55,5 @@ function rawr(dino: RexOrRaptor) { throw "Unexpected " + dino; >"Unexpected " + dino : string >"Unexpected " : string ->dino : "t-rex" | "raptor" +>dino : "t-rex" } diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types index aac177224b115..2d997c93ccbdf 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types @@ -18,35 +18,35 @@ if (x === "foo") { >"foo" : "foo" let a = x; ->a : "foo" | "bar" | "baz" ->x : "foo" | "bar" | "baz" +>a : "foo" +>x : "foo" } else if (x !== "bar") { >x !== "bar" : boolean ->x : "foo" | "bar" | "baz" +>x : "bar" | "baz" >"bar" : "bar" let b = x || y; ->b : "foo" | "bar" | "baz" ->x || y : "foo" | "bar" | "baz" ->x : "foo" | "bar" | "baz" +>b : "baz" | "foo" | "bar" +>x || y : "baz" | "foo" | "bar" +>x : "baz" >y : "foo" | "bar" | "baz" } else { let c = x; ->c : "foo" | "bar" | "baz" ->x : "foo" | "bar" | "baz" +>c : "bar" +>x : "bar" let d = y; >d : "foo" | "bar" | "baz" >y : "foo" | "bar" | "baz" let e: (typeof x) | (typeof y) = c || d; ->e : "foo" | "bar" | "baz" ->x : "foo" | "bar" | "baz" +>e : "bar" | "foo" | "baz" +>x : "bar" >y : "foo" | "bar" | "baz" ->c || d : "foo" | "bar" | "baz" ->c : "foo" | "bar" | "baz" +>c || d : "bar" | "foo" | "baz" +>c : "bar" >d : "foo" | "bar" | "baz" } diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types index c877bfffe3c86..73560ac177430 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types @@ -17,35 +17,35 @@ if (x === "foo") { >"foo" : "foo" let a = x; ->a : "foo" | "bar" | number ->x : "foo" | "bar" | number +>a : "foo" +>x : "foo" } else if (x !== "bar") { >x !== "bar" : boolean ->x : "foo" | "bar" | number +>x : "bar" | number >"bar" : "bar" let b = x || y; ->b : "foo" | "bar" | number ->x || y : "foo" | "bar" | number ->x : "foo" | "bar" | number +>b : number | "foo" | "bar" +>x || y : number | "foo" | "bar" +>x : number >y : number | "foo" | "bar" } else { let c = x; ->c : "foo" | "bar" | number ->x : "foo" | "bar" | number +>c : "bar" +>x : "bar" let d = y; >d : number | "foo" | "bar" >y : number | "foo" | "bar" let e: (typeof x) | (typeof y) = c || d; ->e : "foo" | "bar" | number ->x : "foo" | "bar" | number +>e : "bar" | number | "foo" +>x : "bar" >y : number | "foo" | "bar" ->c || d : "foo" | "bar" | number ->c : "foo" | "bar" | number +>c || d : "bar" | number | "foo" +>c : "bar" >d : number | "foo" | "bar" } diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types index 81e87b727a829..9eb32b584f38b 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types @@ -19,8 +19,8 @@ if (x === "") { >"" : "" let a = x; ->a : "" | "foo" ->x : "" | "foo" +>a : "" +>x : "" } if (x !== "") { @@ -29,18 +29,18 @@ if (x !== "") { >"" : "" let b = x; ->b : "" | "foo" ->x : "" | "foo" +>b : "foo" +>x : "foo" } if (x == "") { >x == "" : boolean ->x : "" | "foo" +>x : "foo" | "" >"" : "" let c = x; ->c : "" | "foo" ->x : "" | "foo" +>c : "" +>x : "" } if (x != "") { @@ -49,12 +49,12 @@ if (x != "") { >"" : "" let d = x; ->d : "" | "foo" ->x : "" | "foo" +>d : "foo" +>x : "foo" } if (x) { ->x : "" | "foo" +>x : "foo" | "" let e = x; >e : "foo" diff --git a/tests/baselines/reference/stringLiteralTypesOverloads01.types b/tests/baselines/reference/stringLiteralTypesOverloads01.types index 21c9831e9e770..71a73222ba688 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads01.types +++ b/tests/baselines/reference/stringLiteralTypesOverloads01.types @@ -46,7 +46,7 @@ function getFalsyPrimitive(x: PrimitiveName): number | string | boolean { } if (x === "number") { >x === "number" : boolean ->x : "string" | "number" | "boolean" +>x : "number" | "boolean" >"number" : "number" return 0; @@ -54,7 +54,7 @@ function getFalsyPrimitive(x: PrimitiveName): number | string | boolean { } if (x === "boolean") { >x === "boolean" : boolean ->x : "string" | "number" | "boolean" +>x : "boolean" >"boolean" : "boolean" return false; From e14fe5b8303e10554f9852891892f19baebf53c3 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 28 Jun 2016 17:12:46 -0700 Subject: [PATCH 12/55] Remove unused functions --- src/compiler/binder.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 27bd3b71c5eef..69147d2da6837 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -617,18 +617,10 @@ namespace ts { return false; } - function isNarrowingNullCheckOperands(expr1: Expression, expr2: Expression) { - return (expr1.kind === SyntaxKind.NullKeyword || expr1.kind === SyntaxKind.Identifier && (expr1).text === "undefined") && isNarrowableOperand(expr2); - } - function isNarrowingTypeofOperands(expr1: Expression, expr2: Expression) { return expr1.kind === SyntaxKind.TypeOfExpression && isNarrowableOperand((expr1).expression) && expr2.kind === SyntaxKind.StringLiteral; } - function isNarrowingDiscriminant(expr: Expression) { - return expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((expr).expression); - } - function isNarrowingBinaryExpression(expr: BinaryExpression) { switch (expr.operatorToken.kind) { case SyntaxKind.EqualsToken: From 70e2c43d28609bb3fe1dc7de6140a1ede5ed8bdf Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 28 Jun 2016 18:04:44 -0700 Subject: [PATCH 13/55] Consider null, undefined, and void to be unit types in type guards --- src/compiler/checker.ts | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 82c37b159ecf4..4493682ed51fb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6865,19 +6865,16 @@ namespace ts { type.flags & TypeFlags.Enum && type.symbol.flags & SymbolFlags.EnumMember ? true : false; } - function isLiteralUnionType(type: Type): boolean { - return type.flags & TypeFlags.Literal ? true : - type.flags & TypeFlags.Enum ? (type.symbol.flags & SymbolFlags.EnumMember) !== 0 : - type.flags & TypeFlags.Union ? forEach((type).types, isLiteralUnionType) : - false; + function isUnitUnionType(type: Type): boolean { + return type.flags & TypeFlags.Union ? forEach((type).types, isUnitType) : isUnitType(type); } - function getBaseTypeOfLiteralType(type: Type): Type { + function getBaseTypeOfUnitType(type: Type): Type { return type.flags & TypeFlags.StringLiteral ? stringType : type.flags & TypeFlags.NumberLiteral ? numberType : type.flags & TypeFlags.BooleanLiteral ? booleanType : type.flags & TypeFlags.Enum && type.symbol.flags & SymbolFlags.EnumMember ? getDeclaredTypeOfSymbol(getParentOfSymbol(type.symbol)) : - type.flags & TypeFlags.Union ? getUnionType(map((type).types, getBaseTypeOfLiteralType)) : + type.flags & TypeFlags.Union ? getUnionType(map((type).types, getBaseTypeOfUnitType)) : type; } @@ -8123,7 +8120,7 @@ namespace ts { } function narrowTypeBySwitchOnDiscriminant(type: Type, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number) { - if (!isLiteralUnionType(type)) { + if (!isUnitUnionType(type)) { return type; } const switchTypes = getSwitchClauseTypes(switchStatement); @@ -11970,7 +11967,7 @@ namespace ts { return false; } const type = checkExpression(node.expression); - if (!isLiteralUnionType(type)) { + if (!isUnitUnionType(type)) { return false; } const switchTypes = getSwitchClauseTypes(node); @@ -12690,11 +12687,11 @@ namespace ts { case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: case SyntaxKind.ExclamationEqualsEqualsToken: - const leftIsLiteral = isLiteralUnionType(leftType); - const rightIsLiteral = isLiteralUnionType(rightType); - if (!leftIsLiteral || !rightIsLiteral) { - leftType = leftIsLiteral ? getBaseTypeOfLiteralType(leftType) : leftType; - rightType = rightIsLiteral ? getBaseTypeOfLiteralType(rightType) : rightType; + const leftIsUnit = isUnitUnionType(leftType); + const rightIsUnit = isUnitUnionType(rightType); + if (!leftIsUnit || !rightIsUnit) { + leftType = leftIsUnit ? getBaseTypeOfUnitType(leftType) : leftType; + rightType = rightIsUnit ? getBaseTypeOfUnitType(rightType) : rightType; } if (!isTypeEqualityComparableTo(leftType, rightType) && !isTypeEqualityComparableTo(rightType, leftType)) { reportOperatorError(); @@ -12836,6 +12833,13 @@ namespace ts { return getUnionType([type1, type2]); } + function isLiteralUnionType(type: Type): boolean { + return type.flags & TypeFlags.Literal ? true : + type.flags & TypeFlags.Enum ? (type.symbol.flags & SymbolFlags.EnumMember) !== 0 : + type.flags & TypeFlags.Union ? forEach((type).types, isLiteralUnionType) : + false; + } + function isLiteralTypeContext(node: Expression) { return isLiteralTypeLocation(node) || isLiteralUnionType(getContextualType(node) || unknownType); } From d37d50afb0a8f19e79445eec020bbe00d363cea8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 1 Jul 2016 09:18:43 -0700 Subject: [PATCH 14/55] Ensure const enum members with same value have same type identity --- src/compiler/checker.ts | 17 ++++++++++++++--- src/compiler/types.ts | 1 + 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4493682ed51fb..7d7ed2afb5252 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3667,12 +3667,23 @@ namespace ts { return links.declaredType; } + function createEnumType(symbol: Symbol): Type { + const type = createType(TypeFlags.Enum); + type.symbol = symbol; + return type; + } + + function getEnumMemberType(symbol: Symbol): Type { + const links = getSymbolLinks(getParentOfSymbol(symbol)); + const map = links.enumMemberTypes || (links.enumMemberTypes = {}); + const value = "" + getEnumMemberValue(symbol.valueDeclaration); + return map[value] || (map[value] = createEnumType(symbol)); + } + function getDeclaredTypeOfEnum(symbol: Symbol): Type { const links = getSymbolLinks(symbol); if (!links.declaredType) { - const type = createType(TypeFlags.Enum); - type.symbol = symbol; - links.declaredType = type; + links.declaredType = symbol.flags & SymbolFlags.EnumMember ? getEnumMemberType(symbol) : createEnumType(symbol); } return links.declaredType; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 486f1e82a9755..3dedd5da1e3f9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2136,6 +2136,7 @@ namespace ts { isDeclarationWithCollidingName?: boolean; // True if symbol is block scoped redeclaration bindingElement?: BindingElement; // Binding element associated with property symbol exportsSomeValue?: boolean; // True if module exports some value (not just types) + enumMemberTypes?: Map; // Enum member types indexed by enum value } /* @internal */ From a91a293430c601c92fca774fc68a3d2e3c645887 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 1 Jul 2016 09:28:39 -0700 Subject: [PATCH 15/55] Accept new baselines --- tests/baselines/reference/constEnums.types | 68 +++++++++++----------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/baselines/reference/constEnums.types b/tests/baselines/reference/constEnums.types index b49c9215df0ec..ba8b90314e438 100644 --- a/tests/baselines/reference/constEnums.types +++ b/tests/baselines/reference/constEnums.types @@ -414,24 +414,24 @@ function foo(x: Enum1) { >C : Enum1.C case Enum1.D: ->Enum1.D : Enum1.D +>Enum1.D : Enum1.B >Enum1 : typeof Enum1 ->D : Enum1.D +>D : Enum1.B case Enum1.E: ->Enum1.E : Enum1.E +>Enum1.E : Enum1.B >Enum1 : typeof Enum1 ->E : Enum1.E +>E : Enum1.B case Enum1.F: ->Enum1.F : Enum1.F +>Enum1.F : Enum1.B >Enum1 : typeof Enum1 ->F : Enum1.F +>F : Enum1.B case Enum1.G: ->Enum1.G : Enum1.G +>Enum1.G : Enum1.B >Enum1 : typeof Enum1 ->G : Enum1.G +>G : Enum1.B case Enum1.H: >Enum1.H : Enum1.H @@ -439,14 +439,14 @@ function foo(x: Enum1) { >H : Enum1.H case Enum1.I: ->Enum1.I : Enum1.I +>Enum1.I : Enum1.A >Enum1 : typeof Enum1 ->I : Enum1.I +>I : Enum1.A case Enum1.J: ->Enum1.J : Enum1.J +>Enum1.J : Enum1.A >Enum1 : typeof Enum1 ->J : Enum1.J +>J : Enum1.A case Enum1.K: >Enum1.K : Enum1.K @@ -454,9 +454,9 @@ function foo(x: Enum1) { >K : Enum1.K case Enum1.L: ->Enum1.L : Enum1.L +>Enum1.L : Enum1.H >Enum1 : typeof Enum1 ->L : Enum1.L +>L : Enum1.H case Enum1.M: >Enum1.M : Enum1.M @@ -464,19 +464,19 @@ function foo(x: Enum1) { >M : Enum1.M case Enum1.N: ->Enum1.N : Enum1.N +>Enum1.N : Enum1.M >Enum1 : typeof Enum1 ->N : Enum1.N +>N : Enum1.M case Enum1.O: ->Enum1.O : Enum1.O +>Enum1.O : Enum1.A >Enum1 : typeof Enum1 ->O : Enum1.O +>O : Enum1.A case Enum1.P: ->Enum1.P : Enum1.P +>Enum1.P : Enum1.A >Enum1 : typeof Enum1 ->P : Enum1.P +>P : Enum1.A case Enum1.Q: >Enum1.Q : Enum1.Q @@ -484,14 +484,14 @@ function foo(x: Enum1) { >Q : Enum1.Q case Enum1.R: ->Enum1.R : Enum1.R +>Enum1.R : Enum1.A >Enum1 : typeof Enum1 ->R : Enum1.R +>R : Enum1.A case Enum1.S: ->Enum1.S : Enum1.S +>Enum1.S : Enum1.A >Enum1 : typeof Enum1 ->S : Enum1.S +>S : Enum1.A case Enum1["T"]: >Enum1["T"] : Enum1 @@ -504,14 +504,14 @@ function foo(x: Enum1) { >U : Enum1.U case Enum1.V: ->Enum1.V : Enum1.V +>Enum1.V : Enum1.U >Enum1 : typeof Enum1 ->V : Enum1.V +>V : Enum1.U case Enum1.W: ->Enum1.W : Enum1.W +>Enum1.W : Enum1.U >Enum1 : typeof Enum1 ->W : Enum1.W +>W : Enum1.U case Enum1.W1: >Enum1.W1 : Enum1.W1 @@ -519,19 +519,19 @@ function foo(x: Enum1) { >W1 : Enum1.W1 case Enum1.W2: ->Enum1.W2 : Enum1.W2 +>Enum1.W2 : Enum1.W1 >Enum1 : typeof Enum1 ->W2 : Enum1.W2 +>W2 : Enum1.W1 case Enum1.W3: ->Enum1.W3 : Enum1.W3 +>Enum1.W3 : Enum1.W1 >Enum1 : typeof Enum1 ->W3 : Enum1.W3 +>W3 : Enum1.W1 case Enum1.W4: ->Enum1.W4 : Enum1.W4 +>Enum1.W4 : Enum1.U >Enum1 : typeof Enum1 ->W4 : Enum1.W4 +>W4 : Enum1.U break; } From 881d5105cdd71c7035386ba9b3c15cd70641f598 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 2 Jul 2016 09:37:50 -0700 Subject: [PATCH 16/55] Detect always truthy and always falsy types with &&, ||, ! operators --- src/compiler/checker.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7d7ed2afb5252..29f98529e29e9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -201,6 +201,7 @@ namespace ts { const numericLiteralTypes: Map = {}; const emptyStringType = getLiteralTypeForText(TypeFlags.StringLiteral, ""); const zeroType = getLiteralTypeForText(TypeFlags.NumberLiteral, "0"); + const trueFalseType = getUnionType([trueType, falseType]); const resolutionTargets: TypeSystemEntity[] = []; const resolutionResults: boolean[] = []; @@ -6889,6 +6890,10 @@ namespace ts { type; } + function isUnionWithTrueOrFalse(type: Type) { + return type.flags & TypeFlags.Union && (contains((type).types, trueType) || contains((type).types, falseType)); + } + /** * Check if a Type was written as a tuple type literal. * Prefer using isTupleLikeType() unless the use of `elementTypes` is required. @@ -12330,7 +12335,11 @@ namespace ts { } return numberType; case SyntaxKind.ExclamationToken: - return booleanType; + const facts = getTypeFacts(operandType) & (TypeFacts.Truthy | TypeFacts.Falsy); + return facts === TypeFacts.Truthy ? falseType : + facts === TypeFacts.Falsy ? trueType : + isUnionWithTrueOrFalse(operandType) ? trueFalseType : + booleanType; case SyntaxKind.PlusPlusToken: case SyntaxKind.MinusMinusToken: const ok = checkArithmeticOperandType(node.operand, getNonNullableType(operandType), @@ -12713,9 +12722,11 @@ namespace ts { case SyntaxKind.InKeyword: return checkInExpression(left, right, leftType, rightType); case SyntaxKind.AmpersandAmpersandToken: - return strictNullChecks ? includeFalsyTypes(rightType, getFalsyFlags(leftType)) : rightType; + return !strictNullChecks ? rightType : + getTypeFacts(leftType) & TypeFacts.Truthy ? includeFalsyTypes(rightType, getFalsyFlags(leftType)) : leftType; case SyntaxKind.BarBarToken: - return getUnionType([strictNullChecks ? removeDefinitelyFalsyTypes(leftType) : leftType, rightType]); + return !strictNullChecks ? getUnionType([leftType, rightType]) : + getTypeFacts(leftType) & TypeFacts.Truthy ? getUnionType([removeDefinitelyFalsyTypes(leftType), rightType]) : rightType; case SyntaxKind.EqualsToken: checkAssignmentOperator(rightType); return getRegularTypeOfObjectLiteral(rightType); From 1cec8dc7983791425e3710a2dab763d1d739ce5f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 3 Jul 2016 16:45:27 -0700 Subject: [PATCH 17/55] All types can be null/undefined and thus falsy in regular type checking mode --- src/compiler/checker.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 29f98529e29e9..8072659fa3ff2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -250,27 +250,27 @@ namespace ts { // The presence of a particular fact means that the given test is true for some (and possibly all) values // of that kind of type. BaseStringStrictFacts = TypeofEQString | TypeofNENumber | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull, - BaseStringFacts = BaseStringStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull, + BaseStringFacts = BaseStringStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy, StringStrictFacts = BaseStringStrictFacts | Truthy | Falsy, - StringFacts = BaseStringFacts | Truthy | Falsy, + StringFacts = BaseStringFacts | Truthy, EmptyStringStrictFacts = BaseStringStrictFacts | Falsy, - EmptyStringFacts = BaseStringFacts | Falsy, + EmptyStringFacts = BaseStringFacts, NonEmptyStringStrictFacts = BaseStringStrictFacts | Truthy, NonEmptyStringFacts = BaseStringFacts | Truthy, BaseNumberStrictFacts = TypeofEQNumber | TypeofNEString | TypeofNEBoolean | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull, - BaseNumberFacts = BaseNumberStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull, + BaseNumberFacts = BaseNumberStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy, NumberStrictFacts = BaseNumberStrictFacts | Truthy | Falsy, - NumberFacts = BaseNumberFacts | Truthy | Falsy, + NumberFacts = BaseNumberFacts | Truthy, ZeroStrictFacts = BaseNumberStrictFacts | Falsy, - ZeroFacts = BaseNumberFacts | Falsy, + ZeroFacts = BaseNumberFacts, NonZeroStrictFacts = BaseNumberStrictFacts | Truthy, NonZeroFacts = BaseNumberFacts | Truthy, BaseBooleanStrictFacts = TypeofEQBoolean | TypeofNEString | TypeofNENumber | TypeofNESymbol | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull, - BaseBooleanFacts = BaseBooleanStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull, + BaseBooleanFacts = BaseBooleanStrictFacts | EQUndefined | EQNull | EQUndefinedOrNull | Falsy, BooleanStrictFacts = BaseBooleanStrictFacts | Truthy | Falsy, - BooleanFacts = BaseBooleanFacts | Truthy | Falsy, + BooleanFacts = BaseBooleanFacts | Truthy, FalseStrictFacts = BaseBooleanStrictFacts | Falsy, - FalseFacts = BaseBooleanFacts | Falsy, + FalseFacts = BaseBooleanFacts, TrueStrictFacts = BaseBooleanStrictFacts | Truthy, TrueFacts = BaseBooleanFacts | Truthy, SymbolStrictFacts = TypeofEQSymbol | TypeofNEString | TypeofNENumber | TypeofNEBoolean | TypeofNEObject | TypeofNEFunction | TypeofNEHostObject | NEUndefined | NENull | NEUndefinedOrNull | Truthy, @@ -7635,8 +7635,8 @@ namespace ts { const constraint = getConstraintOfTypeParameter(type); return constraint ? getTypeFacts(constraint) : TypeFacts.All; } - if (flags & TypeFlags.Intersection) { - return reduceLeft((type).types, (flags, type) => flags |= getTypeFacts(type), TypeFacts.None); + if (flags & TypeFlags.UnionOrIntersection) { + return reduceLeft((type).types, (flags, type) => flags |= getTypeFacts(type), TypeFacts.None); } return TypeFacts.All; } @@ -12722,11 +12722,13 @@ namespace ts { case SyntaxKind.InKeyword: return checkInExpression(left, right, leftType, rightType); case SyntaxKind.AmpersandAmpersandToken: - return !strictNullChecks ? rightType : - getTypeFacts(leftType) & TypeFacts.Truthy ? includeFalsyTypes(rightType, getFalsyFlags(leftType)) : leftType; + return getTypeFacts(leftType) & TypeFacts.Truthy ? + strictNullChecks ? includeFalsyTypes(rightType, getFalsyFlags(leftType)) : rightType : + leftType; case SyntaxKind.BarBarToken: - return !strictNullChecks ? getUnionType([leftType, rightType]) : - getTypeFacts(leftType) & TypeFacts.Truthy ? getUnionType([removeDefinitelyFalsyTypes(leftType), rightType]) : rightType; + return getTypeFacts(leftType) & TypeFacts.Falsy ? + getUnionType([removeDefinitelyFalsyTypes(leftType), rightType]) : + leftType; case SyntaxKind.EqualsToken: checkAssignmentOperator(rightType); return getRegularTypeOfObjectLiteral(rightType); From e8d4a5a22d521f4fe01ad6a63989de6a9db52a19 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 3 Jul 2016 16:47:04 -0700 Subject: [PATCH 18/55] Accept new baselines --- .../logicalAndOperatorStrictMode.types | 80 +++++++------- .../logicalAndOperatorWithEveryType.types | 100 +++++++++--------- .../logicalOrOperatorWithEveryType.types | 34 +++--- .../stringLiteralTypesInUnionTypes04.types | 10 +- .../reference/typeGuardsAsAssertions.types | 2 +- .../baselines/reference/voidAsOperator.types | 4 +- 6 files changed, 115 insertions(+), 115 deletions(-) diff --git a/tests/baselines/reference/logicalAndOperatorStrictMode.types b/tests/baselines/reference/logicalAndOperatorStrictMode.types index afbca253b598a..61e3c4c6301d9 100644 --- a/tests/baselines/reference/logicalAndOperatorStrictMode.types +++ b/tests/baselines/reference/logicalAndOperatorStrictMode.types @@ -230,26 +230,26 @@ const b8 = b && z; >z : string | number | undefined const v1 = v && a; ->v1 : number[] | void ->v && a : number[] | void +>v1 : void +>v && a : void >v : void >a : number[] const v2 = v && s; ->v2 : string | void ->v && s : string | void +>v2 : void +>v && s : void >v : void >s : string const v3 = v && x; ->v3 : number | void ->v && x : number | void +>v3 : void +>v && x : void >v : void >x : number const v4 = v && b; ->v4 : boolean | void ->v && b : boolean | void +>v4 : void +>v && b : void >v : void >b : boolean @@ -266,44 +266,44 @@ const v6 = v && u; >u : undefined const v7 = v && n; ->v7 : void | null ->v && n : void | null +>v7 : void +>v && n : void >v : void >n : null const v8 = v && z; ->v8 : string | number | void ->v && z : string | number | void +>v8 : void +>v && z : void >v : void >z : string | number | undefined const u1 = u && a; ->u1 : number[] | undefined ->u && a : number[] | undefined +>u1 : undefined +>u && a : undefined >u : undefined >a : number[] const u2 = u && s; ->u2 : string | undefined ->u && s : string | undefined +>u2 : undefined +>u && s : undefined >u : undefined >s : string const u3 = u && x; ->u3 : number | undefined ->u && x : number | undefined +>u3 : undefined +>u && x : undefined >u : undefined >x : number const u4 = u && b; ->u4 : boolean | undefined ->u && b : boolean | undefined +>u4 : undefined +>u && b : undefined >u : undefined >b : boolean const u5 = u && v; ->u5 : void ->u && v : void +>u5 : undefined +>u && v : undefined >u : undefined >v : void @@ -314,50 +314,50 @@ const u6 = u && u; >u : never const u7 = u && n; ->u7 : null | undefined ->u && n : null | undefined +>u7 : undefined +>u && n : undefined >u : undefined >n : null const u8 = u && z; ->u8 : string | number | undefined ->u && z : string | number | undefined +>u8 : undefined +>u && z : undefined >u : undefined >z : string | number | undefined const n1 = n && a; ->n1 : number[] | null ->n && a : number[] | null +>n1 : null +>n && a : null >n : null >a : number[] const n2 = n && s; ->n2 : string | null ->n && s : string | null +>n2 : null +>n && s : null >n : null >s : string const n3 = n && x; ->n3 : number | null ->n && x : number | null +>n3 : null +>n && x : null >n : null >x : number const n4 = n && b; ->n4 : boolean | null ->n && b : boolean | null +>n4 : null +>n && b : null >n : null >b : boolean const n5 = n && v; ->n5 : void | null ->n && v : void | null +>n5 : null +>n && v : null >n : null >v : void const n6 = n && u; ->n6 : null | undefined ->n && u : null | undefined +>n6 : null +>n && u : null >n : null >u : undefined @@ -368,8 +368,8 @@ const n7 = n && n; >n : never const n8 = n && z; ->n8 : string | number | null | undefined ->n && z : string | number | null | undefined +>n8 : null +>n && z : null >n : null >z : string | number | undefined diff --git a/tests/baselines/reference/logicalAndOperatorWithEveryType.types b/tests/baselines/reference/logicalAndOperatorWithEveryType.types index bd913e94da58c..99675f42f6372 100644 --- a/tests/baselines/reference/logicalAndOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalAndOperatorWithEveryType.types @@ -58,8 +58,8 @@ var ra4 = a4 && a1; >a1 : any var ra5 = a5 && a1; ->ra5 : any ->a5 && a1 : any +>ra5 : void +>a5 && a1 : void >a5 : void >a1 : any @@ -83,13 +83,13 @@ var ra8 = a8 && a1; var ra9 = null && a1; >ra9 : any ->null && a1 : any +>null && a1 : null >null : null >a1 : any var ra10 = undefined && a1; >ra10 : any ->undefined && a1 : any +>undefined && a1 : undefined >undefined : undefined >a1 : any @@ -118,8 +118,8 @@ var rb4 = a4 && a2; >a2 : boolean var rb5 = a5 && a2; ->rb5 : boolean ->a5 && a2 : boolean +>rb5 : void +>a5 && a2 : void >a5 : void >a2 : boolean @@ -142,14 +142,14 @@ var rb8 = a8 && a2; >a2 : boolean var rb9 = null && a2; ->rb9 : boolean ->null && a2 : boolean +>rb9 : any +>null && a2 : null >null : null >a2 : boolean var rb10 = undefined && a2; ->rb10 : boolean ->undefined && a2 : boolean +>rb10 : any +>undefined && a2 : undefined >undefined : undefined >a2 : boolean @@ -178,8 +178,8 @@ var rc4 = a4 && a3; >a3 : number var rc5 = a5 && a3; ->rc5 : number ->a5 && a3 : number +>rc5 : void +>a5 && a3 : void >a5 : void >a3 : number @@ -202,14 +202,14 @@ var rc8 = a8 && a3; >a3 : number var rc9 = null && a3; ->rc9 : number ->null && a3 : number +>rc9 : any +>null && a3 : null >null : null >a3 : number var rc10 = undefined && a3; ->rc10 : number ->undefined && a3 : number +>rc10 : any +>undefined && a3 : undefined >undefined : undefined >a3 : number @@ -238,8 +238,8 @@ var rd4 = a4 && a4; >a4 : string var rd5 = a5 && a4; ->rd5 : string ->a5 && a4 : string +>rd5 : void +>a5 && a4 : void >a5 : void >a4 : string @@ -262,14 +262,14 @@ var rd8 = a8 && a4; >a4 : string var rd9 = null && a4; ->rd9 : string ->null && a4 : string +>rd9 : any +>null && a4 : null >null : null >a4 : string var rd10 = undefined && a4; ->rd10 : string ->undefined && a4 : string +>rd10 : any +>undefined && a4 : undefined >undefined : undefined >a4 : string @@ -322,14 +322,14 @@ var re8 = a8 && a5; >a5 : void var re9 = null && a5; ->re9 : void ->null && a5 : void +>re9 : any +>null && a5 : null >null : null >a5 : void var re10 = undefined && a5; ->re10 : void ->undefined && a5 : void +>re10 : any +>undefined && a5 : undefined >undefined : undefined >a5 : void @@ -358,8 +358,8 @@ var rf4 = a4 && a6; >a6 : E var rf5 = a5 && a6; ->rf5 : E ->a5 && a6 : E +>rf5 : void +>a5 && a6 : void >a5 : void >a6 : E @@ -382,14 +382,14 @@ var rf8 = a8 && a6; >a6 : E var rf9 = null && a6; ->rf9 : E ->null && a6 : E +>rf9 : any +>null && a6 : null >null : null >a6 : E var rf10 = undefined && a6; ->rf10 : E ->undefined && a6 : E +>rf10 : any +>undefined && a6 : undefined >undefined : undefined >a6 : E @@ -418,8 +418,8 @@ var rg4 = a4 && a7; >a7 : {} var rg5 = a5 && a7; ->rg5 : {} ->a5 && a7 : {} +>rg5 : void +>a5 && a7 : void >a5 : void >a7 : {} @@ -442,14 +442,14 @@ var rg8 = a8 && a7; >a7 : {} var rg9 = null && a7; ->rg9 : {} ->null && a7 : {} +>rg9 : any +>null && a7 : null >null : null >a7 : {} var rg10 = undefined && a7; ->rg10 : {} ->undefined && a7 : {} +>rg10 : any +>undefined && a7 : undefined >undefined : undefined >a7 : {} @@ -478,8 +478,8 @@ var rh4 = a4 && a8; >a8 : string[] var rh5 = a5 && a8; ->rh5 : string[] ->a5 && a8 : string[] +>rh5 : void +>a5 && a8 : void >a5 : void >a8 : string[] @@ -502,14 +502,14 @@ var rh8 = a8 && a8; >a8 : string[] var rh9 = null && a8; ->rh9 : string[] ->null && a8 : string[] +>rh9 : any +>null && a8 : null >null : null >a8 : string[] var rh10 = undefined && a8; ->rh10 : string[] ->undefined && a8 : string[] +>rh10 : any +>undefined && a8 : undefined >undefined : undefined >a8 : string[] @@ -538,8 +538,8 @@ var ri4 = a4 && null; >null : null var ri5 = a5 && null; ->ri5 : any ->a5 && null : null +>ri5 : void +>a5 && null : void >a5 : void >null : null @@ -569,7 +569,7 @@ var ri9 = null && null; var ri10 = undefined && null; >ri10 : any ->undefined && null : null +>undefined && null : undefined >undefined : undefined >null : null @@ -598,8 +598,8 @@ var rj4 = a4 && undefined; >undefined : undefined var rj5 = a5 && undefined; ->rj5 : any ->a5 && undefined : undefined +>rj5 : void +>a5 && undefined : void >a5 : void >undefined : undefined @@ -623,7 +623,7 @@ var rj8 = a8 && undefined; var rj9 = null && undefined; >rj9 : any ->null && undefined : undefined +>null && undefined : null >null : null >undefined : undefined diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.types b/tests/baselines/reference/logicalOrOperatorWithEveryType.types index 4540e35aaf459..88f24d02dae18 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.types @@ -121,8 +121,8 @@ var rb4 = a4 || a2; // string || boolean is string | boolean >a2 : boolean var rb5 = a5 || a2; // void || boolean is void | boolean ->rb5 : void | boolean ->a5 || a2 : void | boolean +>rb5 : boolean +>a5 || a2 : boolean >a5 : void >a2 : boolean @@ -181,8 +181,8 @@ var rc4 = a4 || a3; // string || number is string | number >a3 : number var rc5 = a5 || a3; // void || number is void | number ->rc5 : void | number ->a5 || a3 : void | number +>rc5 : number +>a5 || a3 : number >a5 : void >a3 : number @@ -241,8 +241,8 @@ var rd4 = a4 || a4; // string || string is string >a4 : string var rd5 = a5 || a4; // void || string is void | string ->rd5 : void | string ->a5 || a4 : void | string +>rd5 : string +>a5 || a4 : string >a5 : void >a4 : string @@ -361,8 +361,8 @@ var rg4 = a4 || a6; // string || enum is string | enum >a6 : E var rg5 = a5 || a6; // void || enum is void | enum ->rg5 : void | E ->a5 || a6 : void | E +>rg5 : E +>a5 || a6 : E >a5 : void >a6 : E @@ -421,8 +421,8 @@ var rh4 = a4 || a7; // string || object is string | object >a7 : { a: string; } var rh5 = a5 || a7; // void || object is void | object ->rh5 : void | { a: string; } ->a5 || a7 : void | { a: string; } +>rh5 : { a: string; } +>a5 || a7 : { a: string; } >a5 : void >a7 : { a: string; } @@ -481,8 +481,8 @@ var ri4 = a4 || a8; // string || array is string | array >a8 : string[] var ri5 = a5 || a8; // void || array is void | array ->ri5 : void | string[] ->a5 || a8 : void | string[] +>ri5 : string[] +>a5 || a8 : string[] >a5 : void >a8 : string[] @@ -541,8 +541,8 @@ var rj4 = a4 || null; // string || null is string >null : null var rj5 = a5 || null; // void || null is void ->rj5 : void ->a5 || null : void +>rj5 : any +>a5 || null : null >a5 : void >null : null @@ -601,8 +601,8 @@ var rf4 = a4 || undefined; // string || undefined is string >undefined : undefined var rf5 = a5 || undefined; // void || undefined is void ->rf5 : void ->a5 || undefined : void +>rf5 : any +>a5 || undefined : undefined >a5 : void >undefined : undefined @@ -626,7 +626,7 @@ var rf8 = a8 || undefined; // array || undefined is array var rf9 = null || undefined; // null || undefined is any >rf9 : any ->null || undefined : null +>null || undefined : undefined >null : null >undefined : undefined diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types index 9eb32b584f38b..bf1cc61175f15 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types @@ -66,14 +66,14 @@ if (!x) { >x : "foo" | "" let f = x; ->f : "" ->x : "" +>f : "foo" | "" +>x : "foo" | "" } if (!!x) { >!!x : boolean >!x : boolean ->x : "" | "foo" +>x : "foo" | "" let g = x; >g : "foo" @@ -87,6 +87,6 @@ if (!!!x) { >x : "foo" | "" let h = x; ->h : "" ->x : "" +>h : "foo" | "" +>x : "foo" | "" } diff --git a/tests/baselines/reference/typeGuardsAsAssertions.types b/tests/baselines/reference/typeGuardsAsAssertions.types index 37018c654a897..3ea84efa1c932 100644 --- a/tests/baselines/reference/typeGuardsAsAssertions.types +++ b/tests/baselines/reference/typeGuardsAsAssertions.types @@ -233,7 +233,7 @@ function f3() { >x : undefined if (!x) { ->!x : boolean +>!x : true >x : undefined return; diff --git a/tests/baselines/reference/voidAsOperator.types b/tests/baselines/reference/voidAsOperator.types index 0394e767fd9cc..e95f27f1b5baf 100644 --- a/tests/baselines/reference/voidAsOperator.types +++ b/tests/baselines/reference/voidAsOperator.types @@ -1,7 +1,7 @@ === tests/cases/compiler/voidAsOperator.ts === if (!void 0 !== true) { >!void 0 !== true : boolean ->!void 0 : boolean +>!void 0 : true >void 0 : undefined >0 : number >true : true @@ -11,7 +11,7 @@ if (!void 0 !== true) { //CHECK#2 if (!null !== true) { >!null !== true : boolean ->!null : boolean +>!null : true >null : null >true : true From 280b27e2630e1fae6868492613431819ab40f18c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 6 Jul 2016 19:50:44 -0700 Subject: [PATCH 19/55] Narrowing doesn't require switch expression to be unit type --- src/compiler/checker.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f2066cef0dfeb..2179612d0122a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6946,12 +6946,12 @@ namespace ts { } function isUnitType(type: Type): boolean { - return type.flags & (TypeFlags.Literal | TypeFlags.Void | TypeFlags.Undefined | TypeFlags.Null) || + return type.flags & (TypeFlags.Literal | TypeFlags.Undefined | TypeFlags.Null) || type.flags & TypeFlags.Enum && type.symbol.flags & SymbolFlags.EnumMember ? true : false; } function isUnitUnionType(type: Type): boolean { - return type.flags & TypeFlags.Union ? forEach((type).types, isUnitType) : isUnitType(type); + return type.flags & TypeFlags.Union ? !forEach((type).types, t => !isUnitType(t)) : isUnitType(type); } function getBaseTypeOfUnitType(type: Type): Type { @@ -8209,9 +8209,7 @@ namespace ts { } function narrowTypeBySwitchOnDiscriminant(type: Type, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number) { - if (!isUnitUnionType(type)) { - return type; - } + // We only narrow if all case expressions specify values with unit types const switchTypes = getSwitchClauseTypes(switchStatement); if (!switchTypes.length) { return type; @@ -8223,7 +8221,7 @@ namespace ts { if (!hasDefaultClause) { return caseType; } - const defaultType = filterType(type, t => !eachTypeContainedIn(t, switchTypes)); + const defaultType = filterType(type, t => !(isUnitType(t) && contains(switchTypes, t))); return caseType === neverType ? defaultType : getUnionType([caseType, defaultType]); } From 82c26cd1efcd4597f40760dfa817c98b89bf0169 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 6 Jul 2016 21:00:47 -0700 Subject: [PATCH 20/55] Adding selected tests from #6196 --- ...teralsAssertionsInEqualityComparisons01.ts | 3 ++ ...teralsAssertionsInEqualityComparisons02.ts | 6 ++++ .../stringLiteralsWithEqualityChecks01.ts | 22 ++++++++++++++ .../stringLiteralsWithEqualityChecks02.ts | 22 ++++++++++++++ .../stringLiteralsWithEqualityChecks03.ts | 29 +++++++++++++++++++ .../stringLiteralsWithEqualityChecks04.ts | 29 +++++++++++++++++++ .../stringLiteralsWithSwitchStatements01.ts | 12 ++++++++ .../stringLiteralsWithSwitchStatements02.ts | 14 +++++++++ .../stringLiteralsWithSwitchStatements03.ts | 26 +++++++++++++++++ .../stringLiteralsWithSwitchStatements04.ts | 21 ++++++++++++++ .../stringLiteralsWithTypeAssertions01.ts | 8 +++++ 11 files changed, 192 insertions(+) create mode 100644 tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons01.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements01.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements04.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts diff --git a/tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons01.ts b/tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons01.ts new file mode 100644 index 0000000000000..b161660488ce6 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons01.ts @@ -0,0 +1,3 @@ +var a = "foo" === "bar" as string; +var b = "foo" !== ("bar" as string); +var c = "foo" == ("bar"); \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts b/tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts new file mode 100644 index 0000000000000..8ab4469055feb --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts @@ -0,0 +1,6 @@ +type EnhancedString = string & { enhancements: any }; + +var a = "foo" === "bar" as "baz"; +var b = "foo" !== ("bar" as "foo"); +var c = "foo" == ("bar"); +var d = "foo" === ("bar" as EnhancedString); \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts new file mode 100644 index 0000000000000..3179be186ea48 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts @@ -0,0 +1,22 @@ +let x: "foo"; +let y: "foo" | "bar"; + +let b: boolean; +b = x === y; +b = "foo" === y +b = y === "foo"; +b = "foo" === "bar"; +b = "bar" === x; +b = x === "bar"; +b = y === "bar"; +b = "bar" === y; + +b = x !== y; +b = "foo" !== y +b = y !== "foo"; +b = "foo" !== "bar"; +b = "bar" !== x; +b = x !== "bar"; +b = y !== "bar"; +b = "bar" !== y; + diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts new file mode 100644 index 0000000000000..25a687a8941a8 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts @@ -0,0 +1,22 @@ +let x: "foo"; +let y: "foo" | "bar"; + +let b: boolean; +b = x == y; +b = "foo" == y +b = y == "foo"; +b = "foo" == "bar"; +b = "bar" == x; +b = x == "bar"; +b = y == "bar"; +b = "bar" == y; + +b = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; + diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts new file mode 100644 index 0000000000000..b4fb064818728 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts @@ -0,0 +1,29 @@ +interface Runnable { + isRunning: boolean; +} + +interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; +} + +let x: string; +let y: "foo" | Refrigerator; + +let b: boolean; +b = x === y; +b = "foo" === y +b = y === "foo"; +b = "foo" === "bar"; +b = "bar" === x; +b = x === "bar"; +b = y === "bar"; +b = "bar" === y; + +b = x !== y; +b = "foo" !== y +b = y !== "foo"; +b = "foo" !== "bar"; +b = "bar" !== x; +b = x !== "bar"; +b = y !== "bar"; +b = "bar" !== y; diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts new file mode 100644 index 0000000000000..01e1c0896fb2a --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts @@ -0,0 +1,29 @@ +interface Runnable { + isRunning: boolean; +} + +interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; +} + +let x: string; +let y: "foo" | Refrigerator; + +let b: boolean; +b = x == y; +b = "foo" == y +b = y == "foo"; +b = "foo" == "bar"; +b = "bar" == x; +b = x == "bar"; +b = y == "bar"; +b = "bar" == y; + +b = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements01.ts b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements01.ts new file mode 100644 index 0000000000000..b1c1aaa64cae2 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements01.ts @@ -0,0 +1,12 @@ +let x: "foo"; +let y: "foo" | "bar"; + +switch (x) { + case "foo": + break; + case "bar": + break; + case y: + y; + break; +} diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts new file mode 100644 index 0000000000000..d396eb16bed00 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts @@ -0,0 +1,14 @@ +let x: "foo"; +let y: "foo" | "bar"; + +let b: boolean; +b = x == y; +b = "foo" == y +b = y == "foo"; +b = "foo" == "bar"; + +b = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; + diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts new file mode 100644 index 0000000000000..289ffd11060f3 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts @@ -0,0 +1,26 @@ +let x: "foo"; +let y: "foo" | "bar"; +let z: "bar"; + +declare function randBool(): boolean; + +switch (x) { + case randBool() ? "foo" : "baz": + break; + case (randBool() ? ("bar") : "baz" ? "bar" : "baz"): + break; + case (("bar")): + break; + case (x, y, ("baz")): + x; + y; + break; + case (("foo" || ("bar"))): + break; + case (("bar" || ("baz"))): + break; + case z || "baz": + case "baz" || z: + z; + break; +} diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements04.ts b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements04.ts new file mode 100644 index 0000000000000..ee119cd1db544 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements04.ts @@ -0,0 +1,21 @@ +let x: "foo"; +let y: "foo" | "bar"; + +declare function randBool(): boolean; + +switch (y) { + case "foo", x: + break; + case x, "foo": + break; + case x, "baz": + break; + case "baz", x: + break; + case "baz" && "bar": + break; + case "baz" && ("foo" || "bar"): + break; + case "bar" && ("baz" || "bar"): + break; +} diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts b/tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts new file mode 100644 index 0000000000000..2e3542704129d --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts @@ -0,0 +1,8 @@ +let fooOrBar: "foo" | "bar"; + +let a = "foo" as "bar"; +let b = "bar" as "foo"; +let c = fooOrBar as "foo"; +let d = fooOrBar as "bar"; +let e = fooOrBar as "baz"; +let f = "baz" as typeof fooOrBar; \ No newline at end of file From 871aee14161493110c35779b1c97bd199eb43e45 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 6 Jul 2016 21:01:00 -0700 Subject: [PATCH 21/55] Adding new tests --- .../types/literal/booleanLiteralTypes1.ts | 95 ++++++++++++ .../types/literal/booleanLiteralTypes2.ts | 97 ++++++++++++ .../types/literal/enumLiteralTypes1.ts | 113 ++++++++++++++ .../types/literal/enumLiteralTypes2.ts | 115 ++++++++++++++ .../types/literal/enumLiteralTypes3.ts | 119 +++++++++++++++ .../types/literal/literalTypes1.ts | 90 +++++++++++ .../types/literal/numericLiteralTypes1.ts | 139 +++++++++++++++++ .../types/literal/numericLiteralTypes2.ts | 141 ++++++++++++++++++ .../types/literal/numericLiteralTypes3.ts | 100 +++++++++++++ 9 files changed, 1009 insertions(+) create mode 100644 tests/cases/conformance/types/literal/booleanLiteralTypes1.ts create mode 100644 tests/cases/conformance/types/literal/booleanLiteralTypes2.ts create mode 100644 tests/cases/conformance/types/literal/enumLiteralTypes1.ts create mode 100644 tests/cases/conformance/types/literal/enumLiteralTypes2.ts create mode 100644 tests/cases/conformance/types/literal/enumLiteralTypes3.ts create mode 100644 tests/cases/conformance/types/literal/literalTypes1.ts create mode 100644 tests/cases/conformance/types/literal/numericLiteralTypes1.ts create mode 100644 tests/cases/conformance/types/literal/numericLiteralTypes2.ts create mode 100644 tests/cases/conformance/types/literal/numericLiteralTypes3.ts diff --git a/tests/cases/conformance/types/literal/booleanLiteralTypes1.ts b/tests/cases/conformance/types/literal/booleanLiteralTypes1.ts new file mode 100644 index 0000000000000..e8ccbde080b07 --- /dev/null +++ b/tests/cases/conformance/types/literal/booleanLiteralTypes1.ts @@ -0,0 +1,95 @@ +type A1 = true | false; +type A2 = false | true; + +function f1() { + var a: A1; + var a: A2; + var a: true | false; + var a: false | true; +} + +function f2(a: true | false, b: boolean) { + a = b; + b = a; +} + +function f3(a: true | false, b: true | false) { + var x = a || b; + var x = a && b; + var x = !a; +} + +function f4(t: true, f: false) { + var x1 = t && f; + var x2 = f && t; + var x3 = t || f; + var x4 = f || t; + var x5 = !t; + var x6 = !f; +} + +declare function g(x: true): string; +declare function g(x: false): boolean; +declare function g(x: boolean): number; + +function f5(b: boolean) { + var z1 = g(true); + var z2 = g(false); + var z3 = g(b); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +function f10(x: true | false) { + switch (x) { + case true: return "true"; + case false: return "false"; + } +} + +function f11(x: true | false) { + switch (x) { + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +} + +function f12(x: true | false) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: true | false) { + if (x === true) { + x; + } + else { + x; + } +} + +type Item = + { kind: true, a: string } | + { kind: false, b: string }; + +function f20(x: Item) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } +} + +function f21(x: Item) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } + return assertNever(x); +} \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/booleanLiteralTypes2.ts b/tests/cases/conformance/types/literal/booleanLiteralTypes2.ts new file mode 100644 index 0000000000000..e3ba292abdb57 --- /dev/null +++ b/tests/cases/conformance/types/literal/booleanLiteralTypes2.ts @@ -0,0 +1,97 @@ +// @strictNullChecks: true + +type A1 = true | false; +type A2 = false | true; + +function f1() { + var a: A1; + var a: A2; + var a: true | false; + var a: false | true; +} + +function f2(a: true | false, b: boolean) { + a = b; + b = a; +} + +function f3(a: true | false, b: true | false) { + var x = a || b; + var x = a && b; + var x = !a; +} + +function f4(t: true, f: false) { + var x1 = t && f; + var x2 = f && t; + var x3 = t || f; + var x4 = f || t; + var x5 = !t; + var x6 = !f; +} + +declare function g(x: true): string; +declare function g(x: false): boolean; +declare function g(x: boolean): number; + +function f5(b: boolean) { + var z1 = g(true); + var z2 = g(false); + var z3 = g(b); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +function f10(x: true | false) { + switch (x) { + case true: return "true"; + case false: return "false"; + } +} + +function f11(x: true | false) { + switch (x) { + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +} + +function f12(x: true | false) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: true | false) { + if (x === true) { + x; + } + else { + x; + } +} + +type Item = + { kind: true, a: string } | + { kind: false, b: string }; + +function f20(x: Item) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } +} + +function f21(x: Item) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } + return assertNever(x); +} \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/enumLiteralTypes1.ts b/tests/cases/conformance/types/literal/enumLiteralTypes1.ts new file mode 100644 index 0000000000000..9794b5082b87f --- /dev/null +++ b/tests/cases/conformance/types/literal/enumLiteralTypes1.ts @@ -0,0 +1,113 @@ +const enum Choice { Unknown, Yes, No }; + +type YesNo = Choice.Yes | Choice.No; +type NoYes = Choice.No | Choice.Yes; +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; + +function f1() { + var a: YesNo; + var a: NoYes; + var a: Choice.Yes | Choice.No; + var a: Choice.No | Choice.Yes; +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { + b = a; + c = a; + c = b; +} + +function f3(a: Choice.Yes, b: YesNo) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} + +function f4(a: Choice.Yes, b: YesNo) { + a++; + b++; +} + +declare function g(x: Choice.Yes): string; +declare function g(x: Choice.No): boolean; +declare function g(x: Choice): number; + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { + var z1 = g(Choice.Yes); + var z2 = g(Choice.No); + var z3 = g(a); + var z4 = g(b); + var z5 = g(c); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +function f10(x: YesNo) { + switch (x) { + case Choice.Yes: return "true"; + case Choice.No: return "false"; + } +} + +function f11(x: YesNo) { + switch (x) { + case Choice.Yes: return "true"; + case Choice.No: return "false"; + } + return assertNever(x); +} + +function f12(x: UnknownYesNo) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: UnknownYesNo) { + if (x === Choice.Yes) { + x; + } + else { + x; + } +} + +type Item = + { kind: Choice.Yes, a: string } | + { kind: Choice.No, b: string }; + +function f20(x: Item) { + switch (x.kind) { + case Choice.Yes: return x.a; + case Choice.No: return x.b; + } +} + +function f21(x: Item) { + switch (x.kind) { + case Choice.Yes: return x.a; + case Choice.No: return x.b; + } + return assertNever(x); +} \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/enumLiteralTypes2.ts b/tests/cases/conformance/types/literal/enumLiteralTypes2.ts new file mode 100644 index 0000000000000..26dd11760cb95 --- /dev/null +++ b/tests/cases/conformance/types/literal/enumLiteralTypes2.ts @@ -0,0 +1,115 @@ +// @strictNullChecks: true + +const enum Choice { Unknown, Yes, No }; + +type YesNo = Choice.Yes | Choice.No; +type NoYes = Choice.No | Choice.Yes; +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; + +function f1() { + var a: YesNo; + var a: NoYes; + var a: Choice.Yes | Choice.No; + var a: Choice.No | Choice.Yes; +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { + b = a; + c = a; + c = b; +} + +function f3(a: Choice.Yes, b: UnknownYesNo) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} + +function f4(a: Choice.Yes, b: UnknownYesNo) { + a++; + b++; +} + +declare function g(x: Choice.Yes): string; +declare function g(x: Choice.No): boolean; +declare function g(x: Choice): number; + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { + var z1 = g(Choice.Yes); + var z2 = g(Choice.No); + var z3 = g(a); + var z4 = g(b); + var z5 = g(c); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +function f10(x: YesNo) { + switch (x) { + case Choice.Yes: return "true"; + case Choice.No: return "false"; + } +} + +function f11(x: YesNo) { + switch (x) { + case Choice.Yes: return "true"; + case Choice.No: return "false"; + } + return assertNever(x); +} + +function f12(x: UnknownYesNo) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: UnknownYesNo) { + if (x === Choice.Yes) { + x; + } + else { + x; + } +} + +type Item = + { kind: Choice.Yes, a: string } | + { kind: Choice.No, b: string }; + +function f20(x: Item) { + switch (x.kind) { + case Choice.Yes: return x.a; + case Choice.No: return x.b; + } +} + +function f21(x: Item) { + switch (x.kind) { + case Choice.Yes: return x.a; + case Choice.No: return x.b; + } + return assertNever(x); +} \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/enumLiteralTypes3.ts b/tests/cases/conformance/types/literal/enumLiteralTypes3.ts new file mode 100644 index 0000000000000..11e6b7d3c929c --- /dev/null +++ b/tests/cases/conformance/types/literal/enumLiteralTypes3.ts @@ -0,0 +1,119 @@ +const enum Choice { Unknown, Yes, No }; + +type Yes = Choice.Yes; +type YesNo = Choice.Yes | Choice.No; +type NoYes = Choice.No | Choice.Yes; +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; + +function f1(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a = a; + a = b; + a = c; + a = d; +} + +function f2(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + b = a; + b = b; + b = c; + b = d; +} + +function f3(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + c = a; + c = b; + c = c; + c = d; +} + +function f4(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + d = a; + d = b; + d = c; + d = d; +} + +function f5(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a = Choice.Unknown; + a = Choice.Yes; + a = Choice.No; + b = Choice.Unknown; + b = Choice.Yes; + b = Choice.No; + c = Choice.Unknown; + c = Choice.Yes; + c = Choice.No; + d = Choice.Unknown; + d = Choice.Yes; + d = Choice.No; +} + +function f6(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a === Choice.Unknown; + a === Choice.Yes; + a === Choice.No; + b === Choice.Unknown; + b === Choice.Yes; + b === Choice.No; + c === Choice.Unknown; + c === Choice.Yes; + c === Choice.No; + d === Choice.Unknown; + d === Choice.Yes; + d === Choice.No; +} + +function f7(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a === a; + a === b; + a === c; + a === d; + b === a; + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; +} + +function f10(x: Yes): Yes { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; +} + +function f11(x: YesNo): YesNo { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; +} + +function f12(x: UnknownYesNo): UnknownYesNo { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; +} + +function f13(x: Choice): Choice { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/literalTypes1.ts b/tests/cases/conformance/types/literal/literalTypes1.ts new file mode 100644 index 0000000000000..b793bba2d34cc --- /dev/null +++ b/tests/cases/conformance/types/literal/literalTypes1.ts @@ -0,0 +1,90 @@ +// @strictNullChecks: true + +let zero: 0 = 0; +let one: 1 = 1; +let two: 2 = 2; +let oneOrTwo: 1 | 2 = <1 | 2>1; + +function f1(x: 0 | 1 | 2) { + switch (x) { + case zero: + x; + break; + case one: + x; + break; + case two: + x; + break; + default: + x; + } +} + +function f2(x: 0 | 1 | 2) { + switch (x) { + case zero: + x; + break; + case oneOrTwo: + x; + break; + default: + x; + } +} + +type Falsy = false | 0 | "" | null | undefined; + +function f3(x: Falsy) { + if (x) { + x; + } + else { + x; + } +} + +function f4(x: 0 | 1 | true | string) { + switch (x) { + case 0: + x; + break; + case 1: + x; + break; + case "abc": + case "def": + x; + break; + case null: + x; + break; + case undefined: + x; + break; + default: + x; + } +} + +function f5(x: string | number | boolean) { + switch (x) { + case "abc": + x; + break; + case 0: + case 1: + x; + break; + case true: + x; + break; + case "hello": + case 123: + x; + break; + default: + x; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/numericLiteralTypes1.ts b/tests/cases/conformance/types/literal/numericLiteralTypes1.ts new file mode 100644 index 0000000000000..76d8265a841c3 --- /dev/null +++ b/tests/cases/conformance/types/literal/numericLiteralTypes1.ts @@ -0,0 +1,139 @@ +type A1 = 1; +type A2 = 1.0; +type A3 = 1e0; +type A4 = 10e-1; +type A5 = 1 | 1.0 | 1e0 | 10e-1; + +function f1() { + var a: A1 = 1; + var a: A2 = 1; + var a: A3 = 1; + var a: A4 = 1; + var a: A5 = 1; +} + +type B1 = -1 | 0 | 1; +type B2 = 1 | 0 | -1; +type B3 = 0 | -1 | 1; + +function f2() { + var b: B1 = -1; + var b: B2 = 0; + var b: B3 = 1; +} + +function f3(a: 1, b: 0 | 1 | 2) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} + +function f4(a: 1, b: 0 | 1 | 2) { + a++; + b++; +} + +declare function g(x: 0): string; +declare function g(x: 1): boolean; +declare function g(x: number): number; + +function f5(a: 1, b: 0 | 1 | 2) { + var z1 = g(0); + var z2 = g(1); + var z3 = g(2); + var z4 = g(a); + var z5 = g(b); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +type Tag = 0 | 1 | 2; + +function f10(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} + +function f11(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +} + +function f12(x: Tag) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: Tag) { + if (x === 0 || x === 2) { + x; + } + else { + x; + } +} + +function f14(x: 0 | 1 | 2, y: string) { + var a = x && y; + var b = x || y; +} + +function f15(x: 0 | false, y: 1 | "one") { + var a = x && y; + var b = y && x; + var c = x || y; + var d = y || x; + var e = !x; + var f = !y; +} + +type Item = + { kind: 0, a: string } | + { kind: 1, b: string } | + { kind: 2, c: string }; + +function f20(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } +} + +function f21(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + return assertNever(x); +} \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/numericLiteralTypes2.ts b/tests/cases/conformance/types/literal/numericLiteralTypes2.ts new file mode 100644 index 0000000000000..3ab0fd5631fc8 --- /dev/null +++ b/tests/cases/conformance/types/literal/numericLiteralTypes2.ts @@ -0,0 +1,141 @@ +// @strictNullChecks: true + +type A1 = 1; +type A2 = 1.0; +type A3 = 1e0; +type A4 = 10e-1; +type A5 = 1 | 1.0 | 1e0 | 10e-1; + +function f1() { + var a: A1 = 1; + var a: A2 = 1; + var a: A3 = 1; + var a: A4 = 1; + var a: A5 = 1; +} + +type B1 = -1 | 0 | 1; +type B2 = 1 | 0 | -1; +type B3 = 0 | -1 | 1; + +function f2() { + var b: B1 = -1; + var b: B2 = 0; + var b: B3 = 1; +} + +function f3(a: 1, b: 0 | 1 | 2) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} + +function f4(a: 1, b: 0 | 1 | 2) { + a++; + b++; +} + +declare function g(x: 0): string; +declare function g(x: 1): boolean; +declare function g(x: number): number; + +function f5(a: 1, b: 0 | 1 | 2) { + var z1 = g(0); + var z2 = g(1); + var z3 = g(2); + var z4 = g(a); + var z5 = g(b); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +type Tag = 0 | 1 | 2; + +function f10(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} + +function f11(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +} + +function f12(x: Tag) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: Tag) { + if (x === 0 || x === 2) { + x; + } + else { + x; + } +} + +function f14(x: 0 | 1 | 2, y: string) { + var a = x && y; + var b = x || y; +} + +function f15(x: 0 | false, y: 1 | "one") { + var a = x && y; + var b = y && x; + var c = x || y; + var d = y || x; + var e = !x; + var f = !y; +} + +type Item = + { kind: 0, a: string } | + { kind: 1, b: string } | + { kind: 2, c: string }; + +function f20(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } +} + +function f21(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + return assertNever(x); +} \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/numericLiteralTypes3.ts b/tests/cases/conformance/types/literal/numericLiteralTypes3.ts new file mode 100644 index 0000000000000..5bdbbc0d20e00 --- /dev/null +++ b/tests/cases/conformance/types/literal/numericLiteralTypes3.ts @@ -0,0 +1,100 @@ +type A = 1; +type B = 2 | 3; +type C = 1 | 2 | 3; +type D = 0 | 1 | 2; + +function f1(a: A, b: B, c: C, d: D) { + a = a; + a = b; + a = c; + a = d; +} + +function f2(a: A, b: B, c: C, d: D) { + b = a; + b = b; + b = c; + b = d; +} + +function f3(a: A, b: B, c: C, d: D) { + c = a; + c = b; + c = c; + c = d; +} + +function f4(a: A, b: B, c: C, d: D) { + d = a; + d = b; + d = c; + d = d; +} + +function f5(a: A, b: B, c: C, d: D) { + a = 0; + a = 1; + a = 2; + a = 3; + b = 0; + b = 1; + b = 2; + b = 3; + c = 0; + c = 1; + c = 2; + c = 3; + d = 0; + d = 1; + d = 2; + d = 3; +} + +function f6(a: A, b: B, c: C, d: D) { + a === 0; + a === 1; + a === 2; + a === 3; + b === 0; + b === 1; + b === 2; + b === 3; + c === 0; + c === 1; + c === 2; + c === 3; + d === 0; + d === 1; + d === 2; + d === 3; +} + +function f7(a: A, b: B, c: C, d: D) { + a === a; + a === b; + a === c; + a === d; + b === a; + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; +} + +function f8(x: 0 | 2 | 4) { + switch (x) { + case 0: return; + case 1: return; + case 2: return; + case 3: return; + case 4: return; + case 5: return; + } +} \ No newline at end of file From 6309ada1fa9a8b612d8f7bbc6547cdd1cf2cdc7a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 6 Jul 2016 21:01:51 -0700 Subject: [PATCH 22/55] Accepting new baselines --- .../reference/booleanLiteralTypes1.js | 171 ++++++ .../reference/booleanLiteralTypes1.symbols | 247 +++++++++ .../reference/booleanLiteralTypes1.types | 311 +++++++++++ .../reference/booleanLiteralTypes2.js | 172 ++++++ .../reference/booleanLiteralTypes2.symbols | 248 +++++++++ .../reference/booleanLiteralTypes2.types | 312 +++++++++++ .../baselines/reference/enumLiteralTypes1.js | 205 +++++++ .../reference/enumLiteralTypes1.symbols | 411 +++++++++++++++ .../reference/enumLiteralTypes1.types | 449 ++++++++++++++++ .../baselines/reference/enumLiteralTypes2.js | 206 ++++++++ .../reference/enumLiteralTypes2.symbols | 412 +++++++++++++++ .../reference/enumLiteralTypes2.types | 450 ++++++++++++++++ .../reference/enumLiteralTypes3.errors.txt | 173 ++++++ .../baselines/reference/enumLiteralTypes3.js | 225 ++++++++ tests/baselines/reference/literalTypes1.js | 173 ++++++ .../baselines/reference/literalTypes1.symbols | 170 ++++++ tests/baselines/reference/literalTypes1.types | 200 +++++++ .../reference/numericLiteralTypes1.js | 247 +++++++++ .../reference/numericLiteralTypes1.symbols | 413 +++++++++++++++ .../reference/numericLiteralTypes1.types | 497 +++++++++++++++++ .../reference/numericLiteralTypes2.js | 248 +++++++++ .../reference/numericLiteralTypes2.symbols | 414 +++++++++++++++ .../reference/numericLiteralTypes2.types | 498 ++++++++++++++++++ .../reference/numericLiteralTypes3.errors.txt | 203 +++++++ .../reference/numericLiteralTypes3.js | 191 +++++++ ...teralsAssertionsInEqualityComparisons01.js | 9 + ...sAssertionsInEqualityComparisons01.symbols | 10 + ...alsAssertionsInEqualityComparisons01.types | 24 + ...sertionsInEqualityComparisons02.errors.txt | 24 + ...teralsAssertionsInEqualityComparisons02.js | 13 + ...ingLiteralsWithEqualityChecks01.errors.txt | 44 ++ .../stringLiteralsWithEqualityChecks01.js | 45 ++ ...ingLiteralsWithEqualityChecks02.errors.txt | 44 ++ .../stringLiteralsWithEqualityChecks02.js | 45 ++ ...ingLiteralsWithEqualityChecks03.errors.txt | 39 ++ .../stringLiteralsWithEqualityChecks03.js | 52 ++ ...ingLiteralsWithEqualityChecks04.errors.txt | 39 ++ .../stringLiteralsWithEqualityChecks04.js | 52 ++ ...gLiteralsWithSwitchStatements01.errors.txt | 19 + .../stringLiteralsWithSwitchStatements01.js | 27 + ...gLiteralsWithSwitchStatements02.errors.txt | 24 + .../stringLiteralsWithSwitchStatements02.js | 29 + ...gLiteralsWithSwitchStatements03.errors.txt | 43 ++ .../stringLiteralsWithSwitchStatements03.js | 53 ++ .../stringLiteralsWithSwitchStatements04.js | 43 ++ ...ringLiteralsWithSwitchStatements04.symbols | 37 ++ ...stringLiteralsWithSwitchStatements04.types | 63 +++ ...ingLiteralsWithTypeAssertions01.errors.txt | 25 + .../stringLiteralsWithTypeAssertions01.js | 18 + 49 files changed, 8067 insertions(+) create mode 100644 tests/baselines/reference/booleanLiteralTypes1.js create mode 100644 tests/baselines/reference/booleanLiteralTypes1.symbols create mode 100644 tests/baselines/reference/booleanLiteralTypes1.types create mode 100644 tests/baselines/reference/booleanLiteralTypes2.js create mode 100644 tests/baselines/reference/booleanLiteralTypes2.symbols create mode 100644 tests/baselines/reference/booleanLiteralTypes2.types create mode 100644 tests/baselines/reference/enumLiteralTypes1.js create mode 100644 tests/baselines/reference/enumLiteralTypes1.symbols create mode 100644 tests/baselines/reference/enumLiteralTypes1.types create mode 100644 tests/baselines/reference/enumLiteralTypes2.js create mode 100644 tests/baselines/reference/enumLiteralTypes2.symbols create mode 100644 tests/baselines/reference/enumLiteralTypes2.types create mode 100644 tests/baselines/reference/enumLiteralTypes3.errors.txt create mode 100644 tests/baselines/reference/enumLiteralTypes3.js create mode 100644 tests/baselines/reference/literalTypes1.js create mode 100644 tests/baselines/reference/literalTypes1.symbols create mode 100644 tests/baselines/reference/literalTypes1.types create mode 100644 tests/baselines/reference/numericLiteralTypes1.js create mode 100644 tests/baselines/reference/numericLiteralTypes1.symbols create mode 100644 tests/baselines/reference/numericLiteralTypes1.types create mode 100644 tests/baselines/reference/numericLiteralTypes2.js create mode 100644 tests/baselines/reference/numericLiteralTypes2.symbols create mode 100644 tests/baselines/reference/numericLiteralTypes2.types create mode 100644 tests/baselines/reference/numericLiteralTypes3.errors.txt create mode 100644 tests/baselines/reference/numericLiteralTypes3.js create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.js create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.symbols create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks01.js create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks02.js create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks03.js create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks04.js create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements01.js create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements02.errors.txt create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements02.js create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements03.js create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements04.js create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements04.symbols create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements04.types create mode 100644 tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt create mode 100644 tests/baselines/reference/stringLiteralsWithTypeAssertions01.js diff --git a/tests/baselines/reference/booleanLiteralTypes1.js b/tests/baselines/reference/booleanLiteralTypes1.js new file mode 100644 index 0000000000000..6fb0244ac687d --- /dev/null +++ b/tests/baselines/reference/booleanLiteralTypes1.js @@ -0,0 +1,171 @@ +//// [booleanLiteralTypes1.ts] +type A1 = true | false; +type A2 = false | true; + +function f1() { + var a: A1; + var a: A2; + var a: true | false; + var a: false | true; +} + +function f2(a: true | false, b: boolean) { + a = b; + b = a; +} + +function f3(a: true | false, b: true | false) { + var x = a || b; + var x = a && b; + var x = !a; +} + +function f4(t: true, f: false) { + var x1 = t && f; + var x2 = f && t; + var x3 = t || f; + var x4 = f || t; + var x5 = !t; + var x6 = !f; +} + +declare function g(x: true): string; +declare function g(x: false): boolean; +declare function g(x: boolean): number; + +function f5(b: boolean) { + var z1 = g(true); + var z2 = g(false); + var z3 = g(b); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +function f10(x: true | false) { + switch (x) { + case true: return "true"; + case false: return "false"; + } +} + +function f11(x: true | false) { + switch (x) { + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +} + +function f12(x: true | false) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: true | false) { + if (x === true) { + x; + } + else { + x; + } +} + +type Item = + { kind: true, a: string } | + { kind: false, b: string }; + +function f20(x: Item) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } +} + +function f21(x: Item) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } + return assertNever(x); +} + +//// [booleanLiteralTypes1.js] +function f1() { + var a; + var a; + var a; + var a; +} +function f2(a, b) { + a = b; + b = a; +} +function f3(a, b) { + var x = a || b; + var x = a && b; + var x = !a; +} +function f4(t, f) { + var x1 = t && f; + var x2 = f && t; + var x3 = t || f; + var x4 = f || t; + var x5 = !t; + var x6 = !f; +} +function f5(b) { + var z1 = g(true); + var z2 = g(false); + var z3 = g(b); +} +function assertNever(x) { + throw new Error("Unexpected value"); +} +function f10(x) { + switch (x) { + case true: return "true"; + case false: return "false"; + } +} +function f11(x) { + switch (x) { + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +} +function f12(x) { + if (x) { + x; + } + else { + x; + } +} +function f13(x) { + if (x === true) { + x; + } + else { + x; + } +} +function f20(x) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } +} +function f21(x) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } + return assertNever(x); +} diff --git a/tests/baselines/reference/booleanLiteralTypes1.symbols b/tests/baselines/reference/booleanLiteralTypes1.symbols new file mode 100644 index 0000000000000..ee7ab2ca67449 --- /dev/null +++ b/tests/baselines/reference/booleanLiteralTypes1.symbols @@ -0,0 +1,247 @@ +=== tests/cases/conformance/types/literal/booleanLiteralTypes1.ts === +type A1 = true | false; +>A1 : Symbol(A1, Decl(booleanLiteralTypes1.ts, 0, 0)) + +type A2 = false | true; +>A2 : Symbol(A2, Decl(booleanLiteralTypes1.ts, 0, 23)) + +function f1() { +>f1 : Symbol(f1, Decl(booleanLiteralTypes1.ts, 1, 23)) + + var a: A1; +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 4, 7), Decl(booleanLiteralTypes1.ts, 5, 7), Decl(booleanLiteralTypes1.ts, 6, 7), Decl(booleanLiteralTypes1.ts, 7, 7)) +>A1 : Symbol(A1, Decl(booleanLiteralTypes1.ts, 0, 0)) + + var a: A2; +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 4, 7), Decl(booleanLiteralTypes1.ts, 5, 7), Decl(booleanLiteralTypes1.ts, 6, 7), Decl(booleanLiteralTypes1.ts, 7, 7)) +>A2 : Symbol(A2, Decl(booleanLiteralTypes1.ts, 0, 23)) + + var a: true | false; +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 4, 7), Decl(booleanLiteralTypes1.ts, 5, 7), Decl(booleanLiteralTypes1.ts, 6, 7), Decl(booleanLiteralTypes1.ts, 7, 7)) + + var a: false | true; +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 4, 7), Decl(booleanLiteralTypes1.ts, 5, 7), Decl(booleanLiteralTypes1.ts, 6, 7), Decl(booleanLiteralTypes1.ts, 7, 7)) +} + +function f2(a: true | false, b: boolean) { +>f2 : Symbol(f2, Decl(booleanLiteralTypes1.ts, 8, 1)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 10, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 10, 28)) + + a = b; +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 10, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 10, 28)) + + b = a; +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 10, 28)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 10, 12)) +} + +function f3(a: true | false, b: true | false) { +>f3 : Symbol(f3, Decl(booleanLiteralTypes1.ts, 13, 1)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 15, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 15, 28)) + + var x = a || b; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 16, 7), Decl(booleanLiteralTypes1.ts, 17, 7), Decl(booleanLiteralTypes1.ts, 18, 7)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 15, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 15, 28)) + + var x = a && b; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 16, 7), Decl(booleanLiteralTypes1.ts, 17, 7), Decl(booleanLiteralTypes1.ts, 18, 7)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 15, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 15, 28)) + + var x = !a; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 16, 7), Decl(booleanLiteralTypes1.ts, 17, 7), Decl(booleanLiteralTypes1.ts, 18, 7)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 15, 12)) +} + +function f4(t: true, f: false) { +>f4 : Symbol(f4, Decl(booleanLiteralTypes1.ts, 19, 1)) +>t : Symbol(t, Decl(booleanLiteralTypes1.ts, 21, 12)) +>f : Symbol(f, Decl(booleanLiteralTypes1.ts, 21, 20)) + + var x1 = t && f; +>x1 : Symbol(x1, Decl(booleanLiteralTypes1.ts, 22, 7)) +>t : Symbol(t, Decl(booleanLiteralTypes1.ts, 21, 12)) +>f : Symbol(f, Decl(booleanLiteralTypes1.ts, 21, 20)) + + var x2 = f && t; +>x2 : Symbol(x2, Decl(booleanLiteralTypes1.ts, 23, 7)) +>f : Symbol(f, Decl(booleanLiteralTypes1.ts, 21, 20)) +>t : Symbol(t, Decl(booleanLiteralTypes1.ts, 21, 12)) + + var x3 = t || f; +>x3 : Symbol(x3, Decl(booleanLiteralTypes1.ts, 24, 7)) +>t : Symbol(t, Decl(booleanLiteralTypes1.ts, 21, 12)) +>f : Symbol(f, Decl(booleanLiteralTypes1.ts, 21, 20)) + + var x4 = f || t; +>x4 : Symbol(x4, Decl(booleanLiteralTypes1.ts, 25, 7)) +>f : Symbol(f, Decl(booleanLiteralTypes1.ts, 21, 20)) +>t : Symbol(t, Decl(booleanLiteralTypes1.ts, 21, 12)) + + var x5 = !t; +>x5 : Symbol(x5, Decl(booleanLiteralTypes1.ts, 26, 7)) +>t : Symbol(t, Decl(booleanLiteralTypes1.ts, 21, 12)) + + var x6 = !f; +>x6 : Symbol(x6, Decl(booleanLiteralTypes1.ts, 27, 7)) +>f : Symbol(f, Decl(booleanLiteralTypes1.ts, 21, 20)) +} + +declare function g(x: true): string; +>g : Symbol(g, Decl(booleanLiteralTypes1.ts, 28, 1), Decl(booleanLiteralTypes1.ts, 30, 36), Decl(booleanLiteralTypes1.ts, 31, 38)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 30, 19)) + +declare function g(x: false): boolean; +>g : Symbol(g, Decl(booleanLiteralTypes1.ts, 28, 1), Decl(booleanLiteralTypes1.ts, 30, 36), Decl(booleanLiteralTypes1.ts, 31, 38)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 31, 19)) + +declare function g(x: boolean): number; +>g : Symbol(g, Decl(booleanLiteralTypes1.ts, 28, 1), Decl(booleanLiteralTypes1.ts, 30, 36), Decl(booleanLiteralTypes1.ts, 31, 38)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 32, 19)) + +function f5(b: boolean) { +>f5 : Symbol(f5, Decl(booleanLiteralTypes1.ts, 32, 39)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 34, 12)) + + var z1 = g(true); +>z1 : Symbol(z1, Decl(booleanLiteralTypes1.ts, 35, 7)) +>g : Symbol(g, Decl(booleanLiteralTypes1.ts, 28, 1), Decl(booleanLiteralTypes1.ts, 30, 36), Decl(booleanLiteralTypes1.ts, 31, 38)) + + var z2 = g(false); +>z2 : Symbol(z2, Decl(booleanLiteralTypes1.ts, 36, 7)) +>g : Symbol(g, Decl(booleanLiteralTypes1.ts, 28, 1), Decl(booleanLiteralTypes1.ts, 30, 36), Decl(booleanLiteralTypes1.ts, 31, 38)) + + var z3 = g(b); +>z3 : Symbol(z3, Decl(booleanLiteralTypes1.ts, 37, 7)) +>g : Symbol(g, Decl(booleanLiteralTypes1.ts, 28, 1), Decl(booleanLiteralTypes1.ts, 30, 36), Decl(booleanLiteralTypes1.ts, 31, 38)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 34, 12)) +} + +function assertNever(x: never): never { +>assertNever : Symbol(assertNever, Decl(booleanLiteralTypes1.ts, 38, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 40, 21)) + + throw new Error("Unexpected value"); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +function f10(x: true | false) { +>f10 : Symbol(f10, Decl(booleanLiteralTypes1.ts, 42, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 44, 13)) + + switch (x) { +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 44, 13)) + + case true: return "true"; + case false: return "false"; + } +} + +function f11(x: true | false) { +>f11 : Symbol(f11, Decl(booleanLiteralTypes1.ts, 49, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 51, 13)) + + switch (x) { +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 51, 13)) + + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(booleanLiteralTypes1.ts, 38, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 51, 13)) +} + +function f12(x: true | false) { +>f12 : Symbol(f12, Decl(booleanLiteralTypes1.ts, 57, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 59, 13)) + + if (x) { +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 59, 13)) + + x; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 59, 13)) + } + else { + x; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 59, 13)) + } +} + +function f13(x: true | false) { +>f13 : Symbol(f13, Decl(booleanLiteralTypes1.ts, 66, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 68, 13)) + + if (x === true) { +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 68, 13)) + + x; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 68, 13)) + } + else { + x; +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 68, 13)) + } +} + +type Item = +>Item : Symbol(Item, Decl(booleanLiteralTypes1.ts, 75, 1)) + + { kind: true, a: string } | +>kind : Symbol(kind, Decl(booleanLiteralTypes1.ts, 78, 5)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 78, 17)) + + { kind: false, b: string }; +>kind : Symbol(kind, Decl(booleanLiteralTypes1.ts, 79, 5)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 79, 18)) + +function f20(x: Item) { +>f20 : Symbol(f20, Decl(booleanLiteralTypes1.ts, 79, 31)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 81, 13)) +>Item : Symbol(Item, Decl(booleanLiteralTypes1.ts, 75, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(booleanLiteralTypes1.ts, 78, 5), Decl(booleanLiteralTypes1.ts, 79, 5)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 81, 13)) +>kind : Symbol(kind, Decl(booleanLiteralTypes1.ts, 78, 5), Decl(booleanLiteralTypes1.ts, 79, 5)) + + case true: return x.a; +>x.a : Symbol(a, Decl(booleanLiteralTypes1.ts, 78, 17)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 81, 13)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 78, 17)) + + case false: return x.b; +>x.b : Symbol(b, Decl(booleanLiteralTypes1.ts, 79, 18)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 81, 13)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 79, 18)) + } +} + +function f21(x: Item) { +>f21 : Symbol(f21, Decl(booleanLiteralTypes1.ts, 86, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 88, 13)) +>Item : Symbol(Item, Decl(booleanLiteralTypes1.ts, 75, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(booleanLiteralTypes1.ts, 78, 5), Decl(booleanLiteralTypes1.ts, 79, 5)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 88, 13)) +>kind : Symbol(kind, Decl(booleanLiteralTypes1.ts, 78, 5), Decl(booleanLiteralTypes1.ts, 79, 5)) + + case true: return x.a; +>x.a : Symbol(a, Decl(booleanLiteralTypes1.ts, 78, 17)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 88, 13)) +>a : Symbol(a, Decl(booleanLiteralTypes1.ts, 78, 17)) + + case false: return x.b; +>x.b : Symbol(b, Decl(booleanLiteralTypes1.ts, 79, 18)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 88, 13)) +>b : Symbol(b, Decl(booleanLiteralTypes1.ts, 79, 18)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(booleanLiteralTypes1.ts, 38, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes1.ts, 88, 13)) +} diff --git a/tests/baselines/reference/booleanLiteralTypes1.types b/tests/baselines/reference/booleanLiteralTypes1.types new file mode 100644 index 0000000000000..5e987b105b501 --- /dev/null +++ b/tests/baselines/reference/booleanLiteralTypes1.types @@ -0,0 +1,311 @@ +=== tests/cases/conformance/types/literal/booleanLiteralTypes1.ts === +type A1 = true | false; +>A1 : true | false +>true : true +>false : false + +type A2 = false | true; +>A2 : false | true +>false : false +>true : true + +function f1() { +>f1 : () => void + + var a: A1; +>a : true | false +>A1 : true | false + + var a: A2; +>a : true | false +>A2 : false | true + + var a: true | false; +>a : true | false +>true : true +>false : false + + var a: false | true; +>a : true | false +>false : false +>true : true +} + +function f2(a: true | false, b: boolean) { +>f2 : (a: true | false, b: boolean) => void +>a : true | false +>true : true +>false : false +>b : boolean + + a = b; +>a = b : boolean +>a : true | false +>b : boolean + + b = a; +>b = a : true | false +>b : boolean +>a : true | false +} + +function f3(a: true | false, b: true | false) { +>f3 : (a: true | false, b: true | false) => void +>a : true | false +>true : true +>false : false +>b : true | false +>true : true +>false : false + + var x = a || b; +>x : true | false +>a || b : true | false +>a : true | false +>b : true | false + + var x = a && b; +>x : true | false +>a && b : true | false +>a : true | false +>b : true | false + + var x = !a; +>x : true | false +>!a : true | false +>a : true | false +} + +function f4(t: true, f: false) { +>f4 : (t: true, f: false) => void +>t : true +>true : true +>f : false +>false : false + + var x1 = t && f; +>x1 : false +>t && f : false +>t : true +>f : false + + var x2 = f && t; +>x2 : false +>f && t : false +>f : false +>t : true + + var x3 = t || f; +>x3 : true | false +>t || f : true | false +>t : true +>f : false + + var x4 = f || t; +>x4 : true +>f || t : true +>f : false +>t : true + + var x5 = !t; +>x5 : boolean +>!t : boolean +>t : true + + var x6 = !f; +>x6 : true +>!f : true +>f : false +} + +declare function g(x: true): string; +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>x : true +>true : true + +declare function g(x: false): boolean; +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>x : false +>false : false + +declare function g(x: boolean): number; +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>x : boolean + +function f5(b: boolean) { +>f5 : (b: boolean) => void +>b : boolean + + var z1 = g(true); +>z1 : string +>g(true) : string +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>true : true + + var z2 = g(false); +>z2 : boolean +>g(false) : boolean +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>false : false + + var z3 = g(b); +>z3 : number +>g(b) : number +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>b : boolean +} + +function assertNever(x: never): never { +>assertNever : (x: never) => never +>x : never + + throw new Error("Unexpected value"); +>new Error("Unexpected value") : Error +>Error : ErrorConstructor +>"Unexpected value" : string +} + +function f10(x: true | false) { +>f10 : (x: true | false) => string +>x : true | false +>true : true +>false : false + + switch (x) { +>x : true | false + + case true: return "true"; +>true : true +>"true" : string + + case false: return "false"; +>false : false +>"false" : string + } +} + +function f11(x: true | false) { +>f11 : (x: true | false) => string +>x : true | false +>true : true +>false : false + + switch (x) { +>x : true | false + + case true: return "true"; +>true : true +>"true" : string + + case false: return "false"; +>false : false +>"false" : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} + +function f12(x: true | false) { +>f12 : (x: true | false) => void +>x : true | false +>true : true +>false : false + + if (x) { +>x : true | false + + x; +>x : true + } + else { + x; +>x : true | false + } +} + +function f13(x: true | false) { +>f13 : (x: true | false) => void +>x : true | false +>true : true +>false : false + + if (x === true) { +>x === true : boolean +>x : true | false +>true : true + + x; +>x : true + } + else { + x; +>x : false + } +} + +type Item = +>Item : { kind: true; a: string; } | { kind: false; b: string; } + + { kind: true, a: string } | +>kind : true +>true : true +>a : string + + { kind: false, b: string }; +>kind : false +>false : false +>b : string + +function f20(x: Item) { +>f20 : (x: { kind: true; a: string; } | { kind: false; b: string; }) => string +>x : { kind: true; a: string; } | { kind: false; b: string; } +>Item : { kind: true; a: string; } | { kind: false; b: string; } + + switch (x.kind) { +>x.kind : true | false +>x : { kind: true; a: string; } | { kind: false; b: string; } +>kind : true | false + + case true: return x.a; +>true : true +>x.a : string +>x : { kind: true; a: string; } +>a : string + + case false: return x.b; +>false : false +>x.b : string +>x : { kind: false; b: string; } +>b : string + } +} + +function f21(x: Item) { +>f21 : (x: { kind: true; a: string; } | { kind: false; b: string; }) => string +>x : { kind: true; a: string; } | { kind: false; b: string; } +>Item : { kind: true; a: string; } | { kind: false; b: string; } + + switch (x.kind) { +>x.kind : true | false +>x : { kind: true; a: string; } | { kind: false; b: string; } +>kind : true | false + + case true: return x.a; +>true : true +>x.a : string +>x : { kind: true; a: string; } +>a : string + + case false: return x.b; +>false : false +>x.b : string +>x : { kind: false; b: string; } +>b : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} diff --git a/tests/baselines/reference/booleanLiteralTypes2.js b/tests/baselines/reference/booleanLiteralTypes2.js new file mode 100644 index 0000000000000..7ef643593a684 --- /dev/null +++ b/tests/baselines/reference/booleanLiteralTypes2.js @@ -0,0 +1,172 @@ +//// [booleanLiteralTypes2.ts] + +type A1 = true | false; +type A2 = false | true; + +function f1() { + var a: A1; + var a: A2; + var a: true | false; + var a: false | true; +} + +function f2(a: true | false, b: boolean) { + a = b; + b = a; +} + +function f3(a: true | false, b: true | false) { + var x = a || b; + var x = a && b; + var x = !a; +} + +function f4(t: true, f: false) { + var x1 = t && f; + var x2 = f && t; + var x3 = t || f; + var x4 = f || t; + var x5 = !t; + var x6 = !f; +} + +declare function g(x: true): string; +declare function g(x: false): boolean; +declare function g(x: boolean): number; + +function f5(b: boolean) { + var z1 = g(true); + var z2 = g(false); + var z3 = g(b); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +function f10(x: true | false) { + switch (x) { + case true: return "true"; + case false: return "false"; + } +} + +function f11(x: true | false) { + switch (x) { + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +} + +function f12(x: true | false) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: true | false) { + if (x === true) { + x; + } + else { + x; + } +} + +type Item = + { kind: true, a: string } | + { kind: false, b: string }; + +function f20(x: Item) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } +} + +function f21(x: Item) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } + return assertNever(x); +} + +//// [booleanLiteralTypes2.js] +function f1() { + var a; + var a; + var a; + var a; +} +function f2(a, b) { + a = b; + b = a; +} +function f3(a, b) { + var x = a || b; + var x = a && b; + var x = !a; +} +function f4(t, f) { + var x1 = t && f; + var x2 = f && t; + var x3 = t || f; + var x4 = f || t; + var x5 = !t; + var x6 = !f; +} +function f5(b) { + var z1 = g(true); + var z2 = g(false); + var z3 = g(b); +} +function assertNever(x) { + throw new Error("Unexpected value"); +} +function f10(x) { + switch (x) { + case true: return "true"; + case false: return "false"; + } +} +function f11(x) { + switch (x) { + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +} +function f12(x) { + if (x) { + x; + } + else { + x; + } +} +function f13(x) { + if (x === true) { + x; + } + else { + x; + } +} +function f20(x) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } +} +function f21(x) { + switch (x.kind) { + case true: return x.a; + case false: return x.b; + } + return assertNever(x); +} diff --git a/tests/baselines/reference/booleanLiteralTypes2.symbols b/tests/baselines/reference/booleanLiteralTypes2.symbols new file mode 100644 index 0000000000000..1f64767cbb4d7 --- /dev/null +++ b/tests/baselines/reference/booleanLiteralTypes2.symbols @@ -0,0 +1,248 @@ +=== tests/cases/conformance/types/literal/booleanLiteralTypes2.ts === + +type A1 = true | false; +>A1 : Symbol(A1, Decl(booleanLiteralTypes2.ts, 0, 0)) + +type A2 = false | true; +>A2 : Symbol(A2, Decl(booleanLiteralTypes2.ts, 1, 23)) + +function f1() { +>f1 : Symbol(f1, Decl(booleanLiteralTypes2.ts, 2, 23)) + + var a: A1; +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 5, 7), Decl(booleanLiteralTypes2.ts, 6, 7), Decl(booleanLiteralTypes2.ts, 7, 7), Decl(booleanLiteralTypes2.ts, 8, 7)) +>A1 : Symbol(A1, Decl(booleanLiteralTypes2.ts, 0, 0)) + + var a: A2; +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 5, 7), Decl(booleanLiteralTypes2.ts, 6, 7), Decl(booleanLiteralTypes2.ts, 7, 7), Decl(booleanLiteralTypes2.ts, 8, 7)) +>A2 : Symbol(A2, Decl(booleanLiteralTypes2.ts, 1, 23)) + + var a: true | false; +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 5, 7), Decl(booleanLiteralTypes2.ts, 6, 7), Decl(booleanLiteralTypes2.ts, 7, 7), Decl(booleanLiteralTypes2.ts, 8, 7)) + + var a: false | true; +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 5, 7), Decl(booleanLiteralTypes2.ts, 6, 7), Decl(booleanLiteralTypes2.ts, 7, 7), Decl(booleanLiteralTypes2.ts, 8, 7)) +} + +function f2(a: true | false, b: boolean) { +>f2 : Symbol(f2, Decl(booleanLiteralTypes2.ts, 9, 1)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 11, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 11, 28)) + + a = b; +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 11, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 11, 28)) + + b = a; +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 11, 28)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 11, 12)) +} + +function f3(a: true | false, b: true | false) { +>f3 : Symbol(f3, Decl(booleanLiteralTypes2.ts, 14, 1)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 16, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 16, 28)) + + var x = a || b; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 17, 7), Decl(booleanLiteralTypes2.ts, 18, 7), Decl(booleanLiteralTypes2.ts, 19, 7)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 16, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 16, 28)) + + var x = a && b; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 17, 7), Decl(booleanLiteralTypes2.ts, 18, 7), Decl(booleanLiteralTypes2.ts, 19, 7)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 16, 12)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 16, 28)) + + var x = !a; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 17, 7), Decl(booleanLiteralTypes2.ts, 18, 7), Decl(booleanLiteralTypes2.ts, 19, 7)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 16, 12)) +} + +function f4(t: true, f: false) { +>f4 : Symbol(f4, Decl(booleanLiteralTypes2.ts, 20, 1)) +>t : Symbol(t, Decl(booleanLiteralTypes2.ts, 22, 12)) +>f : Symbol(f, Decl(booleanLiteralTypes2.ts, 22, 20)) + + var x1 = t && f; +>x1 : Symbol(x1, Decl(booleanLiteralTypes2.ts, 23, 7)) +>t : Symbol(t, Decl(booleanLiteralTypes2.ts, 22, 12)) +>f : Symbol(f, Decl(booleanLiteralTypes2.ts, 22, 20)) + + var x2 = f && t; +>x2 : Symbol(x2, Decl(booleanLiteralTypes2.ts, 24, 7)) +>f : Symbol(f, Decl(booleanLiteralTypes2.ts, 22, 20)) +>t : Symbol(t, Decl(booleanLiteralTypes2.ts, 22, 12)) + + var x3 = t || f; +>x3 : Symbol(x3, Decl(booleanLiteralTypes2.ts, 25, 7)) +>t : Symbol(t, Decl(booleanLiteralTypes2.ts, 22, 12)) +>f : Symbol(f, Decl(booleanLiteralTypes2.ts, 22, 20)) + + var x4 = f || t; +>x4 : Symbol(x4, Decl(booleanLiteralTypes2.ts, 26, 7)) +>f : Symbol(f, Decl(booleanLiteralTypes2.ts, 22, 20)) +>t : Symbol(t, Decl(booleanLiteralTypes2.ts, 22, 12)) + + var x5 = !t; +>x5 : Symbol(x5, Decl(booleanLiteralTypes2.ts, 27, 7)) +>t : Symbol(t, Decl(booleanLiteralTypes2.ts, 22, 12)) + + var x6 = !f; +>x6 : Symbol(x6, Decl(booleanLiteralTypes2.ts, 28, 7)) +>f : Symbol(f, Decl(booleanLiteralTypes2.ts, 22, 20)) +} + +declare function g(x: true): string; +>g : Symbol(g, Decl(booleanLiteralTypes2.ts, 29, 1), Decl(booleanLiteralTypes2.ts, 31, 36), Decl(booleanLiteralTypes2.ts, 32, 38)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 31, 19)) + +declare function g(x: false): boolean; +>g : Symbol(g, Decl(booleanLiteralTypes2.ts, 29, 1), Decl(booleanLiteralTypes2.ts, 31, 36), Decl(booleanLiteralTypes2.ts, 32, 38)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 32, 19)) + +declare function g(x: boolean): number; +>g : Symbol(g, Decl(booleanLiteralTypes2.ts, 29, 1), Decl(booleanLiteralTypes2.ts, 31, 36), Decl(booleanLiteralTypes2.ts, 32, 38)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 33, 19)) + +function f5(b: boolean) { +>f5 : Symbol(f5, Decl(booleanLiteralTypes2.ts, 33, 39)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 35, 12)) + + var z1 = g(true); +>z1 : Symbol(z1, Decl(booleanLiteralTypes2.ts, 36, 7)) +>g : Symbol(g, Decl(booleanLiteralTypes2.ts, 29, 1), Decl(booleanLiteralTypes2.ts, 31, 36), Decl(booleanLiteralTypes2.ts, 32, 38)) + + var z2 = g(false); +>z2 : Symbol(z2, Decl(booleanLiteralTypes2.ts, 37, 7)) +>g : Symbol(g, Decl(booleanLiteralTypes2.ts, 29, 1), Decl(booleanLiteralTypes2.ts, 31, 36), Decl(booleanLiteralTypes2.ts, 32, 38)) + + var z3 = g(b); +>z3 : Symbol(z3, Decl(booleanLiteralTypes2.ts, 38, 7)) +>g : Symbol(g, Decl(booleanLiteralTypes2.ts, 29, 1), Decl(booleanLiteralTypes2.ts, 31, 36), Decl(booleanLiteralTypes2.ts, 32, 38)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 35, 12)) +} + +function assertNever(x: never): never { +>assertNever : Symbol(assertNever, Decl(booleanLiteralTypes2.ts, 39, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 41, 21)) + + throw new Error("Unexpected value"); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +function f10(x: true | false) { +>f10 : Symbol(f10, Decl(booleanLiteralTypes2.ts, 43, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 45, 13)) + + switch (x) { +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 45, 13)) + + case true: return "true"; + case false: return "false"; + } +} + +function f11(x: true | false) { +>f11 : Symbol(f11, Decl(booleanLiteralTypes2.ts, 50, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 52, 13)) + + switch (x) { +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 52, 13)) + + case true: return "true"; + case false: return "false"; + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(booleanLiteralTypes2.ts, 39, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 52, 13)) +} + +function f12(x: true | false) { +>f12 : Symbol(f12, Decl(booleanLiteralTypes2.ts, 58, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 60, 13)) + + if (x) { +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 60, 13)) + + x; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 60, 13)) + } + else { + x; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 60, 13)) + } +} + +function f13(x: true | false) { +>f13 : Symbol(f13, Decl(booleanLiteralTypes2.ts, 67, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 69, 13)) + + if (x === true) { +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 69, 13)) + + x; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 69, 13)) + } + else { + x; +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 69, 13)) + } +} + +type Item = +>Item : Symbol(Item, Decl(booleanLiteralTypes2.ts, 76, 1)) + + { kind: true, a: string } | +>kind : Symbol(kind, Decl(booleanLiteralTypes2.ts, 79, 5)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 79, 17)) + + { kind: false, b: string }; +>kind : Symbol(kind, Decl(booleanLiteralTypes2.ts, 80, 5)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 80, 18)) + +function f20(x: Item) { +>f20 : Symbol(f20, Decl(booleanLiteralTypes2.ts, 80, 31)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 82, 13)) +>Item : Symbol(Item, Decl(booleanLiteralTypes2.ts, 76, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(booleanLiteralTypes2.ts, 79, 5), Decl(booleanLiteralTypes2.ts, 80, 5)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 82, 13)) +>kind : Symbol(kind, Decl(booleanLiteralTypes2.ts, 79, 5), Decl(booleanLiteralTypes2.ts, 80, 5)) + + case true: return x.a; +>x.a : Symbol(a, Decl(booleanLiteralTypes2.ts, 79, 17)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 82, 13)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 79, 17)) + + case false: return x.b; +>x.b : Symbol(b, Decl(booleanLiteralTypes2.ts, 80, 18)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 82, 13)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 80, 18)) + } +} + +function f21(x: Item) { +>f21 : Symbol(f21, Decl(booleanLiteralTypes2.ts, 87, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 89, 13)) +>Item : Symbol(Item, Decl(booleanLiteralTypes2.ts, 76, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(booleanLiteralTypes2.ts, 79, 5), Decl(booleanLiteralTypes2.ts, 80, 5)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 89, 13)) +>kind : Symbol(kind, Decl(booleanLiteralTypes2.ts, 79, 5), Decl(booleanLiteralTypes2.ts, 80, 5)) + + case true: return x.a; +>x.a : Symbol(a, Decl(booleanLiteralTypes2.ts, 79, 17)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 89, 13)) +>a : Symbol(a, Decl(booleanLiteralTypes2.ts, 79, 17)) + + case false: return x.b; +>x.b : Symbol(b, Decl(booleanLiteralTypes2.ts, 80, 18)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 89, 13)) +>b : Symbol(b, Decl(booleanLiteralTypes2.ts, 80, 18)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(booleanLiteralTypes2.ts, 39, 1)) +>x : Symbol(x, Decl(booleanLiteralTypes2.ts, 89, 13)) +} diff --git a/tests/baselines/reference/booleanLiteralTypes2.types b/tests/baselines/reference/booleanLiteralTypes2.types new file mode 100644 index 0000000000000..a1d7ee2d36fab --- /dev/null +++ b/tests/baselines/reference/booleanLiteralTypes2.types @@ -0,0 +1,312 @@ +=== tests/cases/conformance/types/literal/booleanLiteralTypes2.ts === + +type A1 = true | false; +>A1 : true | false +>true : true +>false : false + +type A2 = false | true; +>A2 : false | true +>false : false +>true : true + +function f1() { +>f1 : () => void + + var a: A1; +>a : true | false +>A1 : true | false + + var a: A2; +>a : true | false +>A2 : false | true + + var a: true | false; +>a : true | false +>true : true +>false : false + + var a: false | true; +>a : true | false +>false : false +>true : true +} + +function f2(a: true | false, b: boolean) { +>f2 : (a: true | false, b: boolean) => void +>a : true | false +>true : true +>false : false +>b : boolean + + a = b; +>a = b : boolean +>a : true | false +>b : boolean + + b = a; +>b = a : true | false +>b : boolean +>a : true | false +} + +function f3(a: true | false, b: true | false) { +>f3 : (a: true | false, b: true | false) => void +>a : true | false +>true : true +>false : false +>b : true | false +>true : true +>false : false + + var x = a || b; +>x : true | false +>a || b : true | false +>a : true | false +>b : true | false + + var x = a && b; +>x : true | false +>a && b : true | false +>a : true | false +>b : true | false + + var x = !a; +>x : true | false +>!a : true | false +>a : false | true +} + +function f4(t: true, f: false) { +>f4 : (t: true, f: false) => void +>t : true +>true : true +>f : false +>false : false + + var x1 = t && f; +>x1 : false +>t && f : false +>t : true +>f : false + + var x2 = f && t; +>x2 : false +>f && t : false +>f : false +>t : true + + var x3 = t || f; +>x3 : true +>t || f : true +>t : true +>f : false + + var x4 = f || t; +>x4 : true +>f || t : true +>f : false +>t : true + + var x5 = !t; +>x5 : false +>!t : false +>t : true + + var x6 = !f; +>x6 : true +>!f : true +>f : false +} + +declare function g(x: true): string; +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>x : true +>true : true + +declare function g(x: false): boolean; +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>x : false +>false : false + +declare function g(x: boolean): number; +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>x : boolean + +function f5(b: boolean) { +>f5 : (b: boolean) => void +>b : boolean + + var z1 = g(true); +>z1 : string +>g(true) : string +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>true : true + + var z2 = g(false); +>z2 : boolean +>g(false) : boolean +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>false : false + + var z3 = g(b); +>z3 : number +>g(b) : number +>g : { (x: true): string; (x: false): boolean; (x: boolean): number; } +>b : boolean +} + +function assertNever(x: never): never { +>assertNever : (x: never) => never +>x : never + + throw new Error("Unexpected value"); +>new Error("Unexpected value") : Error +>Error : ErrorConstructor +>"Unexpected value" : string +} + +function f10(x: true | false) { +>f10 : (x: true | false) => string +>x : true | false +>true : true +>false : false + + switch (x) { +>x : true | false + + case true: return "true"; +>true : true +>"true" : string + + case false: return "false"; +>false : false +>"false" : string + } +} + +function f11(x: true | false) { +>f11 : (x: true | false) => string +>x : true | false +>true : true +>false : false + + switch (x) { +>x : true | false + + case true: return "true"; +>true : true +>"true" : string + + case false: return "false"; +>false : false +>"false" : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} + +function f12(x: true | false) { +>f12 : (x: true | false) => void +>x : true | false +>true : true +>false : false + + if (x) { +>x : true | false + + x; +>x : true + } + else { + x; +>x : false + } +} + +function f13(x: true | false) { +>f13 : (x: true | false) => void +>x : true | false +>true : true +>false : false + + if (x === true) { +>x === true : boolean +>x : true | false +>true : true + + x; +>x : true + } + else { + x; +>x : false + } +} + +type Item = +>Item : { kind: true; a: string; } | { kind: false; b: string; } + + { kind: true, a: string } | +>kind : true +>true : true +>a : string + + { kind: false, b: string }; +>kind : false +>false : false +>b : string + +function f20(x: Item) { +>f20 : (x: { kind: true; a: string; } | { kind: false; b: string; }) => string +>x : { kind: true; a: string; } | { kind: false; b: string; } +>Item : { kind: true; a: string; } | { kind: false; b: string; } + + switch (x.kind) { +>x.kind : true | false +>x : { kind: true; a: string; } | { kind: false; b: string; } +>kind : true | false + + case true: return x.a; +>true : true +>x.a : string +>x : { kind: true; a: string; } +>a : string + + case false: return x.b; +>false : false +>x.b : string +>x : { kind: false; b: string; } +>b : string + } +} + +function f21(x: Item) { +>f21 : (x: { kind: true; a: string; } | { kind: false; b: string; }) => string +>x : { kind: true; a: string; } | { kind: false; b: string; } +>Item : { kind: true; a: string; } | { kind: false; b: string; } + + switch (x.kind) { +>x.kind : true | false +>x : { kind: true; a: string; } | { kind: false; b: string; } +>kind : true | false + + case true: return x.a; +>true : true +>x.a : string +>x : { kind: true; a: string; } +>a : string + + case false: return x.b; +>false : false +>x.b : string +>x : { kind: false; b: string; } +>b : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} diff --git a/tests/baselines/reference/enumLiteralTypes1.js b/tests/baselines/reference/enumLiteralTypes1.js new file mode 100644 index 0000000000000..714227f4d60a2 --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes1.js @@ -0,0 +1,205 @@ +//// [enumLiteralTypes1.ts] +const enum Choice { Unknown, Yes, No }; + +type YesNo = Choice.Yes | Choice.No; +type NoYes = Choice.No | Choice.Yes; +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; + +function f1() { + var a: YesNo; + var a: NoYes; + var a: Choice.Yes | Choice.No; + var a: Choice.No | Choice.Yes; +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { + b = a; + c = a; + c = b; +} + +function f3(a: Choice.Yes, b: YesNo) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} + +function f4(a: Choice.Yes, b: YesNo) { + a++; + b++; +} + +declare function g(x: Choice.Yes): string; +declare function g(x: Choice.No): boolean; +declare function g(x: Choice): number; + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { + var z1 = g(Choice.Yes); + var z2 = g(Choice.No); + var z3 = g(a); + var z4 = g(b); + var z5 = g(c); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +function f10(x: YesNo) { + switch (x) { + case Choice.Yes: return "true"; + case Choice.No: return "false"; + } +} + +function f11(x: YesNo) { + switch (x) { + case Choice.Yes: return "true"; + case Choice.No: return "false"; + } + return assertNever(x); +} + +function f12(x: UnknownYesNo) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: UnknownYesNo) { + if (x === Choice.Yes) { + x; + } + else { + x; + } +} + +type Item = + { kind: Choice.Yes, a: string } | + { kind: Choice.No, b: string }; + +function f20(x: Item) { + switch (x.kind) { + case Choice.Yes: return x.a; + case Choice.No: return x.b; + } +} + +function f21(x: Item) { + switch (x.kind) { + case Choice.Yes: return x.a; + case Choice.No: return x.b; + } + return assertNever(x); +} + +//// [enumLiteralTypes1.js] +; +function f1() { + var a; + var a; + var a; + var a; +} +function f2(a, b, c) { + b = a; + c = a; + c = b; +} +function f3(a, b) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} +function f4(a, b) { + a++; + b++; +} +function f5(a, b, c) { + var z1 = g(1 /* Yes */); + var z2 = g(2 /* No */); + var z3 = g(a); + var z4 = g(b); + var z5 = g(c); +} +function assertNever(x) { + throw new Error("Unexpected value"); +} +function f10(x) { + switch (x) { + case 1 /* Yes */: return "true"; + case 2 /* No */: return "false"; + } +} +function f11(x) { + switch (x) { + case 1 /* Yes */: return "true"; + case 2 /* No */: return "false"; + } + return assertNever(x); +} +function f12(x) { + if (x) { + x; + } + else { + x; + } +} +function f13(x) { + if (x === 1 /* Yes */) { + x; + } + else { + x; + } +} +function f20(x) { + switch (x.kind) { + case 1 /* Yes */: return x.a; + case 2 /* No */: return x.b; + } +} +function f21(x) { + switch (x.kind) { + case 1 /* Yes */: return x.a; + case 2 /* No */: return x.b; + } + return assertNever(x); +} diff --git a/tests/baselines/reference/enumLiteralTypes1.symbols b/tests/baselines/reference/enumLiteralTypes1.symbols new file mode 100644 index 0000000000000..0919f99330dd5 --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes1.symbols @@ -0,0 +1,411 @@ +=== tests/cases/conformance/types/literal/enumLiteralTypes1.ts === +const enum Choice { Unknown, Yes, No }; +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Unknown : Symbol(Choice.Unknown, Decl(enumLiteralTypes1.ts, 0, 19)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + +type YesNo = Choice.Yes | Choice.No; +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + +type NoYes = Choice.No | Choice.Yes; +>NoYes : Symbol(NoYes, Decl(enumLiteralTypes1.ts, 2, 36)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) + +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes1.ts, 3, 36)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Unknown : Symbol(Choice.Unknown, Decl(enumLiteralTypes1.ts, 0, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + +function f1() { +>f1 : Symbol(f1, Decl(enumLiteralTypes1.ts, 4, 60)) + + var a: YesNo; +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 7, 7), Decl(enumLiteralTypes1.ts, 8, 7), Decl(enumLiteralTypes1.ts, 9, 7), Decl(enumLiteralTypes1.ts, 10, 7)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) + + var a: NoYes; +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 7, 7), Decl(enumLiteralTypes1.ts, 8, 7), Decl(enumLiteralTypes1.ts, 9, 7), Decl(enumLiteralTypes1.ts, 10, 7)) +>NoYes : Symbol(NoYes, Decl(enumLiteralTypes1.ts, 2, 36)) + + var a: Choice.Yes | Choice.No; +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 7, 7), Decl(enumLiteralTypes1.ts, 8, 7), Decl(enumLiteralTypes1.ts, 9, 7), Decl(enumLiteralTypes1.ts, 10, 7)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + + var a: Choice.No | Choice.Yes; +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 7, 7), Decl(enumLiteralTypes1.ts, 8, 7), Decl(enumLiteralTypes1.ts, 9, 7), Decl(enumLiteralTypes1.ts, 10, 7)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { +>f2 : Symbol(f2, Decl(enumLiteralTypes1.ts, 11, 1)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 13, 12)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 13, 21)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes1.ts, 3, 36)) +>c : Symbol(c, Decl(enumLiteralTypes1.ts, 13, 38)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) + + b = a; +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 13, 21)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 13, 12)) + + c = a; +>c : Symbol(c, Decl(enumLiteralTypes1.ts, 13, 38)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 13, 12)) + + c = b; +>c : Symbol(c, Decl(enumLiteralTypes1.ts, 13, 38)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 13, 21)) +} + +function f3(a: Choice.Yes, b: YesNo) { +>f3 : Symbol(f3, Decl(enumLiteralTypes1.ts, 17, 1)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) + + var x = a + b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a - b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a * b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a / b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a % b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a | b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a & b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = a ^ b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = -b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var x = ~b; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 20, 7), Decl(enumLiteralTypes1.ts, 21, 7), Decl(enumLiteralTypes1.ts, 22, 7), Decl(enumLiteralTypes1.ts, 23, 7), Decl(enumLiteralTypes1.ts, 24, 7), Decl(enumLiteralTypes1.ts, 25, 7), Decl(enumLiteralTypes1.ts, 26, 7), Decl(enumLiteralTypes1.ts, 27, 7), Decl(enumLiteralTypes1.ts, 28, 7), Decl(enumLiteralTypes1.ts, 29, 7)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a == b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a != b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a === b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a !== b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a > b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a < b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a >= b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = a <= b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 19, 12)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) + + var y = !b; +>y : Symbol(y, Decl(enumLiteralTypes1.ts, 30, 7), Decl(enumLiteralTypes1.ts, 31, 7), Decl(enumLiteralTypes1.ts, 32, 7), Decl(enumLiteralTypes1.ts, 33, 7), Decl(enumLiteralTypes1.ts, 34, 7), Decl(enumLiteralTypes1.ts, 35, 7), Decl(enumLiteralTypes1.ts, 36, 7), Decl(enumLiteralTypes1.ts, 37, 7), Decl(enumLiteralTypes1.ts, 38, 7)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 19, 26)) +} + +function f4(a: Choice.Yes, b: YesNo) { +>f4 : Symbol(f4, Decl(enumLiteralTypes1.ts, 39, 1)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 41, 12)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 41, 26)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) + + a++; +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 41, 12)) + + b++; +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 41, 26)) +} + +declare function g(x: Choice.Yes): string; +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 46, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) + +declare function g(x: Choice.No): boolean; +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 47, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + +declare function g(x: Choice): number; +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 48, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { +>f5 : Symbol(f5, Decl(enumLiteralTypes1.ts, 48, 38)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 50, 12)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 50, 21)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes1.ts, 3, 36)) +>c : Symbol(c, Decl(enumLiteralTypes1.ts, 50, 38)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) + + var z1 = g(Choice.Yes); +>z1 : Symbol(z1, Decl(enumLiteralTypes1.ts, 51, 7)) +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) + + var z2 = g(Choice.No); +>z2 : Symbol(z2, Decl(enumLiteralTypes1.ts, 52, 7)) +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + + var z3 = g(a); +>z3 : Symbol(z3, Decl(enumLiteralTypes1.ts, 53, 7)) +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 50, 12)) + + var z4 = g(b); +>z4 : Symbol(z4, Decl(enumLiteralTypes1.ts, 54, 7)) +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 50, 21)) + + var z5 = g(c); +>z5 : Symbol(z5, Decl(enumLiteralTypes1.ts, 55, 7)) +>g : Symbol(g, Decl(enumLiteralTypes1.ts, 44, 1), Decl(enumLiteralTypes1.ts, 46, 42), Decl(enumLiteralTypes1.ts, 47, 42)) +>c : Symbol(c, Decl(enumLiteralTypes1.ts, 50, 38)) +} + +function assertNever(x: never): never { +>assertNever : Symbol(assertNever, Decl(enumLiteralTypes1.ts, 56, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 58, 21)) + + throw new Error("Unexpected value"); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +function f10(x: YesNo) { +>f10 : Symbol(f10, Decl(enumLiteralTypes1.ts, 60, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 62, 13)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) + + switch (x) { +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 62, 13)) + + case Choice.Yes: return "true"; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) + + case Choice.No: return "false"; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + } +} + +function f11(x: YesNo) { +>f11 : Symbol(f11, Decl(enumLiteralTypes1.ts, 67, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 69, 13)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes1.ts, 0, 39)) + + switch (x) { +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 69, 13)) + + case Choice.Yes: return "true"; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) + + case Choice.No: return "false"; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(enumLiteralTypes1.ts, 56, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 69, 13)) +} + +function f12(x: UnknownYesNo) { +>f12 : Symbol(f12, Decl(enumLiteralTypes1.ts, 75, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 77, 13)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes1.ts, 3, 36)) + + if (x) { +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 77, 13)) + + x; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 77, 13)) + } + else { + x; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 77, 13)) + } +} + +function f13(x: UnknownYesNo) { +>f13 : Symbol(f13, Decl(enumLiteralTypes1.ts, 84, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 86, 13)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes1.ts, 3, 36)) + + if (x === Choice.Yes) { +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 86, 13)) +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) + + x; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 86, 13)) + } + else { + x; +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 86, 13)) + } +} + +type Item = +>Item : Symbol(Item, Decl(enumLiteralTypes1.ts, 93, 1)) + + { kind: Choice.Yes, a: string } | +>kind : Symbol(kind, Decl(enumLiteralTypes1.ts, 96, 5)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 96, 23)) + + { kind: Choice.No, b: string }; +>kind : Symbol(kind, Decl(enumLiteralTypes1.ts, 97, 5)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 97, 22)) + +function f20(x: Item) { +>f20 : Symbol(f20, Decl(enumLiteralTypes1.ts, 97, 35)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 99, 13)) +>Item : Symbol(Item, Decl(enumLiteralTypes1.ts, 93, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(enumLiteralTypes1.ts, 96, 5), Decl(enumLiteralTypes1.ts, 97, 5)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 99, 13)) +>kind : Symbol(kind, Decl(enumLiteralTypes1.ts, 96, 5), Decl(enumLiteralTypes1.ts, 97, 5)) + + case Choice.Yes: return x.a; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>x.a : Symbol(a, Decl(enumLiteralTypes1.ts, 96, 23)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 99, 13)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 96, 23)) + + case Choice.No: return x.b; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>x.b : Symbol(b, Decl(enumLiteralTypes1.ts, 97, 22)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 99, 13)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 97, 22)) + } +} + +function f21(x: Item) { +>f21 : Symbol(f21, Decl(enumLiteralTypes1.ts, 104, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 106, 13)) +>Item : Symbol(Item, Decl(enumLiteralTypes1.ts, 93, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(enumLiteralTypes1.ts, 96, 5), Decl(enumLiteralTypes1.ts, 97, 5)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 106, 13)) +>kind : Symbol(kind, Decl(enumLiteralTypes1.ts, 96, 5), Decl(enumLiteralTypes1.ts, 97, 5)) + + case Choice.Yes: return x.a; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes1.ts, 0, 28)) +>x.a : Symbol(a, Decl(enumLiteralTypes1.ts, 96, 23)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 106, 13)) +>a : Symbol(a, Decl(enumLiteralTypes1.ts, 96, 23)) + + case Choice.No: return x.b; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes1.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes1.ts, 0, 33)) +>x.b : Symbol(b, Decl(enumLiteralTypes1.ts, 97, 22)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 106, 13)) +>b : Symbol(b, Decl(enumLiteralTypes1.ts, 97, 22)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(enumLiteralTypes1.ts, 56, 1)) +>x : Symbol(x, Decl(enumLiteralTypes1.ts, 106, 13)) +} diff --git a/tests/baselines/reference/enumLiteralTypes1.types b/tests/baselines/reference/enumLiteralTypes1.types new file mode 100644 index 0000000000000..8e1f478baaa2b --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes1.types @@ -0,0 +1,449 @@ +=== tests/cases/conformance/types/literal/enumLiteralTypes1.ts === +const enum Choice { Unknown, Yes, No }; +>Choice : Choice +>Unknown : Choice +>Yes : Choice +>No : Choice + +type YesNo = Choice.Yes | Choice.No; +>YesNo : Choice.Yes | Choice.No +>Choice : any +>Yes : Choice.Yes +>Choice : any +>No : Choice.No + +type NoYes = Choice.No | Choice.Yes; +>NoYes : Choice.No | Choice.Yes +>Choice : any +>No : Choice.No +>Choice : any +>Yes : Choice.Yes + +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>Choice : any +>Unknown : Choice.Unknown +>Choice : any +>Yes : Choice.Yes +>Choice : any +>No : Choice.No + +function f1() { +>f1 : () => void + + var a: YesNo; +>a : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + var a: NoYes; +>a : Choice.Yes | Choice.No +>NoYes : Choice.No | Choice.Yes + + var a: Choice.Yes | Choice.No; +>a : Choice.Yes | Choice.No +>Choice : any +>Yes : Choice.Yes +>Choice : any +>No : Choice.No + + var a: Choice.No | Choice.Yes; +>a : Choice.Yes | Choice.No +>Choice : any +>No : Choice.No +>Choice : any +>Yes : Choice.Yes +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { +>f2 : (a: Choice.Yes | Choice.No, b: Choice.Unknown | Choice.Yes | Choice.No, c: Choice) => void +>a : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No +>b : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>c : Choice +>Choice : Choice + + b = a; +>b = a : Choice.Yes | Choice.No +>b : Choice.Unknown | Choice.Yes | Choice.No +>a : Choice.Yes | Choice.No + + c = a; +>c = a : Choice.Yes | Choice.No +>c : Choice +>a : Choice.Yes | Choice.No + + c = b; +>c = b : Choice.Yes | Choice.No +>c : Choice +>b : Choice.Yes | Choice.No +} + +function f3(a: Choice.Yes, b: YesNo) { +>f3 : (a: Choice.Yes, b: Choice.Yes | Choice.No) => void +>a : Choice.Yes +>Choice : any +>Yes : Choice.Yes +>b : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + var x = a + b; +>x : number +>a + b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a - b; +>x : number +>a - b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a * b; +>x : number +>a * b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a / b; +>x : number +>a / b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a % b; +>x : number +>a % b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a | b; +>x : number +>a | b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a & b; +>x : number +>a & b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = a ^ b; +>x : number +>a ^ b : number +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var x = -b; +>x : number +>-b : number +>b : Choice.Yes | Choice.No + + var x = ~b; +>x : number +>~b : number +>b : Choice.Yes | Choice.No + + var y = a == b; +>y : boolean +>a == b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a != b; +>y : boolean +>a != b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a === b; +>y : boolean +>a === b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a !== b; +>y : boolean +>a !== b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a > b; +>y : boolean +>a > b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a < b; +>y : boolean +>a < b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a >= b; +>y : boolean +>a >= b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = a <= b; +>y : boolean +>a <= b : boolean +>a : Choice.Yes +>b : Choice.Yes | Choice.No + + var y = !b; +>y : boolean +>!b : boolean +>b : Choice.Yes | Choice.No +} + +function f4(a: Choice.Yes, b: YesNo) { +>f4 : (a: Choice.Yes, b: Choice.Yes | Choice.No) => void +>a : Choice.Yes +>Choice : any +>Yes : Choice.Yes +>b : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + a++; +>a++ : number +>a : Choice.Yes + + b++; +>b++ : number +>b : Choice.Yes | Choice.No +} + +declare function g(x: Choice.Yes): string; +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>x : Choice.Yes +>Choice : any +>Yes : Choice.Yes + +declare function g(x: Choice.No): boolean; +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>x : Choice.No +>Choice : any +>No : Choice.No + +declare function g(x: Choice): number; +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>x : Choice +>Choice : Choice + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { +>f5 : (a: Choice.Yes | Choice.No, b: Choice.Unknown | Choice.Yes | Choice.No, c: Choice) => void +>a : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No +>b : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>c : Choice +>Choice : Choice + + var z1 = g(Choice.Yes); +>z1 : string +>g(Choice.Yes) : string +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes + + var z2 = g(Choice.No); +>z2 : boolean +>g(Choice.No) : boolean +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No + + var z3 = g(a); +>z3 : number +>g(a) : number +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>a : Choice.Yes | Choice.No + + var z4 = g(b); +>z4 : number +>g(b) : number +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>b : Choice.Unknown | Choice.Yes | Choice.No + + var z5 = g(c); +>z5 : number +>g(c) : number +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>c : Choice +} + +function assertNever(x: never): never { +>assertNever : (x: never) => never +>x : never + + throw new Error("Unexpected value"); +>new Error("Unexpected value") : Error +>Error : ErrorConstructor +>"Unexpected value" : string +} + +function f10(x: YesNo) { +>f10 : (x: Choice.Yes | Choice.No) => string +>x : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + switch (x) { +>x : Choice.Yes | Choice.No + + case Choice.Yes: return "true"; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>"true" : string + + case Choice.No: return "false"; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>"false" : string + } +} + +function f11(x: YesNo) { +>f11 : (x: Choice.Yes | Choice.No) => string +>x : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + switch (x) { +>x : Choice.Yes | Choice.No + + case Choice.Yes: return "true"; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>"true" : string + + case Choice.No: return "false"; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>"false" : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} + +function f12(x: UnknownYesNo) { +>f12 : (x: Choice.Unknown | Choice.Yes | Choice.No) => void +>x : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No + + if (x) { +>x : Choice.Unknown | Choice.Yes | Choice.No + + x; +>x : Choice.Yes | Choice.No + } + else { + x; +>x : Choice.Unknown | Choice.Yes | Choice.No + } +} + +function f13(x: UnknownYesNo) { +>f13 : (x: Choice.Unknown | Choice.Yes | Choice.No) => void +>x : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No + + if (x === Choice.Yes) { +>x === Choice.Yes : boolean +>x : Choice.Unknown | Choice.Yes | Choice.No +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes + + x; +>x : Choice.Yes + } + else { + x; +>x : Choice.Unknown | Choice.No + } +} + +type Item = +>Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } + + { kind: Choice.Yes, a: string } | +>kind : Choice.Yes +>Choice : any +>Yes : Choice.Yes +>a : string + + { kind: Choice.No, b: string }; +>kind : Choice.No +>Choice : any +>No : Choice.No +>b : string + +function f20(x: Item) { +>f20 : (x: { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; }) => string +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } + + switch (x.kind) { +>x.kind : Choice.Yes | Choice.No +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>kind : Choice.Yes | Choice.No + + case Choice.Yes: return x.a; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>x.a : string +>x : { kind: Choice.Yes; a: string; } +>a : string + + case Choice.No: return x.b; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>x.b : string +>x : { kind: Choice.No; b: string; } +>b : string + } +} + +function f21(x: Item) { +>f21 : (x: { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; }) => string +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } + + switch (x.kind) { +>x.kind : Choice.Yes | Choice.No +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>kind : Choice.Yes | Choice.No + + case Choice.Yes: return x.a; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>x.a : string +>x : { kind: Choice.Yes; a: string; } +>a : string + + case Choice.No: return x.b; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>x.b : string +>x : { kind: Choice.No; b: string; } +>b : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} diff --git a/tests/baselines/reference/enumLiteralTypes2.js b/tests/baselines/reference/enumLiteralTypes2.js new file mode 100644 index 0000000000000..0b2b6d35c5340 --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes2.js @@ -0,0 +1,206 @@ +//// [enumLiteralTypes2.ts] + +const enum Choice { Unknown, Yes, No }; + +type YesNo = Choice.Yes | Choice.No; +type NoYes = Choice.No | Choice.Yes; +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; + +function f1() { + var a: YesNo; + var a: NoYes; + var a: Choice.Yes | Choice.No; + var a: Choice.No | Choice.Yes; +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { + b = a; + c = a; + c = b; +} + +function f3(a: Choice.Yes, b: UnknownYesNo) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} + +function f4(a: Choice.Yes, b: UnknownYesNo) { + a++; + b++; +} + +declare function g(x: Choice.Yes): string; +declare function g(x: Choice.No): boolean; +declare function g(x: Choice): number; + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { + var z1 = g(Choice.Yes); + var z2 = g(Choice.No); + var z3 = g(a); + var z4 = g(b); + var z5 = g(c); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +function f10(x: YesNo) { + switch (x) { + case Choice.Yes: return "true"; + case Choice.No: return "false"; + } +} + +function f11(x: YesNo) { + switch (x) { + case Choice.Yes: return "true"; + case Choice.No: return "false"; + } + return assertNever(x); +} + +function f12(x: UnknownYesNo) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: UnknownYesNo) { + if (x === Choice.Yes) { + x; + } + else { + x; + } +} + +type Item = + { kind: Choice.Yes, a: string } | + { kind: Choice.No, b: string }; + +function f20(x: Item) { + switch (x.kind) { + case Choice.Yes: return x.a; + case Choice.No: return x.b; + } +} + +function f21(x: Item) { + switch (x.kind) { + case Choice.Yes: return x.a; + case Choice.No: return x.b; + } + return assertNever(x); +} + +//// [enumLiteralTypes2.js] +; +function f1() { + var a; + var a; + var a; + var a; +} +function f2(a, b, c) { + b = a; + c = a; + c = b; +} +function f3(a, b) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} +function f4(a, b) { + a++; + b++; +} +function f5(a, b, c) { + var z1 = g(1 /* Yes */); + var z2 = g(2 /* No */); + var z3 = g(a); + var z4 = g(b); + var z5 = g(c); +} +function assertNever(x) { + throw new Error("Unexpected value"); +} +function f10(x) { + switch (x) { + case 1 /* Yes */: return "true"; + case 2 /* No */: return "false"; + } +} +function f11(x) { + switch (x) { + case 1 /* Yes */: return "true"; + case 2 /* No */: return "false"; + } + return assertNever(x); +} +function f12(x) { + if (x) { + x; + } + else { + x; + } +} +function f13(x) { + if (x === 1 /* Yes */) { + x; + } + else { + x; + } +} +function f20(x) { + switch (x.kind) { + case 1 /* Yes */: return x.a; + case 2 /* No */: return x.b; + } +} +function f21(x) { + switch (x.kind) { + case 1 /* Yes */: return x.a; + case 2 /* No */: return x.b; + } + return assertNever(x); +} diff --git a/tests/baselines/reference/enumLiteralTypes2.symbols b/tests/baselines/reference/enumLiteralTypes2.symbols new file mode 100644 index 0000000000000..3bd937c3706fa --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes2.symbols @@ -0,0 +1,412 @@ +=== tests/cases/conformance/types/literal/enumLiteralTypes2.ts === + +const enum Choice { Unknown, Yes, No }; +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Unknown : Symbol(Choice.Unknown, Decl(enumLiteralTypes2.ts, 1, 19)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + +type YesNo = Choice.Yes | Choice.No; +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes2.ts, 1, 39)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + +type NoYes = Choice.No | Choice.Yes; +>NoYes : Symbol(NoYes, Decl(enumLiteralTypes2.ts, 3, 36)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) + +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Unknown : Symbol(Choice.Unknown, Decl(enumLiteralTypes2.ts, 1, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + +function f1() { +>f1 : Symbol(f1, Decl(enumLiteralTypes2.ts, 5, 60)) + + var a: YesNo; +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 8, 7), Decl(enumLiteralTypes2.ts, 9, 7), Decl(enumLiteralTypes2.ts, 10, 7), Decl(enumLiteralTypes2.ts, 11, 7)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes2.ts, 1, 39)) + + var a: NoYes; +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 8, 7), Decl(enumLiteralTypes2.ts, 9, 7), Decl(enumLiteralTypes2.ts, 10, 7), Decl(enumLiteralTypes2.ts, 11, 7)) +>NoYes : Symbol(NoYes, Decl(enumLiteralTypes2.ts, 3, 36)) + + var a: Choice.Yes | Choice.No; +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 8, 7), Decl(enumLiteralTypes2.ts, 9, 7), Decl(enumLiteralTypes2.ts, 10, 7), Decl(enumLiteralTypes2.ts, 11, 7)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + + var a: Choice.No | Choice.Yes; +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 8, 7), Decl(enumLiteralTypes2.ts, 9, 7), Decl(enumLiteralTypes2.ts, 10, 7), Decl(enumLiteralTypes2.ts, 11, 7)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { +>f2 : Symbol(f2, Decl(enumLiteralTypes2.ts, 12, 1)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 14, 12)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes2.ts, 1, 39)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 14, 21)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) +>c : Symbol(c, Decl(enumLiteralTypes2.ts, 14, 38)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) + + b = a; +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 14, 21)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 14, 12)) + + c = a; +>c : Symbol(c, Decl(enumLiteralTypes2.ts, 14, 38)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 14, 12)) + + c = b; +>c : Symbol(c, Decl(enumLiteralTypes2.ts, 14, 38)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 14, 21)) +} + +function f3(a: Choice.Yes, b: UnknownYesNo) { +>f3 : Symbol(f3, Decl(enumLiteralTypes2.ts, 18, 1)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) + + var x = a + b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a - b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a * b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a / b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a % b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a | b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a & b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = a ^ b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = -b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var x = ~b; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 21, 7), Decl(enumLiteralTypes2.ts, 22, 7), Decl(enumLiteralTypes2.ts, 23, 7), Decl(enumLiteralTypes2.ts, 24, 7), Decl(enumLiteralTypes2.ts, 25, 7), Decl(enumLiteralTypes2.ts, 26, 7), Decl(enumLiteralTypes2.ts, 27, 7), Decl(enumLiteralTypes2.ts, 28, 7), Decl(enumLiteralTypes2.ts, 29, 7), Decl(enumLiteralTypes2.ts, 30, 7)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a == b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a != b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a === b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a !== b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a > b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a < b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a >= b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = a <= b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 20, 12)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) + + var y = !b; +>y : Symbol(y, Decl(enumLiteralTypes2.ts, 31, 7), Decl(enumLiteralTypes2.ts, 32, 7), Decl(enumLiteralTypes2.ts, 33, 7), Decl(enumLiteralTypes2.ts, 34, 7), Decl(enumLiteralTypes2.ts, 35, 7), Decl(enumLiteralTypes2.ts, 36, 7), Decl(enumLiteralTypes2.ts, 37, 7), Decl(enumLiteralTypes2.ts, 38, 7), Decl(enumLiteralTypes2.ts, 39, 7)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 20, 26)) +} + +function f4(a: Choice.Yes, b: UnknownYesNo) { +>f4 : Symbol(f4, Decl(enumLiteralTypes2.ts, 40, 1)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 42, 12)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 42, 26)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) + + a++; +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 42, 12)) + + b++; +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 42, 26)) +} + +declare function g(x: Choice.Yes): string; +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 47, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) + +declare function g(x: Choice.No): boolean; +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 48, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + +declare function g(x: Choice): number; +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 49, 19)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { +>f5 : Symbol(f5, Decl(enumLiteralTypes2.ts, 49, 38)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 51, 12)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes2.ts, 1, 39)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 51, 21)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) +>c : Symbol(c, Decl(enumLiteralTypes2.ts, 51, 38)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) + + var z1 = g(Choice.Yes); +>z1 : Symbol(z1, Decl(enumLiteralTypes2.ts, 52, 7)) +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) + + var z2 = g(Choice.No); +>z2 : Symbol(z2, Decl(enumLiteralTypes2.ts, 53, 7)) +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + + var z3 = g(a); +>z3 : Symbol(z3, Decl(enumLiteralTypes2.ts, 54, 7)) +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 51, 12)) + + var z4 = g(b); +>z4 : Symbol(z4, Decl(enumLiteralTypes2.ts, 55, 7)) +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 51, 21)) + + var z5 = g(c); +>z5 : Symbol(z5, Decl(enumLiteralTypes2.ts, 56, 7)) +>g : Symbol(g, Decl(enumLiteralTypes2.ts, 45, 1), Decl(enumLiteralTypes2.ts, 47, 42), Decl(enumLiteralTypes2.ts, 48, 42)) +>c : Symbol(c, Decl(enumLiteralTypes2.ts, 51, 38)) +} + +function assertNever(x: never): never { +>assertNever : Symbol(assertNever, Decl(enumLiteralTypes2.ts, 57, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 59, 21)) + + throw new Error("Unexpected value"); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +function f10(x: YesNo) { +>f10 : Symbol(f10, Decl(enumLiteralTypes2.ts, 61, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 63, 13)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes2.ts, 1, 39)) + + switch (x) { +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 63, 13)) + + case Choice.Yes: return "true"; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) + + case Choice.No: return "false"; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + } +} + +function f11(x: YesNo) { +>f11 : Symbol(f11, Decl(enumLiteralTypes2.ts, 68, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 70, 13)) +>YesNo : Symbol(YesNo, Decl(enumLiteralTypes2.ts, 1, 39)) + + switch (x) { +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 70, 13)) + + case Choice.Yes: return "true"; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) + + case Choice.No: return "false"; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(enumLiteralTypes2.ts, 57, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 70, 13)) +} + +function f12(x: UnknownYesNo) { +>f12 : Symbol(f12, Decl(enumLiteralTypes2.ts, 76, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 78, 13)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) + + if (x) { +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 78, 13)) + + x; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 78, 13)) + } + else { + x; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 78, 13)) + } +} + +function f13(x: UnknownYesNo) { +>f13 : Symbol(f13, Decl(enumLiteralTypes2.ts, 85, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 87, 13)) +>UnknownYesNo : Symbol(UnknownYesNo, Decl(enumLiteralTypes2.ts, 4, 36)) + + if (x === Choice.Yes) { +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 87, 13)) +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) + + x; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 87, 13)) + } + else { + x; +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 87, 13)) + } +} + +type Item = +>Item : Symbol(Item, Decl(enumLiteralTypes2.ts, 94, 1)) + + { kind: Choice.Yes, a: string } | +>kind : Symbol(kind, Decl(enumLiteralTypes2.ts, 97, 5)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 97, 23)) + + { kind: Choice.No, b: string }; +>kind : Symbol(kind, Decl(enumLiteralTypes2.ts, 98, 5)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 98, 22)) + +function f20(x: Item) { +>f20 : Symbol(f20, Decl(enumLiteralTypes2.ts, 98, 35)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 100, 13)) +>Item : Symbol(Item, Decl(enumLiteralTypes2.ts, 94, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(enumLiteralTypes2.ts, 97, 5), Decl(enumLiteralTypes2.ts, 98, 5)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 100, 13)) +>kind : Symbol(kind, Decl(enumLiteralTypes2.ts, 97, 5), Decl(enumLiteralTypes2.ts, 98, 5)) + + case Choice.Yes: return x.a; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>x.a : Symbol(a, Decl(enumLiteralTypes2.ts, 97, 23)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 100, 13)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 97, 23)) + + case Choice.No: return x.b; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>x.b : Symbol(b, Decl(enumLiteralTypes2.ts, 98, 22)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 100, 13)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 98, 22)) + } +} + +function f21(x: Item) { +>f21 : Symbol(f21, Decl(enumLiteralTypes2.ts, 105, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 107, 13)) +>Item : Symbol(Item, Decl(enumLiteralTypes2.ts, 94, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(enumLiteralTypes2.ts, 97, 5), Decl(enumLiteralTypes2.ts, 98, 5)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 107, 13)) +>kind : Symbol(kind, Decl(enumLiteralTypes2.ts, 97, 5), Decl(enumLiteralTypes2.ts, 98, 5)) + + case Choice.Yes: return x.a; +>Choice.Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>Yes : Symbol(Choice.Yes, Decl(enumLiteralTypes2.ts, 1, 28)) +>x.a : Symbol(a, Decl(enumLiteralTypes2.ts, 97, 23)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 107, 13)) +>a : Symbol(a, Decl(enumLiteralTypes2.ts, 97, 23)) + + case Choice.No: return x.b; +>Choice.No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>Choice : Symbol(Choice, Decl(enumLiteralTypes2.ts, 0, 0)) +>No : Symbol(Choice.No, Decl(enumLiteralTypes2.ts, 1, 33)) +>x.b : Symbol(b, Decl(enumLiteralTypes2.ts, 98, 22)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 107, 13)) +>b : Symbol(b, Decl(enumLiteralTypes2.ts, 98, 22)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(enumLiteralTypes2.ts, 57, 1)) +>x : Symbol(x, Decl(enumLiteralTypes2.ts, 107, 13)) +} diff --git a/tests/baselines/reference/enumLiteralTypes2.types b/tests/baselines/reference/enumLiteralTypes2.types new file mode 100644 index 0000000000000..aab06c82fc4fd --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes2.types @@ -0,0 +1,450 @@ +=== tests/cases/conformance/types/literal/enumLiteralTypes2.ts === + +const enum Choice { Unknown, Yes, No }; +>Choice : Choice +>Unknown : Choice +>Yes : Choice +>No : Choice + +type YesNo = Choice.Yes | Choice.No; +>YesNo : Choice.Yes | Choice.No +>Choice : any +>Yes : Choice.Yes +>Choice : any +>No : Choice.No + +type NoYes = Choice.No | Choice.Yes; +>NoYes : Choice.No | Choice.Yes +>Choice : any +>No : Choice.No +>Choice : any +>Yes : Choice.Yes + +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>Choice : any +>Unknown : Choice.Unknown +>Choice : any +>Yes : Choice.Yes +>Choice : any +>No : Choice.No + +function f1() { +>f1 : () => void + + var a: YesNo; +>a : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + var a: NoYes; +>a : Choice.Yes | Choice.No +>NoYes : Choice.No | Choice.Yes + + var a: Choice.Yes | Choice.No; +>a : Choice.Yes | Choice.No +>Choice : any +>Yes : Choice.Yes +>Choice : any +>No : Choice.No + + var a: Choice.No | Choice.Yes; +>a : Choice.Yes | Choice.No +>Choice : any +>No : Choice.No +>Choice : any +>Yes : Choice.Yes +} + +function f2(a: YesNo, b: UnknownYesNo, c: Choice) { +>f2 : (a: Choice.Yes | Choice.No, b: Choice.Unknown | Choice.Yes | Choice.No, c: Choice) => void +>a : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No +>b : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>c : Choice +>Choice : Choice + + b = a; +>b = a : Choice.Yes | Choice.No +>b : Choice.Unknown | Choice.Yes | Choice.No +>a : Choice.Yes | Choice.No + + c = a; +>c = a : Choice.Yes | Choice.No +>c : Choice +>a : Choice.Yes | Choice.No + + c = b; +>c = b : Choice.Yes | Choice.No +>c : Choice +>b : Choice.Yes | Choice.No +} + +function f3(a: Choice.Yes, b: UnknownYesNo) { +>f3 : (a: Choice.Yes, b: Choice.Unknown | Choice.Yes | Choice.No) => void +>a : Choice.Yes +>Choice : any +>Yes : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No + + var x = a + b; +>x : number +>a + b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a - b; +>x : number +>a - b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a * b; +>x : number +>a * b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a / b; +>x : number +>a / b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a % b; +>x : number +>a % b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a | b; +>x : number +>a | b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a & b; +>x : number +>a & b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = a ^ b; +>x : number +>a ^ b : number +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = -b; +>x : number +>-b : number +>b : Choice.Unknown | Choice.Yes | Choice.No + + var x = ~b; +>x : number +>~b : number +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a == b; +>y : boolean +>a == b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a != b; +>y : boolean +>a != b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a === b; +>y : boolean +>a === b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a !== b; +>y : boolean +>a !== b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a > b; +>y : boolean +>a > b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a < b; +>y : boolean +>a < b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a >= b; +>y : boolean +>a >= b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = a <= b; +>y : boolean +>a <= b : boolean +>a : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No + + var y = !b; +>y : boolean +>!b : boolean +>b : Choice.Unknown | Choice.Yes | Choice.No +} + +function f4(a: Choice.Yes, b: UnknownYesNo) { +>f4 : (a: Choice.Yes, b: Choice.Unknown | Choice.Yes | Choice.No) => void +>a : Choice.Yes +>Choice : any +>Yes : Choice.Yes +>b : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No + + a++; +>a++ : number +>a : Choice.Yes + + b++; +>b++ : number +>b : Choice.Unknown | Choice.Yes | Choice.No +} + +declare function g(x: Choice.Yes): string; +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>x : Choice.Yes +>Choice : any +>Yes : Choice.Yes + +declare function g(x: Choice.No): boolean; +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>x : Choice.No +>Choice : any +>No : Choice.No + +declare function g(x: Choice): number; +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>x : Choice +>Choice : Choice + +function f5(a: YesNo, b: UnknownYesNo, c: Choice) { +>f5 : (a: Choice.Yes | Choice.No, b: Choice.Unknown | Choice.Yes | Choice.No, c: Choice) => void +>a : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No +>b : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>c : Choice +>Choice : Choice + + var z1 = g(Choice.Yes); +>z1 : string +>g(Choice.Yes) : string +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes + + var z2 = g(Choice.No); +>z2 : boolean +>g(Choice.No) : boolean +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No + + var z3 = g(a); +>z3 : number +>g(a) : number +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>a : Choice.Yes | Choice.No + + var z4 = g(b); +>z4 : number +>g(b) : number +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>b : Choice.Unknown | Choice.Yes | Choice.No + + var z5 = g(c); +>z5 : number +>g(c) : number +>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } +>c : Choice +} + +function assertNever(x: never): never { +>assertNever : (x: never) => never +>x : never + + throw new Error("Unexpected value"); +>new Error("Unexpected value") : Error +>Error : ErrorConstructor +>"Unexpected value" : string +} + +function f10(x: YesNo) { +>f10 : (x: Choice.Yes | Choice.No) => string +>x : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + switch (x) { +>x : Choice.Yes | Choice.No + + case Choice.Yes: return "true"; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>"true" : string + + case Choice.No: return "false"; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>"false" : string + } +} + +function f11(x: YesNo) { +>f11 : (x: Choice.Yes | Choice.No) => string +>x : Choice.Yes | Choice.No +>YesNo : Choice.Yes | Choice.No + + switch (x) { +>x : Choice.Yes | Choice.No + + case Choice.Yes: return "true"; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>"true" : string + + case Choice.No: return "false"; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>"false" : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} + +function f12(x: UnknownYesNo) { +>f12 : (x: Choice.Unknown | Choice.Yes | Choice.No) => void +>x : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No + + if (x) { +>x : Choice.Unknown | Choice.Yes | Choice.No + + x; +>x : Choice.Yes | Choice.No + } + else { + x; +>x : Choice.Unknown + } +} + +function f13(x: UnknownYesNo) { +>f13 : (x: Choice.Unknown | Choice.Yes | Choice.No) => void +>x : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No + + if (x === Choice.Yes) { +>x === Choice.Yes : boolean +>x : Choice.Unknown | Choice.Yes | Choice.No +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes + + x; +>x : Choice.Yes + } + else { + x; +>x : Choice.Unknown | Choice.No + } +} + +type Item = +>Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } + + { kind: Choice.Yes, a: string } | +>kind : Choice.Yes +>Choice : any +>Yes : Choice.Yes +>a : string + + { kind: Choice.No, b: string }; +>kind : Choice.No +>Choice : any +>No : Choice.No +>b : string + +function f20(x: Item) { +>f20 : (x: { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; }) => string +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } + + switch (x.kind) { +>x.kind : Choice.Yes | Choice.No +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>kind : Choice.Yes | Choice.No + + case Choice.Yes: return x.a; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>x.a : string +>x : { kind: Choice.Yes; a: string; } +>a : string + + case Choice.No: return x.b; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>x.b : string +>x : { kind: Choice.No; b: string; } +>b : string + } +} + +function f21(x: Item) { +>f21 : (x: { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; }) => string +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } + + switch (x.kind) { +>x.kind : Choice.Yes | Choice.No +>x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>kind : Choice.Yes | Choice.No + + case Choice.Yes: return x.a; +>Choice.Yes : Choice.Yes +>Choice : typeof Choice +>Yes : Choice.Yes +>x.a : string +>x : { kind: Choice.Yes; a: string; } +>a : string + + case Choice.No: return x.b; +>Choice.No : Choice.No +>Choice : typeof Choice +>No : Choice.No +>x.b : string +>x : { kind: Choice.No; b: string; } +>b : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} diff --git a/tests/baselines/reference/enumLiteralTypes3.errors.txt b/tests/baselines/reference/enumLiteralTypes3.errors.txt new file mode 100644 index 0000000000000..2f3ea5ada2479 --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes3.errors.txt @@ -0,0 +1,173 @@ +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(10,5): error TS2322: Type 'Yes | No' is not assignable to type 'Yes'. + Type 'No' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(11,5): error TS2322: Type 'Unknown | Yes | No' is not assignable to type 'Yes'. + Type 'Unknown' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(12,5): error TS2322: Type 'Choice' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(18,5): error TS2322: Type 'Unknown | Yes | No' is not assignable to type 'Yes | No'. + Type 'Unknown' is not assignable to type 'Yes | No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(19,5): error TS2322: Type 'Choice' is not assignable to type 'Yes | No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(26,5): error TS2322: Type 'Choice' is not assignable to type 'Unknown | Yes | No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(37,5): error TS2322: Type 'Unknown' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(39,5): error TS2322: Type 'No' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(40,5): error TS2322: Type 'Unknown' is not assignable to type 'Yes | No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(52,5): error TS2365: Operator '===' cannot be applied to types 'Yes' and 'Unknown'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(54,5): error TS2365: Operator '===' cannot be applied to types 'Yes' and 'No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(55,5): error TS2365: Operator '===' cannot be applied to types 'Yes | No' and 'Unknown'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(87,14): error TS2678: Type 'Unknown' is not comparable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(89,14): error TS2678: Type 'No' is not comparable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: Type 'Unknown' is not comparable to type 'Yes | No'. + + +==== tests/cases/conformance/types/literal/enumLiteralTypes3.ts (15 errors) ==== + const enum Choice { Unknown, Yes, No }; + + type Yes = Choice.Yes; + type YesNo = Choice.Yes | Choice.No; + type NoYes = Choice.No | Choice.Yes; + type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; + + function f1(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a = a; + a = b; + ~ +!!! error TS2322: Type 'Yes | No' is not assignable to type 'Yes'. +!!! error TS2322: Type 'No' is not assignable to type 'Yes'. + a = c; + ~ +!!! error TS2322: Type 'Unknown | Yes | No' is not assignable to type 'Yes'. +!!! error TS2322: Type 'Unknown' is not assignable to type 'Yes'. + a = d; + ~ +!!! error TS2322: Type 'Choice' is not assignable to type 'Yes'. + } + + function f2(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + b = a; + b = b; + b = c; + ~ +!!! error TS2322: Type 'Unknown | Yes | No' is not assignable to type 'Yes | No'. +!!! error TS2322: Type 'Unknown' is not assignable to type 'Yes | No'. + b = d; + ~ +!!! error TS2322: Type 'Choice' is not assignable to type 'Yes | No'. + } + + function f3(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + c = a; + c = b; + c = c; + c = d; + ~ +!!! error TS2322: Type 'Choice' is not assignable to type 'Unknown | Yes | No'. + } + + function f4(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + d = a; + d = b; + d = c; + d = d; + } + + function f5(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a = Choice.Unknown; + ~ +!!! error TS2322: Type 'Unknown' is not assignable to type 'Yes'. + a = Choice.Yes; + a = Choice.No; + ~ +!!! error TS2322: Type 'No' is not assignable to type 'Yes'. + b = Choice.Unknown; + ~ +!!! error TS2322: Type 'Unknown' is not assignable to type 'Yes | No'. + b = Choice.Yes; + b = Choice.No; + c = Choice.Unknown; + c = Choice.Yes; + c = Choice.No; + d = Choice.Unknown; + d = Choice.Yes; + d = Choice.No; + } + + function f6(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a === Choice.Unknown; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'Yes' and 'Unknown'. + a === Choice.Yes; + a === Choice.No; + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'Yes' and 'No'. + b === Choice.Unknown; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'Yes | No' and 'Unknown'. + b === Choice.Yes; + b === Choice.No; + c === Choice.Unknown; + c === Choice.Yes; + c === Choice.No; + d === Choice.Unknown; + d === Choice.Yes; + d === Choice.No; + } + + function f7(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a === a; + a === b; + a === c; + a === d; + b === a; + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; + } + + function f10(x: Yes): Yes { + switch (x) { + case Choice.Unknown: return x; + ~~~~~~~~~~~~~~ +!!! error TS2678: Type 'Unknown' is not comparable to type 'Yes'. + case Choice.Yes: return x; + case Choice.No: return x; + ~~~~~~~~~ +!!! error TS2678: Type 'No' is not comparable to type 'Yes'. + } + return x; + } + + function f11(x: YesNo): YesNo { + switch (x) { + case Choice.Unknown: return x; + ~~~~~~~~~~~~~~ +!!! error TS2678: Type 'Unknown' is not comparable to type 'Yes | No'. + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; + } + + function f12(x: UnknownYesNo): UnknownYesNo { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; + } + + function f13(x: Choice): Choice { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; + } \ No newline at end of file diff --git a/tests/baselines/reference/enumLiteralTypes3.js b/tests/baselines/reference/enumLiteralTypes3.js new file mode 100644 index 0000000000000..7eb3d0a1705d1 --- /dev/null +++ b/tests/baselines/reference/enumLiteralTypes3.js @@ -0,0 +1,225 @@ +//// [enumLiteralTypes3.ts] +const enum Choice { Unknown, Yes, No }; + +type Yes = Choice.Yes; +type YesNo = Choice.Yes | Choice.No; +type NoYes = Choice.No | Choice.Yes; +type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; + +function f1(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a = a; + a = b; + a = c; + a = d; +} + +function f2(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + b = a; + b = b; + b = c; + b = d; +} + +function f3(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + c = a; + c = b; + c = c; + c = d; +} + +function f4(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + d = a; + d = b; + d = c; + d = d; +} + +function f5(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a = Choice.Unknown; + a = Choice.Yes; + a = Choice.No; + b = Choice.Unknown; + b = Choice.Yes; + b = Choice.No; + c = Choice.Unknown; + c = Choice.Yes; + c = Choice.No; + d = Choice.Unknown; + d = Choice.Yes; + d = Choice.No; +} + +function f6(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a === Choice.Unknown; + a === Choice.Yes; + a === Choice.No; + b === Choice.Unknown; + b === Choice.Yes; + b === Choice.No; + c === Choice.Unknown; + c === Choice.Yes; + c === Choice.No; + d === Choice.Unknown; + d === Choice.Yes; + d === Choice.No; +} + +function f7(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { + a === a; + a === b; + a === c; + a === d; + b === a; + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; +} + +function f10(x: Yes): Yes { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; +} + +function f11(x: YesNo): YesNo { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; +} + +function f12(x: UnknownYesNo): UnknownYesNo { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; +} + +function f13(x: Choice): Choice { + switch (x) { + case Choice.Unknown: return x; + case Choice.Yes: return x; + case Choice.No: return x; + } + return x; +} + +//// [enumLiteralTypes3.js] +; +function f1(a, b, c, d) { + a = a; + a = b; + a = c; + a = d; +} +function f2(a, b, c, d) { + b = a; + b = b; + b = c; + b = d; +} +function f3(a, b, c, d) { + c = a; + c = b; + c = c; + c = d; +} +function f4(a, b, c, d) { + d = a; + d = b; + d = c; + d = d; +} +function f5(a, b, c, d) { + a = 0 /* Unknown */; + a = 1 /* Yes */; + a = 2 /* No */; + b = 0 /* Unknown */; + b = 1 /* Yes */; + b = 2 /* No */; + c = 0 /* Unknown */; + c = 1 /* Yes */; + c = 2 /* No */; + d = 0 /* Unknown */; + d = 1 /* Yes */; + d = 2 /* No */; +} +function f6(a, b, c, d) { + a === 0 /* Unknown */; + a === 1 /* Yes */; + a === 2 /* No */; + b === 0 /* Unknown */; + b === 1 /* Yes */; + b === 2 /* No */; + c === 0 /* Unknown */; + c === 1 /* Yes */; + c === 2 /* No */; + d === 0 /* Unknown */; + d === 1 /* Yes */; + d === 2 /* No */; +} +function f7(a, b, c, d) { + a === a; + a === b; + a === c; + a === d; + b === a; + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; +} +function f10(x) { + switch (x) { + case 0 /* Unknown */: return x; + case 1 /* Yes */: return x; + case 2 /* No */: return x; + } + return x; +} +function f11(x) { + switch (x) { + case 0 /* Unknown */: return x; + case 1 /* Yes */: return x; + case 2 /* No */: return x; + } + return x; +} +function f12(x) { + switch (x) { + case 0 /* Unknown */: return x; + case 1 /* Yes */: return x; + case 2 /* No */: return x; + } + return x; +} +function f13(x) { + switch (x) { + case 0 /* Unknown */: return x; + case 1 /* Yes */: return x; + case 2 /* No */: return x; + } + return x; +} diff --git a/tests/baselines/reference/literalTypes1.js b/tests/baselines/reference/literalTypes1.js new file mode 100644 index 0000000000000..cf2923e250a12 --- /dev/null +++ b/tests/baselines/reference/literalTypes1.js @@ -0,0 +1,173 @@ +//// [literalTypes1.ts] + +let zero: 0 = 0; +let one: 1 = 1; +let two: 2 = 2; +let oneOrTwo: 1 | 2 = <1 | 2>1; + +function f1(x: 0 | 1 | 2) { + switch (x) { + case zero: + x; + break; + case one: + x; + break; + case two: + x; + break; + default: + x; + } +} + +function f2(x: 0 | 1 | 2) { + switch (x) { + case zero: + x; + break; + case oneOrTwo: + x; + break; + default: + x; + } +} + +type Falsy = false | 0 | "" | null | undefined; + +function f3(x: Falsy) { + if (x) { + x; + } + else { + x; + } +} + +function f4(x: 0 | 1 | true | string) { + switch (x) { + case 0: + x; + break; + case 1: + x; + break; + case "abc": + case "def": + x; + break; + case null: + x; + break; + case undefined: + x; + break; + default: + x; + } +} + +function f5(x: string | number | boolean) { + switch (x) { + case "abc": + x; + break; + case 0: + case 1: + x; + break; + case true: + x; + break; + case "hello": + case 123: + x; + break; + default: + x; + } +} + +//// [literalTypes1.js] +var zero = 0; +var one = 1; +var two = 2; +var oneOrTwo = 1; +function f1(x) { + switch (x) { + case zero: + x; + break; + case one: + x; + break; + case two: + x; + break; + default: + x; + } +} +function f2(x) { + switch (x) { + case zero: + x; + break; + case oneOrTwo: + x; + break; + default: + x; + } +} +function f3(x) { + if (x) { + x; + } + else { + x; + } +} +function f4(x) { + switch (x) { + case 0: + x; + break; + case 1: + x; + break; + case "abc": + case "def": + x; + break; + case null: + x; + break; + case undefined: + x; + break; + default: + x; + } +} +function f5(x) { + switch (x) { + case "abc": + x; + break; + case 0: + case 1: + x; + break; + case true: + x; + break; + case "hello": + case 123: + x; + break; + default: + x; + } +} diff --git a/tests/baselines/reference/literalTypes1.symbols b/tests/baselines/reference/literalTypes1.symbols new file mode 100644 index 0000000000000..ea44ab51acc86 --- /dev/null +++ b/tests/baselines/reference/literalTypes1.symbols @@ -0,0 +1,170 @@ +=== tests/cases/conformance/types/literal/literalTypes1.ts === + +let zero: 0 = 0; +>zero : Symbol(zero, Decl(literalTypes1.ts, 1, 3)) + +let one: 1 = 1; +>one : Symbol(one, Decl(literalTypes1.ts, 2, 3)) + +let two: 2 = 2; +>two : Symbol(two, Decl(literalTypes1.ts, 3, 3)) + +let oneOrTwo: 1 | 2 = <1 | 2>1; +>oneOrTwo : Symbol(oneOrTwo, Decl(literalTypes1.ts, 4, 3)) + +function f1(x: 0 | 1 | 2) { +>f1 : Symbol(f1, Decl(literalTypes1.ts, 4, 31)) +>x : Symbol(x, Decl(literalTypes1.ts, 6, 12)) + + switch (x) { +>x : Symbol(x, Decl(literalTypes1.ts, 6, 12)) + + case zero: +>zero : Symbol(zero, Decl(literalTypes1.ts, 1, 3)) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 6, 12)) + + break; + case one: +>one : Symbol(one, Decl(literalTypes1.ts, 2, 3)) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 6, 12)) + + break; + case two: +>two : Symbol(two, Decl(literalTypes1.ts, 3, 3)) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 6, 12)) + + break; + default: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 6, 12)) + } +} + +function f2(x: 0 | 1 | 2) { +>f2 : Symbol(f2, Decl(literalTypes1.ts, 20, 1)) +>x : Symbol(x, Decl(literalTypes1.ts, 22, 12)) + + switch (x) { +>x : Symbol(x, Decl(literalTypes1.ts, 22, 12)) + + case zero: +>zero : Symbol(zero, Decl(literalTypes1.ts, 1, 3)) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 22, 12)) + + break; + case oneOrTwo: +>oneOrTwo : Symbol(oneOrTwo, Decl(literalTypes1.ts, 4, 3)) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 22, 12)) + + break; + default: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 22, 12)) + } +} + +type Falsy = false | 0 | "" | null | undefined; +>Falsy : Symbol(Falsy, Decl(literalTypes1.ts, 33, 1)) + +function f3(x: Falsy) { +>f3 : Symbol(f3, Decl(literalTypes1.ts, 35, 47)) +>x : Symbol(x, Decl(literalTypes1.ts, 37, 12)) +>Falsy : Symbol(Falsy, Decl(literalTypes1.ts, 33, 1)) + + if (x) { +>x : Symbol(x, Decl(literalTypes1.ts, 37, 12)) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 37, 12)) + } + else { + x; +>x : Symbol(x, Decl(literalTypes1.ts, 37, 12)) + } +} + +function f4(x: 0 | 1 | true | string) { +>f4 : Symbol(f4, Decl(literalTypes1.ts, 44, 1)) +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + switch (x) { +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + case 0: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + break; + case 1: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + break; + case "abc": + case "def": + x; +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + break; + case null: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + break; + case undefined: +>undefined : Symbol(undefined) + + x; +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + + break; + default: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 46, 12)) + } +} + +function f5(x: string | number | boolean) { +>f5 : Symbol(f5, Decl(literalTypes1.ts, 67, 1)) +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + + switch (x) { +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + + case "abc": + x; +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + + break; + case 0: + case 1: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + + break; + case true: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + + break; + case "hello": + case 123: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + + break; + default: + x; +>x : Symbol(x, Decl(literalTypes1.ts, 69, 12)) + } +} diff --git a/tests/baselines/reference/literalTypes1.types b/tests/baselines/reference/literalTypes1.types new file mode 100644 index 0000000000000..1428ce601a0da --- /dev/null +++ b/tests/baselines/reference/literalTypes1.types @@ -0,0 +1,200 @@ +=== tests/cases/conformance/types/literal/literalTypes1.ts === + +let zero: 0 = 0; +>zero : 0 +>0 : 0 + +let one: 1 = 1; +>one : 1 +>1 : 1 + +let two: 2 = 2; +>two : 2 +>2 : 2 + +let oneOrTwo: 1 | 2 = <1 | 2>1; +>oneOrTwo : 1 | 2 +><1 | 2>1 : 1 | 2 +>1 : 1 + +function f1(x: 0 | 1 | 2) { +>f1 : (x: 0 | 1 | 2) => void +>x : 0 | 1 | 2 + + switch (x) { +>x : 0 | 1 | 2 + + case zero: +>zero : 0 + + x; +>x : 0 + + break; + case one: +>one : 1 + + x; +>x : 1 + + break; + case two: +>two : 2 + + x; +>x : 2 + + break; + default: + x; +>x : never + } +} + +function f2(x: 0 | 1 | 2) { +>f2 : (x: 0 | 1 | 2) => void +>x : 0 | 1 | 2 + + switch (x) { +>x : 0 | 1 | 2 + + case zero: +>zero : 0 + + x; +>x : 0 | 1 | 2 + + break; + case oneOrTwo: +>oneOrTwo : 1 | 2 + + x; +>x : 0 | 1 | 2 + + break; + default: + x; +>x : 0 | 1 | 2 + } +} + +type Falsy = false | 0 | "" | null | undefined; +>Falsy : false | 0 | "" | null | undefined +>false : false +>null : null + +function f3(x: Falsy) { +>f3 : (x: false | 0 | "" | null | undefined) => void +>x : false | 0 | "" | null | undefined +>Falsy : false | 0 | "" | null | undefined + + if (x) { +>x : false | 0 | "" | null | undefined + + x; +>x : never + } + else { + x; +>x : false | 0 | "" | null | undefined + } +} + +function f4(x: 0 | 1 | true | string) { +>f4 : (x: 0 | 1 | true | string) => void +>x : 0 | 1 | true | string +>true : true + + switch (x) { +>x : 0 | 1 | true | string + + case 0: +>0 : 0 + + x; +>x : 0 + + break; + case 1: +>1 : 1 + + x; +>x : 1 + + break; + case "abc": +>"abc" : "abc" + + case "def": +>"def" : "def" + + x; +>x : string + + break; + case null: +>null : null + + x; +>x : never + + break; + case undefined: +>undefined : undefined + + x; +>x : never + + break; + default: + x; +>x : true | string + } +} + +function f5(x: string | number | boolean) { +>f5 : (x: string | number | boolean) => void +>x : string | number | boolean + + switch (x) { +>x : string | number | boolean + + case "abc": +>"abc" : "abc" + + x; +>x : string + + break; + case 0: +>0 : 0 + + case 1: +>1 : 1 + + x; +>x : number + + break; + case true: +>true : true + + x; +>x : boolean + + break; + case "hello": +>"hello" : "hello" + + case 123: +>123 : 123 + + x; +>x : string | number + + break; + default: + x; +>x : string | number | boolean + } +} diff --git a/tests/baselines/reference/numericLiteralTypes1.js b/tests/baselines/reference/numericLiteralTypes1.js new file mode 100644 index 0000000000000..17c24d872efe5 --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes1.js @@ -0,0 +1,247 @@ +//// [numericLiteralTypes1.ts] +type A1 = 1; +type A2 = 1.0; +type A3 = 1e0; +type A4 = 10e-1; +type A5 = 1 | 1.0 | 1e0 | 10e-1; + +function f1() { + var a: A1 = 1; + var a: A2 = 1; + var a: A3 = 1; + var a: A4 = 1; + var a: A5 = 1; +} + +type B1 = -1 | 0 | 1; +type B2 = 1 | 0 | -1; +type B3 = 0 | -1 | 1; + +function f2() { + var b: B1 = -1; + var b: B2 = 0; + var b: B3 = 1; +} + +function f3(a: 1, b: 0 | 1 | 2) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} + +function f4(a: 1, b: 0 | 1 | 2) { + a++; + b++; +} + +declare function g(x: 0): string; +declare function g(x: 1): boolean; +declare function g(x: number): number; + +function f5(a: 1, b: 0 | 1 | 2) { + var z1 = g(0); + var z2 = g(1); + var z3 = g(2); + var z4 = g(a); + var z5 = g(b); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +type Tag = 0 | 1 | 2; + +function f10(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} + +function f11(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +} + +function f12(x: Tag) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: Tag) { + if (x === 0 || x === 2) { + x; + } + else { + x; + } +} + +function f14(x: 0 | 1 | 2, y: string) { + var a = x && y; + var b = x || y; +} + +function f15(x: 0 | false, y: 1 | "one") { + var a = x && y; + var b = y && x; + var c = x || y; + var d = y || x; + var e = !x; + var f = !y; +} + +type Item = + { kind: 0, a: string } | + { kind: 1, b: string } | + { kind: 2, c: string }; + +function f20(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } +} + +function f21(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + return assertNever(x); +} + +//// [numericLiteralTypes1.js] +function f1() { + var a = 1; + var a = 1; + var a = 1; + var a = 1; + var a = 1; +} +function f2() { + var b = -1; + var b = 0; + var b = 1; +} +function f3(a, b) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} +function f4(a, b) { + a++; + b++; +} +function f5(a, b) { + var z1 = g(0); + var z2 = g(1); + var z3 = g(2); + var z4 = g(a); + var z5 = g(b); +} +function assertNever(x) { + throw new Error("Unexpected value"); +} +function f10(x) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} +function f11(x) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +} +function f12(x) { + if (x) { + x; + } + else { + x; + } +} +function f13(x) { + if (x === 0 || x === 2) { + x; + } + else { + x; + } +} +function f14(x, y) { + var a = x && y; + var b = x || y; +} +function f15(x, y) { + var a = x && y; + var b = y && x; + var c = x || y; + var d = y || x; + var e = !x; + var f = !y; +} +function f20(x) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } +} +function f21(x) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + return assertNever(x); +} diff --git a/tests/baselines/reference/numericLiteralTypes1.symbols b/tests/baselines/reference/numericLiteralTypes1.symbols new file mode 100644 index 0000000000000..87d2a15b29171 --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes1.symbols @@ -0,0 +1,413 @@ +=== tests/cases/conformance/types/literal/numericLiteralTypes1.ts === +type A1 = 1; +>A1 : Symbol(A1, Decl(numericLiteralTypes1.ts, 0, 0)) + +type A2 = 1.0; +>A2 : Symbol(A2, Decl(numericLiteralTypes1.ts, 0, 12)) + +type A3 = 1e0; +>A3 : Symbol(A3, Decl(numericLiteralTypes1.ts, 1, 14)) + +type A4 = 10e-1; +>A4 : Symbol(A4, Decl(numericLiteralTypes1.ts, 2, 14)) + +type A5 = 1 | 1.0 | 1e0 | 10e-1; +>A5 : Symbol(A5, Decl(numericLiteralTypes1.ts, 3, 16)) + +function f1() { +>f1 : Symbol(f1, Decl(numericLiteralTypes1.ts, 4, 32)) + + var a: A1 = 1; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 7, 7), Decl(numericLiteralTypes1.ts, 8, 7), Decl(numericLiteralTypes1.ts, 9, 7), Decl(numericLiteralTypes1.ts, 10, 7), Decl(numericLiteralTypes1.ts, 11, 7)) +>A1 : Symbol(A1, Decl(numericLiteralTypes1.ts, 0, 0)) + + var a: A2 = 1; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 7, 7), Decl(numericLiteralTypes1.ts, 8, 7), Decl(numericLiteralTypes1.ts, 9, 7), Decl(numericLiteralTypes1.ts, 10, 7), Decl(numericLiteralTypes1.ts, 11, 7)) +>A2 : Symbol(A2, Decl(numericLiteralTypes1.ts, 0, 12)) + + var a: A3 = 1; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 7, 7), Decl(numericLiteralTypes1.ts, 8, 7), Decl(numericLiteralTypes1.ts, 9, 7), Decl(numericLiteralTypes1.ts, 10, 7), Decl(numericLiteralTypes1.ts, 11, 7)) +>A3 : Symbol(A3, Decl(numericLiteralTypes1.ts, 1, 14)) + + var a: A4 = 1; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 7, 7), Decl(numericLiteralTypes1.ts, 8, 7), Decl(numericLiteralTypes1.ts, 9, 7), Decl(numericLiteralTypes1.ts, 10, 7), Decl(numericLiteralTypes1.ts, 11, 7)) +>A4 : Symbol(A4, Decl(numericLiteralTypes1.ts, 2, 14)) + + var a: A5 = 1; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 7, 7), Decl(numericLiteralTypes1.ts, 8, 7), Decl(numericLiteralTypes1.ts, 9, 7), Decl(numericLiteralTypes1.ts, 10, 7), Decl(numericLiteralTypes1.ts, 11, 7)) +>A5 : Symbol(A5, Decl(numericLiteralTypes1.ts, 3, 16)) +} + +type B1 = -1 | 0 | 1; +>B1 : Symbol(B1, Decl(numericLiteralTypes1.ts, 12, 1)) + +type B2 = 1 | 0 | -1; +>B2 : Symbol(B2, Decl(numericLiteralTypes1.ts, 14, 21)) + +type B3 = 0 | -1 | 1; +>B3 : Symbol(B3, Decl(numericLiteralTypes1.ts, 15, 21)) + +function f2() { +>f2 : Symbol(f2, Decl(numericLiteralTypes1.ts, 16, 21)) + + var b: B1 = -1; +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 19, 7), Decl(numericLiteralTypes1.ts, 20, 7), Decl(numericLiteralTypes1.ts, 21, 7)) +>B1 : Symbol(B1, Decl(numericLiteralTypes1.ts, 12, 1)) + + var b: B2 = 0; +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 19, 7), Decl(numericLiteralTypes1.ts, 20, 7), Decl(numericLiteralTypes1.ts, 21, 7)) +>B2 : Symbol(B2, Decl(numericLiteralTypes1.ts, 14, 21)) + + var b: B3 = 1; +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 19, 7), Decl(numericLiteralTypes1.ts, 20, 7), Decl(numericLiteralTypes1.ts, 21, 7)) +>B3 : Symbol(B3, Decl(numericLiteralTypes1.ts, 15, 21)) +} + +function f3(a: 1, b: 0 | 1 | 2) { +>f3 : Symbol(f3, Decl(numericLiteralTypes1.ts, 22, 1)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a + b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a - b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a * b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a / b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a % b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a | b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a & b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = a ^ b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = -b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var x = ~b; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 25, 7), Decl(numericLiteralTypes1.ts, 26, 7), Decl(numericLiteralTypes1.ts, 27, 7), Decl(numericLiteralTypes1.ts, 28, 7), Decl(numericLiteralTypes1.ts, 29, 7), Decl(numericLiteralTypes1.ts, 30, 7), Decl(numericLiteralTypes1.ts, 31, 7), Decl(numericLiteralTypes1.ts, 32, 7), Decl(numericLiteralTypes1.ts, 33, 7), Decl(numericLiteralTypes1.ts, 34, 7)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a == b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a != b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a === b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a !== b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a > b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a < b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a >= b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = a <= b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 24, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) + + var y = !b; +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 35, 7), Decl(numericLiteralTypes1.ts, 36, 7), Decl(numericLiteralTypes1.ts, 37, 7), Decl(numericLiteralTypes1.ts, 38, 7), Decl(numericLiteralTypes1.ts, 39, 7), Decl(numericLiteralTypes1.ts, 40, 7), Decl(numericLiteralTypes1.ts, 41, 7), Decl(numericLiteralTypes1.ts, 42, 7), Decl(numericLiteralTypes1.ts, 43, 7)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 24, 17)) +} + +function f4(a: 1, b: 0 | 1 | 2) { +>f4 : Symbol(f4, Decl(numericLiteralTypes1.ts, 44, 1)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 46, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 46, 17)) + + a++; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 46, 12)) + + b++; +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 46, 17)) +} + +declare function g(x: 0): string; +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 51, 19)) + +declare function g(x: 1): boolean; +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 52, 19)) + +declare function g(x: number): number; +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 53, 19)) + +function f5(a: 1, b: 0 | 1 | 2) { +>f5 : Symbol(f5, Decl(numericLiteralTypes1.ts, 53, 38)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 55, 12)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 55, 17)) + + var z1 = g(0); +>z1 : Symbol(z1, Decl(numericLiteralTypes1.ts, 56, 7)) +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) + + var z2 = g(1); +>z2 : Symbol(z2, Decl(numericLiteralTypes1.ts, 57, 7)) +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) + + var z3 = g(2); +>z3 : Symbol(z3, Decl(numericLiteralTypes1.ts, 58, 7)) +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) + + var z4 = g(a); +>z4 : Symbol(z4, Decl(numericLiteralTypes1.ts, 59, 7)) +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 55, 12)) + + var z5 = g(b); +>z5 : Symbol(z5, Decl(numericLiteralTypes1.ts, 60, 7)) +>g : Symbol(g, Decl(numericLiteralTypes1.ts, 49, 1), Decl(numericLiteralTypes1.ts, 51, 33), Decl(numericLiteralTypes1.ts, 52, 34)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 55, 17)) +} + +function assertNever(x: never): never { +>assertNever : Symbol(assertNever, Decl(numericLiteralTypes1.ts, 61, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 63, 21)) + + throw new Error("Unexpected value"); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +type Tag = 0 | 1 | 2; +>Tag : Symbol(Tag, Decl(numericLiteralTypes1.ts, 65, 1)) + +function f10(x: Tag) { +>f10 : Symbol(f10, Decl(numericLiteralTypes1.ts, 67, 21)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 69, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes1.ts, 65, 1)) + + switch (x) { +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 69, 13)) + + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} + +function f11(x: Tag) { +>f11 : Symbol(f11, Decl(numericLiteralTypes1.ts, 75, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 77, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes1.ts, 65, 1)) + + switch (x) { +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 77, 13)) + + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(numericLiteralTypes1.ts, 61, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 77, 13)) +} + +function f12(x: Tag) { +>f12 : Symbol(f12, Decl(numericLiteralTypes1.ts, 84, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 86, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes1.ts, 65, 1)) + + if (x) { +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 86, 13)) + + x; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 86, 13)) + } + else { + x; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 86, 13)) + } +} + +function f13(x: Tag) { +>f13 : Symbol(f13, Decl(numericLiteralTypes1.ts, 93, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 95, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes1.ts, 65, 1)) + + if (x === 0 || x === 2) { +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 95, 13)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 95, 13)) + + x; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 95, 13)) + } + else { + x; +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 95, 13)) + } +} + +function f14(x: 0 | 1 | 2, y: string) { +>f14 : Symbol(f14, Decl(numericLiteralTypes1.ts, 102, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 104, 13)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 104, 26)) + + var a = x && y; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 105, 7)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 104, 13)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 104, 26)) + + var b = x || y; +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 106, 7)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 104, 13)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 104, 26)) +} + +function f15(x: 0 | false, y: 1 | "one") { +>f15 : Symbol(f15, Decl(numericLiteralTypes1.ts, 107, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 109, 13)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 109, 26)) + + var a = x && y; +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 110, 7)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 109, 13)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 109, 26)) + + var b = y && x; +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 111, 7)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 109, 26)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 109, 13)) + + var c = x || y; +>c : Symbol(c, Decl(numericLiteralTypes1.ts, 112, 7)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 109, 13)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 109, 26)) + + var d = y || x; +>d : Symbol(d, Decl(numericLiteralTypes1.ts, 113, 7)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 109, 26)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 109, 13)) + + var e = !x; +>e : Symbol(e, Decl(numericLiteralTypes1.ts, 114, 7)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 109, 13)) + + var f = !y; +>f : Symbol(f, Decl(numericLiteralTypes1.ts, 115, 7)) +>y : Symbol(y, Decl(numericLiteralTypes1.ts, 109, 26)) +} + +type Item = +>Item : Symbol(Item, Decl(numericLiteralTypes1.ts, 116, 1)) + + { kind: 0, a: string } | +>kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 119, 5)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 119, 14)) + + { kind: 1, b: string } | +>kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 120, 5)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 120, 14)) + + { kind: 2, c: string }; +>kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 121, 5)) +>c : Symbol(c, Decl(numericLiteralTypes1.ts, 121, 14)) + +function f20(x: Item) { +>f20 : Symbol(f20, Decl(numericLiteralTypes1.ts, 121, 27)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 123, 13)) +>Item : Symbol(Item, Decl(numericLiteralTypes1.ts, 116, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 119, 5), Decl(numericLiteralTypes1.ts, 120, 5), Decl(numericLiteralTypes1.ts, 121, 5)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 123, 13)) +>kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 119, 5), Decl(numericLiteralTypes1.ts, 120, 5), Decl(numericLiteralTypes1.ts, 121, 5)) + + case 0: return x.a; +>x.a : Symbol(a, Decl(numericLiteralTypes1.ts, 119, 14)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 123, 13)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 119, 14)) + + case 1: return x.b; +>x.b : Symbol(b, Decl(numericLiteralTypes1.ts, 120, 14)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 123, 13)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 120, 14)) + + case 2: return x.c; +>x.c : Symbol(c, Decl(numericLiteralTypes1.ts, 121, 14)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 123, 13)) +>c : Symbol(c, Decl(numericLiteralTypes1.ts, 121, 14)) + } +} + +function f21(x: Item) { +>f21 : Symbol(f21, Decl(numericLiteralTypes1.ts, 129, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 131, 13)) +>Item : Symbol(Item, Decl(numericLiteralTypes1.ts, 116, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 119, 5), Decl(numericLiteralTypes1.ts, 120, 5), Decl(numericLiteralTypes1.ts, 121, 5)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 131, 13)) +>kind : Symbol(kind, Decl(numericLiteralTypes1.ts, 119, 5), Decl(numericLiteralTypes1.ts, 120, 5), Decl(numericLiteralTypes1.ts, 121, 5)) + + case 0: return x.a; +>x.a : Symbol(a, Decl(numericLiteralTypes1.ts, 119, 14)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 131, 13)) +>a : Symbol(a, Decl(numericLiteralTypes1.ts, 119, 14)) + + case 1: return x.b; +>x.b : Symbol(b, Decl(numericLiteralTypes1.ts, 120, 14)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 131, 13)) +>b : Symbol(b, Decl(numericLiteralTypes1.ts, 120, 14)) + + case 2: return x.c; +>x.c : Symbol(c, Decl(numericLiteralTypes1.ts, 121, 14)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 131, 13)) +>c : Symbol(c, Decl(numericLiteralTypes1.ts, 121, 14)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(numericLiteralTypes1.ts, 61, 1)) +>x : Symbol(x, Decl(numericLiteralTypes1.ts, 131, 13)) +} diff --git a/tests/baselines/reference/numericLiteralTypes1.types b/tests/baselines/reference/numericLiteralTypes1.types new file mode 100644 index 0000000000000..f5632c2fa7192 --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes1.types @@ -0,0 +1,497 @@ +=== tests/cases/conformance/types/literal/numericLiteralTypes1.ts === +type A1 = 1; +>A1 : 1 + +type A2 = 1.0; +>A2 : 1 + +type A3 = 1e0; +>A3 : 1 + +type A4 = 10e-1; +>A4 : 1 + +type A5 = 1 | 1.0 | 1e0 | 10e-1; +>A5 : 1 + +function f1() { +>f1 : () => void + + var a: A1 = 1; +>a : 1 +>A1 : 1 +>1 : 1 + + var a: A2 = 1; +>a : 1 +>A2 : 1 +>1 : 1 + + var a: A3 = 1; +>a : 1 +>A3 : 1 +>1 : 1 + + var a: A4 = 1; +>a : 1 +>A4 : 1 +>1 : 1 + + var a: A5 = 1; +>a : 1 +>A5 : 1 +>1 : 1 +} + +type B1 = -1 | 0 | 1; +>B1 : -1 | 0 | 1 +>-1 : -1 +>1 : number + +type B2 = 1 | 0 | -1; +>B2 : 1 | 0 | -1 +>-1 : -1 +>1 : number + +type B3 = 0 | -1 | 1; +>B3 : 0 | -1 | 1 +>-1 : -1 +>1 : number + +function f2() { +>f2 : () => void + + var b: B1 = -1; +>b : -1 | 0 | 1 +>B1 : -1 | 0 | 1 +>-1 : -1 +>1 : number + + var b: B2 = 0; +>b : -1 | 0 | 1 +>B2 : 1 | 0 | -1 +>0 : 0 + + var b: B3 = 1; +>b : -1 | 0 | 1 +>B3 : 0 | -1 | 1 +>1 : 1 +} + +function f3(a: 1, b: 0 | 1 | 2) { +>f3 : (a: 1, b: 0 | 1 | 2) => void +>a : 1 +>b : 0 | 1 | 2 + + var x = a + b; +>x : number +>a + b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a - b; +>x : number +>a - b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a * b; +>x : number +>a * b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a / b; +>x : number +>a / b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a % b; +>x : number +>a % b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a | b; +>x : number +>a | b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a & b; +>x : number +>a & b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a ^ b; +>x : number +>a ^ b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = -b; +>x : number +>-b : number +>b : 0 | 1 | 2 + + var x = ~b; +>x : number +>~b : number +>b : 0 | 1 | 2 + + var y = a == b; +>y : boolean +>a == b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a != b; +>y : boolean +>a != b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a === b; +>y : boolean +>a === b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a !== b; +>y : boolean +>a !== b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a > b; +>y : boolean +>a > b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a < b; +>y : boolean +>a < b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a >= b; +>y : boolean +>a >= b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a <= b; +>y : boolean +>a <= b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = !b; +>y : boolean +>!b : boolean +>b : 0 | 1 | 2 +} + +function f4(a: 1, b: 0 | 1 | 2) { +>f4 : (a: 1, b: 0 | 1 | 2) => void +>a : 1 +>b : 0 | 1 | 2 + + a++; +>a++ : number +>a : 1 + + b++; +>b++ : number +>b : 0 | 1 | 2 +} + +declare function g(x: 0): string; +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>x : 0 + +declare function g(x: 1): boolean; +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>x : 1 + +declare function g(x: number): number; +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>x : number + +function f5(a: 1, b: 0 | 1 | 2) { +>f5 : (a: 1, b: 0 | 1 | 2) => void +>a : 1 +>b : 0 | 1 | 2 + + var z1 = g(0); +>z1 : string +>g(0) : string +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>0 : 0 + + var z2 = g(1); +>z2 : boolean +>g(1) : boolean +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>1 : 1 + + var z3 = g(2); +>z3 : number +>g(2) : number +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>2 : number + + var z4 = g(a); +>z4 : boolean +>g(a) : boolean +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>a : 1 + + var z5 = g(b); +>z5 : number +>g(b) : number +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>b : 0 | 1 | 2 +} + +function assertNever(x: never): never { +>assertNever : (x: never) => never +>x : never + + throw new Error("Unexpected value"); +>new Error("Unexpected value") : Error +>Error : ErrorConstructor +>"Unexpected value" : string +} + +type Tag = 0 | 1 | 2; +>Tag : 0 | 1 | 2 + +function f10(x: Tag) { +>f10 : (x: 0 | 1 | 2) => string +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + switch (x) { +>x : 0 | 1 | 2 + + case 0: return "a"; +>0 : 0 +>"a" : string + + case 1: return "b"; +>1 : 1 +>"b" : string + + case 2: return "c"; +>2 : 2 +>"c" : string + } +} + +function f11(x: Tag) { +>f11 : (x: 0 | 1 | 2) => string +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + switch (x) { +>x : 0 | 1 | 2 + + case 0: return "a"; +>0 : 0 +>"a" : string + + case 1: return "b"; +>1 : 1 +>"b" : string + + case 2: return "c"; +>2 : 2 +>"c" : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} + +function f12(x: Tag) { +>f12 : (x: 0 | 1 | 2) => void +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + if (x) { +>x : 0 | 1 | 2 + + x; +>x : 1 | 2 + } + else { + x; +>x : 0 | 1 | 2 + } +} + +function f13(x: Tag) { +>f13 : (x: 0 | 1 | 2) => void +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + if (x === 0 || x === 2) { +>x === 0 || x === 2 : boolean +>x === 0 : boolean +>x : 0 | 1 | 2 +>0 : 0 +>x === 2 : boolean +>x : 1 | 2 +>2 : 2 + + x; +>x : 0 | 2 + } + else { + x; +>x : 1 + } +} + +function f14(x: 0 | 1 | 2, y: string) { +>f14 : (x: 0 | 1 | 2, y: string) => void +>x : 0 | 1 | 2 +>y : string + + var a = x && y; +>a : string +>x && y : string +>x : 0 | 1 | 2 +>y : string + + var b = x || y; +>b : 1 | 2 | string +>x || y : 1 | 2 | string +>x : 0 | 1 | 2 +>y : string +} + +function f15(x: 0 | false, y: 1 | "one") { +>f15 : (x: 0 | false, y: 1 | "one") => void +>x : 0 | false +>false : false +>y : 1 | "one" + + var a = x && y; +>a : 0 | false +>x && y : 0 | false +>x : 0 | false +>y : 1 | "one" + + var b = y && x; +>b : 0 | false +>y && x : 0 | false +>y : 1 | "one" +>x : 0 | false + + var c = x || y; +>c : 1 | "one" +>x || y : 1 | "one" +>x : 0 | false +>y : 1 | "one" + + var d = y || x; +>d : 1 | "one" | 0 | false +>y || x : 1 | "one" | 0 | false +>y : 1 | "one" +>x : 0 | false + + var e = !x; +>e : true +>!x : true +>x : 0 | false + + var f = !y; +>f : boolean +>!y : boolean +>y : 1 | "one" +} + +type Item = +>Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } + + { kind: 0, a: string } | +>kind : 0 +>a : string + + { kind: 1, b: string } | +>kind : 1 +>b : string + + { kind: 2, c: string }; +>kind : 2 +>c : string + +function f20(x: Item) { +>f20 : (x: { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; }) => string +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } + + switch (x.kind) { +>x.kind : 0 | 1 | 2 +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>kind : 0 | 1 | 2 + + case 0: return x.a; +>0 : 0 +>x.a : string +>x : { kind: 0; a: string; } +>a : string + + case 1: return x.b; +>1 : 1 +>x.b : string +>x : { kind: 1; b: string; } +>b : string + + case 2: return x.c; +>2 : 2 +>x.c : string +>x : { kind: 2; c: string; } +>c : string + } +} + +function f21(x: Item) { +>f21 : (x: { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; }) => string +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } + + switch (x.kind) { +>x.kind : 0 | 1 | 2 +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>kind : 0 | 1 | 2 + + case 0: return x.a; +>0 : 0 +>x.a : string +>x : { kind: 0; a: string; } +>a : string + + case 1: return x.b; +>1 : 1 +>x.b : string +>x : { kind: 1; b: string; } +>b : string + + case 2: return x.c; +>2 : 2 +>x.c : string +>x : { kind: 2; c: string; } +>c : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} diff --git a/tests/baselines/reference/numericLiteralTypes2.js b/tests/baselines/reference/numericLiteralTypes2.js new file mode 100644 index 0000000000000..ea82d00832cbf --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes2.js @@ -0,0 +1,248 @@ +//// [numericLiteralTypes2.ts] + +type A1 = 1; +type A2 = 1.0; +type A3 = 1e0; +type A4 = 10e-1; +type A5 = 1 | 1.0 | 1e0 | 10e-1; + +function f1() { + var a: A1 = 1; + var a: A2 = 1; + var a: A3 = 1; + var a: A4 = 1; + var a: A5 = 1; +} + +type B1 = -1 | 0 | 1; +type B2 = 1 | 0 | -1; +type B3 = 0 | -1 | 1; + +function f2() { + var b: B1 = -1; + var b: B2 = 0; + var b: B3 = 1; +} + +function f3(a: 1, b: 0 | 1 | 2) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} + +function f4(a: 1, b: 0 | 1 | 2) { + a++; + b++; +} + +declare function g(x: 0): string; +declare function g(x: 1): boolean; +declare function g(x: number): number; + +function f5(a: 1, b: 0 | 1 | 2) { + var z1 = g(0); + var z2 = g(1); + var z3 = g(2); + var z4 = g(a); + var z5 = g(b); +} + +function assertNever(x: never): never { + throw new Error("Unexpected value"); +} + +type Tag = 0 | 1 | 2; + +function f10(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} + +function f11(x: Tag) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +} + +function f12(x: Tag) { + if (x) { + x; + } + else { + x; + } +} + +function f13(x: Tag) { + if (x === 0 || x === 2) { + x; + } + else { + x; + } +} + +function f14(x: 0 | 1 | 2, y: string) { + var a = x && y; + var b = x || y; +} + +function f15(x: 0 | false, y: 1 | "one") { + var a = x && y; + var b = y && x; + var c = x || y; + var d = y || x; + var e = !x; + var f = !y; +} + +type Item = + { kind: 0, a: string } | + { kind: 1, b: string } | + { kind: 2, c: string }; + +function f20(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } +} + +function f21(x: Item) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + return assertNever(x); +} + +//// [numericLiteralTypes2.js] +function f1() { + var a = 1; + var a = 1; + var a = 1; + var a = 1; + var a = 1; +} +function f2() { + var b = -1; + var b = 0; + var b = 1; +} +function f3(a, b) { + var x = a + b; + var x = a - b; + var x = a * b; + var x = a / b; + var x = a % b; + var x = a | b; + var x = a & b; + var x = a ^ b; + var x = -b; + var x = ~b; + var y = a == b; + var y = a != b; + var y = a === b; + var y = a !== b; + var y = a > b; + var y = a < b; + var y = a >= b; + var y = a <= b; + var y = !b; +} +function f4(a, b) { + a++; + b++; +} +function f5(a, b) { + var z1 = g(0); + var z2 = g(1); + var z3 = g(2); + var z4 = g(a); + var z5 = g(b); +} +function assertNever(x) { + throw new Error("Unexpected value"); +} +function f10(x) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} +function f11(x) { + switch (x) { + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +} +function f12(x) { + if (x) { + x; + } + else { + x; + } +} +function f13(x) { + if (x === 0 || x === 2) { + x; + } + else { + x; + } +} +function f14(x, y) { + var a = x && y; + var b = x || y; +} +function f15(x, y) { + var a = x && y; + var b = y && x; + var c = x || y; + var d = y || x; + var e = !x; + var f = !y; +} +function f20(x) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } +} +function f21(x) { + switch (x.kind) { + case 0: return x.a; + case 1: return x.b; + case 2: return x.c; + } + return assertNever(x); +} diff --git a/tests/baselines/reference/numericLiteralTypes2.symbols b/tests/baselines/reference/numericLiteralTypes2.symbols new file mode 100644 index 0000000000000..f0dbbda502e30 --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes2.symbols @@ -0,0 +1,414 @@ +=== tests/cases/conformance/types/literal/numericLiteralTypes2.ts === + +type A1 = 1; +>A1 : Symbol(A1, Decl(numericLiteralTypes2.ts, 0, 0)) + +type A2 = 1.0; +>A2 : Symbol(A2, Decl(numericLiteralTypes2.ts, 1, 12)) + +type A3 = 1e0; +>A3 : Symbol(A3, Decl(numericLiteralTypes2.ts, 2, 14)) + +type A4 = 10e-1; +>A4 : Symbol(A4, Decl(numericLiteralTypes2.ts, 3, 14)) + +type A5 = 1 | 1.0 | 1e0 | 10e-1; +>A5 : Symbol(A5, Decl(numericLiteralTypes2.ts, 4, 16)) + +function f1() { +>f1 : Symbol(f1, Decl(numericLiteralTypes2.ts, 5, 32)) + + var a: A1 = 1; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 8, 7), Decl(numericLiteralTypes2.ts, 9, 7), Decl(numericLiteralTypes2.ts, 10, 7), Decl(numericLiteralTypes2.ts, 11, 7), Decl(numericLiteralTypes2.ts, 12, 7)) +>A1 : Symbol(A1, Decl(numericLiteralTypes2.ts, 0, 0)) + + var a: A2 = 1; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 8, 7), Decl(numericLiteralTypes2.ts, 9, 7), Decl(numericLiteralTypes2.ts, 10, 7), Decl(numericLiteralTypes2.ts, 11, 7), Decl(numericLiteralTypes2.ts, 12, 7)) +>A2 : Symbol(A2, Decl(numericLiteralTypes2.ts, 1, 12)) + + var a: A3 = 1; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 8, 7), Decl(numericLiteralTypes2.ts, 9, 7), Decl(numericLiteralTypes2.ts, 10, 7), Decl(numericLiteralTypes2.ts, 11, 7), Decl(numericLiteralTypes2.ts, 12, 7)) +>A3 : Symbol(A3, Decl(numericLiteralTypes2.ts, 2, 14)) + + var a: A4 = 1; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 8, 7), Decl(numericLiteralTypes2.ts, 9, 7), Decl(numericLiteralTypes2.ts, 10, 7), Decl(numericLiteralTypes2.ts, 11, 7), Decl(numericLiteralTypes2.ts, 12, 7)) +>A4 : Symbol(A4, Decl(numericLiteralTypes2.ts, 3, 14)) + + var a: A5 = 1; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 8, 7), Decl(numericLiteralTypes2.ts, 9, 7), Decl(numericLiteralTypes2.ts, 10, 7), Decl(numericLiteralTypes2.ts, 11, 7), Decl(numericLiteralTypes2.ts, 12, 7)) +>A5 : Symbol(A5, Decl(numericLiteralTypes2.ts, 4, 16)) +} + +type B1 = -1 | 0 | 1; +>B1 : Symbol(B1, Decl(numericLiteralTypes2.ts, 13, 1)) + +type B2 = 1 | 0 | -1; +>B2 : Symbol(B2, Decl(numericLiteralTypes2.ts, 15, 21)) + +type B3 = 0 | -1 | 1; +>B3 : Symbol(B3, Decl(numericLiteralTypes2.ts, 16, 21)) + +function f2() { +>f2 : Symbol(f2, Decl(numericLiteralTypes2.ts, 17, 21)) + + var b: B1 = -1; +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 20, 7), Decl(numericLiteralTypes2.ts, 21, 7), Decl(numericLiteralTypes2.ts, 22, 7)) +>B1 : Symbol(B1, Decl(numericLiteralTypes2.ts, 13, 1)) + + var b: B2 = 0; +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 20, 7), Decl(numericLiteralTypes2.ts, 21, 7), Decl(numericLiteralTypes2.ts, 22, 7)) +>B2 : Symbol(B2, Decl(numericLiteralTypes2.ts, 15, 21)) + + var b: B3 = 1; +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 20, 7), Decl(numericLiteralTypes2.ts, 21, 7), Decl(numericLiteralTypes2.ts, 22, 7)) +>B3 : Symbol(B3, Decl(numericLiteralTypes2.ts, 16, 21)) +} + +function f3(a: 1, b: 0 | 1 | 2) { +>f3 : Symbol(f3, Decl(numericLiteralTypes2.ts, 23, 1)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a + b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a - b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a * b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a / b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a % b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a | b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a & b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = a ^ b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = -b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var x = ~b; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 26, 7), Decl(numericLiteralTypes2.ts, 27, 7), Decl(numericLiteralTypes2.ts, 28, 7), Decl(numericLiteralTypes2.ts, 29, 7), Decl(numericLiteralTypes2.ts, 30, 7), Decl(numericLiteralTypes2.ts, 31, 7), Decl(numericLiteralTypes2.ts, 32, 7), Decl(numericLiteralTypes2.ts, 33, 7), Decl(numericLiteralTypes2.ts, 34, 7), Decl(numericLiteralTypes2.ts, 35, 7)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a == b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a != b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a === b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a !== b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a > b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a < b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a >= b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = a <= b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 25, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) + + var y = !b; +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 36, 7), Decl(numericLiteralTypes2.ts, 37, 7), Decl(numericLiteralTypes2.ts, 38, 7), Decl(numericLiteralTypes2.ts, 39, 7), Decl(numericLiteralTypes2.ts, 40, 7), Decl(numericLiteralTypes2.ts, 41, 7), Decl(numericLiteralTypes2.ts, 42, 7), Decl(numericLiteralTypes2.ts, 43, 7), Decl(numericLiteralTypes2.ts, 44, 7)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 25, 17)) +} + +function f4(a: 1, b: 0 | 1 | 2) { +>f4 : Symbol(f4, Decl(numericLiteralTypes2.ts, 45, 1)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 47, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 47, 17)) + + a++; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 47, 12)) + + b++; +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 47, 17)) +} + +declare function g(x: 0): string; +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 52, 19)) + +declare function g(x: 1): boolean; +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 53, 19)) + +declare function g(x: number): number; +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 54, 19)) + +function f5(a: 1, b: 0 | 1 | 2) { +>f5 : Symbol(f5, Decl(numericLiteralTypes2.ts, 54, 38)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 56, 12)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 56, 17)) + + var z1 = g(0); +>z1 : Symbol(z1, Decl(numericLiteralTypes2.ts, 57, 7)) +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) + + var z2 = g(1); +>z2 : Symbol(z2, Decl(numericLiteralTypes2.ts, 58, 7)) +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) + + var z3 = g(2); +>z3 : Symbol(z3, Decl(numericLiteralTypes2.ts, 59, 7)) +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) + + var z4 = g(a); +>z4 : Symbol(z4, Decl(numericLiteralTypes2.ts, 60, 7)) +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 56, 12)) + + var z5 = g(b); +>z5 : Symbol(z5, Decl(numericLiteralTypes2.ts, 61, 7)) +>g : Symbol(g, Decl(numericLiteralTypes2.ts, 50, 1), Decl(numericLiteralTypes2.ts, 52, 33), Decl(numericLiteralTypes2.ts, 53, 34)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 56, 17)) +} + +function assertNever(x: never): never { +>assertNever : Symbol(assertNever, Decl(numericLiteralTypes2.ts, 62, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 64, 21)) + + throw new Error("Unexpected value"); +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +type Tag = 0 | 1 | 2; +>Tag : Symbol(Tag, Decl(numericLiteralTypes2.ts, 66, 1)) + +function f10(x: Tag) { +>f10 : Symbol(f10, Decl(numericLiteralTypes2.ts, 68, 21)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 70, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes2.ts, 66, 1)) + + switch (x) { +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 70, 13)) + + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } +} + +function f11(x: Tag) { +>f11 : Symbol(f11, Decl(numericLiteralTypes2.ts, 76, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 78, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes2.ts, 66, 1)) + + switch (x) { +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 78, 13)) + + case 0: return "a"; + case 1: return "b"; + case 2: return "c"; + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(numericLiteralTypes2.ts, 62, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 78, 13)) +} + +function f12(x: Tag) { +>f12 : Symbol(f12, Decl(numericLiteralTypes2.ts, 85, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 87, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes2.ts, 66, 1)) + + if (x) { +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 87, 13)) + + x; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 87, 13)) + } + else { + x; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 87, 13)) + } +} + +function f13(x: Tag) { +>f13 : Symbol(f13, Decl(numericLiteralTypes2.ts, 94, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 96, 13)) +>Tag : Symbol(Tag, Decl(numericLiteralTypes2.ts, 66, 1)) + + if (x === 0 || x === 2) { +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 96, 13)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 96, 13)) + + x; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 96, 13)) + } + else { + x; +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 96, 13)) + } +} + +function f14(x: 0 | 1 | 2, y: string) { +>f14 : Symbol(f14, Decl(numericLiteralTypes2.ts, 103, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 105, 13)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 105, 26)) + + var a = x && y; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 106, 7)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 105, 13)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 105, 26)) + + var b = x || y; +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 107, 7)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 105, 13)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 105, 26)) +} + +function f15(x: 0 | false, y: 1 | "one") { +>f15 : Symbol(f15, Decl(numericLiteralTypes2.ts, 108, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 110, 13)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 110, 26)) + + var a = x && y; +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 111, 7)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 110, 13)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 110, 26)) + + var b = y && x; +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 112, 7)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 110, 26)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 110, 13)) + + var c = x || y; +>c : Symbol(c, Decl(numericLiteralTypes2.ts, 113, 7)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 110, 13)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 110, 26)) + + var d = y || x; +>d : Symbol(d, Decl(numericLiteralTypes2.ts, 114, 7)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 110, 26)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 110, 13)) + + var e = !x; +>e : Symbol(e, Decl(numericLiteralTypes2.ts, 115, 7)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 110, 13)) + + var f = !y; +>f : Symbol(f, Decl(numericLiteralTypes2.ts, 116, 7)) +>y : Symbol(y, Decl(numericLiteralTypes2.ts, 110, 26)) +} + +type Item = +>Item : Symbol(Item, Decl(numericLiteralTypes2.ts, 117, 1)) + + { kind: 0, a: string } | +>kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 120, 5)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 120, 14)) + + { kind: 1, b: string } | +>kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 121, 5)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 121, 14)) + + { kind: 2, c: string }; +>kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 122, 5)) +>c : Symbol(c, Decl(numericLiteralTypes2.ts, 122, 14)) + +function f20(x: Item) { +>f20 : Symbol(f20, Decl(numericLiteralTypes2.ts, 122, 27)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 124, 13)) +>Item : Symbol(Item, Decl(numericLiteralTypes2.ts, 117, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 120, 5), Decl(numericLiteralTypes2.ts, 121, 5), Decl(numericLiteralTypes2.ts, 122, 5)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 124, 13)) +>kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 120, 5), Decl(numericLiteralTypes2.ts, 121, 5), Decl(numericLiteralTypes2.ts, 122, 5)) + + case 0: return x.a; +>x.a : Symbol(a, Decl(numericLiteralTypes2.ts, 120, 14)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 124, 13)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 120, 14)) + + case 1: return x.b; +>x.b : Symbol(b, Decl(numericLiteralTypes2.ts, 121, 14)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 124, 13)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 121, 14)) + + case 2: return x.c; +>x.c : Symbol(c, Decl(numericLiteralTypes2.ts, 122, 14)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 124, 13)) +>c : Symbol(c, Decl(numericLiteralTypes2.ts, 122, 14)) + } +} + +function f21(x: Item) { +>f21 : Symbol(f21, Decl(numericLiteralTypes2.ts, 130, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 132, 13)) +>Item : Symbol(Item, Decl(numericLiteralTypes2.ts, 117, 1)) + + switch (x.kind) { +>x.kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 120, 5), Decl(numericLiteralTypes2.ts, 121, 5), Decl(numericLiteralTypes2.ts, 122, 5)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 132, 13)) +>kind : Symbol(kind, Decl(numericLiteralTypes2.ts, 120, 5), Decl(numericLiteralTypes2.ts, 121, 5), Decl(numericLiteralTypes2.ts, 122, 5)) + + case 0: return x.a; +>x.a : Symbol(a, Decl(numericLiteralTypes2.ts, 120, 14)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 132, 13)) +>a : Symbol(a, Decl(numericLiteralTypes2.ts, 120, 14)) + + case 1: return x.b; +>x.b : Symbol(b, Decl(numericLiteralTypes2.ts, 121, 14)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 132, 13)) +>b : Symbol(b, Decl(numericLiteralTypes2.ts, 121, 14)) + + case 2: return x.c; +>x.c : Symbol(c, Decl(numericLiteralTypes2.ts, 122, 14)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 132, 13)) +>c : Symbol(c, Decl(numericLiteralTypes2.ts, 122, 14)) + } + return assertNever(x); +>assertNever : Symbol(assertNever, Decl(numericLiteralTypes2.ts, 62, 1)) +>x : Symbol(x, Decl(numericLiteralTypes2.ts, 132, 13)) +} diff --git a/tests/baselines/reference/numericLiteralTypes2.types b/tests/baselines/reference/numericLiteralTypes2.types new file mode 100644 index 0000000000000..36c5026ba115c --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes2.types @@ -0,0 +1,498 @@ +=== tests/cases/conformance/types/literal/numericLiteralTypes2.ts === + +type A1 = 1; +>A1 : 1 + +type A2 = 1.0; +>A2 : 1 + +type A3 = 1e0; +>A3 : 1 + +type A4 = 10e-1; +>A4 : 1 + +type A5 = 1 | 1.0 | 1e0 | 10e-1; +>A5 : 1 + +function f1() { +>f1 : () => void + + var a: A1 = 1; +>a : 1 +>A1 : 1 +>1 : 1 + + var a: A2 = 1; +>a : 1 +>A2 : 1 +>1 : 1 + + var a: A3 = 1; +>a : 1 +>A3 : 1 +>1 : 1 + + var a: A4 = 1; +>a : 1 +>A4 : 1 +>1 : 1 + + var a: A5 = 1; +>a : 1 +>A5 : 1 +>1 : 1 +} + +type B1 = -1 | 0 | 1; +>B1 : -1 | 0 | 1 +>-1 : -1 +>1 : number + +type B2 = 1 | 0 | -1; +>B2 : 1 | 0 | -1 +>-1 : -1 +>1 : number + +type B3 = 0 | -1 | 1; +>B3 : 0 | -1 | 1 +>-1 : -1 +>1 : number + +function f2() { +>f2 : () => void + + var b: B1 = -1; +>b : -1 | 0 | 1 +>B1 : -1 | 0 | 1 +>-1 : -1 +>1 : number + + var b: B2 = 0; +>b : -1 | 0 | 1 +>B2 : 1 | 0 | -1 +>0 : 0 + + var b: B3 = 1; +>b : -1 | 0 | 1 +>B3 : 0 | -1 | 1 +>1 : 1 +} + +function f3(a: 1, b: 0 | 1 | 2) { +>f3 : (a: 1, b: 0 | 1 | 2) => void +>a : 1 +>b : 0 | 1 | 2 + + var x = a + b; +>x : number +>a + b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a - b; +>x : number +>a - b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a * b; +>x : number +>a * b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a / b; +>x : number +>a / b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a % b; +>x : number +>a % b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a | b; +>x : number +>a | b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a & b; +>x : number +>a & b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = a ^ b; +>x : number +>a ^ b : number +>a : 1 +>b : 0 | 1 | 2 + + var x = -b; +>x : number +>-b : number +>b : 0 | 1 | 2 + + var x = ~b; +>x : number +>~b : number +>b : 0 | 1 | 2 + + var y = a == b; +>y : boolean +>a == b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a != b; +>y : boolean +>a != b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a === b; +>y : boolean +>a === b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a !== b; +>y : boolean +>a !== b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a > b; +>y : boolean +>a > b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a < b; +>y : boolean +>a < b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a >= b; +>y : boolean +>a >= b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = a <= b; +>y : boolean +>a <= b : boolean +>a : 1 +>b : 0 | 1 | 2 + + var y = !b; +>y : boolean +>!b : boolean +>b : 0 | 1 | 2 +} + +function f4(a: 1, b: 0 | 1 | 2) { +>f4 : (a: 1, b: 0 | 1 | 2) => void +>a : 1 +>b : 0 | 1 | 2 + + a++; +>a++ : number +>a : 1 + + b++; +>b++ : number +>b : 0 | 1 | 2 +} + +declare function g(x: 0): string; +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>x : 0 + +declare function g(x: 1): boolean; +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>x : 1 + +declare function g(x: number): number; +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>x : number + +function f5(a: 1, b: 0 | 1 | 2) { +>f5 : (a: 1, b: 0 | 1 | 2) => void +>a : 1 +>b : 0 | 1 | 2 + + var z1 = g(0); +>z1 : string +>g(0) : string +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>0 : 0 + + var z2 = g(1); +>z2 : boolean +>g(1) : boolean +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>1 : 1 + + var z3 = g(2); +>z3 : number +>g(2) : number +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>2 : number + + var z4 = g(a); +>z4 : boolean +>g(a) : boolean +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>a : 1 + + var z5 = g(b); +>z5 : number +>g(b) : number +>g : { (x: 0): string; (x: 1): boolean; (x: number): number; } +>b : 0 | 1 | 2 +} + +function assertNever(x: never): never { +>assertNever : (x: never) => never +>x : never + + throw new Error("Unexpected value"); +>new Error("Unexpected value") : Error +>Error : ErrorConstructor +>"Unexpected value" : string +} + +type Tag = 0 | 1 | 2; +>Tag : 0 | 1 | 2 + +function f10(x: Tag) { +>f10 : (x: 0 | 1 | 2) => string +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + switch (x) { +>x : 0 | 1 | 2 + + case 0: return "a"; +>0 : 0 +>"a" : string + + case 1: return "b"; +>1 : 1 +>"b" : string + + case 2: return "c"; +>2 : 2 +>"c" : string + } +} + +function f11(x: Tag) { +>f11 : (x: 0 | 1 | 2) => string +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + switch (x) { +>x : 0 | 1 | 2 + + case 0: return "a"; +>0 : 0 +>"a" : string + + case 1: return "b"; +>1 : 1 +>"b" : string + + case 2: return "c"; +>2 : 2 +>"c" : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} + +function f12(x: Tag) { +>f12 : (x: 0 | 1 | 2) => void +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + if (x) { +>x : 0 | 1 | 2 + + x; +>x : 1 | 2 + } + else { + x; +>x : 0 + } +} + +function f13(x: Tag) { +>f13 : (x: 0 | 1 | 2) => void +>x : 0 | 1 | 2 +>Tag : 0 | 1 | 2 + + if (x === 0 || x === 2) { +>x === 0 || x === 2 : boolean +>x === 0 : boolean +>x : 0 | 1 | 2 +>0 : 0 +>x === 2 : boolean +>x : 1 | 2 +>2 : 2 + + x; +>x : 0 | 2 + } + else { + x; +>x : 1 + } +} + +function f14(x: 0 | 1 | 2, y: string) { +>f14 : (x: 0 | 1 | 2, y: string) => void +>x : 0 | 1 | 2 +>y : string + + var a = x && y; +>a : string | 0 +>x && y : string | 0 +>x : 0 | 1 | 2 +>y : string + + var b = x || y; +>b : 1 | 2 | string +>x || y : 1 | 2 | string +>x : 0 | 1 | 2 +>y : string +} + +function f15(x: 0 | false, y: 1 | "one") { +>f15 : (x: 0 | false, y: 1 | "one") => void +>x : 0 | false +>false : false +>y : 1 | "one" + + var a = x && y; +>a : 0 | false +>x && y : 0 | false +>x : 0 | false +>y : 1 | "one" + + var b = y && x; +>b : 0 | false +>y && x : 0 | false +>y : 1 | "one" +>x : 0 | false + + var c = x || y; +>c : 1 | "one" +>x || y : 1 | "one" +>x : 0 | false +>y : 1 | "one" + + var d = y || x; +>d : 1 | "one" +>y || x : 1 | "one" +>y : 1 | "one" +>x : 0 | false + + var e = !x; +>e : true +>!x : true +>x : 0 | false + + var f = !y; +>f : false +>!y : false +>y : 1 | "one" +} + +type Item = +>Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } + + { kind: 0, a: string } | +>kind : 0 +>a : string + + { kind: 1, b: string } | +>kind : 1 +>b : string + + { kind: 2, c: string }; +>kind : 2 +>c : string + +function f20(x: Item) { +>f20 : (x: { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; }) => string +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } + + switch (x.kind) { +>x.kind : 0 | 1 | 2 +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>kind : 0 | 1 | 2 + + case 0: return x.a; +>0 : 0 +>x.a : string +>x : { kind: 0; a: string; } +>a : string + + case 1: return x.b; +>1 : 1 +>x.b : string +>x : { kind: 1; b: string; } +>b : string + + case 2: return x.c; +>2 : 2 +>x.c : string +>x : { kind: 2; c: string; } +>c : string + } +} + +function f21(x: Item) { +>f21 : (x: { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; }) => string +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } + + switch (x.kind) { +>x.kind : 0 | 1 | 2 +>x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>kind : 0 | 1 | 2 + + case 0: return x.a; +>0 : 0 +>x.a : string +>x : { kind: 0; a: string; } +>a : string + + case 1: return x.b; +>1 : 1 +>x.b : string +>x : { kind: 1; b: string; } +>b : string + + case 2: return x.c; +>2 : 2 +>x.c : string +>x : { kind: 2; c: string; } +>c : string + } + return assertNever(x); +>assertNever(x) : never +>assertNever : (x: never) => never +>x : never +} diff --git a/tests/baselines/reference/numericLiteralTypes3.errors.txt b/tests/baselines/reference/numericLiteralTypes3.errors.txt new file mode 100644 index 0000000000000..19a61bce78670 --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes3.errors.txt @@ -0,0 +1,203 @@ +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(8,5): error TS2322: Type '2 | 3' is not assignable to type '1'. + Type '2' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(9,5): error TS2322: Type '1 | 2 | 3' is not assignable to type '1'. + Type '2' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(10,5): error TS2322: Type '0 | 1 | 2' is not assignable to type '1'. + Type '0' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(14,5): error TS2322: Type '1' is not assignable to type '2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(16,5): error TS2322: Type '1 | 2 | 3' is not assignable to type '2 | 3'. + Type '1' is not assignable to type '2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(17,5): error TS2322: Type '0 | 1 | 2' is not assignable to type '2 | 3'. + Type '0' is not assignable to type '2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(24,5): error TS2322: Type '0 | 1 | 2' is not assignable to type '1 | 2 | 3'. + Type '0' is not assignable to type '1 | 2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(29,5): error TS2322: Type '2 | 3' is not assignable to type '0 | 1 | 2'. + Type '3' is not assignable to type '0 | 1 | 2'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(30,5): error TS2322: Type '1 | 2 | 3' is not assignable to type '0 | 1 | 2'. + Type '3' is not assignable to type '0 | 1 | 2'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(35,5): error TS2322: Type '0' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(37,5): error TS2322: Type '2' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(38,5): error TS2322: Type '3' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(39,5): error TS2322: Type '0' is not assignable to type '2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(40,5): error TS2322: Type '1' is not assignable to type '2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(43,5): error TS2322: Type '0' is not assignable to type '1 | 2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(50,5): error TS2322: Type '3' is not assignable to type '0 | 1 | 2'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(54,5): error TS2365: Operator '===' cannot be applied to types '1' and '0'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(56,5): error TS2365: Operator '===' cannot be applied to types '1' and '2'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(57,5): error TS2365: Operator '===' cannot be applied to types '1' and '3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(58,5): error TS2365: Operator '===' cannot be applied to types '2 | 3' and '0'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(59,5): error TS2365: Operator '===' cannot be applied to types '2 | 3' and '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(62,5): error TS2365: Operator '===' cannot be applied to types '1 | 2 | 3' and '0'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(69,5): error TS2365: Operator '===' cannot be applied to types '0 | 1 | 2' and '3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(74,5): error TS2365: Operator '===' cannot be applied to types '1' and '2 | 3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(77,5): error TS2365: Operator '===' cannot be applied to types '2 | 3' and '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(94,14): error TS2678: Type '1' is not comparable to type '0 | 2 | 4'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(96,14): error TS2678: Type '3' is not comparable to type '0 | 2 | 4'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(98,14): error TS2678: Type '5' is not comparable to type '0 | 2 | 4'. + + +==== tests/cases/conformance/types/literal/numericLiteralTypes3.ts (28 errors) ==== + type A = 1; + type B = 2 | 3; + type C = 1 | 2 | 3; + type D = 0 | 1 | 2; + + function f1(a: A, b: B, c: C, d: D) { + a = a; + a = b; + ~ +!!! error TS2322: Type '2 | 3' is not assignable to type '1'. +!!! error TS2322: Type '2' is not assignable to type '1'. + a = c; + ~ +!!! error TS2322: Type '1 | 2 | 3' is not assignable to type '1'. +!!! error TS2322: Type '2' is not assignable to type '1'. + a = d; + ~ +!!! error TS2322: Type '0 | 1 | 2' is not assignable to type '1'. +!!! error TS2322: Type '0' is not assignable to type '1'. + } + + function f2(a: A, b: B, c: C, d: D) { + b = a; + ~ +!!! error TS2322: Type '1' is not assignable to type '2 | 3'. + b = b; + b = c; + ~ +!!! error TS2322: Type '1 | 2 | 3' is not assignable to type '2 | 3'. +!!! error TS2322: Type '1' is not assignable to type '2 | 3'. + b = d; + ~ +!!! error TS2322: Type '0 | 1 | 2' is not assignable to type '2 | 3'. +!!! error TS2322: Type '0' is not assignable to type '2 | 3'. + } + + function f3(a: A, b: B, c: C, d: D) { + c = a; + c = b; + c = c; + c = d; + ~ +!!! error TS2322: Type '0 | 1 | 2' is not assignable to type '1 | 2 | 3'. +!!! error TS2322: Type '0' is not assignable to type '1 | 2 | 3'. + } + + function f4(a: A, b: B, c: C, d: D) { + d = a; + d = b; + ~ +!!! error TS2322: Type '2 | 3' is not assignable to type '0 | 1 | 2'. +!!! error TS2322: Type '3' is not assignable to type '0 | 1 | 2'. + d = c; + ~ +!!! error TS2322: Type '1 | 2 | 3' is not assignable to type '0 | 1 | 2'. +!!! error TS2322: Type '3' is not assignable to type '0 | 1 | 2'. + d = d; + } + + function f5(a: A, b: B, c: C, d: D) { + a = 0; + ~ +!!! error TS2322: Type '0' is not assignable to type '1'. + a = 1; + a = 2; + ~ +!!! error TS2322: Type '2' is not assignable to type '1'. + a = 3; + ~ +!!! error TS2322: Type '3' is not assignable to type '1'. + b = 0; + ~ +!!! error TS2322: Type '0' is not assignable to type '2 | 3'. + b = 1; + ~ +!!! error TS2322: Type '1' is not assignable to type '2 | 3'. + b = 2; + b = 3; + c = 0; + ~ +!!! error TS2322: Type '0' is not assignable to type '1 | 2 | 3'. + c = 1; + c = 2; + c = 3; + d = 0; + d = 1; + d = 2; + d = 3; + ~ +!!! error TS2322: Type '3' is not assignable to type '0 | 1 | 2'. + } + + function f6(a: A, b: B, c: C, d: D) { + a === 0; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '1' and '0'. + a === 1; + a === 2; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '1' and '2'. + a === 3; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '1' and '3'. + b === 0; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '2 | 3' and '0'. + b === 1; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '2 | 3' and '1'. + b === 2; + b === 3; + c === 0; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '1 | 2 | 3' and '0'. + c === 1; + c === 2; + c === 3; + d === 0; + d === 1; + d === 2; + d === 3; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '0 | 1 | 2' and '3'. + } + + function f7(a: A, b: B, c: C, d: D) { + a === a; + a === b; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '1' and '2 | 3'. + a === c; + a === d; + b === a; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '2 | 3' and '1'. + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; + } + + function f8(x: 0 | 2 | 4) { + switch (x) { + case 0: return; + case 1: return; + ~ +!!! error TS2678: Type '1' is not comparable to type '0 | 2 | 4'. + case 2: return; + case 3: return; + ~ +!!! error TS2678: Type '3' is not comparable to type '0 | 2 | 4'. + case 4: return; + case 5: return; + ~ +!!! error TS2678: Type '5' is not comparable to type '0 | 2 | 4'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/numericLiteralTypes3.js b/tests/baselines/reference/numericLiteralTypes3.js new file mode 100644 index 0000000000000..730314be8efbd --- /dev/null +++ b/tests/baselines/reference/numericLiteralTypes3.js @@ -0,0 +1,191 @@ +//// [numericLiteralTypes3.ts] +type A = 1; +type B = 2 | 3; +type C = 1 | 2 | 3; +type D = 0 | 1 | 2; + +function f1(a: A, b: B, c: C, d: D) { + a = a; + a = b; + a = c; + a = d; +} + +function f2(a: A, b: B, c: C, d: D) { + b = a; + b = b; + b = c; + b = d; +} + +function f3(a: A, b: B, c: C, d: D) { + c = a; + c = b; + c = c; + c = d; +} + +function f4(a: A, b: B, c: C, d: D) { + d = a; + d = b; + d = c; + d = d; +} + +function f5(a: A, b: B, c: C, d: D) { + a = 0; + a = 1; + a = 2; + a = 3; + b = 0; + b = 1; + b = 2; + b = 3; + c = 0; + c = 1; + c = 2; + c = 3; + d = 0; + d = 1; + d = 2; + d = 3; +} + +function f6(a: A, b: B, c: C, d: D) { + a === 0; + a === 1; + a === 2; + a === 3; + b === 0; + b === 1; + b === 2; + b === 3; + c === 0; + c === 1; + c === 2; + c === 3; + d === 0; + d === 1; + d === 2; + d === 3; +} + +function f7(a: A, b: B, c: C, d: D) { + a === a; + a === b; + a === c; + a === d; + b === a; + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; +} + +function f8(x: 0 | 2 | 4) { + switch (x) { + case 0: return; + case 1: return; + case 2: return; + case 3: return; + case 4: return; + case 5: return; + } +} + +//// [numericLiteralTypes3.js] +function f1(a, b, c, d) { + a = a; + a = b; + a = c; + a = d; +} +function f2(a, b, c, d) { + b = a; + b = b; + b = c; + b = d; +} +function f3(a, b, c, d) { + c = a; + c = b; + c = c; + c = d; +} +function f4(a, b, c, d) { + d = a; + d = b; + d = c; + d = d; +} +function f5(a, b, c, d) { + a = 0; + a = 1; + a = 2; + a = 3; + b = 0; + b = 1; + b = 2; + b = 3; + c = 0; + c = 1; + c = 2; + c = 3; + d = 0; + d = 1; + d = 2; + d = 3; +} +function f6(a, b, c, d) { + a === 0; + a === 1; + a === 2; + a === 3; + b === 0; + b === 1; + b === 2; + b === 3; + c === 0; + c === 1; + c === 2; + c === 3; + d === 0; + d === 1; + d === 2; + d === 3; +} +function f7(a, b, c, d) { + a === a; + a === b; + a === c; + a === d; + b === a; + b === b; + b === c; + b === d; + c === a; + c === b; + c === c; + c === d; + d === a; + d === b; + d === c; + d === d; +} +function f8(x) { + switch (x) { + case 0: return; + case 1: return; + case 2: return; + case 3: return; + case 4: return; + case 5: return; + } +} diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.js b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.js new file mode 100644 index 0000000000000..2c80e8a704e1e --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.js @@ -0,0 +1,9 @@ +//// [stringLiteralsAssertionsInEqualityComparisons01.ts] +var a = "foo" === "bar" as string; +var b = "foo" !== ("bar" as string); +var c = "foo" == ("bar"); + +//// [stringLiteralsAssertionsInEqualityComparisons01.js] +var a = "foo" === "bar"; +var b = "foo" !== "bar"; +var c = "foo" == "bar"; diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.symbols b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.symbols new file mode 100644 index 0000000000000..3affecc854e19 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons01.ts === +var a = "foo" === "bar" as string; +>a : Symbol(a, Decl(stringLiteralsAssertionsInEqualityComparisons01.ts, 0, 3)) + +var b = "foo" !== ("bar" as string); +>b : Symbol(b, Decl(stringLiteralsAssertionsInEqualityComparisons01.ts, 1, 3)) + +var c = "foo" == ("bar"); +>c : Symbol(c, Decl(stringLiteralsAssertionsInEqualityComparisons01.ts, 2, 3)) + diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types new file mode 100644 index 0000000000000..17a835a2461d6 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons01.ts === +var a = "foo" === "bar" as string; +>a : boolean +>"foo" === "bar" as string : boolean +>"foo" : "foo" +>"bar" as string : string +>"bar" : string + +var b = "foo" !== ("bar" as string); +>b : boolean +>"foo" !== ("bar" as string) : boolean +>"foo" : "foo" +>("bar" as string) : string +>"bar" as string : string +>"bar" : string + +var c = "foo" == ("bar"); +>c : boolean +>"foo" == ("bar") : boolean +>"foo" : "foo" +>("bar") : any +>"bar" : any +>"bar" : string + diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt new file mode 100644 index 0000000000000..5daeab5dbeddc --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(3,9): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"baz"'. +tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(3,19): error TS2352: Type '"bar"' cannot be converted to type '"baz"'. +tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(4,20): error TS2352: Type '"bar"' cannot be converted to type '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(5,9): error TS2365: Operator '==' cannot be applied to types 'string' and 'number'. +tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts(5,19): error TS2352: Type 'string' cannot be converted to type 'number'. + + +==== tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts (5 errors) ==== + type EnhancedString = string & { enhancements: any }; + + var a = "foo" === "bar" as "baz"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo"' and '"baz"'. + ~~~~~~~~~~~~~~ +!!! error TS2352: Type '"bar"' cannot be converted to type '"baz"'. + var b = "foo" !== ("bar" as "foo"); + ~~~~~~~~~~~~~~ +!!! error TS2352: Type '"bar"' cannot be converted to type '"foo"'. + var c = "foo" == ("bar"); + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types 'string' and 'number'. + ~~~~~~~~~~~~~ +!!! error TS2352: Type 'string' cannot be converted to type 'number'. + var d = "foo" === ("bar" as EnhancedString); \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js new file mode 100644 index 0000000000000..32beac89bf734 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js @@ -0,0 +1,13 @@ +//// [stringLiteralsAssertionsInEqualityComparisons02.ts] +type EnhancedString = string & { enhancements: any }; + +var a = "foo" === "bar" as "baz"; +var b = "foo" !== ("bar" as "foo"); +var c = "foo" == ("bar"); +var d = "foo" === ("bar" as EnhancedString); + +//// [stringLiteralsAssertionsInEqualityComparisons02.js] +var a = "foo" === "bar"; +var b = "foo" !== "bar"; +var c = "foo" == "bar"; +var d = "foo" === "bar"; diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt new file mode 100644 index 0000000000000..17b4e39e0c5cb --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts(8,5): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts(9,5): error TS2365: Operator '===' cannot be applied to types '"bar"' and '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts(10,5): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts(17,5): error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts(18,5): error TS2365: Operator '!==' cannot be applied to types '"bar"' and '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts(19,5): error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts (6 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + + let b: boolean; + b = x === y; + b = "foo" === y + b = y === "foo"; + b = "foo" === "bar"; + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" === x; + ~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"bar"' and '"foo"'. + b = x === "bar"; + ~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. + b = y === "bar"; + b = "bar" === y; + + b = x !== y; + b = "foo" !== y + b = y !== "foo"; + b = "foo" !== "bar"; + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" !== x; + ~~~~~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types '"bar"' and '"foo"'. + b = x !== "bar"; + ~~~~~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + b = y !== "bar"; + b = "bar" !== y; + + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.js b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.js new file mode 100644 index 0000000000000..fc08a354338d2 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.js @@ -0,0 +1,45 @@ +//// [stringLiteralsWithEqualityChecks01.ts] +let x: "foo"; +let y: "foo" | "bar"; + +let b: boolean; +b = x === y; +b = "foo" === y +b = y === "foo"; +b = "foo" === "bar"; +b = "bar" === x; +b = x === "bar"; +b = y === "bar"; +b = "bar" === y; + +b = x !== y; +b = "foo" !== y +b = y !== "foo"; +b = "foo" !== "bar"; +b = "bar" !== x; +b = x !== "bar"; +b = y !== "bar"; +b = "bar" !== y; + + + +//// [stringLiteralsWithEqualityChecks01.js] +var x; +var y; +var b; +b = x === y; +b = "foo" === y; +b = y === "foo"; +b = "foo" === "bar"; +b = "bar" === x; +b = x === "bar"; +b = y === "bar"; +b = "bar" === y; +b = x !== y; +b = "foo" !== y; +b = y !== "foo"; +b = "foo" !== "bar"; +b = "bar" !== x; +b = x !== "bar"; +b = y !== "bar"; +b = "bar" !== y; diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt new file mode 100644 index 0000000000000..ef01bbf510989 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts(8,5): error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts(9,5): error TS2365: Operator '==' cannot be applied to types '"bar"' and '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts(10,5): error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts(17,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts(18,5): error TS2365: Operator '!=' cannot be applied to types '"bar"' and '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts(19,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts (6 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + + let b: boolean; + b = x == y; + b = "foo" == y + b = y == "foo"; + b = "foo" == "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" == x; + ~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"bar"' and '"foo"'. + b = x == "bar"; + ~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. + b = y == "bar"; + b = "bar" == y; + + b = x != y; + b = "foo" != y + b = y != "foo"; + b = "foo" != "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" != x; + ~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"bar"' and '"foo"'. + b = x != "bar"; + ~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + b = y != "bar"; + b = "bar" != y; + + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.js b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.js new file mode 100644 index 0000000000000..b31246251a393 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.js @@ -0,0 +1,45 @@ +//// [stringLiteralsWithEqualityChecks02.ts] +let x: "foo"; +let y: "foo" | "bar"; + +let b: boolean; +b = x == y; +b = "foo" == y +b = y == "foo"; +b = "foo" == "bar"; +b = "bar" == x; +b = x == "bar"; +b = y == "bar"; +b = "bar" == y; + +b = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; + + + +//// [stringLiteralsWithEqualityChecks02.js] +var x; +var y; +var b; +b = x == y; +b = "foo" == y; +b = y == "foo"; +b = "foo" == "bar"; +b = "bar" == x; +b = x == "bar"; +b = y == "bar"; +b = "bar" == y; +b = x != y; +b = "foo" != y; +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt new file mode 100644 index 0000000000000..a12d3f7f0d204 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt @@ -0,0 +1,39 @@ +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts(16,5): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts(25,5): error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts (2 errors) ==== + interface Runnable { + isRunning: boolean; + } + + interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; + } + + let x: string; + let y: "foo" | Refrigerator; + + let b: boolean; + b = x === y; + b = "foo" === y + b = y === "foo"; + b = "foo" === "bar"; + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" === x; + b = x === "bar"; + b = y === "bar"; + b = "bar" === y; + + b = x !== y; + b = "foo" !== y + b = y !== "foo"; + b = "foo" !== "bar"; + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" !== x; + b = x !== "bar"; + b = y !== "bar"; + b = "bar" !== y; + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.js b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.js new file mode 100644 index 0000000000000..e418c73ff691b --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.js @@ -0,0 +1,52 @@ +//// [stringLiteralsWithEqualityChecks03.ts] +interface Runnable { + isRunning: boolean; +} + +interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; +} + +let x: string; +let y: "foo" | Refrigerator; + +let b: boolean; +b = x === y; +b = "foo" === y +b = y === "foo"; +b = "foo" === "bar"; +b = "bar" === x; +b = x === "bar"; +b = y === "bar"; +b = "bar" === y; + +b = x !== y; +b = "foo" !== y +b = y !== "foo"; +b = "foo" !== "bar"; +b = "bar" !== x; +b = x !== "bar"; +b = y !== "bar"; +b = "bar" !== y; + + +//// [stringLiteralsWithEqualityChecks03.js] +var x; +var y; +var b; +b = x === y; +b = "foo" === y; +b = y === "foo"; +b = "foo" === "bar"; +b = "bar" === x; +b = x === "bar"; +b = y === "bar"; +b = "bar" === y; +b = x !== y; +b = "foo" !== y; +b = y !== "foo"; +b = "foo" !== "bar"; +b = "bar" !== x; +b = x !== "bar"; +b = y !== "bar"; +b = "bar" !== y; diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt new file mode 100644 index 0000000000000..fde735023d97c --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt @@ -0,0 +1,39 @@ +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts(16,5): error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts(25,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts (2 errors) ==== + interface Runnable { + isRunning: boolean; + } + + interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; + } + + let x: string; + let y: "foo" | Refrigerator; + + let b: boolean; + b = x == y; + b = "foo" == y + b = y == "foo"; + b = "foo" == "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" == x; + b = x == "bar"; + b = y == "bar"; + b = "bar" == y; + + b = x != y; + b = "foo" != y + b = y != "foo"; + b = "foo" != "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + b = "bar" != x; + b = x != "bar"; + b = y != "bar"; + b = "bar" != y; + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.js b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.js new file mode 100644 index 0000000000000..52f43cdfa5eef --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.js @@ -0,0 +1,52 @@ +//// [stringLiteralsWithEqualityChecks04.ts] +interface Runnable { + isRunning: boolean; +} + +interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; +} + +let x: string; +let y: "foo" | Refrigerator; + +let b: boolean; +b = x == y; +b = "foo" == y +b = y == "foo"; +b = "foo" == "bar"; +b = "bar" == x; +b = x == "bar"; +b = y == "bar"; +b = "bar" == y; + +b = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; + + +//// [stringLiteralsWithEqualityChecks04.js] +var x; +var y; +var b; +b = x == y; +b = "foo" == y; +b = y == "foo"; +b = "foo" == "bar"; +b = "bar" == x; +b = x == "bar"; +b = y == "bar"; +b = "bar" == y; +b = x != y; +b = "foo" != y; +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt new file mode 100644 index 0000000000000..b127d999d943e --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements01.ts(7,10): error TS2678: Type '"bar"' is not comparable to type '"foo"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements01.ts (1 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + + switch (x) { + case "foo": + break; + case "bar": + ~~~~~ +!!! error TS2678: Type '"bar"' is not comparable to type '"foo"'. + break; + case y: + y; + break; + } + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.js b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.js new file mode 100644 index 0000000000000..b9541ef05e608 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.js @@ -0,0 +1,27 @@ +//// [stringLiteralsWithSwitchStatements01.ts] +let x: "foo"; +let y: "foo" | "bar"; + +switch (x) { + case "foo": + break; + case "bar": + break; + case y: + y; + break; +} + + +//// [stringLiteralsWithSwitchStatements01.js] +var x; +var y; +switch (x) { + case "foo": + break; + case "bar": + break; + case y: + y; + break; +} diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements02.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.errors.txt new file mode 100644 index 0000000000000..1a4d9a4c5602c --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts(8,5): error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts(13,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts (2 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + + let b: boolean; + b = x == y; + b = "foo" == y + b = y == "foo"; + b = "foo" == "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. + + b = x != y; + b = "foo" != y + b = y != "foo"; + b = "foo" != "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements02.js b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.js new file mode 100644 index 0000000000000..0487161561741 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.js @@ -0,0 +1,29 @@ +//// [stringLiteralsWithSwitchStatements02.ts] +let x: "foo"; +let y: "foo" | "bar"; + +let b: boolean; +b = x == y; +b = "foo" == y +b = y == "foo"; +b = "foo" == "bar"; + +b = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; + + + +//// [stringLiteralsWithSwitchStatements02.js] +var x; +var y; +var b; +b = x == y; +b = "foo" == y; +b = y == "foo"; +b = "foo" == "bar"; +b = x != y; +b = "foo" != y; +b = y != "foo"; +b = "foo" != "bar"; diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt new file mode 100644 index 0000000000000..b2cbc96501fad --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt @@ -0,0 +1,43 @@ +tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts(10,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. + Type '"baz"' is not comparable to type '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts(12,10): error TS2678: Type '"bar"' is not comparable to type '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts(22,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. + Type '"baz"' is not comparable to type '"foo"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts (3 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + let z: "bar"; + + declare function randBool(): boolean; + + switch (x) { + case randBool() ? "foo" : "baz": + break; + case (randBool() ? ("bar") : "baz" ? "bar" : "baz"): + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. +!!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. + break; + case (("bar")): + ~~~~~~~~~ +!!! error TS2678: Type '"bar"' is not comparable to type '"foo"'. + break; + case (x, y, ("baz")): + x; + y; + break; + case (("foo" || ("bar"))): + break; + case (("bar" || ("baz"))): + break; + case z || "baz": + ~~~~~~~~~~ +!!! error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. +!!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. + case "baz" || z: + z; + break; + } + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.js b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.js new file mode 100644 index 0000000000000..17596249e6c1b --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.js @@ -0,0 +1,53 @@ +//// [stringLiteralsWithSwitchStatements03.ts] +let x: "foo"; +let y: "foo" | "bar"; +let z: "bar"; + +declare function randBool(): boolean; + +switch (x) { + case randBool() ? "foo" : "baz": + break; + case (randBool() ? ("bar") : "baz" ? "bar" : "baz"): + break; + case (("bar")): + break; + case (x, y, ("baz")): + x; + y; + break; + case (("foo" || ("bar"))): + break; + case (("bar" || ("baz"))): + break; + case z || "baz": + case "baz" || z: + z; + break; +} + + +//// [stringLiteralsWithSwitchStatements03.js] +var x; +var y; +var z; +switch (x) { + case randBool() ? "foo" : "baz": + break; + case (randBool() ? ("bar") : "baz" ? "bar" : "baz"): + break; + case (("bar")): + break; + case (x, y, ("baz")): + x; + y; + break; + case (("foo" || ("bar"))): + break; + case (("bar" || ("baz"))): + break; + case z || "baz": + case "baz" || z: + z; + break; +} diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.js b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.js new file mode 100644 index 0000000000000..da2ce7b4150ba --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.js @@ -0,0 +1,43 @@ +//// [stringLiteralsWithSwitchStatements04.ts] +let x: "foo"; +let y: "foo" | "bar"; + +declare function randBool(): boolean; + +switch (y) { + case "foo", x: + break; + case x, "foo": + break; + case x, "baz": + break; + case "baz", x: + break; + case "baz" && "bar": + break; + case "baz" && ("foo" || "bar"): + break; + case "bar" && ("baz" || "bar"): + break; +} + + +//// [stringLiteralsWithSwitchStatements04.js] +var x; +var y; +switch (y) { + case "foo", x: + break; + case x, "foo": + break; + case x, "baz": + break; + case "baz", x: + break; + case "baz" && "bar": + break; + case "baz" && ("foo" || "bar"): + break; + case "bar" && ("baz" || "bar"): + break; +} diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.symbols b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.symbols new file mode 100644 index 0000000000000..40062a34b473d --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements04.ts === +let x: "foo"; +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements04.ts, 0, 3)) + +let y: "foo" | "bar"; +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements04.ts, 1, 3)) + +declare function randBool(): boolean; +>randBool : Symbol(randBool, Decl(stringLiteralsWithSwitchStatements04.ts, 1, 21)) + +switch (y) { +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements04.ts, 1, 3)) + + case "foo", x: +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements04.ts, 0, 3)) + + break; + case x, "foo": +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements04.ts, 0, 3)) + + break; + case x, "baz": +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements04.ts, 0, 3)) + + break; + case "baz", x: +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements04.ts, 0, 3)) + + break; + case "baz" && "bar": + break; + case "baz" && ("foo" || "bar"): + break; + case "bar" && ("baz" || "bar"): + break; +} + diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types new file mode 100644 index 0000000000000..fc395576a7221 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types @@ -0,0 +1,63 @@ +=== tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements04.ts === +let x: "foo"; +>x : "foo" + +let y: "foo" | "bar"; +>y : "foo" | "bar" + +declare function randBool(): boolean; +>randBool : () => boolean + +switch (y) { +>y : "foo" | "bar" + + case "foo", x: +>"foo", x : "foo" +>"foo" : string +>x : "foo" + + break; + case x, "foo": +>x, "foo" : string +>x : "foo" +>"foo" : string + + break; + case x, "baz": +>x, "baz" : string +>x : "foo" +>"baz" : string + + break; + case "baz", x: +>"baz", x : "foo" +>"baz" : string +>x : "foo" + + break; + case "baz" && "bar": +>"baz" && "bar" : string +>"baz" : string +>"bar" : string + + break; + case "baz" && ("foo" || "bar"): +>"baz" && ("foo" || "bar") : string +>"baz" : string +>("foo" || "bar") : string +>"foo" || "bar" : string +>"foo" : string +>"bar" : string + + break; + case "bar" && ("baz" || "bar"): +>"bar" && ("baz" || "bar") : string +>"bar" : string +>("baz" || "bar") : string +>"baz" || "bar" : string +>"baz" : string +>"bar" : string + + break; +} + diff --git a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt new file mode 100644 index 0000000000000..d9d465c7afc24 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt @@ -0,0 +1,25 @@ +tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts(3,9): error TS2352: Type '"foo"' cannot be converted to type '"bar"'. +tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts(4,9): error TS2352: Type '"bar"' cannot be converted to type '"foo"'. +tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts(7,9): error TS2352: Type '"foo" | "bar"' cannot be converted to type '"baz"'. + Type '"bar"' is not comparable to type '"baz"'. +tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts(8,9): error TS2352: Type '"baz"' cannot be converted to type '"foo" | "bar"'. + + +==== tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts (4 errors) ==== + let fooOrBar: "foo" | "bar"; + + let a = "foo" as "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2352: Type '"foo"' cannot be converted to type '"bar"'. + let b = "bar" as "foo"; + ~~~~~~~~~~~~~~ +!!! error TS2352: Type '"bar"' cannot be converted to type '"foo"'. + let c = fooOrBar as "foo"; + let d = fooOrBar as "bar"; + let e = fooOrBar as "baz"; + ~~~~~~~~~~~~~~~~~ +!!! error TS2352: Type '"foo" | "bar"' cannot be converted to type '"baz"'. +!!! error TS2352: Type '"bar"' is not comparable to type '"baz"'. + let f = "baz" as typeof fooOrBar; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Type '"baz"' cannot be converted to type '"foo" | "bar"'. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.js b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.js new file mode 100644 index 0000000000000..6e74c73751745 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.js @@ -0,0 +1,18 @@ +//// [stringLiteralsWithTypeAssertions01.ts] +let fooOrBar: "foo" | "bar"; + +let a = "foo" as "bar"; +let b = "bar" as "foo"; +let c = fooOrBar as "foo"; +let d = fooOrBar as "bar"; +let e = fooOrBar as "baz"; +let f = "baz" as typeof fooOrBar; + +//// [stringLiteralsWithTypeAssertions01.js] +var fooOrBar; +var a = "foo"; +var b = "bar"; +var c = fooOrBar; +var d = fooOrBar; +var e = fooOrBar; +var f = "baz"; From 44339dd55f95373bc116f6c83d61487644fbaa93 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 14 Jul 2016 09:21:18 -0700 Subject: [PATCH 23/55] Performance optimizations --- src/compiler/checker.ts | 61 ++++++++++++++++++++++++++++------------- src/compiler/core.ts | 13 +++++---- 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2179612d0122a..996ad2586dfc3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6244,10 +6244,13 @@ namespace ts { function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean): Ternary { const targetTypes = target.types; - let len = targetTypes.length; + if (contains(targetTypes, source)) { + return Ternary.True; + } // The null and undefined types are guaranteed to be at the end of the constituent type list. In order // to produce the best possible errors we first check the nullable types, such that the last type we // check and report errors from is a non-nullable type if one is present. + let len = targetTypes.length; while (len >= 2 && targetTypes[len - 1].flags & TypeFlags.Nullable) { const related = isRelatedTo(source, targetTypes[len - 1], /*reportErrors*/ false); if (related) { @@ -6280,10 +6283,13 @@ namespace ts { function someTypeRelatedToType(source: UnionOrIntersectionType, target: Type, reportErrors: boolean): Ternary { const sourceTypes = source.types; - let len = sourceTypes.length; + if (contains(sourceTypes, target)) { + return Ternary.True; + } // The null and undefined types are guaranteed to be at the end of the constituent type list. In order // to produce the best possible errors we first check the nullable types, such that the last type we // check and report errors from is a non-nullable type if one is present. + let len = sourceTypes.length; while (len >= 2 && sourceTypes[len - 1].flags & TypeFlags.Nullable) { const related = isRelatedTo(sourceTypes[len - 1], target, /*reportErrors*/ false); if (related) { @@ -6803,9 +6809,11 @@ namespace ts { // A source signature partially matches a target signature if the target signature has no fewer required // parameters and no more overall parameters than the source signature (where a signature with a rest // parameter is always considered to have more overall parameters than one without). + const sourceRestCount = source.hasRestParameter ? 1 : 0; + const targetRestCount = target.hasRestParameter ? 1 : 0; if (partialMatch && source.minArgumentCount <= target.minArgumentCount && ( - source.hasRestParameter && !target.hasRestParameter || - source.hasRestParameter === target.hasRestParameter && source.parameters.length >= target.parameters.length)) { + sourceRestCount > targetRestCount || + sourceRestCount === targetRestCount && source.parameters.length >= target.parameters.length)) { return true; } return false; @@ -7259,10 +7267,17 @@ namespace ts { function inferFromTypes(source: Type, target: Type) { if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union || source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) { - // Source and target are both unions or both intersections. First, find each - // target constituent type that has an identically matching source constituent - // type, and for each such target constituent type infer from the type to itself. - // When inferring from a type to itself we effectively find all type parameter + // Source and target are both unions or both intersections. If source and target + // are the same type, just relate each constituent type to itself. + if (source === target) { + for (const t of (source).types) { + inferFromTypes(t, t); + } + return; + } + // Find each target constituent type that has an identically matching source + // constituent type, and for each such target constituent type infer from the type to + // itself. When inferring from a type to itself we effectively find all type parameter // occurrences within that type and infer themselves as their type arguments. let matchingTypes: Type[]; for (const t of (target).types) { @@ -7654,12 +7669,20 @@ namespace ts { if (declaredType !== assignedType && declaredType.flags & TypeFlags.Union) { const reducedTypes = filter(declaredType.types, t => typeMaybeAssignableTo(assignedType, t)); if (reducedTypes.length) { - return reducedTypes.length === 1 ? reducedTypes[0] : getUnionType(reducedTypes); + return reducedTypes.length === 1 ? reducedTypes[0] : getUnionType(reducedTypes, /*noSubtypeReduction*/ true); } } return declaredType; } + function getTypeFactsOfTypes(types: Type[]): TypeFacts { + let result: TypeFacts = TypeFacts.None; + for (const t of types) { + result |= getTypeFacts(t); + } + return result; + } + function getTypeFacts(type: Type): TypeFacts { const flags = type.flags; if (flags & TypeFlags.String) { @@ -7709,7 +7732,7 @@ namespace ts { return constraint ? getTypeFacts(constraint) : TypeFacts.All; } if (flags & TypeFlags.UnionOrIntersection) { - return reduceLeft((type).types, (flags, type) => flags |= getTypeFacts(type), TypeFacts.None); + return getTypeFactsOfTypes((type).types); } return TypeFacts.All; } @@ -7885,7 +7908,7 @@ namespace ts { function filterType(type: Type, f: (t: Type) => boolean): Type { return type.flags & TypeFlags.Union ? - getUnionType(filter((type).types, f)) : + getUnionType(filter((type).types, f), /*noSubtypeReduction*/ true) : f(type) ? type : neverType; } @@ -8039,7 +8062,7 @@ namespace ts { antecedentTypes.push(type); } } - return getUnionType(antecedentTypes); + return getUnionType(antecedentTypes, /*noSubtypeReduction*/ true); } function getTypeAtFlowLoopLabel(flow: FlowLabel) { @@ -8059,7 +8082,7 @@ namespace ts { // the non-looping control flow path that leads to the top. for (let i = flowLoopStart; i < flowLoopCount; i++) { if (flowLoopNodes[i] === flow && flowLoopKeys[i] === key) { - return getUnionType(flowLoopTypes[i]); + return getUnionType(flowLoopTypes[i], /*noSubtypeReduction*/ true); } } // Add the flow loop junction and reference to the in-process stack and analyze @@ -8088,7 +8111,7 @@ namespace ts { break; } } - return cache[key] = getUnionType(antecedentTypes); + return cache[key] = getUnionType(antecedentTypes, /*noSubtypeReduction*/ true); } function isMatchingPropertyAccess(expr: Expression) { @@ -8216,13 +8239,13 @@ namespace ts { } const clauseTypes = switchTypes.slice(clauseStart, clauseEnd); const hasDefaultClause = clauseStart === clauseEnd || contains(clauseTypes, neverType); - const discriminantType = getUnionType(clauseTypes); + const discriminantType = getUnionType(clauseTypes, /*noSubtypeReduction*/ true); const caseType = discriminantType === neverType ? 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]); + return caseType === neverType ? defaultType : getUnionType([caseType, defaultType], /*noSubtypeReduction*/ true); } function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { @@ -8266,7 +8289,7 @@ namespace ts { constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct); } if (constructSignatures && constructSignatures.length) { - targetType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature)))); + targetType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature))), /*noSubtypeReduction*/ true); } } @@ -8280,7 +8303,7 @@ namespace ts { function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean) { if (!assumeTrue) { return type.flags & TypeFlags.Union ? - getUnionType(filter((type).types, t => !isTypeSubtypeOf(t, candidate))) : + getUnionType(filter((type).types, t => !isTypeSubtypeOf(t, candidate)), /*noSubtypeReduction*/ true) : type; } // If the current type is a union type, remove all constituents that aren't assignable to @@ -8288,7 +8311,7 @@ namespace ts { if (type.flags & TypeFlags.Union) { const assignableConstituents = filter((type).types, t => isTypeAssignableTo(t, candidate)); if (assignableConstituents.length) { - return getUnionType(assignableConstituents); + return getUnionType(assignableConstituents, /*noSubtypeReduction*/ true); } } // If the candidate type is assignable to the target type, narrow to the candidate type. diff --git a/src/compiler/core.ts b/src/compiler/core.ts index fe4731a1c9144..35c32d160c61c 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -91,10 +91,10 @@ namespace ts { return undefined; } - export function contains(array: T[], value: T, areEqual?: (a: T, b: T) => boolean): boolean { + export function contains(array: T[], value: T): boolean { if (array) { for (const v of array) { - if (areEqual ? areEqual(v, value) : v === value) { + if (v === value) { return true; } } @@ -180,10 +180,13 @@ namespace ts { let result: T[]; if (array) { result = []; - for (const item of array) { - if (!contains(result, item, areEqual)) { - result.push(item); + loop: for (const item of array) { + for (const res of result) { + if (areEqual ? areEqual(res, item) : res === item) { + continue loop; + } } + result.push(item); } } return result; From 4501b3ec60bc725a15768801de45892171d87d42 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 14 Jul 2016 09:21:54 -0700 Subject: [PATCH 24/55] Accept new baselines --- .../controlFlowBinaryOrExpression.symbols | 12 +++--- .../controlFlowBinaryOrExpression.types | 12 +++--- .../stringLiteralTypesInUnionTypes02.types | 38 +++++++++---------- .../baselines/reference/typeGuardEnums.types | 4 +- .../reference/typeGuardOfFormInstanceOf.types | 2 +- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/baselines/reference/controlFlowBinaryOrExpression.symbols b/tests/baselines/reference/controlFlowBinaryOrExpression.symbols index e47bdb19d346c..8af9a35c18213 100644 --- a/tests/baselines/reference/controlFlowBinaryOrExpression.symbols +++ b/tests/baselines/reference/controlFlowBinaryOrExpression.symbols @@ -64,9 +64,9 @@ if (isNodeList(sourceObj)) { >sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) sourceObj.length; ->sourceObj.length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +>sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 14, 33), Decl(controlFlowBinaryOrExpression.ts, 10, 27)) >sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) ->length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +>length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 14, 33), Decl(controlFlowBinaryOrExpression.ts, 10, 27)) } if (isHTMLCollection(sourceObj)) { @@ -74,9 +74,9 @@ if (isHTMLCollection(sourceObj)) { >sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) sourceObj.length; ->sourceObj.length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +>sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 14, 33), Decl(controlFlowBinaryOrExpression.ts, 10, 27)) >sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) ->length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +>length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 14, 33), Decl(controlFlowBinaryOrExpression.ts, 10, 27)) } if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { @@ -86,8 +86,8 @@ if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { >sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) sourceObj.length; ->sourceObj.length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +>sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 14, 33), Decl(controlFlowBinaryOrExpression.ts, 10, 27)) >sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) ->length : Symbol(HTMLCollection.length, Decl(controlFlowBinaryOrExpression.ts, 14, 33)) +>length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 14, 33), Decl(controlFlowBinaryOrExpression.ts, 10, 27)) } diff --git a/tests/baselines/reference/controlFlowBinaryOrExpression.types b/tests/baselines/reference/controlFlowBinaryOrExpression.types index 8c1cd32d8d9d7..5f9d02b4443b6 100644 --- a/tests/baselines/reference/controlFlowBinaryOrExpression.types +++ b/tests/baselines/reference/controlFlowBinaryOrExpression.types @@ -76,22 +76,22 @@ var sourceObj: EventTargetLike = undefined; if (isNodeList(sourceObj)) { >isNodeList(sourceObj) : boolean >isNodeList : (sourceObj: any) => sourceObj is NodeList ->sourceObj : { a: string; } | HTMLCollection +>sourceObj : { a: string; } | HTMLCollection | NodeList sourceObj.length; >sourceObj.length : number ->sourceObj : HTMLCollection +>sourceObj : HTMLCollection | NodeList >length : number } if (isHTMLCollection(sourceObj)) { >isHTMLCollection(sourceObj) : boolean >isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection ->sourceObj : HTMLCollection | { a: string; } +>sourceObj : HTMLCollection | NodeList | { a: string; } sourceObj.length; >sourceObj.length : number ->sourceObj : HTMLCollection +>sourceObj : HTMLCollection | NodeList >length : number } @@ -99,14 +99,14 @@ if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { >isNodeList(sourceObj) || isHTMLCollection(sourceObj) : boolean >isNodeList(sourceObj) : boolean >isNodeList : (sourceObj: any) => sourceObj is NodeList ->sourceObj : HTMLCollection | { a: string; } +>sourceObj : HTMLCollection | NodeList | { a: string; } >isHTMLCollection(sourceObj) : boolean >isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection >sourceObj : { a: string; } sourceObj.length; >sourceObj.length : number ->sourceObj : HTMLCollection +>sourceObj : HTMLCollection | NodeList | ({ a: string; } & HTMLCollection) >length : number } diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types index 7b61b7e26fb11..2b8bbbcca9c19 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types @@ -14,49 +14,49 @@ var y: T = undefined; if (x === "foo") { >x === "foo" : boolean ->x : string +>x : "foo" | "bar" | "baz" | string >"foo" : "foo" let a = x; ->a : string ->x : string +>a : "foo" | string +>x : "foo" | string } else if (x !== "bar") { >x !== "bar" : boolean ->x : string +>x : "bar" | "baz" | string >"bar" : "bar" let b = x || y; >b : string >x || y : string ->x : string ->y : string +>x : "baz" | string +>y : string | "foo" | "bar" | "baz" } else { let c = x; ->c : string ->x : string +>c : "bar" | string +>x : "bar" | string let d = y; ->d : string ->y : string +>d : string | "foo" | "bar" | "baz" +>y : string | "foo" | "bar" | "baz" let e: (typeof x) | (typeof y) = c || d; ->e : string ->x : string ->y : string +>e : "bar" | string | "foo" | "baz" +>x : "bar" | string +>y : string | "foo" | "bar" | "baz" >c || d : string ->c : string ->d : string +>c : "bar" | string +>d : string | "foo" | "bar" | "baz" } x = y; ->x = y : string +>x = y : string | "foo" | "bar" | "baz" >x : "foo" | "bar" | "baz" | string ->y : string +>y : string | "foo" | "bar" | "baz" y = x; ->y = x : string +>y = x : "foo" | "bar" | "baz" | string >y : string | "foo" | "bar" | "baz" ->x : string +>x : "foo" | "bar" | "baz" | string diff --git a/tests/baselines/reference/typeGuardEnums.types b/tests/baselines/reference/typeGuardEnums.types index 255326e66d26e..f106896c52fe7 100644 --- a/tests/baselines/reference/typeGuardEnums.types +++ b/tests/baselines/reference/typeGuardEnums.types @@ -27,7 +27,7 @@ else { if (typeof x !== "number") { >typeof x !== "number" : boolean >typeof x : string ->x : number | string +>x : number | E | V | string >"number" : "number" x; // string @@ -35,6 +35,6 @@ if (typeof x !== "number") { } else { x; // number|E|V ->x : number +>x : number | E | V } diff --git a/tests/baselines/reference/typeGuardOfFormInstanceOf.types b/tests/baselines/reference/typeGuardOfFormInstanceOf.types index 608e827f47995..98f627866a86a 100644 --- a/tests/baselines/reference/typeGuardOfFormInstanceOf.types +++ b/tests/baselines/reference/typeGuardOfFormInstanceOf.types @@ -204,7 +204,7 @@ if (ctor5 instanceof C1) { ctor5.p1; // C1 >ctor5.p1 : string ->ctor5 : C1 +>ctor5 : C1 | D1 >p1 : string } else { From b5a5758169c44060277ee2ac181cadad4c7f9dae Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 16 Jul 2016 07:46:28 -0700 Subject: [PATCH 25/55] No subtype reduction in createUnionOrIntersectionProperty for performance --- src/compiler/checker.ts | 14 ++++++++++++-- src/harness/loggedIO.ts | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 996ad2586dfc3..47fa9918d2be3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4327,7 +4327,7 @@ namespace ts { result.containingType = containingType; result.declarations = declarations; result.isReadonly = isReadonly; - result.type = containingType.flags & TypeFlags.Union ? getUnionType(propTypes) : getIntersectionType(propTypes); + result.type = containingType.flags & TypeFlags.Union ? getUnionType(propTypes, /*noSubtypeReduction*/ true) : getIntersectionType(propTypes); return result; } @@ -5148,7 +5148,8 @@ namespace ts { if (type.flags & TypeFlags.Null) typeSet.containsNull = true; if (!(type.flags & TypeFlags.ContainsWideningType)) typeSet.containsNonWideningType = true; } - else if (type !== neverType && !contains(typeSet, type)) { + else if (type !== neverType && !contains(typeSet, type) && + !(type.flags & TypeFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && containsIdenticalType(typeSet, type))) { typeSet.push(type); } } @@ -5161,6 +5162,15 @@ namespace ts { } } + function containsIdenticalType(types: Type[], type: Type) { + for (const t of types) { + if (isTypeIdenticalTo(t, type)) { + return true; + } + } + return false; + } + function isSubtypeOfAny(candidate: Type, types: Type[]): boolean { for (let i = 0, len = types.length; i < len; i++) { if (candidate !== types[i] && isTypeSubtypeOf(candidate, types[i])) { diff --git a/src/harness/loggedIO.ts b/src/harness/loggedIO.ts index 25e982cf6804e..33a46450a178a 100644 --- a/src/harness/loggedIO.ts +++ b/src/harness/loggedIO.ts @@ -209,7 +209,7 @@ namespace Playback { memoize(path => findResultByFields(replayLog.pathsResolved, { path }, !ts.isRootedDiskPath(ts.normalizeSlashes(path)) && replayLog.currentDirectory ? replayLog.currentDirectory + "/" + path : ts.normalizeSlashes(path)))); wrapper.readFile = recordReplay(wrapper.readFile, underlying)( - path => { + (path: string) => { const result = underlying.readFile(path); const logEntry = { path, codepage: 0, result: { contents: result, codepage: 0 } }; recordLog.filesRead.push(logEntry); From 01a33f707c3654ca1a3a2c00eca89aadf5af5e2f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 16 Jul 2016 07:47:03 -0700 Subject: [PATCH 26/55] Accept new baselines --- .../reference/unionTypeWithRecursiveSubtypeReduction1.types | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/unionTypeWithRecursiveSubtypeReduction1.types b/tests/baselines/reference/unionTypeWithRecursiveSubtypeReduction1.types index caaa02b7b5391..f609301c19c2f 100644 --- a/tests/baselines/reference/unionTypeWithRecursiveSubtypeReduction1.types +++ b/tests/baselines/reference/unionTypeWithRecursiveSubtypeReduction1.types @@ -39,7 +39,7 @@ var t: Class | Property; >Property : Property t.parent; ->t.parent : Namespace | Class +>t.parent : Namespace | Module | Class >t : Class | Property ->parent : Namespace | Class +>parent : Namespace | Module | Class From 614d171a21b5c9e95e60a6c62ecec3e97879de6f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 16 Jul 2016 14:45:38 -0700 Subject: [PATCH 27/55] Include type parameter constrains in literal type context determination --- src/compiler/checker.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 47fa9918d2be3..bbe74231f5a1e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13007,8 +13007,22 @@ namespace ts { false; } + function hasLiteralContextualType(node: Expression) { + const contextualType = getContextualType(node); + if (!contextualType) { + return false; + } + if (contextualType.flags & TypeFlags.TypeParameter) { + const apparentType = getApparentTypeOfTypeParameter(contextualType); + if (apparentType.flags & (TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.BooleanLike)) { + return true; + } + } + return isLiteralUnionType(contextualType); + } + function isLiteralTypeContext(node: Expression) { - return isLiteralTypeLocation(node) || isLiteralUnionType(getContextualType(node) || unknownType); + return isLiteralTypeLocation(node) || hasLiteralContextualType(node); } function checkLiteralExpression(node: Expression): Type { From a96d38ef960f65e9d85364b6c79af6594661b03d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 16 Jul 2016 14:46:10 -0700 Subject: [PATCH 28/55] Accept new baselines --- .../assignmentNonObjectTypeConstraints.types | 6 ++-- ...meterConstrainedToOuterTypeParameter.types | 6 ++-- .../derivedGenericClassWithAny.errors.txt | 8 ++--- ...meterConstrainedToOuterTypeParameter.types | 6 ++-- ...ypesAsTypeParameterConstraint02.errors.txt | 15 --------- ...LiteralTypesAsTypeParameterConstraint02.js | 4 +-- ...alTypesAsTypeParameterConstraint02.symbols | 25 ++++++++++++++ ...eralTypesAsTypeParameterConstraint02.types | 33 +++++++++++++++++++ 8 files changed, 73 insertions(+), 30 deletions(-) delete mode 100644 tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.errors.txt create mode 100644 tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.symbols create mode 100644 tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.types diff --git a/tests/baselines/reference/assignmentNonObjectTypeConstraints.types b/tests/baselines/reference/assignmentNonObjectTypeConstraints.types index 94391e2ea5f32..e2c3176940d38 100644 --- a/tests/baselines/reference/assignmentNonObjectTypeConstraints.types +++ b/tests/baselines/reference/assignmentNonObjectTypeConstraints.types @@ -19,14 +19,14 @@ function foo(x: T) { foo(5); >foo(5) : void >foo : (x: T) => void ->5 : number +>5 : 5 foo(E.A); >foo(E.A) : void >foo : (x: T) => void ->E.A : E +>E.A : E.A >E : typeof E ->A : E +>A : E.A class A { a } >A : A diff --git a/tests/baselines/reference/callExpressionWithTypeParameterConstrainedToOuterTypeParameter.types b/tests/baselines/reference/callExpressionWithTypeParameterConstrainedToOuterTypeParameter.types index fe7d3a6ad089c..76b8a51370261 100644 --- a/tests/baselines/reference/callExpressionWithTypeParameterConstrainedToOuterTypeParameter.types +++ b/tests/baselines/reference/callExpressionWithTypeParameterConstrainedToOuterTypeParameter.types @@ -15,8 +15,8 @@ var i: I; >I : I var y = i(""); // y should be string ->y : string ->i("") : string +>y : "" +>i("") : "" >i : I ->"" : string +>"" : "" diff --git a/tests/baselines/reference/derivedGenericClassWithAny.errors.txt b/tests/baselines/reference/derivedGenericClassWithAny.errors.txt index ab28ccc9c8dc5..81e43f7d8fef7 100644 --- a/tests/baselines/reference/derivedGenericClassWithAny.errors.txt +++ b/tests/baselines/reference/derivedGenericClassWithAny.errors.txt @@ -2,8 +2,8 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(11,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(19,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,25): error TS2322: Type 'string' is not assignable to type 'T'. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(32,16): error TS2322: Type 'string' is not assignable to type 'T'. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(30,25): error TS2322: Type '""' is not assignable to type 'T'. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(32,16): error TS2322: Type '""' is not assignable to type 'T'. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericClassWithAny.ts(41,1): error TS2322: Type 'E' is not assignable to type 'C'. Types of property 'x' are incompatible. Type 'string' is not assignable to type 'number'. @@ -49,11 +49,11 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedGenericC ~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. ~~ -!!! error TS2322: Type 'string' is not assignable to type 'T'. +!!! error TS2322: Type '""' is not assignable to type 'T'. foo(): T { return ''; // error ~~ -!!! error TS2322: Type 'string' is not assignable to type 'T'. +!!! error TS2322: Type '""' is not assignable to type 'T'. } } diff --git a/tests/baselines/reference/newExpressionWithTypeParameterConstrainedToOuterTypeParameter.types b/tests/baselines/reference/newExpressionWithTypeParameterConstrainedToOuterTypeParameter.types index e07fa21fafec9..6d54119880233 100644 --- a/tests/baselines/reference/newExpressionWithTypeParameterConstrainedToOuterTypeParameter.types +++ b/tests/baselines/reference/newExpressionWithTypeParameterConstrainedToOuterTypeParameter.types @@ -15,8 +15,8 @@ var i: I; >I : I var y = new i(""); // y should be string ->y : string ->new i("") : string +>y : "" +>new i("") : "" >i : I ->"" : string +>"" : "" diff --git a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.errors.txt b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.errors.txt deleted file mode 100644 index ed6450ad3293f..0000000000000 --- a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTypeParameterConstraint02.ts(6,13): error TS2345: Argument of type '(y: "foo" | "bar") => string' is not assignable to parameter of type '(x: "foo") => "foo"'. - Type 'string' is not assignable to type '"foo"'. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTypeParameterConstraint02.ts (1 errors) ==== - - function foo(f: (x: T) => T) { - return f; - } - - let f = foo((y: "foo" | "bar") => y === "foo" ? y : "foo"); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(y: "foo" | "bar") => string' is not assignable to parameter of type '(x: "foo") => "foo"'. -!!! error TS2345: Type 'string' is not assignable to type '"foo"'. - let fResult = f("foo"); \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.js b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.js index c024ac6bc43b2..173e74a6eef86 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.js +++ b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.js @@ -17,5 +17,5 @@ var fResult = f("foo"); //// [stringLiteralTypesAsTypeParameterConstraint02.d.ts] declare function foo(f: (x: T) => T): (x: T) => T; -declare let f: any; -declare let fResult: any; +declare let f: (x: "foo") => "foo"; +declare let fResult: "foo"; diff --git a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.symbols b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.symbols new file mode 100644 index 0000000000000..1c5eb4577887e --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTypeParameterConstraint02.ts === + +function foo(f: (x: T) => T) { +>foo : Symbol(foo, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 0, 0)) +>T : Symbol(T, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 1, 13)) +>f : Symbol(f, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 1, 30)) +>x : Symbol(x, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 1, 34)) +>T : Symbol(T, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 1, 13)) +>T : Symbol(T, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 1, 13)) + + return f; +>f : Symbol(f, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 1, 30)) +} + +let f = foo((y: "foo" | "bar") => y === "foo" ? y : "foo"); +>f : Symbol(f, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 5, 3)) +>foo : Symbol(foo, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 0, 0)) +>y : Symbol(y, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 5, 13)) +>y : Symbol(y, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 5, 13)) +>y : Symbol(y, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 5, 13)) + +let fResult = f("foo"); +>fResult : Symbol(fResult, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 6, 3)) +>f : Symbol(f, Decl(stringLiteralTypesAsTypeParameterConstraint02.ts, 5, 3)) + diff --git a/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.types b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.types new file mode 100644 index 0000000000000..3a1b8fdc05c83 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypesAsTypeParameterConstraint02.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTypeParameterConstraint02.ts === + +function foo(f: (x: T) => T) { +>foo : (f: (x: T) => T) => (x: T) => T +>T : T +>f : (x: T) => T +>x : T +>T : T +>T : T + + return f; +>f : (x: T) => T +} + +let f = foo((y: "foo" | "bar") => y === "foo" ? y : "foo"); +>f : (x: "foo") => "foo" +>foo((y: "foo" | "bar") => y === "foo" ? y : "foo") : (x: "foo") => "foo" +>foo : (f: (x: T) => T) => (x: T) => T +>(y: "foo" | "bar") => y === "foo" ? y : "foo" : (y: "foo" | "bar") => "foo" +>y : "foo" | "bar" +>y === "foo" ? y : "foo" : "foo" +>y === "foo" : boolean +>y : "foo" | "bar" +>"foo" : "foo" +>y : "foo" +>"foo" : "foo" + +let fResult = f("foo"); +>fResult : "foo" +>f("foo") : "foo" +>f : (x: "foo") => "foo" +>"foo" : "foo" + From cb27e54ba76939e67ef2819e53e9978acff097a5 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 18 Jul 2016 11:15:19 -0700 Subject: [PATCH 29/55] Fix fourslash test --- .../fourslash/quickInfoDisplayPartsTypeParameterInFunction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInFunction.ts b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInFunction.ts index ff843b00db42a..2cbb50bbea7ea 100644 --- a/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInFunction.ts +++ b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterInFunction.ts @@ -114,4 +114,4 @@ verifyTypeParameter("U", getFunctionDisplay("foo2", /*instance*/ undefined, stri verifyParameter("a", "U", stringTypeDisplay); // Call -verifyFunctionDisplay("foo2", stringTypeDisplay); \ No newline at end of file +verifyFunctionDisplay("foo2", [{ text: "\"hello\"", kind: "stringLiteral" }]); \ No newline at end of file From c48cd4a93be6a7f993f8d3ff5010537ca52587ad Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 18 Jul 2016 13:16:11 -0700 Subject: [PATCH 30/55] Unify 'boolean' and 'true | false' --- src/compiler/checker.ts | 153 ++++++++++++++++++++++++++-------------- src/compiler/types.ts | 3 +- 2 files changed, 101 insertions(+), 55 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bbe74231f5a1e..c7983d634a550 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -108,15 +108,21 @@ namespace ts { isOptionalParameter }; + const tupleTypes: Map = {}; + const unionTypes: Map = {}; + const intersectionTypes: Map = {}; + const stringLiteralTypes: Map = {}; + const numericLiteralTypes: Map = {}; + const unknownSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "unknown"); const resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__"); const anyType = createIntrinsicType(TypeFlags.Any, "any"); const stringType = createIntrinsicType(TypeFlags.String, "string"); const numberType = createIntrinsicType(TypeFlags.Number, "number"); - const booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean"); const trueType = createIntrinsicType(TypeFlags.BooleanLiteral, "true"); const falseType = createIntrinsicType(TypeFlags.BooleanLiteral, "false"); + const booleanType = createBooleanType([trueType, falseType]); const esSymbolType = createIntrinsicType(TypeFlags.ESSymbol, "symbol"); const voidType = createIntrinsicType(TypeFlags.Void, "void"); const undefinedType = createIntrinsicType(TypeFlags.Undefined, "undefined"); @@ -196,14 +202,8 @@ namespace ts { let flowLoopCount = 0; let visitedFlowCount = 0; - const tupleTypes: Map = {}; - const unionTypes: Map = {}; - const intersectionTypes: Map = {}; - const stringLiteralTypes: Map = {}; - const numericLiteralTypes: Map = {}; const emptyStringType = getLiteralTypeForText(TypeFlags.StringLiteral, ""); const zeroType = getLiteralTypeForText(TypeFlags.NumberLiteral, "0"); - const trueFalseType = getUnionType([trueType, falseType]); const resolutionTargets: TypeSystemEntity[] = []; const resolutionResults: boolean[] = []; @@ -1547,6 +1547,13 @@ namespace ts { return type; } + function createBooleanType(trueFalseTypes: Type[]): IntrinsicType { + const type = getUnionType(trueFalseTypes, /*noSubtypeReduction*/ true); + type.flags |= TypeFlags.Boolean; + type.intrinsicName = "boolean"; + return type; + } + function createObjectType(kind: TypeFlags, symbol?: Symbol): ObjectType { const type = createType(kind); type.symbol = symbol; @@ -1921,6 +1928,19 @@ namespace ts { return result; } + function replaceTrueFalseWithBoolean(types: Type[]): Type[] { + if (contains(types, trueType) && contains(types, falseType)) { + const result: Type[] = []; + for (const t of types) { + if (t !== falseType) { + result.push(t === trueType ? booleanType : t); + } + } + return result; + } + return types; + } + function visibilityToString(flags: NodeFlags) { if (flags === NodeFlags.Private) { return "private"; @@ -2213,7 +2233,12 @@ namespace ts { if (flags & TypeFormatFlags.InElementType) { writePunctuation(writer, SyntaxKind.OpenParenToken); } - writeTypeList(type.types, type.flags & TypeFlags.Union ? SyntaxKind.BarToken : SyntaxKind.AmpersandToken); + if (type.flags & TypeFlags.Union) { + writeTypeList(replaceTrueFalseWithBoolean(type.types), SyntaxKind.BarToken); + } + else { + writeTypeList(type.types, SyntaxKind.AmpersandToken); + } if (flags & TypeFormatFlags.InElementType) { writePunctuation(writer, SyntaxKind.CloseParenToken); } @@ -5661,7 +5686,7 @@ namespace ts { if (type.flags & TypeFlags.Tuple) { return createTupleType(instantiateList((type).elementTypes, mapper, instantiateType)); } - if (type.flags & TypeFlags.Union) { + if (type.flags & TypeFlags.Union && !(type.flags & TypeFlags.Primitive)) { return getUnionType(instantiateList((type).types, mapper, instantiateType), /*noSubtypeReduction*/ true); } if (type.flags & TypeFlags.Intersection) { @@ -6070,10 +6095,10 @@ namespace ts { // Note that these checks are specifically ordered to produce correct results. if (source.flags & TypeFlags.Union) { if (relation === comparableRelation) { - result = someTypeRelatedToType(source as UnionType, target, reportErrors); + result = someTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive)); } else { - result = eachTypeRelatedToType(source as UnionType, target, reportErrors); + result = eachTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive)); } if (result) { @@ -6110,12 +6135,9 @@ namespace ts { } } if (target.flags & TypeFlags.Union) { - if (result = typeRelatedToSomeType(source, target, reportErrors && !(source.flags & TypeFlags.Primitive))) { + if (result = typeRelatedToSomeType(source, target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive))) { return result; } - if (source === booleanType && contains((target).types, trueType) && contains((target).types, falseType)) { - return Ternary.True; - } } } @@ -6969,7 +6991,9 @@ namespace ts { } function isUnitUnionType(type: Type): boolean { - return type.flags & TypeFlags.Union ? !forEach((type).types, t => !isUnitType(t)) : isUnitType(type); + return type.flags & TypeFlags.Boolean ? true : + type.flags & TypeFlags.Union ? !forEach((type).types, t => !isUnitType(t)) : + isUnitType(type); } function getBaseTypeOfUnitType(type: Type): Type { @@ -6981,10 +7005,6 @@ namespace ts { type; } - function isUnionWithTrueOrFalse(type: Type) { - return type.flags & TypeFlags.Union && (contains((type).types, trueType) || contains((type).types, falseType)); - } - /** * Check if a Type was written as a tuple type literal. * Prefer using isTupleLikeType() unless the use of `elementTypes` is required. @@ -7001,12 +7021,15 @@ namespace ts { return result; } + // Returns the String, Number, Boolean, StringLiteral, NumberLiteral, BooleanLiteral, Void, Undefined, or Null + // flags for the string, number, boolean, "", 0, false, void, undefined, or null types respectively. Returns + // no flags for all other types (including non-falsy literal types). function getFalsyFlags(type: Type): TypeFlags { - return type === emptyStringType ? TypeFlags.StringLiteral : - type === zeroType ? TypeFlags.NumberLiteral : - type === falseType ? TypeFlags.BooleanLiteral : - type.flags & TypeFlags.Union ? getFalsyFlagsOfTypes((type).types) : - type.flags & TypeFlags.AlwaysPossiblyFalsy; + 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.BooleanLiteral ? type === falseType ? TypeFlags.BooleanLiteral : 0 : + type.flags & TypeFlags.PossiblyFalsy; } function includeFalsyTypes(type: Type, flags: TypeFlags) { @@ -10403,8 +10426,11 @@ namespace ts { checkClassPropertyAccess(node, left, apparentType, prop); } - const propType = prop.flags & SymbolFlags.EnumMember && getParentOfSymbol(prop).flags & SymbolFlags.ConstEnum && - isLiteralTypeContext(node) ? getDeclaredTypeOfSymbol(prop) : getTypeOfSymbol(prop); + let propType = getTypeOfSymbol(prop); + if (prop.flags & SymbolFlags.EnumMember && getParentOfSymbol(prop).flags & SymbolFlags.ConstEnum && isLiteralContextForType(node, propType)) { + propType = getDeclaredTypeOfSymbol(prop); + } + // Only compute control flow type if this is a property access expression that isn't an // assignment target, and the referenced property was declared as a variable, property, // accessor, or optional method. @@ -12460,7 +12486,7 @@ namespace ts { function checkPrefixUnaryExpression(node: PrefixUnaryExpression): Type { const operandType = checkExpression(node.operand); - if (node.operator === SyntaxKind.MinusToken && node.operand.kind === SyntaxKind.NumericLiteral && isLiteralTypeContext(node)) { + if (node.operator === SyntaxKind.MinusToken && node.operand.kind === SyntaxKind.NumericLiteral && isLiteralContextForType(node, numberType)) { return getLiteralTypeForText(TypeFlags.NumberLiteral, "" + -(node.operand).text); } switch (node.operator) { @@ -12475,7 +12501,6 @@ namespace ts { const facts = getTypeFacts(operandType) & (TypeFacts.Truthy | TypeFacts.Falsy); return facts === TypeFacts.Truthy ? falseType : facts === TypeFacts.Falsy ? trueType : - isUnionWithTrueOrFalse(operandType) ? trueFalseType : booleanType; case SyntaxKind.PlusPlusToken: case SyntaxKind.MinusMinusToken: @@ -12866,7 +12891,7 @@ namespace ts { return checkInExpression(left, right, leftType, rightType); case SyntaxKind.AmpersandAmpersandToken: return getTypeFacts(leftType) & TypeFacts.Truthy ? - strictNullChecks ? includeFalsyTypes(rightType, getFalsyFlags(leftType)) : rightType : + includeFalsyTypes(rightType, getFalsyFlags(strictNullChecks ? leftType : getBaseTypeOfUnitType(rightType))) : leftType; case SyntaxKind.BarBarToken: return getTypeFacts(leftType) & TypeFacts.Falsy ? @@ -13000,45 +13025,64 @@ namespace ts { return getUnionType([type1, type2]); } - function isLiteralUnionType(type: Type): boolean { - return type.flags & TypeFlags.Literal ? true : - type.flags & TypeFlags.Enum ? (type.symbol.flags & SymbolFlags.EnumMember) !== 0 : - type.flags & TypeFlags.Union ? forEach((type).types, isLiteralUnionType) : - false; + function typeContainsEnumLiteral(type: Type, enumType: Type) { + if (type.flags & TypeFlags.Union) { + for (const t of (type).types) { + if (t.flags & TypeFlags.Enum && t.symbol.flags & SymbolFlags.EnumMember && t.symbol.parent === enumType.symbol) { + return true; + } + } + } + if (type.flags & TypeFlags.Enum) { + return type.symbol.flags & SymbolFlags.EnumMember && type.symbol.parent === enumType.symbol; + } + return false; } - function hasLiteralContextualType(node: Expression) { - const contextualType = getContextualType(node); - if (!contextualType) { - return false; + function isLiteralContextForType(node: Expression, type: Type) { + if (isLiteralTypeLocation(node)) { + return true; } - if (contextualType.flags & TypeFlags.TypeParameter) { - const apparentType = getApparentTypeOfTypeParameter(contextualType); - if (apparentType.flags & (TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.BooleanLike)) { - return true; + let contextualType = getContextualType(node); + if (contextualType) { + if (contextualType.flags & TypeFlags.TypeParameter) { + const apparentType = getApparentTypeOfTypeParameter(contextualType); + // If the type parameter is constrained to the base primitive type we're checking for, + // consider this a literal context. For example, given a type parameter 'T extends string', + // this causes us to infer string literal types for T. + if (type === apparentType) { + return true; + } + contextualType = apparentType; + } + if (type.flags & TypeFlags.String) { + return maybeTypeOfKind(contextualType, TypeFlags.StringLiteral); + } + if (type.flags & TypeFlags.Number) { + return maybeTypeOfKind(contextualType, TypeFlags.NumberLiteral); + } + if (type.flags & TypeFlags.Boolean) { + return maybeTypeOfKind(contextualType, TypeFlags.BooleanLiteral) && !isTypeAssignableTo(booleanType, contextualType); + } + if (type.flags & TypeFlags.Enum && type.symbol.flags & SymbolFlags.ConstEnum) { + return typeContainsEnumLiteral(contextualType, type); } } - return isLiteralUnionType(contextualType); - } - - function isLiteralTypeContext(node: Expression) { - return isLiteralTypeLocation(node) || hasLiteralContextualType(node); + return false; } function checkLiteralExpression(node: Expression): Type { if (node.kind === SyntaxKind.NumericLiteral) { checkGrammarNumericLiteral(node); } - const hasLiteralType = isLiteralTypeContext(node); switch (node.kind) { case SyntaxKind.StringLiteral: - return hasLiteralType ? getLiteralTypeForText(TypeFlags.StringLiteral, (node).text) : stringType; + return isLiteralContextForType(node, stringType) ? getLiteralTypeForText(TypeFlags.StringLiteral, (node).text) : stringType; case SyntaxKind.NumericLiteral: - return hasLiteralType ? getLiteralTypeForText(TypeFlags.NumberLiteral, (node).text) : numberType; + return isLiteralContextForType(node, numberType) ? getLiteralTypeForText(TypeFlags.NumberLiteral, (node).text) : numberType; case SyntaxKind.TrueKeyword: - return hasLiteralType ? trueType : booleanType; case SyntaxKind.FalseKeyword: - return hasLiteralType ? falseType : booleanType; + return isLiteralContextForType(node, booleanType) ? node.kind === SyntaxKind.TrueKeyword ? trueType : falseType : booleanType; } } @@ -18324,6 +18368,9 @@ namespace ts { } } + // The built-in boolean type is 'true | false', also mark 'false | true' as a boolean type + createBooleanType([falseType, trueType]); + // Setup global builtins addToSymbolTable(globals, builtinGlobals, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 8c1f3f0f9ed49..3d1962826d16c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2254,7 +2254,6 @@ namespace ts { /* @internal */ DefinitelyFalsy = StringLiteral | NumberLiteral | BooleanLiteral | Void | Undefined | Null, PossiblyFalsy = DefinitelyFalsy | String | Number | Boolean, - AlwaysPossiblyFalsy = String | Number | Boolean | Void | Undefined | Null, /* @internal */ Intrinsic = Any | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never, /* @internal */ @@ -2269,7 +2268,7 @@ namespace ts { // 'Narrowable' types are types where narrowing actually narrows. // This *should* be every type other than null, undefined, void, and never Narrowable = Any | StructuredType | TypeParameter | StringLike | NumberLike | BooleanLike | ESSymbol, - NotUnionOrUnit = Any | String | Number | Boolean | ESSymbol | ObjectType, + NotUnionOrUnit = Any | String | Number | ESSymbol | ObjectType, /* @internal */ RequiresWidening = ContainsWideningType | ContainsObjectLiteral, /* @internal */ From 32f4cbb58a85a73058c84a41eed65bedf646a56a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 18 Jul 2016 13:16:45 -0700 Subject: [PATCH 31/55] Accept new baselines --- .../assignmentNonObjectTypeConstraints.types | 4 +- .../reference/booleanLiteralTypes1.types | 92 +++++++++---------- .../reference/booleanLiteralTypes2.types | 86 ++++++++--------- ...torWithIncompleteTypeAnnotation.errors.txt | 19 +++- .../contextualTypeWithTuple.errors.txt | 4 +- .../controlFlowBinaryOrExpression.types | 2 +- .../reference/controlFlowIfStatement.types | 2 +- .../controlFlowIterationErrors.errors.txt | 8 +- .../reference/controlFlowWhileStatement.types | 4 +- .../genericCallWithTupleType.errors.txt | 4 +- tests/baselines/reference/literalTypes1.types | 4 +- .../logicalAndOperatorStrictMode.types | 2 +- .../logicalAndOperatorWithEveryType.types | 2 +- .../logicalOrOperatorWithEveryType.types | 32 +++---- .../reference/strictNullLogicalAndOr.types | 2 +- ...ngLiteralTypesWithVariousOperators01.types | 4 +- ...itchCaseWithIntersectionTypes01.errors.txt | 2 - .../reference/typeGuardFunction.types | 2 +- .../reference/typeGuardNesting.types | 4 +- ...peGuardsInRightOperandOfOrOrOperator.types | 16 ++-- 20 files changed, 151 insertions(+), 144 deletions(-) diff --git a/tests/baselines/reference/assignmentNonObjectTypeConstraints.types b/tests/baselines/reference/assignmentNonObjectTypeConstraints.types index e2c3176940d38..26c0b1724435e 100644 --- a/tests/baselines/reference/assignmentNonObjectTypeConstraints.types +++ b/tests/baselines/reference/assignmentNonObjectTypeConstraints.types @@ -24,9 +24,9 @@ foo(5); foo(E.A); >foo(E.A) : void >foo : (x: T) => void ->E.A : E.A +>E.A : E >E : typeof E ->A : E.A +>A : E class A { a } >A : A diff --git a/tests/baselines/reference/booleanLiteralTypes1.types b/tests/baselines/reference/booleanLiteralTypes1.types index 5e987b105b501..3ea81df09c385 100644 --- a/tests/baselines/reference/booleanLiteralTypes1.types +++ b/tests/baselines/reference/booleanLiteralTypes1.types @@ -1,11 +1,11 @@ === tests/cases/conformance/types/literal/booleanLiteralTypes1.ts === type A1 = true | false; ->A1 : true | false +>A1 : boolean >true : true >false : false type A2 = false | true; ->A2 : false | true +>A2 : boolean >false : false >true : true @@ -13,67 +13,67 @@ function f1() { >f1 : () => void var a: A1; ->a : true | false ->A1 : true | false +>a : boolean +>A1 : boolean var a: A2; ->a : true | false ->A2 : false | true +>a : boolean +>A2 : boolean var a: true | false; ->a : true | false +>a : boolean >true : true >false : false var a: false | true; ->a : true | false +>a : boolean >false : false >true : true } function f2(a: true | false, b: boolean) { ->f2 : (a: true | false, b: boolean) => void ->a : true | false +>f2 : (a: boolean, b: boolean) => void +>a : boolean >true : true >false : false >b : boolean a = b; >a = b : boolean ->a : true | false +>a : boolean >b : boolean b = a; ->b = a : true | false +>b = a : boolean >b : boolean ->a : true | false +>a : boolean } function f3(a: true | false, b: true | false) { ->f3 : (a: true | false, b: true | false) => void ->a : true | false +>f3 : (a: boolean, b: boolean) => void +>a : boolean >true : true >false : false ->b : true | false +>b : boolean >true : true >false : false var x = a || b; ->x : true | false ->a || b : true | false ->a : true | false ->b : true | false +>x : boolean +>a || b : boolean +>a : boolean +>b : boolean var x = a && b; ->x : true | false ->a && b : true | false ->a : true | false ->b : true | false +>x : boolean +>a && b : boolean +>a : boolean +>b : boolean var x = !a; ->x : true | false ->!a : true | false ->a : true | false +>x : boolean +>!a : boolean +>a : boolean } function f4(t: true, f: false) { @@ -96,8 +96,8 @@ function f4(t: true, f: false) { >t : true var x3 = t || f; ->x3 : true | false ->t || f : true | false +>x3 : boolean +>t || f : boolean >t : true >f : false @@ -166,13 +166,13 @@ function assertNever(x: never): never { } function f10(x: true | false) { ->f10 : (x: true | false) => string ->x : true | false +>f10 : (x: boolean) => string +>x : boolean >true : true >false : false switch (x) { ->x : true | false +>x : boolean case true: return "true"; >true : true @@ -185,13 +185,13 @@ function f10(x: true | false) { } function f11(x: true | false) { ->f11 : (x: true | false) => string ->x : true | false +>f11 : (x: boolean) => string +>x : boolean >true : true >false : false switch (x) { ->x : true | false +>x : boolean case true: return "true"; >true : true @@ -208,32 +208,32 @@ function f11(x: true | false) { } function f12(x: true | false) { ->f12 : (x: true | false) => void ->x : true | false +>f12 : (x: boolean) => void +>x : boolean >true : true >false : false if (x) { ->x : true | false +>x : boolean x; >x : true } else { x; ->x : true | false +>x : boolean } } function f13(x: true | false) { ->f13 : (x: true | false) => void ->x : true | false +>f13 : (x: boolean) => void +>x : boolean >true : true >false : false if (x === true) { >x === true : boolean ->x : true | false +>x : boolean >true : true x; @@ -264,9 +264,9 @@ function f20(x: Item) { >Item : { kind: true; a: string; } | { kind: false; b: string; } switch (x.kind) { ->x.kind : true | false +>x.kind : boolean >x : { kind: true; a: string; } | { kind: false; b: string; } ->kind : true | false +>kind : boolean case true: return x.a; >true : true @@ -288,9 +288,9 @@ function f21(x: Item) { >Item : { kind: true; a: string; } | { kind: false; b: string; } switch (x.kind) { ->x.kind : true | false +>x.kind : boolean >x : { kind: true; a: string; } | { kind: false; b: string; } ->kind : true | false +>kind : boolean case true: return x.a; >true : true diff --git a/tests/baselines/reference/booleanLiteralTypes2.types b/tests/baselines/reference/booleanLiteralTypes2.types index a1d7ee2d36fab..7b6d16c35d2e2 100644 --- a/tests/baselines/reference/booleanLiteralTypes2.types +++ b/tests/baselines/reference/booleanLiteralTypes2.types @@ -1,12 +1,12 @@ === tests/cases/conformance/types/literal/booleanLiteralTypes2.ts === type A1 = true | false; ->A1 : true | false +>A1 : boolean >true : true >false : false type A2 = false | true; ->A2 : false | true +>A2 : boolean >false : false >true : true @@ -14,67 +14,67 @@ function f1() { >f1 : () => void var a: A1; ->a : true | false ->A1 : true | false +>a : boolean +>A1 : boolean var a: A2; ->a : true | false ->A2 : false | true +>a : boolean +>A2 : boolean var a: true | false; ->a : true | false +>a : boolean >true : true >false : false var a: false | true; ->a : true | false +>a : boolean >false : false >true : true } function f2(a: true | false, b: boolean) { ->f2 : (a: true | false, b: boolean) => void ->a : true | false +>f2 : (a: boolean, b: boolean) => void +>a : boolean >true : true >false : false >b : boolean a = b; >a = b : boolean ->a : true | false +>a : boolean >b : boolean b = a; ->b = a : true | false +>b = a : boolean >b : boolean ->a : true | false +>a : boolean } function f3(a: true | false, b: true | false) { ->f3 : (a: true | false, b: true | false) => void ->a : true | false +>f3 : (a: boolean, b: boolean) => void +>a : boolean >true : true >false : false ->b : true | false +>b : boolean >true : true >false : false var x = a || b; ->x : true | false ->a || b : true | false ->a : true | false ->b : true | false +>x : boolean +>a || b : boolean +>a : boolean +>b : boolean var x = a && b; ->x : true | false ->a && b : true | false ->a : true | false ->b : true | false +>x : boolean +>a && b : boolean +>a : boolean +>b : boolean var x = !a; ->x : true | false ->!a : true | false ->a : false | true +>x : boolean +>!a : boolean +>a : boolean } function f4(t: true, f: false) { @@ -167,13 +167,13 @@ function assertNever(x: never): never { } function f10(x: true | false) { ->f10 : (x: true | false) => string ->x : true | false +>f10 : (x: boolean) => string +>x : boolean >true : true >false : false switch (x) { ->x : true | false +>x : boolean case true: return "true"; >true : true @@ -186,13 +186,13 @@ function f10(x: true | false) { } function f11(x: true | false) { ->f11 : (x: true | false) => string ->x : true | false +>f11 : (x: boolean) => string +>x : boolean >true : true >false : false switch (x) { ->x : true | false +>x : boolean case true: return "true"; >true : true @@ -209,13 +209,13 @@ function f11(x: true | false) { } function f12(x: true | false) { ->f12 : (x: true | false) => void ->x : true | false +>f12 : (x: boolean) => void +>x : boolean >true : true >false : false if (x) { ->x : true | false +>x : boolean x; >x : true @@ -227,14 +227,14 @@ function f12(x: true | false) { } function f13(x: true | false) { ->f13 : (x: true | false) => void ->x : true | false +>f13 : (x: boolean) => void +>x : boolean >true : true >false : false if (x === true) { >x === true : boolean ->x : true | false +>x : boolean >true : true x; @@ -265,9 +265,9 @@ function f20(x: Item) { >Item : { kind: true; a: string; } | { kind: false; b: string; } switch (x.kind) { ->x.kind : true | false +>x.kind : boolean >x : { kind: true; a: string; } | { kind: false; b: string; } ->kind : true | false +>kind : boolean case true: return x.a; >true : true @@ -289,9 +289,9 @@ function f21(x: Item) { >Item : { kind: true; a: string; } | { kind: false; b: string; } switch (x.kind) { ->x.kind : true | false +>x.kind : boolean >x : { kind: true; a: string; } | { kind: false; b: string; } ->kind : true | false +>kind : boolean case true: return x.a; >true : true diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index b9804b1b6dbcb..20f4ac1a33582 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -12,12 +12,12 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(32,18): error TS tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(35,17): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(35,26): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(35,28): error TS2304: Cannot find name 'bfs'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(36,21): error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(36,21): error TS2365: Operator '!=' cannot be applied to types 'boolean' and '0'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(39,17): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(41,28): error TS2304: Cannot find name 'bfs'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(41,41): error TS1005: ';' expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(41,45): error TS1002: Unterminated string literal. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(42,21): error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(42,21): error TS2365: Operator '!=' cannot be applied to types 'boolean' and '0'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(48,17): error TS2304: Cannot find name 'console'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(50,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(54,13): error TS2304: Cannot find name 'console'. @@ -38,6 +38,9 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(160,30): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(160,31): error TS2304: Cannot find name 'Property'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(167,13): error TS2365: Operator '+=' cannot be applied to types 'number' and 'void'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(181,40): error TS2447: The '^' operator is not allowed for boolean types. Consider using '!==' instead. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(182,13): error TS2322: Type 'boolean' is not assignable to type 'true | number'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(184,13): error TS2322: Type 'boolean' is not assignable to type 'true | number'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(192,13): error TS2322: Type 'boolean' is not assignable to type 'true | number'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(206,28): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(214,16): error TS2304: Cannot find name 'bool'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(219,10): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. @@ -83,7 +86,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(260,55): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(262,1): error TS1128: Declaration or statement expected. -==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (83 errors) ==== +==== tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts (86 errors) ==== declare module "fs" { export class File { @@ -152,7 +155,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(262,1): error TS !!! error TS2304: Cannot find name 'bfs'. if (retValue != 0) { ~~~~~~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. +!!! error TS2365: Operator '!=' cannot be applied to types 'boolean' and '0'. return 1 && } @@ -168,7 +171,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(262,1): error TS !!! error TS1002: Unterminated string literal. if (retValue != 0) { ~~~~~~~~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types 'boolean' and 'number'. +!!! error TS2365: Operator '!=' cannot be applied to types 'boolean' and '0'. return 1; } @@ -349,8 +352,12 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(262,1): error TS ~~~~~~~~~~~~ !!! error TS2447: The '^' operator is not allowed for boolean types. Consider using '!==' instead. b = !b;/*!*/ + ~ +!!! error TS2322: Type 'boolean' is not assignable to type 'true | number'. i = ~i;/*~i*/ b = i < (i - 1) && (i + 1) > i;/*< && >*/ + ~ +!!! error TS2322: Type 'boolean' is not assignable to type 'true | number'. var f = true ? 1 : 0;/*? :*/ // YES : i++;/*++*/ i--;/*--*/ @@ -359,6 +366,8 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(262,1): error TS i = i >> 5;/*>>*/ var j = i; b = i == j && i != j && i <= j && i >= j;/*= == && != <= >=*/ + ~ +!!! error TS2322: Type 'boolean' is not assignable to type 'true | number'. i += 5.0;/*+=*/ i -= i;/*-=*/ i *= i;/**=*/ diff --git a/tests/baselines/reference/contextualTypeWithTuple.errors.txt b/tests/baselines/reference/contextualTypeWithTuple.errors.txt index a2d3b224ddc29..d0091aa1e22b8 100644 --- a/tests/baselines/reference/contextualTypeWithTuple.errors.txt +++ b/tests/baselines/reference/contextualTypeWithTuple.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(3,5): error TS232 Types of property 'pop' are incompatible. Type '() => number | string | boolean' is not assignable to type '() => number | string'. Type 'number | string | boolean' is not assignable to type 'number | string'. - Type 'boolean' is not assignable to type 'number | string'. + Type 'true' is not assignable to type 'number | string'. tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(15,1): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'. tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(18,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]'. Types of property '0' are incompatible. @@ -32,7 +32,7 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS23 !!! error TS2322: Types of property 'pop' are incompatible. !!! error TS2322: Type '() => number | string | boolean' is not assignable to type '() => number | string'. !!! error TS2322: Type 'number | string | boolean' is not assignable to type 'number | string'. -!!! error TS2322: Type 'boolean' is not assignable to type 'number | string'. +!!! error TS2322: Type 'true' is not assignable to type 'number | string'. var numStrBoolTuple: [number, string, boolean] = [5, "foo", true]; var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5]; var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]]; diff --git a/tests/baselines/reference/controlFlowBinaryOrExpression.types b/tests/baselines/reference/controlFlowBinaryOrExpression.types index 5f9d02b4443b6..bf2a55e24e743 100644 --- a/tests/baselines/reference/controlFlowBinaryOrExpression.types +++ b/tests/baselines/reference/controlFlowBinaryOrExpression.types @@ -25,7 +25,7 @@ x = ""; >"" : string cond || (x = 0); ->cond || (x = 0) : boolean | number +>cond || (x = 0) : true | number >cond : boolean >(x = 0) : number >x = 0 : number diff --git a/tests/baselines/reference/controlFlowIfStatement.types b/tests/baselines/reference/controlFlowIfStatement.types index dc07e23275f0f..716491ea58baa 100644 --- a/tests/baselines/reference/controlFlowIfStatement.types +++ b/tests/baselines/reference/controlFlowIfStatement.types @@ -20,7 +20,7 @@ if (x /* RegExp */, (x = true)) { >true : boolean x; // boolean ->x : boolean +>x : true x = ""; >x = "" : string diff --git a/tests/baselines/reference/controlFlowIterationErrors.errors.txt b/tests/baselines/reference/controlFlowIterationErrors.errors.txt index 737a9e9557bfb..1f090ccd35fbb 100644 --- a/tests/baselines/reference/controlFlowIterationErrors.errors.txt +++ b/tests/baselines/reference/controlFlowIterationErrors.errors.txt @@ -8,10 +8,10 @@ tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(46,17): error Type 'string' is not assignable to type 'number'. tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(77,13): error TS7022: 'y' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(77,26): error TS2345: Argument of type 'string | number | boolean' is not assignable to parameter of type 'string | number'. - Type 'boolean' is not assignable to type 'string | number'. + Type 'true' is not assignable to type 'string | number'. tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(88,13): error TS7022: 'y' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(88,26): error TS2345: Argument of type 'string | number | boolean' is not assignable to parameter of type 'string | number'. - Type 'boolean' is not assignable to type 'string | number'. + Type 'true' is not assignable to type 'string | number'. ==== tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts (8 errors) ==== @@ -108,7 +108,7 @@ tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(88,26): error !!! error TS7022: 'y' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. ~ !!! error TS2345: Argument of type 'string | number | boolean' is not assignable to parameter of type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. +!!! error TS2345: Type 'true' is not assignable to type 'string | number'. x = y + 1; x; } @@ -124,7 +124,7 @@ tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts(88,26): error !!! error TS7022: 'y' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. ~ !!! error TS2345: Argument of type 'string | number | boolean' is not assignable to parameter of type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. +!!! error TS2345: Type 'true' is not assignable to type 'string | number'. x = y + 1; x; } diff --git a/tests/baselines/reference/controlFlowWhileStatement.types b/tests/baselines/reference/controlFlowWhileStatement.types index 33f5d455f9beb..5ab48e02e2b8e 100644 --- a/tests/baselines/reference/controlFlowWhileStatement.types +++ b/tests/baselines/reference/controlFlowWhileStatement.types @@ -148,7 +148,7 @@ function f() { >cond : boolean if (cond) { ->cond : boolean +>cond : true x = 42; >x = 42 : number @@ -158,7 +158,7 @@ function f() { break; } if (cond) { ->cond : boolean +>cond : true x = true; >x = true : boolean diff --git a/tests/baselines/reference/genericCallWithTupleType.errors.txt b/tests/baselines/reference/genericCallWithTupleType.errors.txt index 24e0505d0097b..0194dc61311ee 100644 --- a/tests/baselines/reference/genericCallWithTupleType.errors.txt +++ b/tests/baselines/reference/genericCallWithTupleType.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTup Types of property 'pop' are incompatible. Type '() => string | number | boolean' is not assignable to type '() => string | number'. Type 'string | number | boolean' is not assignable to type 'string | number'. - Type 'boolean' is not assignable to type 'string | number'. + Type 'true' is not assignable to type 'string | number'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(14,1): error TS2322: Type '{ a: string; }' is not assignable to type 'string | number'. Type '{ a: string; }' is not assignable to type 'number'. tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTupleType.ts(22,1): error TS2322: Type '[number, string]' is not assignable to type '[string, number]'. @@ -33,7 +33,7 @@ tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithTup !!! error TS2322: Types of property 'pop' are incompatible. !!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => string | number'. !!! error TS2322: Type 'string | number | boolean' is not assignable to type 'string | number'. -!!! error TS2322: Type 'boolean' is not assignable to type 'string | number'. +!!! error TS2322: Type 'true' is not assignable to type 'string | number'. var e3 = i1.tuple1[2]; // {} i1.tuple1[3] = { a: "string" }; ~~~~~~~~~~~~ diff --git a/tests/baselines/reference/literalTypes1.types b/tests/baselines/reference/literalTypes1.types index 1428ce601a0da..e7a44f8d753fe 100644 --- a/tests/baselines/reference/literalTypes1.types +++ b/tests/baselines/reference/literalTypes1.types @@ -180,7 +180,7 @@ function f5(x: string | number | boolean) { >true : true x; ->x : boolean +>x : true break; case "hello": @@ -195,6 +195,6 @@ function f5(x: string | number | boolean) { break; default: x; ->x : string | number | boolean +>x : string | number | false } } diff --git a/tests/baselines/reference/logicalAndOperatorStrictMode.types b/tests/baselines/reference/logicalAndOperatorStrictMode.types index 61e3c4c6301d9..c47c54ad1b7a0 100644 --- a/tests/baselines/reference/logicalAndOperatorStrictMode.types +++ b/tests/baselines/reference/logicalAndOperatorStrictMode.types @@ -203,7 +203,7 @@ const b4 = b && b; >b4 : boolean >b && b : boolean >b : boolean ->b : boolean +>b : true const b5 = b && v; >b5 : void | false diff --git a/tests/baselines/reference/logicalAndOperatorWithEveryType.types b/tests/baselines/reference/logicalAndOperatorWithEveryType.types index 99675f42f6372..25771ede18621 100644 --- a/tests/baselines/reference/logicalAndOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalAndOperatorWithEveryType.types @@ -103,7 +103,7 @@ var rb2 = a2 && a2; >rb2 : boolean >a2 && a2 : boolean >a2 : boolean ->a2 : boolean +>a2 : true var rb3 = a3 && a2; >rb3 : boolean diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.types b/tests/baselines/reference/logicalOrOperatorWithEveryType.types index 88f24d02dae18..4a8f5e6a3e173 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.types @@ -163,8 +163,8 @@ var rc1 = a1 || a3; // any || number is any >a3 : number var rc2 = a2 || a3; // boolean || number is boolean | number ->rc2 : boolean | number ->a2 || a3 : boolean | number +>rc2 : true | number +>a2 || a3 : true | number >a2 : boolean >a3 : number @@ -223,8 +223,8 @@ var rd1 = a1 || a4; // any || string is any >a4 : string var rd2 = a2 || a4; // boolean || string is boolean | string ->rd2 : boolean | string ->a2 || a4 : boolean | string +>rd2 : true | string +>a2 || a4 : true | string >a2 : boolean >a4 : string @@ -283,8 +283,8 @@ var re1 = a1 || a5; // any || void is any >a5 : void var re2 = a2 || a5; // boolean || void is boolean | void ->re2 : boolean | void ->a2 || a5 : boolean | void +>re2 : true | void +>a2 || a5 : true | void >a2 : boolean >a5 : void @@ -343,8 +343,8 @@ var rg1 = a1 || a6; // any || enum is any >a6 : E var rg2 = a2 || a6; // boolean || enum is boolean | enum ->rg2 : boolean | E ->a2 || a6 : boolean | E +>rg2 : true | E +>a2 || a6 : true | E >a2 : boolean >a6 : E @@ -403,8 +403,8 @@ var rh1 = a1 || a7; // any || object is any >a7 : { a: string; } var rh2 = a2 || a7; // boolean || object is boolean | object ->rh2 : boolean | { a: string; } ->a2 || a7 : boolean | { a: string; } +>rh2 : true | { a: string; } +>a2 || a7 : true | { a: string; } >a2 : boolean >a7 : { a: string; } @@ -463,8 +463,8 @@ var ri1 = a1 || a8; // any || array is any >a8 : string[] var ri2 = a2 || a8; // boolean || array is boolean | array ->ri2 : boolean | string[] ->a2 || a8 : boolean | string[] +>ri2 : true | string[] +>a2 || a8 : true | string[] >a2 : boolean >a8 : string[] @@ -523,8 +523,8 @@ var rj1 = a1 || null; // any || null is any >null : null var rj2 = a2 || null; // boolean || null is boolean ->rj2 : boolean ->a2 || null : boolean +>rj2 : true +>a2 || null : true >a2 : boolean >null : null @@ -583,8 +583,8 @@ var rf1 = a1 || undefined; // any || undefined is any >undefined : undefined var rf2 = a2 || undefined; // boolean || undefined is boolean ->rf2 : boolean ->a2 || undefined : boolean +>rf2 : true +>a2 || undefined : true >a2 : boolean >undefined : undefined diff --git a/tests/baselines/reference/strictNullLogicalAndOr.types b/tests/baselines/reference/strictNullLogicalAndOr.types index b82496845b768..ac02ec1378b30 100644 --- a/tests/baselines/reference/strictNullLogicalAndOr.types +++ b/tests/baselines/reference/strictNullLogicalAndOr.types @@ -44,7 +44,7 @@ function sq(n?: number): number { >n*n : number >n : number >n : number ->0 : 0 +>0 : number return r; >r : number diff --git a/tests/baselines/reference/stringLiteralTypesWithVariousOperators01.types b/tests/baselines/reference/stringLiteralTypesWithVariousOperators01.types index 46442d75ad4ac..90cb538b800d1 100644 --- a/tests/baselines/reference/stringLiteralTypesWithVariousOperators01.types +++ b/tests/baselines/reference/stringLiteralTypesWithVariousOperators01.types @@ -16,9 +16,9 @@ let abcOrXyz: "ABC" | "XYZ" = abc || xyz; let abcOrXyzOrNumber: "ABC" | "XYZ" | number = abcOrXyz || 100; >abcOrXyzOrNumber : "ABC" | "XYZ" | number ->abcOrXyz || 100 : "ABC" | "XYZ" | 100 +>abcOrXyz || 100 : "ABC" | "XYZ" | number >abcOrXyz : "ABC" | "XYZ" ->100 : 100 +>100 : number let a = "" + abc; >a : string diff --git a/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt b/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt index d42f407a784d9..ad2ca8bc123a9 100644 --- a/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt +++ b/tests/baselines/reference/switchCaseWithIntersectionTypes01.errors.txt @@ -1,7 +1,6 @@ tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(19,10): error TS2678: Type 'number & boolean' is not comparable to type 'string & number'. Type 'number & boolean' is not comparable to type 'string'. tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts(23,10): error TS2678: Type 'boolean' is not comparable to type 'string & number'. - Type 'boolean' is not comparable to type 'string'. ==== tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithIntersectionTypes01.ts (2 errors) ==== @@ -33,6 +32,5 @@ tests/cases/conformance/types/typeRelationships/comparable/switchCaseWithInterse case bool: ~~~~ !!! error TS2678: Type 'boolean' is not comparable to type 'string & number'. -!!! error TS2678: Type 'boolean' is not comparable to type 'string'. break; } \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardFunction.types b/tests/baselines/reference/typeGuardFunction.types index 50a5fcaf32411..7f60bbc0a3bd6 100644 --- a/tests/baselines/reference/typeGuardFunction.types +++ b/tests/baselines/reference/typeGuardFunction.types @@ -223,7 +223,7 @@ let union2: C | B; let union3: boolean | B = isA(union2) || union2; >union3 : boolean | B >B : B ->isA(union2) || union2 : boolean | B +>isA(union2) || union2 : true | B >isA(union2) : boolean >isA : (p1: any) => p1 is A >union2 : C | B diff --git a/tests/baselines/reference/typeGuardNesting.types b/tests/baselines/reference/typeGuardNesting.types index cb06d457a3097..0532e4d253697 100644 --- a/tests/baselines/reference/typeGuardNesting.types +++ b/tests/baselines/reference/typeGuardNesting.types @@ -14,7 +14,7 @@ if ((typeof strOrBool === 'boolean' && !strOrBool) || typeof strOrBool === 'stri >strOrBool : boolean >typeof strOrBool === 'string' : boolean >typeof strOrBool : string ->strOrBool : string | boolean +>strOrBool : string | true >'string' : "string" let label: string = (typeof strOrBool === 'string') ? strOrBool : "string"; @@ -74,7 +74,7 @@ if ((typeof strOrBool !== 'string' && !strOrBool) || typeof strOrBool !== 'boole >strOrBool : boolean >typeof strOrBool !== 'boolean' : boolean >typeof strOrBool : string ->strOrBool : string | boolean +>strOrBool : string | true >'boolean' : "boolean" let label: string = (typeof strOrBool === 'string') ? strOrBool : "string"; diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types index b251664e9ee2f..141fab13b3d92 100644 --- a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types +++ b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types @@ -19,12 +19,12 @@ function foo(x: number | string) { >10 : 10 } function foo2(x: number | string) { ->foo2 : (x: number | string) => boolean | number +>foo2 : (x: number | string) => true | number >x : number | string // modify x in right hand operand return typeof x !== "string" || ((x = 10) || x); // string | number ->typeof x !== "string" || ((x = 10) || x) : boolean | number +>typeof x !== "string" || ((x = 10) || x) : true | number >typeof x !== "string" : boolean >typeof x : string >x : number | string @@ -38,12 +38,12 @@ function foo2(x: number | string) { >x : number } function foo3(x: number | string) { ->foo3 : (x: number | string) => boolean | string +>foo3 : (x: number | string) => true | string >x : number | string // modify x in right hand operand with string type itself return typeof x !== "string" || ((x = "hello") || x); // string | number ->typeof x !== "string" || ((x = "hello") || x) : boolean | string +>typeof x !== "string" || ((x = "hello") || x) : true | string >typeof x !== "string" : boolean >typeof x : string >x : number | string @@ -138,7 +138,7 @@ function foo6(x: number | string | boolean) { >10 : 10 } function foo7(x: number | string | boolean) { ->foo7 : (x: number | string | boolean) => boolean | number | string +>foo7 : (x: number | string | boolean) => true | number | string >x : number | string | boolean var y: number| boolean | string; @@ -149,15 +149,15 @@ function foo7(x: number | string | boolean) { // Mixing typeguard narrowing return typeof x === "string" ->typeof x === "string" || ((z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString()))) : boolean | number | string +>typeof x === "string" || ((z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString()))) : true | number | string >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean >"string" : "string" || ((z = x) // number | boolean ->((z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString()))) : number | boolean | string ->(z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString())) : number | boolean | string +>((z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString()))) : number | true | string +>(z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString())) : number | true | string >(z = x) : number | boolean >z = x : number | boolean >z : number | boolean | string From 0f132cdb7f2907d5a338565fc3ab91cbad0de2ba Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 18 Jul 2016 17:14:14 -0700 Subject: [PATCH 32/55] Order union type constituents by type ID --- src/compiler/checker.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c7983d634a550..641b96bf6c45d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5215,6 +5215,10 @@ namespace ts { } } + function compareTypeIds(type1: Type, type2: Type): number { + return type1.id - type2.id; + } + // We reduce the constituent type set to only include types that aren't subtypes of other types, unless // the noSubtypeReduction flag is specified, in which case we perform a simple deduplication based on // object identity. Subtype reduction is possible only when union types are known not to circularly @@ -5234,6 +5238,7 @@ namespace ts { if (typeSet.containsAny) { return anyType; } + typeSet.sort(compareTypeIds); if (strictNullChecks) { if (typeSet.containsNull) typeSet.push(nullType); if (typeSet.containsUndefined) typeSet.push(undefinedType); From 15a66676cc314411950d5343d27f74d84555f585 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 18 Jul 2016 17:14:34 -0700 Subject: [PATCH 33/55] Fix fourslash tests --- tests/cases/fourslash/completionEntryForUnionProperty.ts | 2 +- tests/cases/fourslash/genericTypeArgumentInference1.ts | 4 ++-- tests/cases/fourslash/genericTypeArgumentInference2.ts | 4 ++-- tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts | 2 +- tests/cases/fourslash/quickinfoForUnionProperty.ts | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/cases/fourslash/completionEntryForUnionProperty.ts b/tests/cases/fourslash/completionEntryForUnionProperty.ts index e34923eb69ca1..bc0f9405a1ba8 100644 --- a/tests/cases/fourslash/completionEntryForUnionProperty.ts +++ b/tests/cases/fourslash/completionEntryForUnionProperty.ts @@ -15,6 +15,6 @@ ////x./**/ goTo.marker(); -verify.memberListContains("commonProperty", "(property) commonProperty: number | string"); +verify.memberListContains("commonProperty", "(property) commonProperty: string | number"); verify.memberListContains("commonFunction", "(method) commonFunction(): number"); verify.memberListCount(2); \ No newline at end of file diff --git a/tests/cases/fourslash/genericTypeArgumentInference1.ts b/tests/cases/fourslash/genericTypeArgumentInference1.ts index c8d23ba256574..d8c332449e177 100644 --- a/tests/cases/fourslash/genericTypeArgumentInference1.ts +++ b/tests/cases/fourslash/genericTypeArgumentInference1.ts @@ -18,9 +18,9 @@ ////var /*4*/r4 = _./*41*/all([true], _.identity); goTo.marker('1'); -verify.quickInfoIs('var r: boolean | number | string'); +verify.quickInfoIs('var r: string | number | boolean'); goTo.marker('11'); -verify.quickInfoIs('(method) Underscore.Static.all(list: (boolean | number | string)[], iterator?: Underscore.Iterator, context?: any): boolean | number | string'); +verify.quickInfoIs('(method) Underscore.Static.all(list: (string | number | boolean)[], iterator?: Underscore.Iterator, context?: any): string | number | boolean'); goTo.marker('2'); verify.quickInfoIs('var r2: boolean'); diff --git a/tests/cases/fourslash/genericTypeArgumentInference2.ts b/tests/cases/fourslash/genericTypeArgumentInference2.ts index 2303e3298a311..aaf0d138f2f76 100644 --- a/tests/cases/fourslash/genericTypeArgumentInference2.ts +++ b/tests/cases/fourslash/genericTypeArgumentInference2.ts @@ -18,9 +18,9 @@ ////var /*4*/r4 = _./*41*/all([true], _.identity); goTo.marker('1'); -verify.quickInfoIs('var r: boolean | number | string'); +verify.quickInfoIs('var r: string | number | boolean'); goTo.marker('11'); -verify.quickInfoIs('(method) Underscore.Static.all(list: (boolean | number | string)[], iterator?: Underscore.Iterator, context?: any): boolean | number | string'); +verify.quickInfoIs('(method) Underscore.Static.all(list: (string | number | boolean)[], iterator?: Underscore.Iterator, context?: any): string | number | boolean'); goTo.marker('2'); verify.quickInfoIs('var r2: boolean'); diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts index cf70f883e99f6..987ebf4b79030 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics24.ts @@ -13,4 +13,4 @@ //// x.canVote/**/; goTo.marker(); -verify.quickInfoIs('(property) Person.canVote: boolean | number'); +verify.quickInfoIs('(property) Person.canVote: number | boolean'); diff --git a/tests/cases/fourslash/quickinfoForUnionProperty.ts b/tests/cases/fourslash/quickinfoForUnionProperty.ts index 4cb87b3b3f81c..5292eb6c2c889 100644 --- a/tests/cases/fourslash/quickinfoForUnionProperty.ts +++ b/tests/cases/fourslash/quickinfoForUnionProperty.ts @@ -21,7 +21,7 @@ verify.quickInfoIs('var x: One | Two'); goTo.marker("2"); -verify.quickInfoIs('(property) commonProperty: number | string'); +verify.quickInfoIs('(property) commonProperty: string | number'); goTo.marker("3"); verify.quickInfoIs('(method) commonFunction(): number'); From 7d1c2fcf70fc6b2b8019f841e27ab38b7158e4c6 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 18 Jul 2016 17:18:35 -0700 Subject: [PATCH 34/55] Accept new baselines --- .../reference/ES5For-of30.errors.txt | 4 +- .../reference/ES5For-ofTypeCheck11.errors.txt | 4 +- .../reference/ES5For-ofTypeCheck5.types | 2 +- .../reference/ES5For-ofTypeCheck9.errors.txt | 4 +- .../reference/TypeGuardWithEnumUnion.types | 22 ++-- .../reference/aliasUsageInOrExpression.types | 2 +- .../reference/arrayBestCommonTypes.types | 12 +-- .../reference/arrayLiteralComments.types | 4 +- ...teralExpressionContextualTyping.errors.txt | 8 +- ...ayLiteralWithMultipleBestCommonTypes.types | 4 +- .../reference/arrayLiterals2ES5.types | 12 +-- .../reference/arrayLiterals2ES6.types | 20 ++-- .../reference/arrayLiterals3.errors.txt | 24 ++--- tests/baselines/reference/asOperator1.types | 6 +- ...nmentCompatBetweenTupleAndArray.errors.txt | 8 +- .../baselines/reference/awaitUnion_es6.types | 32 +++--- ...stCommonTypeOfConditionalExpressions.types | 4 +- ...tCommonTypeOfConditionalExpressions2.types | 4 +- .../reference/bestCommonTypeOfTuple.types | 4 +- .../reference/bestCommonTypeOfTuple2.types | 8 +- .../baselines/reference/callWithSpread.types | 4 +- .../reference/callWithSpreadES6.types | 4 +- .../computedPropertyNames1_ES5.types | 4 +- .../computedPropertyNames1_ES6.types | 4 +- .../computedPropertyNames4_ES5.types | 4 +- .../computedPropertyNames4_ES6.types | 4 +- ...utedPropertyNamesContextualType6_ES5.types | 4 +- ...utedPropertyNamesContextualType6_ES6.types | 4 +- ...utedPropertyNamesContextualType7_ES5.types | 4 +- ...utedPropertyNamesContextualType7_ES6.types | 4 +- .../conditionalExpression1.errors.txt | 8 +- .../conditionalOperatorWithIdenticalBCT.types | 2 +- ...torWithIncompleteTypeAnnotation.errors.txt | 12 +-- .../contextualSignatureInstantiation.types | 22 ++-- .../contextualTypeWithTuple.errors.txt | 12 +-- .../reference/contextualTyping21.errors.txt | 8 +- .../reference/contextualTyping30.errors.txt | 8 +- ...ontextualTypingOfArrayLiterals1.errors.txt | 8 +- .../reference/contextuallyTypedIife.types | 18 ++-- .../controlFlowAssignmentExpression.types | 12 +-- .../controlFlowBinaryOrExpression.symbols | 12 +-- .../controlFlowBinaryOrExpression.types | 20 ++-- .../reference/controlFlowCommaOperator.types | 2 +- .../reference/controlFlowDeleteOperator.types | 52 ++++----- .../controlFlowDoWhileStatement.types | 20 ++-- .../reference/controlFlowForInStatement.types | 12 +-- .../reference/controlFlowForOfStatement.types | 2 +- .../controlFlowPropertyDeclarations.types | 4 +- .../reference/controlFlowWhileStatement.types | 22 ++-- .../declFileTypeAnnotationParenType.js | 2 +- .../declFileTypeAnnotationParenType.types | 8 +- .../declFileTypeAnnotationTypeAlias.types | 6 +- .../declarationEmitDestructuring3.js | 2 +- .../declarationEmitDestructuring3.types | 8 +- ...clarationEmitDestructuringArrayPattern1.js | 6 +- ...rationEmitDestructuringArrayPattern1.types | 18 ++-- ...clarationEmitDestructuringArrayPattern2.js | 2 +- ...clarationEmitDestructuringArrayPattern4.js | 8 +- ...rationEmitDestructuringArrayPattern4.types | 28 ++--- ...ecoratedDefaultExportsGetExportedAmd.types | 12 +-- ...tedDefaultExportsGetExportedCommonjs.types | 12 +-- ...ratedDefaultExportsGetExportedSystem.types | 12 +-- ...ecoratedDefaultExportsGetExportedUmd.types | 12 +-- .../reference/decoratorMetadataPromise.types | 10 +- .../destructureOptionalParameter.types | 4 +- ...tructuringParameterDeclaration2.errors.txt | 16 +-- ...estructuringParameterDeclaration3ES5.types | 12 +-- ...estructuringParameterDeclaration3ES6.types | 12 +-- ...tructuringParameterDeclaration4.errors.txt | 12 +-- ...destructuringVariableDeclaration1ES5.types | 10 +- ...destructuringVariableDeclaration1ES6.types | 10 +- .../emitDecoratorMetadata_restArgs.types | 16 +-- .../reference/enumAssignmentCompat4.types | 4 +- tests/baselines/reference/enumBasics.types | 8 +- .../reference/enumLiteralTypes1.types | 42 ++++---- .../reference/enumLiteralTypes2.types | 92 ++++++++-------- .../reference/enumLiteralTypes3.errors.txt | 16 +-- tests/baselines/reference/for-of11.errors.txt | 4 +- tests/baselines/reference/for-of12.errors.txt | 4 +- .../reference/functionImplementations.types | 2 +- .../reference/functionOverloads43.types | 12 +-- .../reference/functionOverloads44.types | 22 ++-- .../reference/functionOverloads45.types | 8 +- ...nericArgumentCallSigAssignmentCompat.types | 2 +- .../genericCallWithArrayLiteralArgs.types | 10 +- .../genericTypeArgumentInference1.types | 6 +- .../heterogeneousArrayAndOverloads.errors.txt | 8 +- .../heterogeneousArrayLiterals.types | 36 +++---- .../reference/implicitIndexSignatures.types | 8 +- .../reference/indexerWithTuple.types | 24 ++--- .../reference/instanceOfAssignability.types | 6 +- .../reference/iteratorSpreadInCall12.types | 6 +- .../reference/iteratorSpreadInCall5.types | 6 +- .../iteratorSpreadInCall6.errors.txt | 4 +- .../baselines/reference/json.stringify.types | 20 ++-- tests/baselines/reference/literalTypes1.types | 20 ++-- .../logicalAndOperatorStrictMode.types | 20 ++-- .../logicalOrOperatorWithEveryType.types | 68 ++++++------ ...citTypeParameterAndArgumentType.errors.txt | 8 +- .../reference/narrowTypeByInstanceof.types | 16 +-- .../reference/numericLiteralTypes1.types | 48 ++++----- .../reference/numericLiteralTypes2.types | 44 ++++---- .../objectLiteralExcessProperties.errors.txt | 8 +- tests/baselines/reference/promiseType.types | 8 +- .../recursiveUnionTypeInference.types | 8 +- ...rfaceNameWithSameLetDeclarationName2.types | 4 +- ...nDestructuringForArrayBindingPattern.types | 12 +-- ...DestructuringForArrayBindingPattern2.types | 20 ++-- ...gForArrayBindingPatternDefaultValues.types | 12 +-- ...ForArrayBindingPatternDefaultValues2.types | 20 ++-- ...estructuringForOfArrayBindingPattern.types | 6 +- ...structuringForOfArrayBindingPattern2.types | 20 ++-- ...orOfArrayBindingPatternDefaultValues.types | 6 +- ...rOfArrayBindingPatternDefaultValues2.types | 20 ++-- ...cturingParametertArrayBindingPattern.types | 4 +- ...tertArrayBindingPatternDefaultValues.types | 4 +- ...VariableStatementArrayBindingPattern.types | 2 +- ...ariableStatementArrayBindingPattern3.types | 20 ++-- ...mentArrayBindingPatternDefaultValues.types | 2 +- ...entArrayBindingPatternDefaultValues3.types | 20 ++-- ...ymousTypeNotReferencingTypeParameter.types | 4 +- .../reference/strictNullLogicalAndOr.types | 2 +- .../stringLiteralCheckedInIf01.types | 12 +-- .../stringLiteralCheckedInIf02.types | 22 ++-- .../stringLiteralMatchedInSwitch01.types | 10 +- .../stringLiteralTypeAssertion01.types | 46 ++++---- .../stringLiteralTypesInUnionTypes01.types | 8 +- .../stringLiteralTypesInUnionTypes02.types | 28 ++--- .../stringLiteralTypesInUnionTypes03.types | 16 +-- .../stringLiteralTypesInUnionTypes04.types | 18 ++-- .../stringLiteralTypesOverloads01.js | 2 +- .../stringLiteralTypesOverloads01.types | 66 ++++++------ .../stringLiteralTypesOverloads02.js | 2 +- ...ngLiteralTypesWithVariousOperators01.types | 24 ++--- ...eralTypesWithVariousOperators02.errors.txt | 20 ++-- ...typesOfTypeParameterWithConstraints2.types | 12 +-- ...typesOfTypeParameterWithConstraints3.types | 8 +- .../reference/subtypesOfUnion.errors.txt | 60 +++++------ .../subtypingWithCallSignatures2.types | 12 +-- .../subtypingWithCallSignatures3.types | 8 +- .../subtypingWithCallSignatures4.types | 16 +-- .../subtypingWithConstructSignatures2.types | 16 +-- .../subtypingWithConstructSignatures3.types | 8 +- .../subtypingWithConstructSignatures4.types | 16 +-- tests/baselines/reference/symbolType11.types | 2 +- .../baselines/reference/targetTypeTest2.types | 2 +- .../reference/targetTypeTest3.errors.txt | 8 +- .../reference/templateStringInArray.types | 4 +- ...emplateStringWithEmbeddedConditional.types | 2 +- ...lateStringWithEmbeddedConditionalES6.types | 2 +- .../reference/thisTypeInTuples.types | 20 ++-- ...ommaInHeterogenousArrayLiteral1.errors.txt | 16 +-- .../baselines/reference/tupleTypes.errors.txt | 8 +- ...ypeAliasDoesntMakeModuleInstantiated.types | 2 +- .../reference/typeAssertions.errors.txt | 4 +- .../baselines/reference/typeGuardEnums.types | 6 +- .../reference/typeGuardFunction.types | 4 +- .../reference/typeGuardNesting.types | 10 +- .../typeGuardOfFormExpr1AndExpr2.types | 14 +-- .../typeGuardOfFormExpr1OrExpr2.types | 4 +- .../reference/typeGuardOfFormInstanceOf.types | 10 +- ...typeGuardOfFormInstanceOfOnInterface.types | 6 +- .../reference/typeGuardOfFormIsType.types | 4 +- .../typeGuardOfFormIsTypeOnInterfaces.types | 4 +- .../reference/typeGuardOfFormNotExpr.types | 14 +-- .../typeGuardOfFormTypeOfBoolean.types | 6 +- .../typeGuardOfFormTypeOfNumber.types | 4 +- .../typeGuardOfFormTypeOfOther.types | 6 +- .../reference/typeGuardRedundancy.types | 10 +- .../reference/typeGuardTypeOfUndefined.types | 80 +++++++------- .../reference/typeGuardsAsAssertions.types | 28 ++--- .../typeGuardsInConditionalExpression.types | 102 +++++++++--------- .../reference/typeGuardsInDoStatement.types | 4 +- .../reference/typeGuardsInForStatement.types | 2 +- .../typeGuardsInFunctionAndModuleBlock.types | 50 ++++----- ...GuardsInRightOperandOfAndAndOperator.types | 56 +++++----- ...peGuardsInRightOperandOfOrOrOperator.types | 68 ++++++------ .../typeGuardsInWhileStatement.types | 2 +- .../reference/typeGuardsOnClassProperty.types | 24 ++--- ...nstanceOfByConstructorSignature.errors.txt | 8 +- .../typeParameterAsElementType.types | 4 +- .../baselines/reference/underscoreTest1.types | 8 +- .../unionAndIntersectionInference1.types | 20 ++-- .../unionAndIntersectionInference2.types | 22 ++-- ...IfEveryConstituentTypeIsSubtype.errors.txt | 60 +++++------ .../reference/unionTypeCallSignatures2.types | 28 ++--- .../reference/unionTypeIndexSignature.types | 12 +-- .../reference/unionTypeInference.types | 2 +- .../unionTypePropertyAccessibility.errors.txt | 8 +- ...onTypeWithRecursiveSubtypeReduction1.types | 4 +- .../unionTypesAssignability.errors.txt | 8 +- ...unusedLocalsAndParametersTypeAliases.types | 2 +- 192 files changed, 1351 insertions(+), 1351 deletions(-) diff --git a/tests/baselines/reference/ES5For-of30.errors.txt b/tests/baselines/reference/ES5For-of30.errors.txt index ee2d14a4f5809..e99b8284bf336 100644 --- a/tests/baselines/reference/ES5For-of30.errors.txt +++ b/tests/baselines/reference/ES5For-of30.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,6): error TS2461: Type 'number | string' is not an array type. +tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,6): error TS2461: Type 'string | number' is not an array type. tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,7): error TS2322: Type 'number' is not assignable to type 'string'. tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,14): error TS2322: Type 'string' is not assignable to type 'number'. @@ -8,7 +8,7 @@ tests/cases/conformance/statements/for-ofStatements/ES5For-of30.ts(3,14): error var tuple: [number, string] = [2, "3"]; for ([a = 1, b = ""] of tuple) { ~~~~~~~~~~~~~~~ -!!! error TS2461: Type 'number | string' is not an array type. +!!! error TS2461: Type 'string | number' is not an array type. ~ !!! error TS2322: Type 'number' is not assignable to type 'string'. ~ diff --git a/tests/baselines/reference/ES5For-ofTypeCheck11.errors.txt b/tests/baselines/reference/ES5For-ofTypeCheck11.errors.txt index 57a28b6612c54..635bb09616afa 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck11.errors.txt +++ b/tests/baselines/reference/ES5For-ofTypeCheck11.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts(3,6): error TS2322: Type 'number | string' is not assignable to type 'string'. +tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts(3,6): error TS2322: Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -7,5 +7,5 @@ tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts(3,6) var v: string; for (v of union) { } ~ -!!! error TS2322: Type 'number | string' is not assignable to type 'string'. +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/ES5For-ofTypeCheck5.types b/tests/baselines/reference/ES5For-ofTypeCheck5.types index f24aa54c7f323..ed3d13f3918a7 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck5.types +++ b/tests/baselines/reference/ES5For-ofTypeCheck5.types @@ -3,6 +3,6 @@ var union: string | number[]; >union : string | number[] for (var v of union) { } ->v : number | string +>v : string | number >union : string | number[] diff --git a/tests/baselines/reference/ES5For-ofTypeCheck9.errors.txt b/tests/baselines/reference/ES5For-ofTypeCheck9.errors.txt index 3f382d72a08d0..156eb18880367 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck9.errors.txt +++ b/tests/baselines/reference/ES5For-ofTypeCheck9.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck9.ts(2,15): error TS2461: Type 'string[] | number | symbol' is not an array type. +tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck9.ts(2,15): error TS2461: Type 'number | symbol | string[]' is not an array type. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck9.ts (1 errors) ==== var union: string | string[] | number | symbol; for (let v of union) { } ~~~~~ -!!! error TS2461: Type 'string[] | number | symbol' is not an array type. \ No newline at end of file +!!! error TS2461: Type 'number | symbol | string[]' is not an array type. \ No newline at end of file diff --git a/tests/baselines/reference/TypeGuardWithEnumUnion.types b/tests/baselines/reference/TypeGuardWithEnumUnion.types index bf5625e0c991e..dee8feae27d4a 100644 --- a/tests/baselines/reference/TypeGuardWithEnumUnion.types +++ b/tests/baselines/reference/TypeGuardWithEnumUnion.types @@ -6,14 +6,14 @@ enum Color { R, G, B } >B : Color function f1(x: Color | string) { ->f1 : (x: Color | string) => void ->x : Color | string +>f1 : (x: string | Color) => void +>x : string | Color >Color : Color if (typeof x === "number") { >typeof x === "number" : boolean >typeof x : string ->x : Color | string +>x : string | Color >"number" : "number" var y = x; @@ -35,14 +35,14 @@ function f1(x: Color | string) { } function f2(x: Color | string | string[]) { ->f2 : (x: Color | string | string[]) => void ->x : Color | string | string[] +>f2 : (x: string | Color | string[]) => void +>x : string | Color | string[] >Color : Color if (typeof x === "object") { >typeof x === "object" : boolean >typeof x : string ->x : Color | string | string[] +>x : string | Color | string[] >"object" : "object" var y = x; @@ -55,7 +55,7 @@ function f2(x: Color | string | string[]) { if (typeof x === "number") { >typeof x === "number" : boolean >typeof x : string ->x : string[] | Color | string +>x : string | Color | string[] >"number" : "number" var z = x; @@ -68,16 +68,16 @@ function f2(x: Color | string | string[]) { } else { var w = x; ->w : string[] | string ->x : string[] | string +>w : string | string[] +>x : string | string[] var w: string | string[]; ->w : string[] | string +>w : string | string[] } if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : Color | string[] | string +>x : string | Color | string[] >"string" : "string" var a = x; diff --git a/tests/baselines/reference/aliasUsageInOrExpression.types b/tests/baselines/reference/aliasUsageInOrExpression.types index c43b7889cc555..0fcf3c3590d22 100644 --- a/tests/baselines/reference/aliasUsageInOrExpression.types +++ b/tests/baselines/reference/aliasUsageInOrExpression.types @@ -34,7 +34,7 @@ var d2: IHasVisualizationModel = i || moduleA; var d2: IHasVisualizationModel = moduleA || i; >d2 : IHasVisualizationModel >IHasVisualizationModel : IHasVisualizationModel ->moduleA || i : typeof moduleA +>moduleA || i : IHasVisualizationModel >moduleA : typeof moduleA >i : IHasVisualizationModel diff --git a/tests/baselines/reference/arrayBestCommonTypes.types b/tests/baselines/reference/arrayBestCommonTypes.types index fca66793f40ec..2e87dc2ca15e8 100644 --- a/tests/baselines/reference/arrayBestCommonTypes.types +++ b/tests/baselines/reference/arrayBestCommonTypes.types @@ -366,22 +366,22 @@ module EmptyTypes { >base2 : typeof base2 var b1 = [baseObj, base2Obj, ifaceObj]; ->b1 : base[] ->[baseObj, base2Obj, ifaceObj] : base[] +>b1 : iface[] +>[baseObj, base2Obj, ifaceObj] : iface[] >baseObj : base >base2Obj : base2 >ifaceObj : iface var b2 = [base2Obj, baseObj, ifaceObj]; ->b2 : base2[] ->[base2Obj, baseObj, ifaceObj] : base2[] +>b2 : iface[] +>[base2Obj, baseObj, ifaceObj] : iface[] >base2Obj : base2 >baseObj : base >ifaceObj : iface var b3 = [baseObj, ifaceObj, base2Obj]; ->b3 : base[] ->[baseObj, ifaceObj, base2Obj] : base[] +>b3 : iface[] +>[baseObj, ifaceObj, base2Obj] : iface[] >baseObj : base >ifaceObj : iface >base2Obj : base2 diff --git a/tests/baselines/reference/arrayLiteralComments.types b/tests/baselines/reference/arrayLiteralComments.types index a8c32b48e41a3..e18635167927c 100644 --- a/tests/baselines/reference/arrayLiteralComments.types +++ b/tests/baselines/reference/arrayLiteralComments.types @@ -1,7 +1,7 @@ === tests/cases/compiler/arrayLiteralComments.ts === var testArrayWithFunc = [ ->testArrayWithFunc : ((() => void) | string | number | { a: number; } | number[])[] ->[ // Function comment function() { let x = 1; }, // String comment '1', // Numeric comment 2, // Object comment { a: 1 }, // Array comment [1, 2, 3]] : ((() => void) | string | number | { a: number; } | number[])[] +>testArrayWithFunc : (string | number | (() => void) | number[] | { a: number; })[] +>[ // Function comment function() { let x = 1; }, // String comment '1', // Numeric comment 2, // Object comment { a: 1 }, // Array comment [1, 2, 3]] : (string | number | (() => void) | number[] | { a: number; })[] // Function comment function() { diff --git a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt index 72ba14113207d..3e9777aea7c26 100644 --- a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt +++ b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(8,5): error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, number]'. Types of property 'pop' are incompatible. - Type '() => number | string' is not assignable to type '() => number'. - Type 'number | string' is not assignable to type 'number'. + Type '() => string | number' is not assignable to type '() => number'. + Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(14,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. Property '0' is missing in type 'number[]'. @@ -19,8 +19,8 @@ tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionConte ~~~~ !!! error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, number]'. !!! error TS2322: Types of property 'pop' are incompatible. -!!! error TS2322: Type '() => number | string' is not assignable to type '() => number'. -!!! error TS2322: Type 'number | string' is not assignable to type 'number'. +!!! error TS2322: Type '() => string | number' is not assignable to type '() => number'. +!!! error TS2322: Type 'string | number' is not assignable to type 'number'. !!! error TS2322: Type 'string' is not assignable to type 'number'. // In a contextually typed array literal expression containing one or more spread elements, diff --git a/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types b/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types index 1bbb6c41e8aeb..aad515b62ee5f 100644 --- a/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types +++ b/tests/baselines/reference/arrayLiteralWithMultipleBestCommonTypes.types @@ -23,8 +23,8 @@ var as = [a, b]; // { x: number; y?: number };[] >b : { x: number; z?: number; } var bs = [b, a]; // { x: number; z?: number };[] ->bs : ({ x: number; z?: number; } | { x: number; y?: number; })[] ->[b, a] : ({ x: number; z?: number; } | { x: number; y?: number; })[] +>bs : ({ x: number; y?: number; } | { x: number; z?: number; })[] +>[b, a] : ({ x: number; y?: number; } | { x: number; z?: number; })[] >b : { x: number; z?: number; } >a : { x: number; y?: number; } diff --git a/tests/baselines/reference/arrayLiterals2ES5.types b/tests/baselines/reference/arrayLiterals2ES5.types index a9cf31611c26f..6eae997f4654c 100644 --- a/tests/baselines/reference/arrayLiterals2ES5.types +++ b/tests/baselines/reference/arrayLiterals2ES5.types @@ -24,8 +24,8 @@ var a1 = ["hello", "world"] >"world" : string var a2 = [, , , ...a0, "hello"]; ->a2 : (number | string)[] ->[, , , ...a0, "hello"] : (number | string)[] +>a2 : (string | number)[] +>[, , , ...a0, "hello"] : (string | number)[] > : undefined > : undefined > : undefined @@ -151,8 +151,8 @@ interface myArray2 extends Array { } >String : String var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[] ->d0 : (number | boolean | string)[] ->[1, true, ...temp,] : (number | boolean | string)[] +>d0 : (string | number | boolean)[] +>[1, true, ...temp,] : (string | number | boolean)[] >1 : number >true : boolean >...temp : string @@ -214,8 +214,8 @@ var d8: number[][] = [[...temp1]] >temp1 : number[] var d9 = [[...temp1], ...["hello"]]; ->d9 : (number[] | string)[] ->[[...temp1], ...["hello"]] : (number[] | string)[] +>d9 : (string | number[])[] +>[[...temp1], ...["hello"]] : (string | number[])[] >[...temp1] : number[] >...temp1 : number >temp1 : number[] diff --git a/tests/baselines/reference/arrayLiterals2ES6.types b/tests/baselines/reference/arrayLiterals2ES6.types index b6bf4f1de1b39..f05b0ca9282a6 100644 --- a/tests/baselines/reference/arrayLiterals2ES6.types +++ b/tests/baselines/reference/arrayLiterals2ES6.types @@ -24,8 +24,8 @@ var a1 = ["hello", "world"] >"world" : string var a2 = [, , , ...a0, "hello"]; ->a2 : (number | string)[] ->[, , , ...a0, "hello"] : (number | string)[] +>a2 : (string | number)[] +>[, , , ...a0, "hello"] : (string | number)[] > : undefined > : undefined > : undefined @@ -140,8 +140,8 @@ interface myArray2 extends Array { } >String : String var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[] ->d0 : (number | boolean | string)[] ->[1, true, ...temp, ] : (number | boolean | string)[] +>d0 : (string | number | boolean)[] +>[1, true, ...temp, ] : (string | number | boolean)[] >1 : number >true : boolean >...temp : string @@ -176,10 +176,10 @@ var d4: myArray2 = [...temp, ...temp1]; >temp1 : number[] var d5 = [...a2]; ->d5 : (number | string)[] ->[...a2] : (number | string)[] ->...a2 : number | string ->a2 : (number | string)[] +>d5 : (string | number)[] +>[...a2] : (string | number)[] +>...a2 : string | number +>a2 : (string | number)[] var d6 = [...a3]; >d6 : number[] @@ -201,8 +201,8 @@ var d8: number[][] = [[...temp1]] >temp1 : number[] var d9 = [[...temp1], ...["hello"]]; ->d9 : (number[] | string)[] ->[[...temp1], ...["hello"]] : (number[] | string)[] +>d9 : (string | number[])[] +>[[...temp1], ...["hello"]] : (string | number[])[] >[...temp1] : number[] >...temp1 : number >temp1 : number[] diff --git a/tests/baselines/reference/arrayLiterals3.errors.txt b/tests/baselines/reference/arrayLiterals3.errors.txt index f205e90ecedef..8e6c7eccf81f8 100644 --- a/tests/baselines/reference/arrayLiterals3.errors.txt +++ b/tests/baselines/reference/arrayLiterals3.errors.txt @@ -5,19 +5,19 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(11,5): error Type 'string' is not assignable to type 'boolean'. tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(17,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. Types of property 'pop' are incompatible. - Type '() => number | string | boolean' is not assignable to type '() => number'. - Type 'number | string | boolean' is not assignable to type 'number'. + Type '() => string | number | boolean' is not assignable to type '() => number'. + Type 'string | number | boolean' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error TS2322: Type '(number[] | string[])[]' is not assignable to type 'tup'. Property '0' is missing in type '(number[] | string[])[]'. tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. Property '0' is missing in type 'number[]'. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(number | string)[]' is not assignable to type 'myArray'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. Types of property 'push' are incompatible. - Type '(...items: (number | string)[]) => number' is not assignable to type '(...items: Number[]) => number'. + Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. Types of parameters 'items' and 'items' are incompatible. - Type 'Number' is not assignable to type 'number | string'. - Type 'Number' is not assignable to type 'string'. + Type 'Number' is not assignable to type 'string | number'. + Type 'Number' is not assignable to type 'number'. ==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts (6 errors) ==== @@ -48,8 +48,8 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error ~~~~~~~~ !!! error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. !!! error TS2322: Types of property 'pop' are incompatible. -!!! error TS2322: Type '() => number | string | boolean' is not assignable to type '() => number'. -!!! error TS2322: Type 'number | string | boolean' is not assignable to type 'number'. +!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => number'. +!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'number'. !!! error TS2322: Type 'string' is not assignable to type 'number'. // The resulting type an array literal expression is determined as follows: @@ -75,10 +75,10 @@ tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error !!! error TS2322: Property '0' is missing in type 'number[]'. var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[] ~~ -!!! error TS2322: Type '(number | string)[]' is not assignable to type 'myArray'. +!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. !!! error TS2322: Types of property 'push' are incompatible. -!!! error TS2322: Type '(...items: (number | string)[]) => number' is not assignable to type '(...items: Number[]) => number'. +!!! error TS2322: Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. !!! error TS2322: Types of parameters 'items' and 'items' are incompatible. -!!! error TS2322: Type 'Number' is not assignable to type 'number | string'. -!!! error TS2322: Type 'Number' is not assignable to type 'string'. +!!! error TS2322: Type 'Number' is not assignable to type 'string | number'. +!!! error TS2322: Type 'Number' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/asOperator1.types b/tests/baselines/reference/asOperator1.types index cc8a49ddc55fa..3f69871ea0942 100644 --- a/tests/baselines/reference/asOperator1.types +++ b/tests/baselines/reference/asOperator1.types @@ -24,12 +24,12 @@ var z = Date as any as string; // Should parse as a union type, not a bitwise 'or' of (32 as number) and 'string' var j = 32 as number|string; ->j : number | string ->32 as number|string : number | string +>j : string | number +>32 as number|string : string | number >32 : number j = ''; >j = '' : string ->j : number | string +>j : string | number >'' : string diff --git a/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt b/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt index c7552c3fdb2a9..03dcee9baf3e1 100644 --- a/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt +++ b/tests/baselines/reference/assignmentCompatBetweenTupleAndArray.errors.txt @@ -1,7 +1,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(17,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]'. Types of property 'pop' are incompatible. - Type '() => number | string' is not assignable to type '() => number'. - Type 'number | string' is not assignable to type 'number'. + Type '() => string | number' is not assignable to type '() => number'. + Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatBetweenTupleAndArray.ts(18,1): error TS2322: Type '{}[]' is not assignable to type '[{}]'. Property '0' is missing in type '{}[]'. @@ -28,8 +28,8 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme ~~~~~~~~ !!! error TS2322: Type '[number, string]' is not assignable to type 'number[]'. !!! error TS2322: Types of property 'pop' are incompatible. -!!! error TS2322: Type '() => number | string' is not assignable to type '() => number'. -!!! error TS2322: Type 'number | string' is not assignable to type 'number'. +!!! error TS2322: Type '() => string | number' is not assignable to type '() => number'. +!!! error TS2322: Type 'string | number' is not assignable to type 'number'. !!! error TS2322: Type 'string' is not assignable to type 'number'. emptyObjTuple = emptyObjArray; ~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/awaitUnion_es6.types b/tests/baselines/reference/awaitUnion_es6.types index 97d4bd2fc579b..eabcb56e59cfc 100644 --- a/tests/baselines/reference/awaitUnion_es6.types +++ b/tests/baselines/reference/awaitUnion_es6.types @@ -1,6 +1,6 @@ === tests/cases/conformance/async/es6/awaitUnion_es6.ts === declare let a: number | string; ->a : number | string +>a : string | number declare let b: PromiseLike | PromiseLike; >b : PromiseLike | PromiseLike @@ -8,7 +8,7 @@ declare let b: PromiseLike | PromiseLike; >PromiseLike : PromiseLike declare let c: PromiseLike; ->c : PromiseLike +>c : PromiseLike >PromiseLike : PromiseLike declare let d: number | PromiseLike; @@ -16,34 +16,34 @@ declare let d: number | PromiseLike; >PromiseLike : PromiseLike declare let e: number | PromiseLike; ->e : number | PromiseLike +>e : number | PromiseLike >PromiseLike : PromiseLike async function f() { >f : () => Promise let await_a = await a; ->await_a : number | string ->await a : number | string ->a : number | string +>await_a : string | number +>await a : string | number +>a : string | number let await_b = await b; ->await_b : number | string ->await b : number | string +>await_b : string | number +>await b : string | number >b : PromiseLike | PromiseLike let await_c = await c; ->await_c : number | string ->await c : number | string ->c : PromiseLike +>await_c : string | number +>await c : string | number +>c : PromiseLike let await_d = await d; ->await_d : number | string ->await d : number | string +>await_d : string | number +>await d : string | number >d : number | PromiseLike let await_e = await e; ->await_e : number | string ->await e : number | string ->e : number | PromiseLike +>await_e : string | number +>await e : string | number +>e : number | PromiseLike } diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types index 1191004a32bef..2a5ee6a2fe230 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions.types @@ -60,8 +60,8 @@ var r4 = true ? a : b; // typeof a >b : { x: number; z?: number; } var r5 = true ? b : a; // typeof b ->r5 : { x: number; z?: number; } | { x: number; y?: number; } ->true ? b : a : { x: number; z?: number; } | { x: number; y?: number; } +>r5 : { x: number; y?: number; } | { x: number; z?: number; } +>true ? b : a : { x: number; y?: number; } | { x: number; z?: number; } >true : boolean >b : { x: number; z?: number; } >a : { x: number; y?: number; } diff --git a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.types b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.types index ef9ecfb2a1190..833bddd0e7c62 100644 --- a/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.types +++ b/tests/baselines/reference/bestCommonTypeOfConditionalExpressions2.types @@ -29,8 +29,8 @@ var derived2: Derived2; >Derived2 : Derived2 var r2 = true ? 1 : ''; ->r2 : number | string ->true ? 1 : '' : number | string +>r2 : string | number +>true ? 1 : '' : string | number >true : boolean >1 : number >'' : string diff --git a/tests/baselines/reference/bestCommonTypeOfTuple.types b/tests/baselines/reference/bestCommonTypeOfTuple.types index 7d3330f486341..6aa84f37ebac6 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple.types +++ b/tests/baselines/reference/bestCommonTypeOfTuple.types @@ -98,8 +98,8 @@ var e3 = t3[2]; // any >2 : number var e4 = t4[3]; // number ->e4 : E1 | E2 | number ->t4[3] : E1 | E2 | number +>e4 : number | E1 | E2 +>t4[3] : number | E1 | E2 >t4 : [E1, E2, number] >3 : number diff --git a/tests/baselines/reference/bestCommonTypeOfTuple2.types b/tests/baselines/reference/bestCommonTypeOfTuple2.types index 573e346637601..864d3030d8886 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple2.types +++ b/tests/baselines/reference/bestCommonTypeOfTuple2.types @@ -66,8 +66,8 @@ var t5: [C1, F] >F : F var e11 = t1[4]; // base ->e11 : C | base ->t1[4] : C | base +>e11 : base | C +>t1[4] : base | C >t1 : [C, base] >4 : number @@ -90,8 +90,8 @@ var e41 = t4[2]; // base1 >2 : number var e51 = t5[2]; // {} ->e51 : C1 | F ->t5[2] : C1 | F +>e51 : F | C1 +>t5[2] : F | C1 >t5 : [C1, F] >2 : number diff --git a/tests/baselines/reference/callWithSpread.types b/tests/baselines/reference/callWithSpread.types index eae92c471e91f..bc120dc4043bc 100644 --- a/tests/baselines/reference/callWithSpread.types +++ b/tests/baselines/reference/callWithSpread.types @@ -163,8 +163,8 @@ xa[1].foo(1, 2, ...a, "abc"); >xa : X[] >1 : number >foo : (x: number, y: number, ...z: string[]) => any ->...[1, 2, "abc"] : number | string ->[1, 2, "abc"] : (number | string)[] +>...[1, 2, "abc"] : string | number +>[1, 2, "abc"] : (string | number)[] >1 : number >2 : number >"abc" : string diff --git a/tests/baselines/reference/callWithSpreadES6.types b/tests/baselines/reference/callWithSpreadES6.types index b0c118855fef7..99fe1330df9aa 100644 --- a/tests/baselines/reference/callWithSpreadES6.types +++ b/tests/baselines/reference/callWithSpreadES6.types @@ -164,8 +164,8 @@ xa[1].foo(1, 2, ...a, "abc"); >xa : X[] >1 : number >foo : (x: number, y: number, ...z: string[]) => any ->...[1, 2, "abc"] : number | string ->[1, 2, "abc"] : (number | string)[] +>...[1, 2, "abc"] : string | number +>[1, 2, "abc"] : (string | number)[] >1 : number >2 : number >"abc" : string diff --git a/tests/baselines/reference/computedPropertyNames1_ES5.types b/tests/baselines/reference/computedPropertyNames1_ES5.types index bcff3b34177f7..a77895e06d1fc 100644 --- a/tests/baselines/reference/computedPropertyNames1_ES5.types +++ b/tests/baselines/reference/computedPropertyNames1_ES5.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/computedProperties/computedPropertyNames1_ES5.ts === var v = { ->v : { [x: number]: number | string; } ->{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : { [x: number]: number | string; } +>v : { [x: number]: string | number; } +>{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : { [x: number]: string | number; } get [0 + 1]() { return 0 }, >0 + 1 : number diff --git a/tests/baselines/reference/computedPropertyNames1_ES6.types b/tests/baselines/reference/computedPropertyNames1_ES6.types index df2237a463f02..503988b0314f7 100644 --- a/tests/baselines/reference/computedPropertyNames1_ES6.types +++ b/tests/baselines/reference/computedPropertyNames1_ES6.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/computedProperties/computedPropertyNames1_ES6.ts === var v = { ->v : { [x: number]: number | string; } ->{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : { [x: number]: number | string; } +>v : { [x: number]: string | number; } +>{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : { [x: number]: string | number; } get [0 + 1]() { return 0 }, >0 + 1 : number diff --git a/tests/baselines/reference/computedPropertyNames4_ES5.types b/tests/baselines/reference/computedPropertyNames4_ES5.types index 3c5f884640fbe..a71b3984ec8fb 100644 --- a/tests/baselines/reference/computedPropertyNames4_ES5.types +++ b/tests/baselines/reference/computedPropertyNames4_ES5.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [x: string]: number | string; [x: number]: number | string; [0]: number; [""]: number; } ->{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [x: string]: number | string; [x: number]: number | string; [0]: number; [""]: number; } +>v : { [x: string]: string | number; [x: number]: string | number; [0]: number; [""]: number; } +>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [x: string]: string | number; [x: number]: string | number; [0]: number; [""]: number; } [s]: 0, >s : string diff --git a/tests/baselines/reference/computedPropertyNames4_ES6.types b/tests/baselines/reference/computedPropertyNames4_ES6.types index 335c2415bd060..a4bcc59711c11 100644 --- a/tests/baselines/reference/computedPropertyNames4_ES6.types +++ b/tests/baselines/reference/computedPropertyNames4_ES6.types @@ -9,8 +9,8 @@ var a: any; >a : any var v = { ->v : { [x: string]: number | string; [x: number]: number | string; [0]: number; [""]: number; } ->{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [x: string]: number | string; [x: number]: number | string; [0]: number; [""]: number; } +>v : { [x: string]: string | number; [x: number]: string | number; [0]: number; [""]: number; } +>{ [s]: 0, [n]: n, [s + s]: 1, [s + n]: 2, [+s]: s, [""]: 0, [0]: 0, [a]: 1, [true]: 0, [`hello bye`]: 0, [`hello ${a} bye`]: 0} : { [x: string]: string | number; [x: number]: string | number; [0]: number; [""]: number; } [s]: 0, >s : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types index b49724ccded92..e5b7440f49e62 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES5.types @@ -17,9 +17,9 @@ declare function foo(obj: I): T >T : T foo({ ->foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | boolean | number | number[] +>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]: string | (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | number | boolean | (() => void) | number[]; [x: number]: number | (() => void) | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types index e88959d7cdc5f..71498d7f3d4ad 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType6_ES6.types @@ -17,9 +17,9 @@ declare function foo(obj: I): T >T : T foo({ ->foo({ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : string | (() => void) | boolean | number | number[] +>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]: string | (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; p: string; } +>{ p: "", 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: string | number | boolean | (() => void) | number[]; [x: number]: number | (() => void) | number[]; 0: () => void; p: string; } p: "", >p : string diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types index 64367864881c9..c209945630332 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES5.types @@ -33,9 +33,9 @@ declare function g(obj: J): T; >T : T foo({ ->foo({ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[] +>foo({ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | (() => void) | number[] >foo : (obj: I) => T ->{ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; } +>{ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: number | boolean | (() => void) | number[]; [x: number]: number | (() => void) | number[]; 0: () => void; } 0: () => { }, >() => { } : () => void diff --git a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types index 07aeda807b0c5..6ae7d7eeadacc 100644 --- a/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types +++ b/tests/baselines/reference/computedPropertyNamesContextualType7_ES6.types @@ -33,9 +33,9 @@ declare function g(obj: J): T; >T : T foo({ ->foo({ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : (() => void) | number | number[] +>foo({ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]}) : number | (() => void) | number[] >foo : (obj: I) => T ->{ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: (() => void) | boolean | number | number[]; [x: number]: (() => void) | number | number[]; 0: () => void; } +>{ 0: () => { }, ["hi" + "bye"]: true, [0 + 1]: 0, [+"hi"]: [0]} : { [x: string]: number | boolean | (() => void) | number[]; [x: number]: number | (() => void) | number[]; 0: () => void; } 0: () => { }, >() => { } : () => void diff --git a/tests/baselines/reference/conditionalExpression1.errors.txt b/tests/baselines/reference/conditionalExpression1.errors.txt index 49ed20953532c..0e2919867858d 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 'number | string' is not assignable to type 'boolean'. - Type 'number' is not assignable to type 'boolean'. +tests/cases/compiler/conditionalExpression1.ts(1,5): error TS2322: Type 'string | number' is not assignable to type 'boolean'. + Type 'string' 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 'number | string' is not assignable to type 'boolean'. -!!! error TS2322: Type 'number' is not assignable to type 'boolean'. \ No newline at end of file +!!! error TS2322: Type 'string | number' is not assignable to type 'boolean'. +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. \ No newline at end of file diff --git a/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types b/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types index 026c8f4227218..3f5f6454eda08 100644 --- a/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types +++ b/tests/baselines/reference/conditionalOperatorWithIdenticalBCT.types @@ -218,7 +218,7 @@ var result10: (t: X) => any = true ? (m) => m.propertyX1 : (n) => n.propertyX2; //Expr1 and Expr2 are literals var result11: any = true ? 1 : 'string'; >result11 : any ->true ? 1 : 'string' : number | string +>true ? 1 : 'string' : string | number >true : boolean >1 : number >'string' : string diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt index 20f4ac1a33582..4011a51f557e9 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.errors.txt @@ -38,9 +38,9 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(160,30): error T tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(160,31): error TS2304: Cannot find name 'Property'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(167,13): error TS2365: Operator '+=' cannot be applied to types 'number' and 'void'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(181,40): error TS2447: The '^' operator is not allowed for boolean types. Consider using '!==' instead. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(182,13): error TS2322: Type 'boolean' is not assignable to type 'true | number'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(184,13): error TS2322: Type 'boolean' is not assignable to type 'true | number'. -tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(192,13): error TS2322: Type 'boolean' is not assignable to type 'true | number'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(182,13): error TS2322: Type 'boolean' is not assignable to type 'number | true'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(184,13): error TS2322: Type 'boolean' is not assignable to type 'number | true'. +tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(192,13): error TS2322: Type 'boolean' is not assignable to type 'number | true'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(206,28): error TS1109: Expression expected. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(214,16): error TS2304: Cannot find name 'bool'. tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(219,10): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. @@ -353,11 +353,11 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(262,1): error TS !!! error TS2447: The '^' operator is not allowed for boolean types. Consider using '!==' instead. b = !b;/*!*/ ~ -!!! error TS2322: Type 'boolean' is not assignable to type 'true | number'. +!!! error TS2322: Type 'boolean' is not assignable to type 'number | true'. i = ~i;/*~i*/ b = i < (i - 1) && (i + 1) > i;/*< && >*/ ~ -!!! error TS2322: Type 'boolean' is not assignable to type 'true | number'. +!!! error TS2322: Type 'boolean' is not assignable to type 'number | true'. var f = true ? 1 : 0;/*? :*/ // YES : i++;/*++*/ i--;/*--*/ @@ -367,7 +367,7 @@ tests/cases/compiler/constructorWithIncompleteTypeAnnotation.ts(262,1): error TS var j = i; b = i == j && i != j && i <= j && i >= j;/*= == && != <= >=*/ ~ -!!! error TS2322: Type 'boolean' is not assignable to type 'true | number'. +!!! error TS2322: Type 'boolean' is not assignable to type 'number | true'. i += 5.0;/*+=*/ i -= i;/*-=*/ i *= i;/**=*/ diff --git a/tests/baselines/reference/contextualSignatureInstantiation.types b/tests/baselines/reference/contextualSignatureInstantiation.types index dd88a00ae3a3e..49d6871804c04 100644 --- a/tests/baselines/reference/contextualSignatureInstantiation.types +++ b/tests/baselines/reference/contextualSignatureInstantiation.types @@ -87,24 +87,24 @@ var a = baz(1, 1, g); // Should be number >g : (x: T, y: T) => T var b: number | string; ->b : number | string +>b : string | number var b = foo(g); // Should be number | string ->b : number | string ->foo(g) : number | string +>b : string | number +>foo(g) : string | number >foo : (cb: (x: number, y: string) => T) => T >g : (x: T, y: T) => T var b = bar(1, "one", g); // Should be number | string ->b : number | string ->bar(1, "one", g) : number | string +>b : string | number +>bar(1, "one", g) : string | number >bar : (x: T, y: U, cb: (x: T, y: U) => V) => V >1 : number >"one" : string >g : (x: T, y: T) => T var b = bar("one", 1, g); // Should be number | string ->b : number | string +>b : string | number >bar("one", 1, g) : string | number >bar : (x: T, y: U, cb: (x: T, y: U) => V) => V >"one" : string @@ -112,11 +112,11 @@ var b = bar("one", 1, g); // Should be number | string >g : (x: T, y: T) => T var b = baz(b, b, g); // Should be number | string ->b : number | string ->baz(b, b, g) : number | string +>b : string | number +>baz(b, b, g) : string | number >baz : (x: T, y: T, cb: (x: T, y: T) => U) => U ->b : number | string ->b : number | string +>b : string | number +>b : string | number >g : (x: T, y: T) => T var d: number[] | string[]; @@ -138,7 +138,7 @@ var d = bar(1, "one", h); // Should be number[] | string[] var d = bar("one", 1, h); // Should be number[] | string[] >d : number[] | string[] ->bar("one", 1, h) : string[] | number[] +>bar("one", 1, h) : number[] | string[] >bar : (x: T, y: U, cb: (x: T, y: U) => V) => V >"one" : string >1 : number diff --git a/tests/baselines/reference/contextualTypeWithTuple.errors.txt b/tests/baselines/reference/contextualTypeWithTuple.errors.txt index d0091aa1e22b8..e0580ca237961 100644 --- a/tests/baselines/reference/contextualTypeWithTuple.errors.txt +++ b/tests/baselines/reference/contextualTypeWithTuple.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(3,5): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'. Types of property 'pop' are incompatible. - Type '() => number | string | boolean' is not assignable to type '() => number | string'. - Type 'number | string | boolean' is not assignable to type 'number | string'. - Type 'true' is not assignable to type 'number | string'. + Type '() => string | number | boolean' is not assignable to type '() => string | number'. + Type 'string | number | boolean' is not assignable to type 'string | number'. + Type 'true' is not assignable to type 'string | number'. tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(15,1): error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'. tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(18,1): error TS2322: Type '[{}, number]' is not assignable to type '[{ a: string; }, number]'. Types of property '0' are incompatible. @@ -30,9 +30,9 @@ tests/cases/conformance/types/tuple/contextualTypeWithTuple.ts(25,1): error TS23 ~~~~~~~~~~~~ !!! error TS2322: Type '[number, string, boolean]' is not assignable to type '[number, string]'. !!! error TS2322: Types of property 'pop' are incompatible. -!!! error TS2322: Type '() => number | string | boolean' is not assignable to type '() => number | string'. -!!! error TS2322: Type 'number | string | boolean' is not assignable to type 'number | string'. -!!! error TS2322: Type 'true' is not assignable to type 'number | string'. +!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => string | number'. +!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'string | number'. +!!! error TS2322: Type 'true' is not assignable to type 'string | number'. var numStrBoolTuple: [number, string, boolean] = [5, "foo", true]; var objNumTuple: [{ a: string }, number] = [{ a: "world" }, 5]; var strTupleTuple: [string, [number, {}]] = ["bar", [5, { x: 1, y: 1 }]]; diff --git a/tests/baselines/reference/contextualTyping21.errors.txt b/tests/baselines/reference/contextualTyping21.errors.txt index db6ecd32b97f5..0bac30d5b4462 100644 --- a/tests/baselines/reference/contextualTyping21.errors.txt +++ b/tests/baselines/reference/contextualTyping21.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type '({ id: number; } | number)[]' is not assignable to type '{ id: number; }[]'. - Type '{ id: number; } | number' is not assignable to type '{ id: number; }'. +tests/cases/compiler/contextualTyping21.ts(1,36): error TS2322: Type '(number | { id: number; })[]' is not assignable to type '{ id: number; }[]'. + Type 'number | { id: number; }' is not assignable to type '{ id: number; }'. Type 'number' is not assignable to type '{ id: number; }'. ==== tests/cases/compiler/contextualTyping21.ts (1 errors) ==== var foo:{id:number;}[] = [{id:1}]; foo = [{id:1}, 1]; ~~~ -!!! error TS2322: Type '({ id: number; } | number)[]' is not assignable to type '{ id: number; }[]'. -!!! error TS2322: Type '{ id: number; } | number' is not assignable to type '{ id: number; }'. +!!! error TS2322: Type '(number | { id: number; })[]' is not assignable to type '{ id: number; }[]'. +!!! error TS2322: Type 'number | { id: number; }' is not assignable to type '{ id: number; }'. !!! error TS2322: Type 'number' is not assignable to type '{ id: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTyping30.errors.txt b/tests/baselines/reference/contextualTyping30.errors.txt index bce19c508967c..eda30769ac81d 100644 --- a/tests/baselines/reference/contextualTyping30.errors.txt +++ b/tests/baselines/reference/contextualTyping30.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. - Type 'number | string' is not assignable to type 'number'. +tests/cases/compiler/contextualTyping30.ts(1,37): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. ==== tests/cases/compiler/contextualTyping30.ts (1 errors) ==== function foo(param:number[]){}; foo([1, "a"]); ~~~~~~~~ -!!! error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type 'number | string' is not assignable to type 'number'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number'. !!! error TS2345: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt index 698a8e789f0d8..be73de51f138b 100644 --- a/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt +++ b/tests/baselines/reference/contextualTypingOfArrayLiterals1.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '(Date | number)[]' is not assignable to type 'I'. +tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Type '(number | Date)[]' is not assignable to type 'I'. Index signatures are incompatible. - Type 'Date | number' is not assignable to type 'Date'. + Type 'number | Date' is not assignable to type 'Date'. Type 'number' is not assignable to type 'Date'. @@ -11,9 +11,9 @@ tests/cases/compiler/contextualTypingOfArrayLiterals1.ts(5,5): error TS2322: Typ var x3: I = [new Date(), 1]; ~~ -!!! error TS2322: Type '(Date | number)[]' is not assignable to type 'I'. +!!! error TS2322: Type '(number | Date)[]' is not assignable to type 'I'. !!! error TS2322: Index signatures are incompatible. -!!! error TS2322: Type 'Date | number' is not assignable to type 'Date'. +!!! error TS2322: Type 'number | Date' is not assignable to type 'Date'. !!! error TS2322: Type 'number' is not assignable to type 'Date'. var r2 = x3[1]; r2.getDate(); diff --git a/tests/baselines/reference/contextuallyTypedIife.types b/tests/baselines/reference/contextuallyTypedIife.types index 0f2092ef7c381..8777e3cef3f95 100644 --- a/tests/baselines/reference/contextuallyTypedIife.types +++ b/tests/baselines/reference/contextuallyTypedIife.types @@ -119,18 +119,18 @@ ((...mixed) => mixed.every(n => !!n))(5,'oops','oh no'); >((...mixed) => mixed.every(n => !!n))(5,'oops','oh no') : boolean ->((...mixed) => mixed.every(n => !!n)) : (...mixed: (number | string)[]) => boolean ->(...mixed) => mixed.every(n => !!n) : (...mixed: (number | string)[]) => boolean ->mixed : (number | string)[] +>((...mixed) => mixed.every(n => !!n)) : (...mixed: (string | number)[]) => boolean +>(...mixed) => mixed.every(n => !!n) : (...mixed: (string | number)[]) => boolean +>mixed : (string | number)[] >mixed.every(n => !!n) : boolean ->mixed.every : (callbackfn: (value: number | string, index: number, array: (number | string)[]) => boolean, thisArg?: any) => boolean ->mixed : (number | string)[] ->every : (callbackfn: (value: number | string, index: number, array: (number | string)[]) => boolean, thisArg?: any) => boolean ->n => !!n : (n: number | string) => boolean ->n : number | string +>mixed.every : (callbackfn: (value: string | number, index: number, array: (string | number)[]) => boolean, thisArg?: any) => boolean +>mixed : (string | number)[] +>every : (callbackfn: (value: string | number, index: number, array: (string | number)[]) => boolean, thisArg?: any) => boolean +>n => !!n : (n: string | number) => boolean +>n : string | number >!!n : boolean >!n : boolean ->n : number | string +>n : string | number >5 : number >'oops' : string >'oh no' : string diff --git a/tests/baselines/reference/controlFlowAssignmentExpression.types b/tests/baselines/reference/controlFlowAssignmentExpression.types index 24355fd8c4a40..107fb4cb332ec 100644 --- a/tests/baselines/reference/controlFlowAssignmentExpression.types +++ b/tests/baselines/reference/controlFlowAssignmentExpression.types @@ -1,18 +1,18 @@ === tests/cases/conformance/controlFlow/controlFlowAssignmentExpression.ts === let x: string | boolean | number; ->x : string | boolean | number +>x : string | number | boolean let obj: any; >obj : any x = ""; >x = "" : string ->x : string | boolean | number +>x : string | number | boolean >"" : string x = x.length; >x = x.length : number ->x : string | boolean | number +>x : string | number | boolean >x.length : number >x : string >length : number @@ -22,7 +22,7 @@ x; // number x = true; >x = true : boolean ->x : string | boolean | number +>x : string | number | boolean >true : boolean (x = "", obj).foo = (x = x.length); @@ -31,13 +31,13 @@ x = true; >(x = "", obj) : any >x = "", obj : any >x = "" : string ->x : string | boolean | number +>x : string | number | boolean >"" : string >obj : any >foo : any >(x = x.length) : number >x = x.length : number ->x : string | boolean | number +>x : string | number | boolean >x.length : number >x : string >length : number diff --git a/tests/baselines/reference/controlFlowBinaryOrExpression.symbols b/tests/baselines/reference/controlFlowBinaryOrExpression.symbols index 8af9a35c18213..e76cfbf4caba9 100644 --- a/tests/baselines/reference/controlFlowBinaryOrExpression.symbols +++ b/tests/baselines/reference/controlFlowBinaryOrExpression.symbols @@ -64,9 +64,9 @@ if (isNodeList(sourceObj)) { >sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) sourceObj.length; ->sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 14, 33), Decl(controlFlowBinaryOrExpression.ts, 10, 27)) +>sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33)) >sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) ->length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 14, 33), Decl(controlFlowBinaryOrExpression.ts, 10, 27)) +>length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33)) } if (isHTMLCollection(sourceObj)) { @@ -74,9 +74,9 @@ if (isHTMLCollection(sourceObj)) { >sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) sourceObj.length; ->sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 14, 33), Decl(controlFlowBinaryOrExpression.ts, 10, 27)) +>sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33)) >sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) ->length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 14, 33), Decl(controlFlowBinaryOrExpression.ts, 10, 27)) +>length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33)) } if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { @@ -86,8 +86,8 @@ if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { >sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) sourceObj.length; ->sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 14, 33), Decl(controlFlowBinaryOrExpression.ts, 10, 27)) +>sourceObj.length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33)) >sourceObj : Symbol(sourceObj, Decl(controlFlowBinaryOrExpression.ts, 23, 3)) ->length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 14, 33), Decl(controlFlowBinaryOrExpression.ts, 10, 27)) +>length : Symbol(length, Decl(controlFlowBinaryOrExpression.ts, 10, 27), Decl(controlFlowBinaryOrExpression.ts, 14, 33)) } diff --git a/tests/baselines/reference/controlFlowBinaryOrExpression.types b/tests/baselines/reference/controlFlowBinaryOrExpression.types index bf2a55e24e743..11f28b3df19ed 100644 --- a/tests/baselines/reference/controlFlowBinaryOrExpression.types +++ b/tests/baselines/reference/controlFlowBinaryOrExpression.types @@ -25,7 +25,7 @@ x = ""; >"" : string cond || (x = 0); ->cond || (x = 0) : true | number +>cond || (x = 0) : number | true >cond : boolean >(x = 0) : number >x = 0 : number @@ -62,36 +62,36 @@ declare function isHTMLCollection(sourceObj: any): sourceObj is HTMLCollection; >HTMLCollection : HTMLCollection type EventTargetLike = {a: string} | HTMLCollection | NodeList; ->EventTargetLike : { a: string; } | HTMLCollection | NodeList +>EventTargetLike : NodeList | HTMLCollection | { a: string; } >a : string >HTMLCollection : HTMLCollection >NodeList : NodeList var sourceObj: EventTargetLike = undefined; ->sourceObj : { a: string; } | HTMLCollection | NodeList ->EventTargetLike : { a: string; } | HTMLCollection | NodeList +>sourceObj : NodeList | HTMLCollection | { a: string; } +>EventTargetLike : NodeList | HTMLCollection | { a: string; } >undefined : any >undefined : undefined if (isNodeList(sourceObj)) { >isNodeList(sourceObj) : boolean >isNodeList : (sourceObj: any) => sourceObj is NodeList ->sourceObj : { a: string; } | HTMLCollection | NodeList +>sourceObj : NodeList | HTMLCollection | { a: string; } sourceObj.length; >sourceObj.length : number ->sourceObj : HTMLCollection | NodeList +>sourceObj : NodeList | HTMLCollection >length : number } if (isHTMLCollection(sourceObj)) { >isHTMLCollection(sourceObj) : boolean >isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection ->sourceObj : HTMLCollection | NodeList | { a: string; } +>sourceObj : NodeList | HTMLCollection | { a: string; } sourceObj.length; >sourceObj.length : number ->sourceObj : HTMLCollection | NodeList +>sourceObj : NodeList | HTMLCollection >length : number } @@ -99,14 +99,14 @@ if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { >isNodeList(sourceObj) || isHTMLCollection(sourceObj) : boolean >isNodeList(sourceObj) : boolean >isNodeList : (sourceObj: any) => sourceObj is NodeList ->sourceObj : HTMLCollection | NodeList | { a: string; } +>sourceObj : NodeList | HTMLCollection | { a: string; } >isHTMLCollection(sourceObj) : boolean >isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection >sourceObj : { a: string; } sourceObj.length; >sourceObj.length : number ->sourceObj : HTMLCollection | NodeList | ({ a: string; } & HTMLCollection) +>sourceObj : NodeList | HTMLCollection | ({ a: string; } & HTMLCollection) >length : number } diff --git a/tests/baselines/reference/controlFlowCommaOperator.types b/tests/baselines/reference/controlFlowCommaOperator.types index 328bffc42ab05..211fae3655a14 100644 --- a/tests/baselines/reference/controlFlowCommaOperator.types +++ b/tests/baselines/reference/controlFlowCommaOperator.types @@ -66,6 +66,6 @@ function f(x: string | number | boolean) { >y : string z; // number | boolean ->z : boolean | number +>z : number | boolean } diff --git a/tests/baselines/reference/controlFlowDeleteOperator.types b/tests/baselines/reference/controlFlowDeleteOperator.types index 365174db0587d..b0040f12bc2c2 100644 --- a/tests/baselines/reference/controlFlowDeleteOperator.types +++ b/tests/baselines/reference/controlFlowDeleteOperator.types @@ -4,76 +4,76 @@ function f() { >f : () => void let x: { a?: number | string, b: number | string } = { b: 1 }; ->x : { a?: number | string | undefined; b: number | string; } ->a : number | string | undefined ->b : number | string +>x : { a?: string | number | undefined; b: string | number; } +>a : string | number | undefined +>b : string | number >{ b: 1 } : { b: number; } >b : number >1 : number x.a; ->x.a : number | string | undefined ->x : { a?: number | string | undefined; b: number | string; } ->a : number | string | undefined +>x.a : string | number | undefined +>x : { a?: string | number | undefined; b: string | number; } +>a : string | number | undefined x.b; ->x.b : number | string ->x : { a?: number | string | undefined; b: number | string; } ->b : number | string +>x.b : string | number +>x : { a?: string | number | undefined; b: string | number; } +>b : string | number x.a = 1; >x.a = 1 : number ->x.a : number | string | undefined ->x : { a?: number | string | undefined; b: number | string; } ->a : number | string | undefined +>x.a : string | number | undefined +>x : { a?: string | number | undefined; b: string | number; } +>a : string | number | undefined >1 : number x.b = 1; >x.b = 1 : number ->x.b : number | string ->x : { a?: number | string | undefined; b: number | string; } ->b : number | string +>x.b : string | number +>x : { a?: string | number | undefined; b: string | number; } +>b : string | number >1 : number x.a; >x.a : number ->x : { a?: number | string | undefined; b: number | string; } +>x : { a?: string | number | undefined; b: string | number; } >a : number x.b; >x.b : number ->x : { a?: number | string | undefined; b: number | string; } +>x : { a?: string | number | undefined; b: string | number; } >b : number delete x.a; >delete x.a : boolean >x.a : number ->x : { a?: number | string | undefined; b: number | string; } +>x : { a?: string | number | undefined; b: string | number; } >a : number delete x.b; >delete x.b : boolean >x.b : number ->x : { a?: number | string | undefined; b: number | string; } +>x : { a?: string | number | undefined; b: string | number; } >b : number x.a; >x.a : undefined ->x : { a?: number | string | undefined; b: number | string; } +>x : { a?: string | number | undefined; b: string | number; } >a : undefined x.b; ->x.b : number | string ->x : { a?: number | string | undefined; b: number | string; } ->b : number | string +>x.b : string | number +>x : { a?: string | number | undefined; b: string | number; } +>b : string | number x; ->x : { a?: number | string | undefined; b: number | string; } +>x : { a?: string | number | undefined; b: string | number; } delete x; // No effect >delete x : boolean ->x : { a?: number | string | undefined; b: number | string; } +>x : { a?: string | number | undefined; b: string | number; } x; ->x : { a?: number | string | undefined; b: number | string; } +>x : { a?: string | number | undefined; b: string | number; } } diff --git a/tests/baselines/reference/controlFlowDoWhileStatement.types b/tests/baselines/reference/controlFlowDoWhileStatement.types index ffd9f03096f52..55329cbcea1d5 100644 --- a/tests/baselines/reference/controlFlowDoWhileStatement.types +++ b/tests/baselines/reference/controlFlowDoWhileStatement.types @@ -131,13 +131,13 @@ function f() { >f : () => void let x: string | number | boolean | RegExp | Function; ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >RegExp : RegExp >Function : Function x = ""; >x = "" : string ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >"" : string do { @@ -146,7 +146,7 @@ function f() { x = 42; >x = 42 : number ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >42 : number break; @@ -156,14 +156,14 @@ function f() { x = true; >x = true : boolean ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >true : boolean continue; } x = /a/; >x = /a/ : RegExp ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >/a/ : RegExp } while (cond) @@ -176,13 +176,13 @@ function g() { >g : () => void let x: string | number | boolean | RegExp | Function; ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >RegExp : RegExp >Function : Function x = ""; >x = "" : string ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >"" : string do { @@ -191,7 +191,7 @@ function g() { x = 42; >x = 42 : number ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >42 : number break; @@ -201,14 +201,14 @@ function g() { x = true; >x = true : boolean ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >true : boolean continue; } x = /a/; >x = /a/ : RegExp ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >/a/ : RegExp } while (true) diff --git a/tests/baselines/reference/controlFlowForInStatement.types b/tests/baselines/reference/controlFlowForInStatement.types index e46db37bb16fb..cab3a70160231 100644 --- a/tests/baselines/reference/controlFlowForInStatement.types +++ b/tests/baselines/reference/controlFlowForInStatement.types @@ -1,6 +1,6 @@ === tests/cases/conformance/controlFlow/controlFlowForInStatement.ts === let x: string | number | boolean | RegExp | Function; ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >RegExp : RegExp >Function : Function @@ -12,7 +12,7 @@ let cond: boolean; x = /a/; >x = /a/ : RegExp ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >/a/ : RegExp for (let y in obj) { @@ -21,7 +21,7 @@ for (let y in obj) { x = y; >x = y : string ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >y : string if (cond) { @@ -29,7 +29,7 @@ for (let y in obj) { x = 42; >x = 42 : number ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >42 : number continue; @@ -39,12 +39,12 @@ for (let y in obj) { x = true; >x = true : boolean ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >true : boolean break; } } x; // RegExp | string | number | boolean ->x : RegExp | number | string | boolean +>x : string | number | boolean | RegExp diff --git a/tests/baselines/reference/controlFlowForOfStatement.types b/tests/baselines/reference/controlFlowForOfStatement.types index 437576e51b6c4..41e312347e798 100644 --- a/tests/baselines/reference/controlFlowForOfStatement.types +++ b/tests/baselines/reference/controlFlowForOfStatement.types @@ -27,6 +27,6 @@ function a() { >toExponential : (fractionDigits?: number) => string } x; // string | boolean ->x : boolean | string +>x : string | boolean } diff --git a/tests/baselines/reference/controlFlowPropertyDeclarations.types b/tests/baselines/reference/controlFlowPropertyDeclarations.types index 38f05122d69d1..030f22a1ffb0d 100644 --- a/tests/baselines/reference/controlFlowPropertyDeclarations.types +++ b/tests/baselines/reference/controlFlowPropertyDeclarations.types @@ -316,9 +316,9 @@ export class HTMLtoJSX { >'{' + JSON.stringify(whitespace) : string >'{' : string >JSON.stringify(whitespace) : string ->JSON.stringify : { (value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (number | string)[], space?: string | number): string; } +>JSON.stringify : { (value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; } >JSON : JSON ->stringify : { (value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (number | string)[], space?: string | number): string; } +>stringify : { (value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; } >whitespace : string >'}' : string diff --git a/tests/baselines/reference/controlFlowWhileStatement.types b/tests/baselines/reference/controlFlowWhileStatement.types index 5ab48e02e2b8e..8caae2238d229 100644 --- a/tests/baselines/reference/controlFlowWhileStatement.types +++ b/tests/baselines/reference/controlFlowWhileStatement.types @@ -135,13 +135,13 @@ function f() { >f : () => void let x: string | number | boolean | RegExp | Function; ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >RegExp : RegExp >Function : Function x = ""; >x = "" : string ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >"" : string while (cond) { @@ -152,7 +152,7 @@ function f() { x = 42; >x = 42 : number ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >42 : number break; @@ -162,30 +162,30 @@ function f() { x = true; >x = true : boolean ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >true : boolean continue; } x = /a/; >x = /a/ : RegExp ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >/a/ : RegExp } x; // string | number | boolean | RegExp ->x : string | boolean | RegExp | number +>x : string | number | boolean | RegExp } function g() { >g : () => void let x: string | number | boolean | RegExp | Function; ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >RegExp : RegExp >Function : Function x = ""; >x = "" : string ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >"" : string while (true) { @@ -196,7 +196,7 @@ function g() { x = 42; >x = 42 : number ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >42 : number break; @@ -206,14 +206,14 @@ function g() { x = true; >x = true : boolean ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >true : boolean continue; } x = /a/; >x = /a/ : RegExp ->x : string | number | boolean | RegExp | Function +>x : string | number | boolean | Function | RegExp >/a/ : RegExp } x; // number diff --git a/tests/baselines/reference/declFileTypeAnnotationParenType.js b/tests/baselines/reference/declFileTypeAnnotationParenType.js index 4afe07cc9d8d0..4707007cd1b3f 100644 --- a/tests/baselines/reference/declFileTypeAnnotationParenType.js +++ b/tests/baselines/reference/declFileTypeAnnotationParenType.js @@ -29,4 +29,4 @@ declare class c { declare var x: (() => c)[]; declare var y: (() => c)[]; declare var k: (() => c) | string; -declare var l: (() => c) | string; +declare var l: string | (() => c); diff --git a/tests/baselines/reference/declFileTypeAnnotationParenType.types b/tests/baselines/reference/declFileTypeAnnotationParenType.types index 6776a0f492f41..31b6ad037513d 100644 --- a/tests/baselines/reference/declFileTypeAnnotationParenType.types +++ b/tests/baselines/reference/declFileTypeAnnotationParenType.types @@ -23,9 +23,9 @@ var y = [() => new c()]; >c : typeof c var k: (() => c) | string = (() => new c()) || ""; ->k : (() => c) | string +>k : string | (() => c) >c : c ->(() => new c()) || "" : (() => c) | string +>(() => new c()) || "" : string | (() => c) >(() => new c()) : () => c >() => new c() : () => c >new c() : c @@ -33,8 +33,8 @@ var k: (() => c) | string = (() => new c()) || ""; >"" : string var l = (() => new c()) || ""; ->l : (() => c) | string ->(() => new c()) || "" : (() => c) | string +>l : string | (() => c) +>(() => new c()) || "" : string | (() => c) >(() => new c()) : () => c >() => new c() : () => c >new c() : c diff --git a/tests/baselines/reference/declFileTypeAnnotationTypeAlias.types b/tests/baselines/reference/declFileTypeAnnotationTypeAlias.types index e93f86dbde72f..beef88c0ca25c 100644 --- a/tests/baselines/reference/declFileTypeAnnotationTypeAlias.types +++ b/tests/baselines/reference/declFileTypeAnnotationTypeAlias.types @@ -47,7 +47,7 @@ module M { >M : typeof M export type W = Window | string; ->W : Window | string +>W : string | Window >Window : Window export module N { @@ -57,7 +57,7 @@ module M { >Window : Window export var p: W; ->p : Window | string ->W : Window | string +>p : string | Window +>W : string | Window } } diff --git a/tests/baselines/reference/declarationEmitDestructuring3.js b/tests/baselines/reference/declarationEmitDestructuring3.js index 81cb1d96fd8fc..b21c63203c894 100644 --- a/tests/baselines/reference/declarationEmitDestructuring3.js +++ b/tests/baselines/reference/declarationEmitDestructuring3.js @@ -15,4 +15,4 @@ function foo(_a) { //// [declarationEmitDestructuring3.d.ts] declare function bar([x, z, ...w]: any[]): void; -declare function foo([x, ...y]?: (number | string | boolean)[]): void; +declare function foo([x, ...y]?: (string | number | boolean)[]): void; diff --git a/tests/baselines/reference/declarationEmitDestructuring3.types b/tests/baselines/reference/declarationEmitDestructuring3.types index 737bb39e078f8..da9fc6d66061b 100644 --- a/tests/baselines/reference/declarationEmitDestructuring3.types +++ b/tests/baselines/reference/declarationEmitDestructuring3.types @@ -6,10 +6,10 @@ function bar([x, z, ...w]) { } >w : any[] function foo([x, ...y] = [1, "string", true]) { } ->foo : ([x, ...y]?: (number | string | boolean)[]) => void ->x : number | string | boolean ->y : (number | string | boolean)[] ->[1, "string", true] : (number | string | boolean)[] +>foo : ([x, ...y]?: (string | number | boolean)[]) => void +>x : string | number | boolean +>y : (string | number | boolean)[] +>[1, "string", true] : (string | number | boolean)[] >1 : number >"string" : string >true : boolean diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js index 28330d94f7797..9a9be8c69da32 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js @@ -23,6 +23,6 @@ var x3 = a[0], y3 = a[1], z3 = a[2]; // emit x3, y3, z3 declare var x: number; declare var x1: number, y1: string; declare var z1: number; -declare var a: (number | string)[]; -declare var x2: number | string; -declare var x3: number | string, y3: number | string, z3: number | string; +declare var a: (string | number)[]; +declare var x2: string | number; +declare var x3: string | number, y3: string | number, z3: string | number; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types index 9629324b9f92b..0feeaf2db1ad0 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types @@ -1,7 +1,7 @@ === tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts === var [] = [1, "hello"]; // Dont emit anything ->[1, "hello"] : (number | string)[] +>[1, "hello"] : (string | number)[] >1 : number >"hello" : string @@ -28,18 +28,18 @@ var [, , z1] = [0, 1, 2]; // emit z1: number >2 : number var a = [1, "hello"]; ->a : (number | string)[] ->[1, "hello"] : (number | string)[] +>a : (string | number)[] +>[1, "hello"] : (string | number)[] >1 : number >"hello" : string var [x2] = a; // emit x2: number | string ->x2 : number | string ->a : (number | string)[] +>x2 : string | number +>a : (string | number)[] var [x3, y3, z3] = a; // emit x3, y3, z3 ->x3 : number | string ->y3 : number | string ->z3 : number | string ->a : (number | string)[] +>x3 : string | number +>y3 : string | number +>z3 : string | number +>a : (string | number)[] diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js index 662b4625ec807..818b3a6f7a97b 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js @@ -25,7 +25,7 @@ declare var x11: number, y11: string; declare var a11: any, b11: any, c11: any; declare var a2: number, b2: string, x12: number, c2: boolean; declare var x13: number, y13: string; -declare var a3: (number | string)[], b3: { +declare var a3: (string | number)[], b3: { x: number; y: string; }; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js index d83c1b721d871..1bd07e7b974e8 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js @@ -25,7 +25,7 @@ declare var a5: number[]; declare var x14: number, a6: number[]; declare var x15: number, y15: number, a7: number[]; declare var x16: number, y16: number, z16: number, a8: number[]; -declare var a9: (number | string | boolean)[]; -declare var x17: number | string | boolean, a10: (number | string | boolean)[]; -declare var x18: number | string | boolean, y18: number | string | boolean, a12: (number | string | boolean)[]; -declare var x19: number | string | boolean, y19: number | string | boolean, z19: number | string | boolean, a13: (number | string | boolean)[]; +declare var a9: (string | number | boolean)[]; +declare var x17: string | number | boolean, a10: (string | number | boolean)[]; +declare var x18: string | number | boolean, y18: string | number | boolean, a12: (string | number | boolean)[]; +declare var x19: string | number | boolean, y19: string | number | boolean, z19: string | number | boolean, a13: (string | number | boolean)[]; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types index 1e8701eedb520..2cc56abcb05b5 100644 --- a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types @@ -34,35 +34,35 @@ var [x16, y16, z16, ...a8] = [1, 2, 3]; >3 : number var [...a9] = [1, "hello", true]; ->a9 : (number | string | boolean)[] ->[1, "hello", true] : (number | string | boolean)[] +>a9 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] >1 : number >"hello" : string >true : boolean var [x17, ...a10] = [1, "hello", true]; ->x17 : number | string | boolean ->a10 : (number | string | boolean)[] ->[1, "hello", true] : (number | string | boolean)[] +>x17 : string | number | boolean +>a10 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] >1 : number >"hello" : string >true : boolean var [x18, y18, ...a12] = [1, "hello", true]; ->x18 : number | string | boolean ->y18 : number | string | boolean ->a12 : (number | string | boolean)[] ->[1, "hello", true] : (number | string | boolean)[] +>x18 : string | number | boolean +>y18 : string | number | boolean +>a12 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] >1 : number >"hello" : string >true : boolean var [x19, y19, z19, ...a13] = [1, "hello", true]; ->x19 : number | string | boolean ->y19 : number | string | boolean ->z19 : number | string | boolean ->a13 : (number | string | boolean)[] ->[1, "hello", true] : (number | string | boolean)[] +>x19 : string | number | boolean +>y19 : string | number | boolean +>z19 : string | number | boolean +>a13 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] >1 : number >"hello" : string >true : boolean diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.types b/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.types index 16dc655cc2f89..8e42146b8242b 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.types +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.types @@ -1,21 +1,21 @@ === tests/cases/conformance/es6/moduleExportsAmd/a.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => TFunction | void ->ClassDecorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction +>ClassDecorator : (target: TFunction) => void | TFunction @decorator ->decorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction export default class Foo {} >Foo : Foo === tests/cases/conformance/es6/moduleExportsAmd/b.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => TFunction | void ->ClassDecorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction +>ClassDecorator : (target: TFunction) => void | TFunction @decorator ->decorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction export default class {} diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.types b/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.types index 01aaf5c0dbe4b..ec4bd9f5476ae 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.types +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.types @@ -1,21 +1,21 @@ === tests/cases/conformance/es6/moduleExportsCommonjs/a.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => TFunction | void ->ClassDecorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction +>ClassDecorator : (target: TFunction) => void | TFunction @decorator ->decorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction export default class Foo {} >Foo : Foo === tests/cases/conformance/es6/moduleExportsCommonjs/b.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => TFunction | void ->ClassDecorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction +>ClassDecorator : (target: TFunction) => void | TFunction @decorator ->decorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction export default class {} diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.types b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.types index ae36b44266513..0577559b7d9df 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.types +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.types @@ -1,20 +1,20 @@ === tests/cases/conformance/es6/moduleExportsSystem/a.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => TFunction | void ->ClassDecorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction +>ClassDecorator : (target: TFunction) => void | TFunction @decorator ->decorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction export default class Foo {} >Foo : Foo === tests/cases/conformance/es6/moduleExportsSystem/b.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => TFunction | void ->ClassDecorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction +>ClassDecorator : (target: TFunction) => void | TFunction @decorator ->decorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction export default class {} diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.types b/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.types index 68212835a6fce..399c0a79ee259 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.types +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.types @@ -1,21 +1,21 @@ === tests/cases/conformance/es6/moduleExportsUmd/a.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => TFunction | void ->ClassDecorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction +>ClassDecorator : (target: TFunction) => void | TFunction @decorator ->decorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction export default class Foo {} >Foo : Foo === tests/cases/conformance/es6/moduleExportsUmd/b.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => TFunction | void ->ClassDecorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction +>ClassDecorator : (target: TFunction) => void | TFunction @decorator ->decorator : (target: TFunction) => TFunction | void +>decorator : (target: TFunction) => void | TFunction export default class {} diff --git a/tests/baselines/reference/decoratorMetadataPromise.types b/tests/baselines/reference/decoratorMetadataPromise.types index 900e751e84172..953458ca5fe8d 100644 --- a/tests/baselines/reference/decoratorMetadataPromise.types +++ b/tests/baselines/reference/decoratorMetadataPromise.types @@ -1,20 +1,20 @@ === tests/cases/compiler/decoratorMetadataPromise.ts === declare const decorator: MethodDecorator; ->decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void ->MethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void +>decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor +>MethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor class A { >A : A @decorator ->decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void +>decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor async foo() {} >foo : () => Promise @decorator ->decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void +>decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor async bar(): Promise { return 0; } >bar : () => Promise @@ -22,7 +22,7 @@ class A { >0 : number @decorator ->decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void +>decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor baz(n: Promise): Promise { return n; } >baz : (n: Promise) => Promise diff --git a/tests/baselines/reference/destructureOptionalParameter.types b/tests/baselines/reference/destructureOptionalParameter.types index 2e569dee0a0ea..ea0e8c4b754e2 100644 --- a/tests/baselines/reference/destructureOptionalParameter.types +++ b/tests/baselines/reference/destructureOptionalParameter.types @@ -40,7 +40,7 @@ interface QueryMetadataFactory { >QueryMetadataFactory : QueryMetadataFactory (selector: Type | string, {descendants, read}?: { ->selector : Type | string +>selector : string | Type >Type : Type >descendants : boolean | undefined >read : any @@ -55,7 +55,7 @@ interface QueryMetadataFactory { >ParameterDecorator : (target: Object, propertyKey: string | symbol, parameterIndex: number) => void new (selector: Type | string, {descendants, read}?: { ->selector : Type | string +>selector : string | Type >Type : Type >descendants : boolean | undefined >read : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt index d68220c830871..878bb38abf0fc 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt @@ -4,8 +4,8 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,29): error TS1005: ',' expected. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(8,4): error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. Types of property 'pop' are incompatible. - Type '() => number | string[][] | string' is not assignable to type '() => number | string[][]'. - Type 'number | string[][] | string' is not assignable to type 'number | string[][]'. + Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. + Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. Type 'string' is not assignable to type 'number | string[][]'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. @@ -25,9 +25,9 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(37,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z?: number; }'. Types of property 'z' are incompatible. Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(38,4): error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: number | string; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(38,4): error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'. Types of property 'b' are incompatible. - Type 'boolean' is not assignable to type 'number | string'. + Type 'boolean' is not assignable to type 'string | number'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(39,4): error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. Types of property '2' are incompatible. Type 'boolean' is not assignable to type '[[any]]'. @@ -70,8 +70,8 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. !!! error TS2345: Types of property 'pop' are incompatible. -!!! error TS2345: Type '() => number | string[][] | string' is not assignable to type '() => number | string[][]'. -!!! error TS2345: Type 'number | string[][] | string' is not assignable to type 'number | string[][]'. +!!! error TS2345: Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. +!!! error TS2345: Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. !!! error TS2345: Type 'string' is not assignable to type 'number | string[][]'. @@ -131,9 +131,9 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( !!! error TS2345: Type 'boolean' is not assignable to type 'number'. c3({ b: true }); // Error, implied type is { b: number|string }. ~~~~~~~~~~~ -!!! error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: number | string; }'. +!!! error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'. !!! error TS2345: Types of property 'b' are incompatible. -!!! error TS2345: Type 'boolean' is not assignable to type 'number | string'. +!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] ~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5.types b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types index b8d48dcb9d41d..d51a0e32dc8c8 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES5.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types @@ -23,8 +23,8 @@ type stringOrNumArray = Array; >Number : Number function a1(...x: (number|string)[]) { } ->a1 : (...x: (number | string)[]) => void ->x : (number | string)[] +>a1 : (...x: (string | number)[]) => void +>x : (string | number)[] function a2(...a) { } >a2 : (...a: any[]) => void @@ -75,8 +75,8 @@ var array = [1, 2, 3]; >3 : number var array2 = [true, false, "hello"]; ->array2 : (boolean | string)[] ->[true, false, "hello"] : (boolean | string)[] +>array2 : (string | boolean)[] +>[true, false, "hello"] : (string | boolean)[] >true : boolean >false : boolean >"hello" : string @@ -90,7 +90,7 @@ a2([...array]); a1(...array); >a1(...array) : void ->a1 : (...x: (number | string)[]) => void +>a1 : (...x: (string | number)[]) => void >...array : number >array : number[] @@ -109,7 +109,7 @@ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]] a10([1, 2, [["string"]], false, true]); // Parameter type is any[] >a10([1, 2, [["string"]], false, true]) : void >a10 : ([a, b, [[c]], ...x]: Iterable) => void ->[1, 2, [["string"]], false, true] : (number | string[][] | boolean)[] +>[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] >1 : number >2 : number >[["string"]] : string[][] diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types index b439c4134ba00..63d5d074a8d65 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types @@ -23,8 +23,8 @@ type stringOrNumArray = Array; >Number : Number function a1(...x: (number|string)[]) { } ->a1 : (...x: (number | string)[]) => void ->x : (number | string)[] +>a1 : (...x: (string | number)[]) => void +>x : (string | number)[] function a2(...a) { } >a2 : (...a: any[]) => void @@ -75,8 +75,8 @@ var array = [1, 2, 3]; >3 : number var array2 = [true, false, "hello"]; ->array2 : (boolean | string)[] ->[true, false, "hello"] : (boolean | string)[] +>array2 : (string | boolean)[] +>[true, false, "hello"] : (string | boolean)[] >true : boolean >false : boolean >"hello" : string @@ -90,7 +90,7 @@ a2([...array]); a1(...array); >a1(...array) : void ->a1 : (...x: (number | string)[]) => void +>a1 : (...x: (string | number)[]) => void >...array : number >array : number[] @@ -109,7 +109,7 @@ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]] a10([1, 2, [["string"]], false, true]); // Parameter type is any[] >a10([1, 2, [["string"]], false, true]) : void >a10 : ([a, b, [[c]], ...x]: Iterable) => void ->[1, 2, [["string"]], false, true] : (number | string[][] | boolean)[] +>[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] >1 : number >2 : number >[["string"]] : string[][] diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt index 89c771139ce54..c89fa97b4cdc9 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -2,15 +2,15 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(13,13): error TS2370: A rest parameter must be of an array type. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(14,17): error TS1047: A rest parameter cannot be optional. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(15,16): error TS1048: A rest parameter cannot have an initializer. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(20,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number | string'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(20,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(21,7): error TS2304: Cannot find name 'array2'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(22,4): error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. Types of property '2' are incompatible. Type 'string' is not assignable to type '[[any]]'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(23,4): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'. Property '2' is missing in type '[number, number]'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(24,4): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. - Type 'number | string' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(24,4): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(29,17): error TS1317: A parameter property cannot be declared using a rest parameter. tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,22): error TS2304: Cannot find name 'E1'. @@ -47,7 +47,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] ~~~~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'number | string'. +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. a1(...array2); // Error parameter type is (number|string)[] ~~~~~~ !!! error TS2304: Cannot find name 'array2'. @@ -62,8 +62,8 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( !!! error TS2345: Property '2' is missing in type '[number, number]'. a6([1, 2, "string"]); // Error, parameter type is number[] ~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type 'number | string' is not assignable to type 'number'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number'. !!! error TS2345: Type 'string' is not assignable to type 'number'. diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types index f8188147a7908..c4693fac23fba 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -84,8 +84,8 @@ var [...c1] = [1,2,3]; >3 : number var [...c2] = [1,2,3, "string"]; ->c2 : (number | string)[] ->[1,2,3, "string"] : (number | string)[] +>c2 : (string | number)[] +>[1,2,3, "string"] : (string | number)[] >1 : number >2 : number >3 : number @@ -113,9 +113,9 @@ var temp1 = [true, false, true] >true : boolean var [d3, d4] = [1, "string", ...temp1]; ->d3 : number | string | boolean ->d4 : number | string | boolean ->[1, "string", ...temp1] : (number | string | boolean)[] +>d3 : string | number | boolean +>d4 : string | number | boolean +>[1, "string", ...temp1] : (string | number | boolean)[] >1 : number >"string" : string >...temp1 : boolean diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types index 7b4fe5409dbaa..847831ccc84cd 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -84,8 +84,8 @@ var [...c1] = [1,2,3]; >3 : number var [...c2] = [1,2,3, "string"]; ->c2 : (number | string)[] ->[1,2,3, "string"] : (number | string)[] +>c2 : (string | number)[] +>[1,2,3, "string"] : (string | number)[] >1 : number >2 : number >3 : number @@ -113,9 +113,9 @@ var temp1 = [true, false, true] >true : boolean var [d3, d4] = [1, "string", ...temp1]; ->d3 : number | string | boolean ->d4 : number | string | boolean ->[1, "string", ...temp1] : (number | string | boolean)[] +>d3 : string | number | boolean +>d4 : string | number | boolean +>[1, "string", ...temp1] : (string | number | boolean)[] >1 : number >"string" : string >...temp1 : boolean diff --git a/tests/baselines/reference/emitDecoratorMetadata_restArgs.types b/tests/baselines/reference/emitDecoratorMetadata_restArgs.types index 4820d3a7d8dc2..96605d0e7f288 100644 --- a/tests/baselines/reference/emitDecoratorMetadata_restArgs.types +++ b/tests/baselines/reference/emitDecoratorMetadata_restArgs.types @@ -1,15 +1,15 @@ === tests/cases/compiler/emitDecoratorMetadata_restArgs.ts === declare const MyClassDecorator: ClassDecorator; ->MyClassDecorator : (target: TFunction) => TFunction | void ->ClassDecorator : (target: TFunction) => TFunction | void +>MyClassDecorator : (target: TFunction) => void | TFunction +>ClassDecorator : (target: TFunction) => void | TFunction declare const MyMethodDecorator: MethodDecorator; ->MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void ->MethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void +>MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor +>MethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor @MyClassDecorator ->MyClassDecorator : (target: TFunction) => TFunction | void +>MyClassDecorator : (target: TFunction) => void | TFunction class A { >A : A @@ -18,7 +18,7 @@ class A { >args : any[] @MyMethodDecorator ->MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void +>MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor method(...args) {} >method : (...args: any[]) => void @@ -26,7 +26,7 @@ class A { } @MyClassDecorator ->MyClassDecorator : (target: TFunction) => TFunction | void +>MyClassDecorator : (target: TFunction) => void | TFunction class B { >B : B @@ -35,7 +35,7 @@ class B { >args : number[] @MyMethodDecorator ->MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void +>MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor method(...args: string[]) {} >method : (...args: string[]) => void diff --git a/tests/baselines/reference/enumAssignmentCompat4.types b/tests/baselines/reference/enumAssignmentCompat4.types index db7f5ce8ba21d..8d96024586224 100644 --- a/tests/baselines/reference/enumAssignmentCompat4.types +++ b/tests/baselines/reference/enumAssignmentCompat4.types @@ -45,8 +45,8 @@ namespace N { } let broken = [ ->broken : ({ foo: N.MyEnum; } | { foo: M.MyEnum; })[] ->[ N.object1, M.object2] : ({ foo: N.MyEnum; } | { foo: M.MyEnum; })[] +>broken : ({ foo: M.MyEnum; } | { foo: N.MyEnum; })[] +>[ N.object1, M.object2] : ({ foo: M.MyEnum; } | { foo: N.MyEnum; })[] N.object1, >N.object1 : { foo: N.MyEnum; } diff --git a/tests/baselines/reference/enumBasics.types b/tests/baselines/reference/enumBasics.types index cecd8f5113606..9e68b06bc3ef9 100644 --- a/tests/baselines/reference/enumBasics.types +++ b/tests/baselines/reference/enumBasics.types @@ -172,8 +172,8 @@ enum E9 { // (refer to .js to validate) // Enum constant members are propagated var doNotPropagate = [ ->doNotPropagate : (E8 | E7 | E4 | E3)[] ->[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : (E8 | E7 | E4 | E3)[] +>doNotPropagate : (E3 | E4 | E7 | E8)[] +>[ E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z] : (E3 | E4 | E7 | E8)[] E8.B, E7.A, E4.Z, E3.X, E3.Y, E3.Z >E8.B : E8 @@ -198,8 +198,8 @@ var doNotPropagate = [ ]; // Enum computed members are not propagated var doPropagate = [ ->doPropagate : (E9 | E6 | E5)[] ->[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : (E9 | E6 | E5)[] +>doPropagate : (E5 | E6 | E9)[] +>[ E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C] : (E5 | E6 | E9)[] E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C >E9.A : E9 diff --git a/tests/baselines/reference/enumLiteralTypes1.types b/tests/baselines/reference/enumLiteralTypes1.types index 8e1f478baaa2b..f73f98e405bff 100644 --- a/tests/baselines/reference/enumLiteralTypes1.types +++ b/tests/baselines/reference/enumLiteralTypes1.types @@ -13,14 +13,14 @@ type YesNo = Choice.Yes | Choice.No; >No : Choice.No type NoYes = Choice.No | Choice.Yes; ->NoYes : Choice.No | Choice.Yes +>NoYes : Choice.Yes | Choice.No >Choice : any >No : Choice.No >Choice : any >Yes : Choice.Yes type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; ->UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown >Choice : any >Unknown : Choice.Unknown >Choice : any @@ -37,7 +37,7 @@ function f1() { var a: NoYes; >a : Choice.Yes | Choice.No ->NoYes : Choice.No | Choice.Yes +>NoYes : Choice.Yes | Choice.No var a: Choice.Yes | Choice.No; >a : Choice.Yes | Choice.No @@ -55,17 +55,17 @@ function f1() { } function f2(a: YesNo, b: UnknownYesNo, c: Choice) { ->f2 : (a: Choice.Yes | Choice.No, b: Choice.Unknown | Choice.Yes | Choice.No, c: Choice) => void +>f2 : (a: Choice.Yes | Choice.No, b: Choice.Yes | Choice.No | Choice.Unknown, c: Choice) => void >a : Choice.Yes | Choice.No >YesNo : Choice.Yes | Choice.No ->b : Choice.Unknown | Choice.Yes | Choice.No ->UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown +>UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown >c : Choice >Choice : Choice b = a; >b = a : Choice.Yes | Choice.No ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown >a : Choice.Yes | Choice.No c = a; @@ -234,11 +234,11 @@ declare function g(x: Choice): number; >Choice : Choice function f5(a: YesNo, b: UnknownYesNo, c: Choice) { ->f5 : (a: Choice.Yes | Choice.No, b: Choice.Unknown | Choice.Yes | Choice.No, c: Choice) => void +>f5 : (a: Choice.Yes | Choice.No, b: Choice.Yes | Choice.No | Choice.Unknown, c: Choice) => void >a : Choice.Yes | Choice.No >YesNo : Choice.Yes | Choice.No ->b : Choice.Unknown | Choice.Yes | Choice.No ->UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown +>UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown >c : Choice >Choice : Choice @@ -268,7 +268,7 @@ function f5(a: YesNo, b: UnknownYesNo, c: Choice) { >z4 : number >g(b) : number >g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var z5 = g(c); >z5 : number @@ -336,30 +336,30 @@ function f11(x: YesNo) { } function f12(x: UnknownYesNo) { ->f12 : (x: Choice.Unknown | Choice.Yes | Choice.No) => void ->x : Choice.Unknown | Choice.Yes | Choice.No ->UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>f12 : (x: Choice.Yes | Choice.No | Choice.Unknown) => void +>x : Choice.Yes | Choice.No | Choice.Unknown +>UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown if (x) { ->x : Choice.Unknown | Choice.Yes | Choice.No +>x : Choice.Yes | Choice.No | Choice.Unknown x; >x : Choice.Yes | Choice.No } else { x; ->x : Choice.Unknown | Choice.Yes | Choice.No +>x : Choice.Yes | Choice.No | Choice.Unknown } } function f13(x: UnknownYesNo) { ->f13 : (x: Choice.Unknown | Choice.Yes | Choice.No) => void ->x : Choice.Unknown | Choice.Yes | Choice.No ->UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>f13 : (x: Choice.Yes | Choice.No | Choice.Unknown) => void +>x : Choice.Yes | Choice.No | Choice.Unknown +>UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown if (x === Choice.Yes) { >x === Choice.Yes : boolean ->x : Choice.Unknown | Choice.Yes | Choice.No +>x : Choice.Yes | Choice.No | Choice.Unknown >Choice.Yes : Choice.Yes >Choice : typeof Choice >Yes : Choice.Yes @@ -369,7 +369,7 @@ function f13(x: UnknownYesNo) { } else { x; ->x : Choice.Unknown | Choice.No +>x : Choice.No | Choice.Unknown } } diff --git a/tests/baselines/reference/enumLiteralTypes2.types b/tests/baselines/reference/enumLiteralTypes2.types index aab06c82fc4fd..45f5853d14080 100644 --- a/tests/baselines/reference/enumLiteralTypes2.types +++ b/tests/baselines/reference/enumLiteralTypes2.types @@ -14,14 +14,14 @@ type YesNo = Choice.Yes | Choice.No; >No : Choice.No type NoYes = Choice.No | Choice.Yes; ->NoYes : Choice.No | Choice.Yes +>NoYes : Choice.Yes | Choice.No >Choice : any >No : Choice.No >Choice : any >Yes : Choice.Yes type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; ->UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown >Choice : any >Unknown : Choice.Unknown >Choice : any @@ -38,7 +38,7 @@ function f1() { var a: NoYes; >a : Choice.Yes | Choice.No ->NoYes : Choice.No | Choice.Yes +>NoYes : Choice.Yes | Choice.No var a: Choice.Yes | Choice.No; >a : Choice.Yes | Choice.No @@ -56,17 +56,17 @@ function f1() { } function f2(a: YesNo, b: UnknownYesNo, c: Choice) { ->f2 : (a: Choice.Yes | Choice.No, b: Choice.Unknown | Choice.Yes | Choice.No, c: Choice) => void +>f2 : (a: Choice.Yes | Choice.No, b: Choice.Yes | Choice.No | Choice.Unknown, c: Choice) => void >a : Choice.Yes | Choice.No >YesNo : Choice.Yes | Choice.No ->b : Choice.Unknown | Choice.Yes | Choice.No ->UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown +>UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown >c : Choice >Choice : Choice b = a; >b = a : Choice.Yes | Choice.No ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown >a : Choice.Yes | Choice.No c = a; @@ -81,132 +81,132 @@ function f2(a: YesNo, b: UnknownYesNo, c: Choice) { } function f3(a: Choice.Yes, b: UnknownYesNo) { ->f3 : (a: Choice.Yes, b: Choice.Unknown | Choice.Yes | Choice.No) => void +>f3 : (a: Choice.Yes, b: Choice.Yes | Choice.No | Choice.Unknown) => void >a : Choice.Yes >Choice : any >Yes : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No ->UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown +>UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown var x = a + b; >x : number >a + b : number >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var x = a - b; >x : number >a - b : number >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var x = a * b; >x : number >a * b : number >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var x = a / b; >x : number >a / b : number >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var x = a % b; >x : number >a % b : number >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var x = a | b; >x : number >a | b : number >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var x = a & b; >x : number >a & b : number >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var x = a ^ b; >x : number >a ^ b : number >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var x = -b; >x : number >-b : number ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var x = ~b; >x : number >~b : number ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var y = a == b; >y : boolean >a == b : boolean >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var y = a != b; >y : boolean >a != b : boolean >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var y = a === b; >y : boolean >a === b : boolean >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var y = a !== b; >y : boolean >a !== b : boolean >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var y = a > b; >y : boolean >a > b : boolean >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var y = a < b; >y : boolean >a < b : boolean >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var y = a >= b; >y : boolean >a >= b : boolean >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var y = a <= b; >y : boolean >a <= b : boolean >a : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var y = !b; >y : boolean >!b : boolean ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown } function f4(a: Choice.Yes, b: UnknownYesNo) { ->f4 : (a: Choice.Yes, b: Choice.Unknown | Choice.Yes | Choice.No) => void +>f4 : (a: Choice.Yes, b: Choice.Yes | Choice.No | Choice.Unknown) => void >a : Choice.Yes >Choice : any >Yes : Choice.Yes ->b : Choice.Unknown | Choice.Yes | Choice.No ->UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown +>UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown a++; >a++ : number @@ -214,7 +214,7 @@ function f4(a: Choice.Yes, b: UnknownYesNo) { b++; >b++ : number ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown } declare function g(x: Choice.Yes): string; @@ -235,11 +235,11 @@ declare function g(x: Choice): number; >Choice : Choice function f5(a: YesNo, b: UnknownYesNo, c: Choice) { ->f5 : (a: Choice.Yes | Choice.No, b: Choice.Unknown | Choice.Yes | Choice.No, c: Choice) => void +>f5 : (a: Choice.Yes | Choice.No, b: Choice.Yes | Choice.No | Choice.Unknown, c: Choice) => void >a : Choice.Yes | Choice.No >YesNo : Choice.Yes | Choice.No ->b : Choice.Unknown | Choice.Yes | Choice.No ->UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown +>UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown >c : Choice >Choice : Choice @@ -269,7 +269,7 @@ function f5(a: YesNo, b: UnknownYesNo, c: Choice) { >z4 : number >g(b) : number >g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } ->b : Choice.Unknown | Choice.Yes | Choice.No +>b : Choice.Yes | Choice.No | Choice.Unknown var z5 = g(c); >z5 : number @@ -337,12 +337,12 @@ function f11(x: YesNo) { } function f12(x: UnknownYesNo) { ->f12 : (x: Choice.Unknown | Choice.Yes | Choice.No) => void ->x : Choice.Unknown | Choice.Yes | Choice.No ->UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>f12 : (x: Choice.Yes | Choice.No | Choice.Unknown) => void +>x : Choice.Yes | Choice.No | Choice.Unknown +>UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown if (x) { ->x : Choice.Unknown | Choice.Yes | Choice.No +>x : Choice.Yes | Choice.No | Choice.Unknown x; >x : Choice.Yes | Choice.No @@ -354,13 +354,13 @@ function f12(x: UnknownYesNo) { } function f13(x: UnknownYesNo) { ->f13 : (x: Choice.Unknown | Choice.Yes | Choice.No) => void ->x : Choice.Unknown | Choice.Yes | Choice.No ->UnknownYesNo : Choice.Unknown | Choice.Yes | Choice.No +>f13 : (x: Choice.Yes | Choice.No | Choice.Unknown) => void +>x : Choice.Yes | Choice.No | Choice.Unknown +>UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown if (x === Choice.Yes) { >x === Choice.Yes : boolean ->x : Choice.Unknown | Choice.Yes | Choice.No +>x : Choice.Yes | Choice.No | Choice.Unknown >Choice.Yes : Choice.Yes >Choice : typeof Choice >Yes : Choice.Yes @@ -370,7 +370,7 @@ function f13(x: UnknownYesNo) { } else { x; ->x : Choice.Unknown | Choice.No +>x : Choice.No | Choice.Unknown } } diff --git a/tests/baselines/reference/enumLiteralTypes3.errors.txt b/tests/baselines/reference/enumLiteralTypes3.errors.txt index 2f3ea5ada2479..bfc8d5ac0d013 100644 --- a/tests/baselines/reference/enumLiteralTypes3.errors.txt +++ b/tests/baselines/reference/enumLiteralTypes3.errors.txt @@ -1,12 +1,12 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(10,5): error TS2322: Type 'Yes | No' is not assignable to type 'Yes'. Type 'No' is not assignable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(11,5): error TS2322: Type 'Unknown | Yes | No' is not assignable to type 'Yes'. - Type 'Unknown' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(11,5): error TS2322: Type 'Yes | No | Unknown' is not assignable to type 'Yes'. + Type 'No' is not assignable to type 'Yes'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(12,5): error TS2322: Type 'Choice' is not assignable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(18,5): error TS2322: Type 'Unknown | Yes | No' is not assignable to type 'Yes | No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(18,5): error TS2322: Type 'Yes | No | Unknown' is not assignable to type 'Yes | No'. Type 'Unknown' is not assignable to type 'Yes | No'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(19,5): error TS2322: Type 'Choice' is not assignable to type 'Yes | No'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(26,5): error TS2322: Type 'Choice' is not assignable to type 'Unknown | Yes | No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(26,5): error TS2322: Type 'Choice' is not assignable to type 'Yes | No | Unknown'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(37,5): error TS2322: Type 'Unknown' is not assignable to type 'Yes'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(39,5): error TS2322: Type 'No' is not assignable to type 'Yes'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(40,5): error TS2322: Type 'Unknown' is not assignable to type 'Yes | No'. @@ -34,8 +34,8 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: !!! error TS2322: Type 'No' is not assignable to type 'Yes'. a = c; ~ -!!! error TS2322: Type 'Unknown | Yes | No' is not assignable to type 'Yes'. -!!! error TS2322: Type 'Unknown' is not assignable to type 'Yes'. +!!! error TS2322: Type 'Yes | No | Unknown' is not assignable to type 'Yes'. +!!! error TS2322: Type 'No' is not assignable to type 'Yes'. a = d; ~ !!! error TS2322: Type 'Choice' is not assignable to type 'Yes'. @@ -46,7 +46,7 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: b = b; b = c; ~ -!!! error TS2322: Type 'Unknown | Yes | No' is not assignable to type 'Yes | No'. +!!! error TS2322: Type 'Yes | No | Unknown' is not assignable to type 'Yes | No'. !!! error TS2322: Type 'Unknown' is not assignable to type 'Yes | No'. b = d; ~ @@ -59,7 +59,7 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: c = c; c = d; ~ -!!! error TS2322: Type 'Choice' is not assignable to type 'Unknown | Yes | No'. +!!! error TS2322: Type 'Choice' is not assignable to type 'Yes | No | Unknown'. } function f4(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { diff --git a/tests/baselines/reference/for-of11.errors.txt b/tests/baselines/reference/for-of11.errors.txt index 7c00e454d4e3e..dc527e73efe2b 100644 --- a/tests/baselines/reference/for-of11.errors.txt +++ b/tests/baselines/reference/for-of11.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/for-ofStatements/for-of11.ts(2,6): error TS2322: Type 'number | string' is not assignable to type 'string'. +tests/cases/conformance/es6/for-ofStatements/for-of11.ts(2,6): error TS2322: Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -6,5 +6,5 @@ tests/cases/conformance/es6/for-ofStatements/for-of11.ts(2,6): error TS2322: Typ var v: string; for (v of [0, ""]) { } ~ -!!! error TS2322: Type 'number | string' is not assignable to type 'string'. +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/for-of12.errors.txt b/tests/baselines/reference/for-of12.errors.txt index 6100564ba58a2..f19fa5ed0146d 100644 --- a/tests/baselines/reference/for-of12.errors.txt +++ b/tests/baselines/reference/for-of12.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/for-ofStatements/for-of12.ts(2,6): error TS2322: Type 'number | string' is not assignable to type 'string'. +tests/cases/conformance/es6/for-ofStatements/for-of12.ts(2,6): error TS2322: Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -6,5 +6,5 @@ tests/cases/conformance/es6/for-ofStatements/for-of12.ts(2,6): error TS2322: Typ var v: string; for (v of [0, ""].values()) { } ~ -!!! error TS2322: Type 'number | string' is not assignable to type 'string'. +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/functionImplementations.types b/tests/baselines/reference/functionImplementations.types index 6690ca68c98c6..6cb1cde1c82ab 100644 --- a/tests/baselines/reference/functionImplementations.types +++ b/tests/baselines/reference/functionImplementations.types @@ -325,7 +325,7 @@ class AnotherClass { private x } var f7: (x: number) => string | number = x => { // should be (x: number) => number | string >f7 : (x: number) => string | number >x : number ->x => { // should be (x: number) => number | string if (x < 0) { return x; } return x.toString();} : (x: number) => number | string +>x => { // should be (x: number) => number | string if (x < 0) { return x; } return x.toString();} : (x: number) => string | number >x : number if (x < 0) { return x; } diff --git a/tests/baselines/reference/functionOverloads43.types b/tests/baselines/reference/functionOverloads43.types index 7c0fa8eb8185b..e48ffd41f6016 100644 --- a/tests/baselines/reference/functionOverloads43.types +++ b/tests/baselines/reference/functionOverloads43.types @@ -11,16 +11,16 @@ function foo(bar: { a:string }[]): string; function foo([x]: { a:number | string }[]): string | number { >foo : { (bar: { a: number; }[]): number; (bar: { a: string; }[]): string; } ->x : { a: number | string; } ->a : number | string +>x : { a: string | number; } +>a : string | number if (x) { ->x : { a: number | string; } +>x : { a: string | number; } return x.a; ->x.a : number | string ->x : { a: number | string; } ->a : number | string +>x.a : string | number +>x : { a: string | number; } +>a : string | number } return undefined; diff --git a/tests/baselines/reference/functionOverloads44.types b/tests/baselines/reference/functionOverloads44.types index 56cad09b47287..48fcfa3371bc9 100644 --- a/tests/baselines/reference/functionOverloads44.types +++ b/tests/baselines/reference/functionOverloads44.types @@ -27,8 +27,8 @@ function foo1(bar: { a:string }[]): Animal; function foo1([x]: { a:number | string }[]): Dog { >foo1 : { (bar: { a: number; }[]): Dog; (bar: { a: string; }[]): Animal; } ->x : { a: number | string; } ->a : number | string +>x : { a: string | number; } +>a : string | number >Dog : Dog return undefined; @@ -36,22 +36,22 @@ function foo1([x]: { a:number | string }[]): Dog { } function foo2(bar: { a:number }[]): Cat; ->foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; } +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog | Cat; } >bar : { a: number; }[] >a : number >Cat : Cat function foo2(bar: { a:string }[]): Cat | Dog; ->foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; } +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog | Cat; } >bar : { a: string; }[] >a : string >Cat : Cat >Dog : Dog function foo2([x]: { a:number | string }[]): Cat { ->foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; } ->x : { a: number | string; } ->a : number | string +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog | Cat; } +>x : { a: string | number; } +>a : string | number >Cat : Cat return undefined; @@ -78,9 +78,9 @@ var y1 = foo1([{a: 100}]); >100 : number var x2 = foo2([{a: "str"}]); ->x2 : Cat | Dog ->foo2([{a: "str"}]) : Cat | Dog ->foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; } +>x2 : Dog | Cat +>foo2([{a: "str"}]) : Dog | Cat +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog | Cat; } >[{a: "str"}] : { a: string; }[] >{a: "str"} : { a: string; } >a : string @@ -89,7 +89,7 @@ var x2 = foo2([{a: "str"}]); var y2 = foo2([{a: 100}]); >y2 : Cat >foo2([{a: 100}]) : Cat ->foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Cat | Dog; } +>foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog | Cat; } >[{a: 100}] : { a: number; }[] >{a: 100} : { a: number; } >a : number diff --git a/tests/baselines/reference/functionOverloads45.types b/tests/baselines/reference/functionOverloads45.types index 257a615e3349d..29eb55a40edee 100644 --- a/tests/baselines/reference/functionOverloads45.types +++ b/tests/baselines/reference/functionOverloads45.types @@ -27,8 +27,8 @@ function foo1(bar: { a:string }[]): Dog; function foo1([x]: { a:number | string }[]): Animal { >foo1 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; } ->x : { a: number | string; } ->a : number | string +>x : { a: string | number; } +>a : string | number >Animal : Animal return undefined; @@ -49,8 +49,8 @@ function foo2(bar: { a:string }[]): Dog; function foo2([x]: { a:number | string }[]): Cat | Dog { >foo2 : { (bar: { a: number; }[]): Cat; (bar: { a: string; }[]): Dog; } ->x : { a: number | string; } ->a : number | string +>x : { a: string | number; } +>a : string | number >Cat : Cat >Dog : Dog diff --git a/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types index 5c7500fb5ed94..c5fd984d32767 100644 --- a/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types +++ b/tests/baselines/reference/genericArgumentCallSigAssignmentCompat.types @@ -49,7 +49,7 @@ _.all([true, 1, null, 'yes'], _.identity); >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => boolean >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => boolean ->[true, 1, null, 'yes'] : (boolean | number | string)[] +>[true, 1, null, 'yes'] : (string | number | boolean)[] >true : boolean >1 : number >null : null diff --git a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types index c8e8b41b5fdda..48a7150ef4426 100644 --- a/tests/baselines/reference/genericCallWithArrayLiteralArgs.types +++ b/tests/baselines/reference/genericCallWithArrayLiteralArgs.types @@ -46,10 +46,10 @@ var r3 = foo([]); // number[] >[] : undefined[] var r4 = foo([1, '']); // {}[] ->r4 : (number | string)[] ->foo([1, '']) : (number | string)[] +>r4 : (string | number)[] +>foo([1, '']) : (string | number)[] >foo : (t: T) => T ->[1, ''] : (number | string)[] +>[1, ''] : (string | number)[] >1 : number >'' : string @@ -57,7 +57,7 @@ var r5 = foo([1, '']); // any[] >r5 : any[] >foo([1, '']) : any[] >foo : (t: T) => T ->[1, ''] : (number | string)[] +>[1, ''] : (string | number)[] >1 : number >'' : string @@ -66,7 +66,7 @@ var r6 = foo([1, '']); // Object[] >foo([1, '']) : Object[] >foo : (t: T) => T >Object : Object ->[1, ''] : (number | string)[] +>[1, ''] : (string | number)[] >1 : number >'' : string diff --git a/tests/baselines/reference/genericTypeArgumentInference1.types b/tests/baselines/reference/genericTypeArgumentInference1.types index 405c328bc4573..2d64c8f5c58d7 100644 --- a/tests/baselines/reference/genericTypeArgumentInference1.types +++ b/tests/baselines/reference/genericTypeArgumentInference1.types @@ -42,12 +42,12 @@ declare var _: Underscore.Static; >Static : Underscore.Static var r = _.all([true, 1, null, 'yes'], _.identity); ->r : boolean | number | string ->_.all([true, 1, null, 'yes'], _.identity) : boolean | number | string +>r : string | number | boolean +>_.all([true, 1, null, 'yes'], _.identity) : string | number | boolean >_.all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T >_ : Underscore.Static >all : (list: T[], iterator?: Underscore.Iterator, context?: any) => T ->[true, 1, null, 'yes'] : (boolean | number | string)[] +>[true, 1, null, 'yes'] : (string | number | boolean)[] >true : boolean >1 : number >null : null diff --git a/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt b/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt index 20e113faf2aa2..e5c2be7a598a1 100644 --- a/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt +++ b/tests/baselines/reference/heterogeneousArrayAndOverloads.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'string[]'. - Type 'number | string' is not assignable to type 'string'. +tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'string[]'. + Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -14,8 +14,8 @@ tests/cases/compiler/heterogeneousArrayAndOverloads.ts(9,19): error TS2345: Argu this.test([]); this.test([1, 2, "hi", 5]); // Error ~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'string[]'. -!!! error TS2345: Type 'number | string' is not assignable to type 'string'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'string[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'string'. !!! error TS2345: Type 'number' is not assignable to type 'string'. } } \ No newline at end of file diff --git a/tests/baselines/reference/heterogeneousArrayLiterals.types b/tests/baselines/reference/heterogeneousArrayLiterals.types index c760e5a566f3e..026e9c26baeb3 100644 --- a/tests/baselines/reference/heterogeneousArrayLiterals.types +++ b/tests/baselines/reference/heterogeneousArrayLiterals.types @@ -2,8 +2,8 @@ // type of an array is the best common type of its elements (plus its contextual type if it exists) var a = [1, '']; // {}[] ->a : (number | string)[] ->[1, ''] : (number | string)[] +>a : (string | number)[] +>[1, ''] : (string | number)[] >1 : number >'' : string @@ -14,8 +14,8 @@ var b = [1, null]; // number[] >null : null var c = [1, '', null]; // {}[] ->c : (number | string)[] ->[1, '', null] : (number | string)[] +>c : (string | number)[] +>[1, '', null] : (string | number)[] >1 : number >'' : string >null : null @@ -296,8 +296,8 @@ function foo(t: T, u: U) { >u : U var d = [t, 1]; // {}[] ->d : (T | number)[] ->[t, 1] : (T | number)[] +>d : (number | T)[] +>[t, 1] : (number | T)[] >t : T >1 : number @@ -350,8 +350,8 @@ function foo2(t: T, u: U) { >u : U var d = [t, 1]; // {}[] ->d : (T | number)[] ->[t, 1] : (T | number)[] +>d : (number | T)[] +>[t, 1] : (number | T)[] >t : T >1 : number @@ -380,8 +380,8 @@ function foo2(t: T, u: U) { >base : Base var h = [t, derived]; // Derived[] ->h : (T | Derived)[] ->[t, derived] : (T | Derived)[] +>h : (Derived | T)[] +>[t, derived] : (Derived | T)[] >t : T >derived : Derived @@ -428,8 +428,8 @@ function foo3(t: T, u: U) { >u : U var d = [t, 1]; // {}[] ->d : (T | number)[] ->[t, 1] : (T | number)[] +>d : (number | T)[] +>[t, 1] : (number | T)[] >t : T >1 : number @@ -506,8 +506,8 @@ function foo4(t: T, u: U) { >u : U var d = [t, 1]; // {}[] ->d : (T | number)[] ->[t, 1] : (T | number)[] +>d : (number | T)[] +>[t, 1] : (number | T)[] >t : T >1 : number @@ -536,8 +536,8 @@ function foo4(t: T, u: U) { >base : Base var h = [t, derived]; // Derived[] ->h : (T | Derived)[] ->[t, derived] : (T | Derived)[] +>h : (Derived | T)[] +>[t, derived] : (Derived | T)[] >t : T >derived : Derived @@ -548,8 +548,8 @@ function foo4(t: T, u: U) { >base : Base var j = [u, derived]; // Derived[] ->j : (U | Derived)[] ->[u, derived] : (U | Derived)[] +>j : (Derived | U)[] +>[u, derived] : (Derived | U)[] >u : U >derived : Derived diff --git a/tests/baselines/reference/implicitIndexSignatures.types b/tests/baselines/reference/implicitIndexSignatures.types index 7d335c0049107..6d670c6341b55 100644 --- a/tests/baselines/reference/implicitIndexSignatures.types +++ b/tests/baselines/reference/implicitIndexSignatures.types @@ -147,14 +147,14 @@ function f3() { >b : string const v1 = getStringIndexValue(o1); ->v1 : number | string ->getStringIndexValue(o1) : number | string +>v1 : string | number +>getStringIndexValue(o1) : string | number >getStringIndexValue : (map: { [x: string]: T; }) => T >o1 : { a: number; b: string; } const v2 = getStringIndexValue(o2); ->v2 : number | string ->getStringIndexValue(o2) : number | string +>v2 : string | number +>getStringIndexValue(o2) : string | number >getStringIndexValue : (map: { [x: string]: T; }) => T >o2 : { a: number; b: string; } } diff --git a/tests/baselines/reference/indexerWithTuple.types b/tests/baselines/reference/indexerWithTuple.types index 7605fba051866..4faae2cda29c3 100644 --- a/tests/baselines/reference/indexerWithTuple.types +++ b/tests/baselines/reference/indexerWithTuple.types @@ -101,20 +101,20 @@ var eleUnion11 = unionTuple1[1]; // string | number >1 : number var eleUnion12 = unionTuple1[2]; // string | number ->eleUnion12 : number | string ->unionTuple1[2] : number | string +>eleUnion12 : string | number +>unionTuple1[2] : string | number >unionTuple1 : [number, string | number] >2 : number var eleUnion13 = unionTuple1[idx0]; // string | number ->eleUnion13 : number | string ->unionTuple1[idx0] : number | string +>eleUnion13 : string | number +>unionTuple1[idx0] : string | number >unionTuple1 : [number, string | number] >idx0 : number var eleUnion14 = unionTuple1[idx1]; // string | number ->eleUnion14 : number | string ->unionTuple1[idx1] : number | string +>eleUnion14 : string | number +>unionTuple1[idx1] : string | number >unionTuple1 : [number, string | number] >idx1 : number @@ -143,20 +143,20 @@ var eleUnion21 = unionTuple2[1]; // string | number >1 : number var eleUnion22 = unionTuple2[2]; // string | number | boolean ->eleUnion22 : boolean | string | number ->unionTuple2[2] : boolean | string | number +>eleUnion22 : string | number | boolean +>unionTuple2[2] : string | number | boolean >unionTuple2 : [boolean, string | number] >2 : number var eleUnion23 = unionTuple2[idx0]; // string | number | boolean ->eleUnion23 : boolean | string | number ->unionTuple2[idx0] : boolean | string | number +>eleUnion23 : string | number | boolean +>unionTuple2[idx0] : string | number | boolean >unionTuple2 : [boolean, string | number] >idx0 : number var eleUnion24 = unionTuple2[idx1]; // string | number | boolean ->eleUnion24 : boolean | string | number ->unionTuple2[idx1] : boolean | string | number +>eleUnion24 : string | number | boolean +>unionTuple2[idx1] : string | number | boolean >unionTuple2 : [boolean, string | number] >idx1 : number diff --git a/tests/baselines/reference/instanceOfAssignability.types b/tests/baselines/reference/instanceOfAssignability.types index 44ec45e206901..192db8bcd1b69 100644 --- a/tests/baselines/reference/instanceOfAssignability.types +++ b/tests/baselines/reference/instanceOfAssignability.types @@ -46,14 +46,14 @@ class Giraffe extends Mammal { neck; } >neck : any function fn1(x: Array|Array|boolean) { ->fn1 : (x: number[] | string[] | boolean) => void ->x : number[] | string[] | boolean +>fn1 : (x: boolean | number[] | string[]) => void +>x : boolean | number[] | string[] >Array : T[] >Array : T[] if(x instanceof Array) { >x instanceof Array : boolean ->x : number[] | string[] | boolean +>x : boolean | number[] | string[] >Array : ArrayConstructor // 1.5: y: Array|Array diff --git a/tests/baselines/reference/iteratorSpreadInCall12.types b/tests/baselines/reference/iteratorSpreadInCall12.types index 5e3e7bcdbc425..8543e59f55fff 100644 --- a/tests/baselines/reference/iteratorSpreadInCall12.types +++ b/tests/baselines/reference/iteratorSpreadInCall12.types @@ -1,9 +1,9 @@ === tests/cases/conformance/es6/spread/iteratorSpreadInCall12.ts === new Foo(...[...new SymbolIterator, ...[...new StringIterator]]); ->new Foo(...[...new SymbolIterator, ...[...new StringIterator]]) : Foo +>new Foo(...[...new SymbolIterator, ...[...new StringIterator]]) : Foo >Foo : typeof Foo ->...[...new SymbolIterator, ...[...new StringIterator]] : symbol | string ->[...new SymbolIterator, ...[...new StringIterator]] : (symbol | string)[] +>...[...new SymbolIterator, ...[...new StringIterator]] : string | symbol +>[...new SymbolIterator, ...[...new StringIterator]] : (string | symbol)[] >...new SymbolIterator : symbol >new SymbolIterator : SymbolIterator >SymbolIterator : typeof SymbolIterator diff --git a/tests/baselines/reference/iteratorSpreadInCall5.types b/tests/baselines/reference/iteratorSpreadInCall5.types index 043536ab4c0ea..bf4a0f7ad65ab 100644 --- a/tests/baselines/reference/iteratorSpreadInCall5.types +++ b/tests/baselines/reference/iteratorSpreadInCall5.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/spread/iteratorSpreadInCall5.ts === foo(...new SymbolIterator, ...new StringIterator); >foo(...new SymbolIterator, ...new StringIterator) : void ->foo : (...s: (symbol | string)[]) => void +>foo : (...s: (string | symbol)[]) => void >...new SymbolIterator : symbol >new SymbolIterator : SymbolIterator >SymbolIterator : typeof SymbolIterator @@ -10,8 +10,8 @@ foo(...new SymbolIterator, ...new StringIterator); >StringIterator : typeof StringIterator function foo(...s: (symbol | string)[]) { } ->foo : (...s: (symbol | string)[]) => void ->s : (symbol | string)[] +>foo : (...s: (string | symbol)[]) => void +>s : (string | symbol)[] class SymbolIterator { >SymbolIterator : SymbolIterator diff --git a/tests/baselines/reference/iteratorSpreadInCall6.errors.txt b/tests/baselines/reference/iteratorSpreadInCall6.errors.txt index ee9945f7af674..93aaec8c33005 100644 --- a/tests/baselines/reference/iteratorSpreadInCall6.errors.txt +++ b/tests/baselines/reference/iteratorSpreadInCall6.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/es6/spread/iteratorSpreadInCall6.ts(1,28): error TS2345: Argument of type 'string' is not assignable to parameter of type 'symbol | number'. +tests/cases/conformance/es6/spread/iteratorSpreadInCall6.ts(1,28): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number | symbol'. ==== tests/cases/conformance/es6/spread/iteratorSpreadInCall6.ts (1 errors) ==== foo(...new SymbolIterator, ...new StringIterator); ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'symbol | number'. +!!! error TS2345: Argument of type 'string' is not assignable to parameter of type 'number | symbol'. function foo(...s: (symbol | number)[]) { } class SymbolIterator { diff --git a/tests/baselines/reference/json.stringify.types b/tests/baselines/reference/json.stringify.types index 7cce2d3ed249e..aaf92a17c0a2a 100644 --- a/tests/baselines/reference/json.stringify.types +++ b/tests/baselines/reference/json.stringify.types @@ -6,27 +6,27 @@ var value = null; JSON.stringify(value, undefined, 2); >JSON.stringify(value, undefined, 2) : string ->JSON.stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (number | string)[] | null | undefined, space?: string | number | undefined): string; } +>JSON.stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; } >JSON : JSON ->stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (number | string)[] | null | undefined, space?: string | number | undefined): string; } +>stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; } >value : null >undefined : undefined >2 : number JSON.stringify(value, null, 2); >JSON.stringify(value, null, 2) : string ->JSON.stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (number | string)[] | null | undefined, space?: string | number | undefined): string; } +>JSON.stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; } >JSON : JSON ->stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (number | string)[] | null | undefined, space?: string | number | undefined): string; } +>stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; } >value : null >null : null >2 : number JSON.stringify(value, ["a", 1], 2); >JSON.stringify(value, ["a", 1], 2) : string ->JSON.stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (number | string)[] | null | undefined, space?: string | number | undefined): string; } +>JSON.stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; } >JSON : JSON ->stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (number | string)[] | null | undefined, space?: string | number | undefined): string; } +>stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; } >value : null >["a", 1] : (string | number)[] >"a" : string @@ -35,9 +35,9 @@ JSON.stringify(value, ["a", 1], 2); JSON.stringify(value, (k) => undefined, 2); >JSON.stringify(value, (k) => undefined, 2) : string ->JSON.stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (number | string)[] | null | undefined, space?: string | number | undefined): string; } +>JSON.stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; } >JSON : JSON ->stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (number | string)[] | null | undefined, space?: string | number | undefined): string; } +>stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; } >value : null >(k) => undefined : (k: string) => undefined >k : string @@ -46,9 +46,9 @@ JSON.stringify(value, (k) => undefined, 2); JSON.stringify(value, undefined, 2); >JSON.stringify(value, undefined, 2) : string ->JSON.stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (number | string)[] | null | undefined, space?: string | number | undefined): string; } +>JSON.stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; } >JSON : JSON ->stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (number | string)[] | null | undefined, space?: string | number | undefined): string; } +>stringify : { (value: any, replacer?: ((key: string, value: any) => any) | undefined, space?: string | number | undefined): string; (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string; } >value : null >undefined : undefined >2 : number diff --git a/tests/baselines/reference/literalTypes1.types b/tests/baselines/reference/literalTypes1.types index e7a44f8d753fe..d34b5aebf9c79 100644 --- a/tests/baselines/reference/literalTypes1.types +++ b/tests/baselines/reference/literalTypes1.types @@ -79,34 +79,34 @@ function f2(x: 0 | 1 | 2) { } type Falsy = false | 0 | "" | null | undefined; ->Falsy : false | 0 | "" | null | undefined +>Falsy : false | "" | 0 | null | undefined >false : false >null : null function f3(x: Falsy) { ->f3 : (x: false | 0 | "" | null | undefined) => void ->x : false | 0 | "" | null | undefined ->Falsy : false | 0 | "" | null | undefined +>f3 : (x: false | "" | 0 | null | undefined) => void +>x : false | "" | 0 | null | undefined +>Falsy : false | "" | 0 | null | undefined if (x) { ->x : false | 0 | "" | null | undefined +>x : false | "" | 0 | null | undefined x; >x : never } else { x; ->x : false | 0 | "" | null | undefined +>x : false | "" | 0 | null | undefined } } function f4(x: 0 | 1 | true | string) { ->f4 : (x: 0 | 1 | true | string) => void ->x : 0 | 1 | true | string +>f4 : (x: string | true | 0 | 1) => void +>x : string | true | 0 | 1 >true : true switch (x) { ->x : 0 | 1 | true | string +>x : string | true | 0 | 1 case 0: >0 : 0 @@ -148,7 +148,7 @@ function f4(x: 0 | 1 | true | string) { break; default: x; ->x : true | string +>x : string | true } } diff --git a/tests/baselines/reference/logicalAndOperatorStrictMode.types b/tests/baselines/reference/logicalAndOperatorStrictMode.types index c47c54ad1b7a0..a2321b0695805 100644 --- a/tests/baselines/reference/logicalAndOperatorStrictMode.types +++ b/tests/baselines/reference/logicalAndOperatorStrictMode.types @@ -86,8 +86,8 @@ const a8 = a && z; >z : string | number | undefined const s1 = s && a; ->s1 : number[] | "" ->s && a : number[] | "" +>s1 : "" | number[] +>s && a : "" | number[] >s : string >a : number[] @@ -134,8 +134,8 @@ const s8 = s && z; >z : string | number | undefined const x1 = x && a; ->x1 : number[] | 0 ->x && a : number[] | 0 +>x1 : 0 | number[] +>x && a : 0 | number[] >x : number >a : number[] @@ -182,8 +182,8 @@ const x8 = x && z; >z : string | number | undefined const b1 = b && a; ->b1 : number[] | false ->b && a : number[] | false +>b1 : false | number[] +>b && a : false | number[] >b : boolean >a : number[] @@ -206,8 +206,8 @@ const b4 = b && b; >b : true const b5 = b && v; ->b5 : void | false ->b && v : void | false +>b5 : false | void +>b && v : false | void >b : boolean >v : void @@ -374,8 +374,8 @@ const n8 = n && z; >z : string | number | undefined const z1 = z && a; ->z1 : number[] | "" | 0 | undefined ->z && a : number[] | "" | 0 | undefined +>z1 : "" | 0 | number[] | undefined +>z && a : "" | 0 | number[] | undefined >z : string | number | undefined >a : number[] diff --git a/tests/baselines/reference/logicalOrOperatorWithEveryType.types b/tests/baselines/reference/logicalOrOperatorWithEveryType.types index 4a8f5e6a3e173..8f2f4af069851 100644 --- a/tests/baselines/reference/logicalOrOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalOrOperatorWithEveryType.types @@ -127,20 +127,20 @@ var rb5 = a5 || a2; // void || boolean is void | boolean >a2 : boolean var rb6 = a6 || a2; // enum || boolean is E | boolean ->rb6 : E | boolean ->a6 || a2 : E | boolean +>rb6 : boolean | E +>a6 || a2 : boolean | E >a6 : E >a2 : boolean var rb7 = a7 || a2; // object || boolean is object | boolean ->rb7 : { a: string; } | boolean ->a7 || a2 : { a: string; } | boolean +>rb7 : boolean | { a: string; } +>a7 || a2 : boolean | { a: string; } >a7 : { a: string; } >a2 : boolean var rb8 = a8 || a2; // array || boolean is array | boolean ->rb8 : string[] | boolean ->a8 || a2 : string[] | boolean +>rb8 : boolean | string[] +>a8 || a2 : boolean | string[] >a8 : string[] >a2 : boolean @@ -163,8 +163,8 @@ var rc1 = a1 || a3; // any || number is any >a3 : number var rc2 = a2 || a3; // boolean || number is boolean | number ->rc2 : true | number ->a2 || a3 : true | number +>rc2 : number | true +>a2 || a3 : number | true >a2 : boolean >a3 : number @@ -193,14 +193,14 @@ var rc6 = a6 || a3; // enum || number is number >a3 : number var rc7 = a7 || a3; // object || number is object | number ->rc7 : { a: string; } | number ->a7 || a3 : { a: string; } | number +>rc7 : number | { a: string; } +>a7 || a3 : number | { a: string; } >a7 : { a: string; } >a3 : number var rc8 = a8 || a3; // array || number is array | number ->rc8 : string[] | number ->a8 || a3 : string[] | number +>rc8 : number | string[] +>a8 || a3 : number | string[] >a8 : string[] >a3 : number @@ -223,14 +223,14 @@ var rd1 = a1 || a4; // any || string is any >a4 : string var rd2 = a2 || a4; // boolean || string is boolean | string ->rd2 : true | string ->a2 || a4 : true | string +>rd2 : string | true +>a2 || a4 : string | true >a2 : boolean >a4 : string var rd3 = a3 || a4; // number || string is number | string ->rd3 : number | string ->a3 || a4 : number | string +>rd3 : string | number +>a3 || a4 : string | number >a3 : number >a4 : string @@ -247,20 +247,20 @@ var rd5 = a5 || a4; // void || string is void | string >a4 : string var rd6 = a6 || a4; // enum || string is enum | string ->rd6 : E | string ->a6 || a4 : E | string +>rd6 : string | E +>a6 || a4 : string | E >a6 : E >a4 : string var rd7 = a7 || a4; // object || string is object | string ->rd7 : { a: string; } | string ->a7 || a4 : { a: string; } | string +>rd7 : string | { a: string; } +>a7 || a4 : string | { a: string; } >a7 : { a: string; } >a4 : string var rd8 = a8 || a4; // array || string is array | string ->rd8 : string[] | string ->a8 || a4 : string[] | string +>rd8 : string | string[] +>a8 || a4 : string | string[] >a8 : string[] >a4 : string @@ -307,20 +307,20 @@ var re5 = a5 || a5; // void || void is void >a5 : void var re6 = a6 || a5; // enum || void is enum | void ->re6 : E | void ->a6 || a5 : E | void +>re6 : void | E +>a6 || a5 : void | E >a6 : E >a5 : void var re7 = a7 || a5; // object || void is object | void ->re7 : { a: string; } | void ->a7 || a5 : { a: string; } | void +>re7 : void | { a: string; } +>a7 || a5 : void | { a: string; } >a7 : { a: string; } >a5 : void var re8 = a8 || a5; // array || void is array | void ->re8 : string[] | void ->a8 || a5 : string[] | void +>re8 : void | string[] +>a8 || a5 : void | string[] >a8 : string[] >a5 : void @@ -373,14 +373,14 @@ var rg6 = a6 || a6; // enum || enum is E >a6 : E var rg7 = a7 || a6; // object || enum is object | enum ->rg7 : { a: string; } | E ->a7 || a6 : { a: string; } | E +>rg7 : E | { a: string; } +>a7 || a6 : E | { a: string; } >a7 : { a: string; } >a6 : E var rg8 = a8 || a6; // array || enum is array | enum ->rg8 : string[] | E ->a8 || a6 : string[] | E +>rg8 : E | string[] +>a8 || a6 : E | string[] >a8 : string[] >a6 : E @@ -439,8 +439,8 @@ var rh7 = a7 || a7; // object || object is object >a7 : { a: string; } var rh8 = a8 || a7; // array || object is array | object ->rh8 : string[] | { a: string; } ->a8 || a7 : string[] | { a: string; } +>rh8 : { a: string; } | string[] +>a8 || a7 : { a: string; } | string[] >a8 : string[] >a7 : { a: string; } diff --git a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt index e8649cfb5672a..2fb7bd1bfbbb7 100644 --- a/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt +++ b/tests/baselines/reference/mismatchedExplicitTypeParameterAndArgumentType.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. - Type 'number | string' is not assignable to type 'number'. +tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(10,30): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): error TS2346: Supplied parameters do not match any signature of call target. @@ -16,8 +16,8 @@ tests/cases/compiler/mismatchedExplicitTypeParameterAndArgumentType.ts(11,11): e var r6 = map([1, ""], (x) => x.toString()); var r7 = map([1, ""], (x) => x.toString()); // error ~~~~~~~ -!!! error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type 'number | string' is not assignable to type 'number'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number'. !!! error TS2345: Type 'string' is not assignable to type 'number'. var r7b = map([1, ""], (x) => x.toString()); // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/narrowTypeByInstanceof.types b/tests/baselines/reference/narrowTypeByInstanceof.types index 8bc13d12ca11c..b98b1e4d234e0 100644 --- a/tests/baselines/reference/narrowTypeByInstanceof.types +++ b/tests/baselines/reference/narrowTypeByInstanceof.types @@ -22,24 +22,24 @@ } type FileMatchOrMatch = FileMatch | Match; ->FileMatchOrMatch : FileMatch | Match +>FileMatchOrMatch : Match | FileMatch >FileMatch : FileMatch >Match : Match let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch; ->elementA : FileMatch | Match ->FileMatchOrMatch : FileMatch | Match ->elementB : FileMatch | Match ->FileMatchOrMatch : FileMatch | Match +>elementA : Match | FileMatch +>FileMatchOrMatch : Match | FileMatch +>elementB : Match | FileMatch +>FileMatchOrMatch : Match | FileMatch if (elementA instanceof FileMatch && elementB instanceof FileMatch) { >elementA instanceof FileMatch && elementB instanceof FileMatch : boolean >elementA instanceof FileMatch : boolean ->elementA : FileMatch | Match +>elementA : Match | FileMatch >FileMatch : typeof FileMatch >elementB instanceof FileMatch : boolean ->elementB : FileMatch | Match +>elementB : Match | FileMatch >FileMatch : typeof FileMatch let a = elementA.resource().path; @@ -66,7 +66,7 @@ if (elementA instanceof FileMatch && elementB instanceof FileMatch) { >elementA : Match | FileMatch >Match : typeof Match >elementB instanceof Match : boolean ->elementB : FileMatch | Match +>elementB : Match | FileMatch >Match : typeof Match let a = elementA.range(); diff --git a/tests/baselines/reference/numericLiteralTypes1.types b/tests/baselines/reference/numericLiteralTypes1.types index f5632c2fa7192..277148b1afbb8 100644 --- a/tests/baselines/reference/numericLiteralTypes1.types +++ b/tests/baselines/reference/numericLiteralTypes1.types @@ -44,17 +44,17 @@ function f1() { } type B1 = -1 | 0 | 1; ->B1 : -1 | 0 | 1 +>B1 : 0 | 1 | -1 >-1 : -1 >1 : number type B2 = 1 | 0 | -1; ->B2 : 1 | 0 | -1 +>B2 : 0 | 1 | -1 >-1 : -1 >1 : number type B3 = 0 | -1 | 1; ->B3 : 0 | -1 | 1 +>B3 : 0 | 1 | -1 >-1 : -1 >1 : number @@ -62,19 +62,19 @@ function f2() { >f2 : () => void var b: B1 = -1; ->b : -1 | 0 | 1 ->B1 : -1 | 0 | 1 +>b : 0 | 1 | -1 +>B1 : 0 | 1 | -1 >-1 : -1 >1 : number var b: B2 = 0; ->b : -1 | 0 | 1 ->B2 : 1 | 0 | -1 +>b : 0 | 1 | -1 +>B2 : 0 | 1 | -1 >0 : 0 var b: B3 = 1; ->b : -1 | 0 | 1 ->B3 : 0 | -1 | 1 +>b : 0 | 1 | -1 +>B3 : 0 | 1 | -1 >1 : 1 } @@ -370,46 +370,46 @@ function f14(x: 0 | 1 | 2, y: string) { >y : string var b = x || y; ->b : 1 | 2 | string ->x || y : 1 | 2 | string +>b : string | 1 | 2 +>x || y : string | 1 | 2 >x : 0 | 1 | 2 >y : string } function f15(x: 0 | false, y: 1 | "one") { ->f15 : (x: 0 | false, y: 1 | "one") => void ->x : 0 | false +>f15 : (x: false | 0, y: 1 | "one") => void +>x : false | 0 >false : false >y : 1 | "one" var a = x && y; ->a : 0 | false ->x && y : 0 | false ->x : 0 | false +>a : false | 0 +>x && y : false | 0 +>x : false | 0 >y : 1 | "one" var b = y && x; ->b : 0 | false ->y && x : 0 | false +>b : false | 0 +>y && x : false | 0 >y : 1 | "one" ->x : 0 | false +>x : false | 0 var c = x || y; >c : 1 | "one" >x || y : 1 | "one" ->x : 0 | false +>x : false | 0 >y : 1 | "one" var d = y || x; ->d : 1 | "one" | 0 | false ->y || x : 1 | "one" | 0 | false +>d : false | 0 | 1 | "one" +>y || x : false | 0 | 1 | "one" >y : 1 | "one" ->x : 0 | false +>x : false | 0 var e = !x; >e : true >!x : true ->x : 0 | false +>x : false | 0 var f = !y; >f : boolean diff --git a/tests/baselines/reference/numericLiteralTypes2.types b/tests/baselines/reference/numericLiteralTypes2.types index 36c5026ba115c..d71c55fd5a2c3 100644 --- a/tests/baselines/reference/numericLiteralTypes2.types +++ b/tests/baselines/reference/numericLiteralTypes2.types @@ -45,17 +45,17 @@ function f1() { } type B1 = -1 | 0 | 1; ->B1 : -1 | 0 | 1 +>B1 : 0 | 1 | -1 >-1 : -1 >1 : number type B2 = 1 | 0 | -1; ->B2 : 1 | 0 | -1 +>B2 : 0 | 1 | -1 >-1 : -1 >1 : number type B3 = 0 | -1 | 1; ->B3 : 0 | -1 | 1 +>B3 : 0 | 1 | -1 >-1 : -1 >1 : number @@ -63,19 +63,19 @@ function f2() { >f2 : () => void var b: B1 = -1; ->b : -1 | 0 | 1 ->B1 : -1 | 0 | 1 +>b : 0 | 1 | -1 +>B1 : 0 | 1 | -1 >-1 : -1 >1 : number var b: B2 = 0; ->b : -1 | 0 | 1 ->B2 : 1 | 0 | -1 +>b : 0 | 1 | -1 +>B2 : 0 | 1 | -1 >0 : 0 var b: B3 = 1; ->b : -1 | 0 | 1 ->B3 : 0 | -1 | 1 +>b : 0 | 1 | -1 +>B3 : 0 | 1 | -1 >1 : 1 } @@ -371,46 +371,46 @@ function f14(x: 0 | 1 | 2, y: string) { >y : string var b = x || y; ->b : 1 | 2 | string ->x || y : 1 | 2 | string +>b : string | 1 | 2 +>x || y : string | 1 | 2 >x : 0 | 1 | 2 >y : string } function f15(x: 0 | false, y: 1 | "one") { ->f15 : (x: 0 | false, y: 1 | "one") => void ->x : 0 | false +>f15 : (x: false | 0, y: 1 | "one") => void +>x : false | 0 >false : false >y : 1 | "one" var a = x && y; ->a : 0 | false ->x && y : 0 | false ->x : 0 | false +>a : false | 0 +>x && y : false | 0 +>x : false | 0 >y : 1 | "one" var b = y && x; ->b : 0 | false ->y && x : 0 | false +>b : false | 0 +>y && x : false | 0 >y : 1 | "one" ->x : 0 | false +>x : false | 0 var c = x || y; >c : 1 | "one" >x || y : 1 | "one" ->x : 0 | false +>x : false | 0 >y : 1 | "one" var d = y || x; >d : 1 | "one" >y || x : 1 | "one" >y : 1 | "one" ->x : 0 | false +>x : false | 0 var e = !x; >e : true >!x : true ->x : 0 | false +>x : false | 0 var f = !y; >f : false diff --git a/tests/baselines/reference/objectLiteralExcessProperties.errors.txt b/tests/baselines/reference/objectLiteralExcessProperties.errors.txt index b96b9b0c54241..98f2e30287c76 100644 --- a/tests/baselines/reference/objectLiteralExcessProperties.errors.txt +++ b/tests/baselines/reference/objectLiteralExcessProperties.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/objectLiteralExcessProperties.ts(9,18): error TS2322: Type '{ forword: string; }' is not assignable to type 'Book'. Object literal may only specify known properties, and 'forword' does not exist in type 'Book'. -tests/cases/compiler/objectLiteralExcessProperties.ts(11,27): error TS2322: Type '{ foreward: string; }' is not assignable to type 'Book | string'. - Object literal may only specify known properties, and 'foreward' does not exist in type 'Book | string'. +tests/cases/compiler/objectLiteralExcessProperties.ts(11,27): error TS2322: Type '{ foreward: string; }' is not assignable to type 'string | Book'. + Object literal may only specify known properties, and 'foreward' does not exist in type 'string | Book'. tests/cases/compiler/objectLiteralExcessProperties.ts(13,53): error TS2322: Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book | Book[]'. Type '({ foreword: string; } | { forwards: string; })[]' is not assignable to type 'Book[]'. Type '{ foreword: string; } | { forwards: string; }' is not assignable to type 'Book'. @@ -41,8 +41,8 @@ tests/cases/compiler/objectLiteralExcessProperties.ts(33,27): error TS2322: Type var b2: Book | string = { foreward: "nope" }; ~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '{ foreward: string; }' is not assignable to type 'Book | string'. -!!! error TS2322: Object literal may only specify known properties, and 'foreward' does not exist in type 'Book | string'. +!!! error TS2322: Type '{ foreward: string; }' is not assignable to type 'string | Book'. +!!! error TS2322: Object literal may only specify known properties, and 'foreward' does not exist in type 'string | Book'. var b3: Book | (Book[]) = [{ foreword: "hello" }, { forwards: "back" }]; ~~~~~~~~~~~~~~~~ diff --git a/tests/baselines/reference/promiseType.types b/tests/baselines/reference/promiseType.types index 42f885eff68bc..1608182d6e9fd 100644 --- a/tests/baselines/reference/promiseType.types +++ b/tests/baselines/reference/promiseType.types @@ -21,8 +21,8 @@ const b = p.then(b => 1); >1 : number const c = p.then(b => 1, e => 'error'); ->c : Promise ->p.then(b => 1, e => 'error') : Promise +>c : Promise +>p.then(b => 1, e => 'error') : Promise >p.then : { (onfulfilled: (value: boolean) => TResult1 | PromiseLike, onrejected: (reason: any) => TResult2 | PromiseLike): Promise; (onfulfilled: (value: boolean) => TResult | PromiseLike, onrejected: (reason: any) => TResult | PromiseLike): Promise; (onfulfilled: (value: boolean) => TResult | PromiseLike): Promise; (): Promise; } >p : Promise >then : { (onfulfilled: (value: boolean) => TResult1 | PromiseLike, onrejected: (reason: any) => TResult2 | PromiseLike): Promise; (onfulfilled: (value: boolean) => TResult | PromiseLike, onrejected: (reason: any) => TResult | PromiseLike): Promise; (onfulfilled: (value: boolean) => TResult | PromiseLike): Promise; (): Promise; } @@ -78,8 +78,8 @@ const f = p.then(b => 1, e => Promise.reject(Error())); >Error : ErrorConstructor const g = p.catch(e => 'error'); ->g : Promise ->p.catch(e => 'error') : Promise +>g : Promise +>p.catch(e => 'error') : Promise >p.catch : { (onrejected: (reason: any) => TResult | PromiseLike): Promise; (onrejected: (reason: any) => boolean | PromiseLike): Promise; } >p : Promise >catch : { (onrejected: (reason: any) => TResult | PromiseLike): Promise; (onrejected: (reason: any) => boolean | PromiseLike): Promise; } diff --git a/tests/baselines/reference/recursiveUnionTypeInference.types b/tests/baselines/reference/recursiveUnionTypeInference.types index e5d62a051a539..72fb1efad3e34 100644 --- a/tests/baselines/reference/recursiveUnionTypeInference.types +++ b/tests/baselines/reference/recursiveUnionTypeInference.types @@ -9,16 +9,16 @@ interface Foo { } function bar(x: Foo | string): T { ->bar : (x: Foo | string) => T +>bar : (x: string | Foo) => T >T : T ->x : Foo | string +>x : string | Foo >Foo : Foo >T : T >T : T return bar(x); >bar(x) : T ->bar : (x: Foo | string) => T ->x : Foo | string +>bar : (x: string | Foo) => T +>x : string | Foo } diff --git a/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.types b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.types index 6c52661ef4995..1220152d21231 100644 --- a/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.types +++ b/tests/baselines/reference/resolveInterfaceNameWithSameLetDeclarationName2.types @@ -6,12 +6,12 @@ interface bar { } >bar : bar let bar: bar | foo; ->bar : bar | foo +>bar : foo | bar >bar : bar >foo : foo let foo: bar | foo; ->foo : bar | foo +>foo : foo | bar >bar : bar >foo : foo diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern.types index fbe264eeeae67..c2a88a6883816 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern.types @@ -429,7 +429,7 @@ for (let [nameMA, [primarySkillA, secondarySkillA]] = ["trimmer", ["trimming", " for (let [numberA3, ...robotAInfo] = robotA, i = 0; i < 1; i++) { >numberA3 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >robotA : [number, string, string] >i : number >0 : number @@ -448,7 +448,7 @@ for (let [numberA3, ...robotAInfo] = robotA, i = 0; i < 1; i++) { } for (let [numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >numberA3 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >getRobot() : [number, string, string] >getRobot : () => [number, string, string] >i : number @@ -467,9 +467,9 @@ for (let [numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >numberA3 : number } for (let [numberA3, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < 1; i++) { ->numberA3 : number | string ->robotAInfo : (number | string)[] ->[2, "trimmer", "trimming"] : (number | string)[] +>numberA3 : string | number +>robotAInfo : (string | number)[] +>[2, "trimmer", "trimming"] : (string | number)[] >2 : number >"trimmer" : string >"trimming" : string @@ -486,7 +486,7 @@ for (let [numberA3, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < 1; i >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->numberA3 : number | string +>numberA3 : string | number } for (let [...multiRobotAInfo] = multiRobotA, i = 0; i < 1; i++) { >multiRobotAInfo : (string | [string, string])[] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern2.types b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern2.types index a50f506262d5b..e9f7a0a740600 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern2.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPattern2.types @@ -69,7 +69,7 @@ let numberA2: number, nameA2: string, skillA2: string, nameMA: string; let numberA3: number, robotAInfo: (number | string)[], multiRobotAInfo: (string | [string, string])[]; >numberA3 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >multiRobotAInfo : (string | [string, string])[] let i: number; @@ -531,10 +531,10 @@ for ([nameMA, [primarySkillA, secondarySkillA]] = ["trimmer", ["trimming", "edgi for ([numberA3, ...robotAInfo] = robotA, i = 0; i < 1; i++) { >[numberA3, ...robotAInfo] = robotA, i = 0 : number >[numberA3, ...robotAInfo] = robotA : [number, string, string] ->[numberA3, ...robotAInfo] : (number | string)[] +>[numberA3, ...robotAInfo] : (string | number)[] >numberA3 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >robotA : [number, string, string] >i = 0 : number >i : number @@ -555,10 +555,10 @@ for ([numberA3, ...robotAInfo] = robotA, i = 0; i < 1; i++) { for ([numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >[numberA3, ...robotAInfo] = getRobot(), i = 0 : number >[numberA3, ...robotAInfo] = getRobot() : [number, string, string] ->[numberA3, ...robotAInfo] : (number | string)[] +>[numberA3, ...robotAInfo] : (string | number)[] >numberA3 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >getRobot() : [number, string, string] >getRobot : () => [number, string, string] >i = 0 : number @@ -580,10 +580,10 @@ for ([numberA3, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { for ([numberA3, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < 1; i++) { >[numberA3, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0 : number >[numberA3, ...robotAInfo] = [2, "trimmer", "trimming"] : [number, string, string] ->[numberA3, ...robotAInfo] : (number | string)[] +>[numberA3, ...robotAInfo] : (string | number)[] >numberA3 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >[2, "trimmer", "trimming"] : [number, string, string] >Robot : [number, string, string] >[2, "trimmer", "trimming"] : [number, string, string] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues.types index 245328296ebed..700e7b9f86307 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues.types @@ -534,7 +534,7 @@ for (let [numberA3 = -1, ...robotAInfo] = robotA, i = 0; i < 1; i++) { >numberA3 : number >-1 : number >1 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >robotA : [number, string, string] >i : number >0 : number @@ -555,7 +555,7 @@ for (let [numberA3 = -1, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >numberA3 : number >-1 : number >1 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >getRobot() : [number, string, string] >getRobot : () => [number, string, string] >i : number @@ -574,11 +574,11 @@ for (let [numberA3 = -1, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >numberA3 : number } for (let [numberA3 = -1, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < 1; i++) { ->numberA3 : number | string +>numberA3 : string | number >-1 : number >1 : number ->robotAInfo : (number | string)[] ->[2, "trimmer", "trimming"] : (number | string)[] +>robotAInfo : (string | number)[] +>[2, "trimmer", "trimming"] : (string | number)[] >2 : number >"trimmer" : string >"trimming" : string @@ -595,5 +595,5 @@ for (let [numberA3 = -1, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->numberA3 : number | string +>numberA3 : string | number } diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.types b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.types index 3bef86dcf80a8..93d149a6bdec5 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForArrayBindingPatternDefaultValues2.types @@ -69,7 +69,7 @@ let numberA2: number, nameA2: string, skillA2: string, nameMA: string; let numberA3: number, robotAInfo: (number | string)[], multiRobotAInfo: (string | [string, string])[]; >numberA3 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >multiRobotAInfo : (string | [string, string])[] let i: number; @@ -666,13 +666,13 @@ for ([nameMA = "noName", for ([numberA3 = -1, ...robotAInfo] = robotA, i = 0; i < 1; i++) { >[numberA3 = -1, ...robotAInfo] = robotA, i = 0 : number >[numberA3 = -1, ...robotAInfo] = robotA : [number, string, string] ->[numberA3 = -1, ...robotAInfo] : (number | string)[] +>[numberA3 = -1, ...robotAInfo] : (string | number)[] >numberA3 = -1 : number >numberA3 : number >-1 : number >1 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >robotA : [number, string, string] >i = 0 : number >i : number @@ -693,13 +693,13 @@ for ([numberA3 = -1, ...robotAInfo] = robotA, i = 0; i < 1; i++) { for ([numberA3 = -1, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { >[numberA3 = -1, ...robotAInfo] = getRobot(), i = 0 : number >[numberA3 = -1, ...robotAInfo] = getRobot() : [number, string, string] ->[numberA3 = -1, ...robotAInfo] : (number | string)[] +>[numberA3 = -1, ...robotAInfo] : (string | number)[] >numberA3 = -1 : number >numberA3 : number >-1 : number >1 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >getRobot() : [number, string, string] >getRobot : () => [number, string, string] >i = 0 : number @@ -721,13 +721,13 @@ for ([numberA3 = -1, ...robotAInfo] = getRobot(), i = 0; i < 1; i++) { for ([numberA3 = -1, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0; i < 1; i++) { >[numberA3 = -1, ...robotAInfo] = [2, "trimmer", "trimming"], i = 0 : number >[numberA3 = -1, ...robotAInfo] = [2, "trimmer", "trimming"] : [number, string, string] ->[numberA3 = -1, ...robotAInfo] : (number | string)[] +>[numberA3 = -1, ...robotAInfo] : (string | number)[] >numberA3 = -1 : number >numberA3 : number >-1 : number >1 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >[2, "trimmer", "trimming"] : [number, string, string] >Robot : [number, string, string] >[2, "trimmer", "trimming"] : [number, string, string] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern.types index 95c947f8fcc20..aebfe16dcde88 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern.types @@ -314,7 +314,7 @@ for (let [nameMA, [primarySkillA, secondarySkillA]] of [multiRobotA, multiRobotB for (let [numberA3, ...robotAInfo] of robots) { >numberA3 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >robots : [number, string, string][] console.log(numberA3); @@ -326,7 +326,7 @@ for (let [numberA3, ...robotAInfo] of robots) { } for (let [numberA3, ...robotAInfo] of getRobots()) { >numberA3 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >getRobots() : [number, string, string][] >getRobots : () => [number, string, string][] @@ -339,7 +339,7 @@ for (let [numberA3, ...robotAInfo] of getRobots()) { } for (let [numberA3, ...robotAInfo] of [robotA, robotB]) { >numberA3 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >[robotA, robotB] : [number, string, string][] >robotA : [number, string, string] >robotB : [number, string, string] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern2.types b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern2.types index 78cb778b5451b..be84bbe3459bb 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern2.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPattern2.types @@ -89,7 +89,7 @@ let numberA2: number, nameA2: string, skillA2: string, nameMA: string; let numberA3: number, robotAInfo: (number | string)[], multiRobotAInfo: (string | [string, string])[]; >numberA3 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >multiRobotAInfo : (string | [string, string])[] for ([, nameA] of robots) { @@ -357,10 +357,10 @@ for ([nameMA, [primarySkillA, secondarySkillA]] of [multiRobotA, multiRobotB]) { } for ([numberA3, ...robotAInfo] of robots) { ->[numberA3, ...robotAInfo] : (number | string)[] +>[numberA3, ...robotAInfo] : (string | number)[] >numberA3 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >robots : [number, string, string][] console.log(numberA3); @@ -371,10 +371,10 @@ for ([numberA3, ...robotAInfo] of robots) { >numberA3 : number } for ([numberA3, ...robotAInfo] of getRobots()) { ->[numberA3, ...robotAInfo] : (number | string)[] +>[numberA3, ...robotAInfo] : (string | number)[] >numberA3 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >getRobots() : [number, string, string][] >getRobots : () => [number, string, string][] @@ -386,10 +386,10 @@ for ([numberA3, ...robotAInfo] of getRobots()) { >numberA3 : number } for ([numberA3, ...robotAInfo] of [robotA, robotB]) { ->[numberA3, ...robotAInfo] : (number | string)[] +>[numberA3, ...robotAInfo] : (string | number)[] >numberA3 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >[robotA, robotB] : [number, string, string][] >robotA : [number, string, string] >robotB : [number, string, string] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.types index 488b5c4614537..80ba5df531fa0 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues.types @@ -409,7 +409,7 @@ for (let [numberA3 = -1, ...robotAInfo] of robots) { >numberA3 : number >-1 : number >1 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >robots : [number, string, string][] console.log(numberA3); @@ -423,7 +423,7 @@ for (let [numberA3 = -1, ...robotAInfo] of getRobots()) { >numberA3 : number >-1 : number >1 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >getRobots() : [number, string, string][] >getRobots : () => [number, string, string][] @@ -438,7 +438,7 @@ for (let [numberA3 = -1, ...robotAInfo] of [robotA, robotB]) { >numberA3 : number >-1 : number >1 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >[robotA, robotB] : [number, string, string][] >robotA : [number, string, string] >robotB : [number, string, string] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues2.types b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues2.types index 5f580ad38f442..257663d7fe33a 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues2.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringForOfArrayBindingPatternDefaultValues2.types @@ -89,7 +89,7 @@ let numberA2: number, nameA2: string, skillA2: string, nameMA: string; let numberA3: number, robotAInfo: (number | string)[], multiRobotAInfo: (string | [string, string])[]; >numberA3 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >multiRobotAInfo : (string | [string, string])[] for ([, nameA = "noName"] of robots) { @@ -489,13 +489,13 @@ for ([nameMA = "noName", [ } for ([numberA3 = -1, ...robotAInfo] of robots) { ->[numberA3 = -1, ...robotAInfo] : (number | string)[] +>[numberA3 = -1, ...robotAInfo] : (string | number)[] >numberA3 = -1 : number >numberA3 : number >-1 : number >1 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >robots : [number, string, string][] console.log(numberA3); @@ -506,13 +506,13 @@ for ([numberA3 = -1, ...robotAInfo] of robots) { >numberA3 : number } for ([numberA3 = -1, ...robotAInfo] of getRobots()) { ->[numberA3 = -1, ...robotAInfo] : (number | string)[] +>[numberA3 = -1, ...robotAInfo] : (string | number)[] >numberA3 = -1 : number >numberA3 : number >-1 : number >1 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >getRobots() : [number, string, string][] >getRobots : () => [number, string, string][] @@ -524,13 +524,13 @@ for ([numberA3 = -1, ...robotAInfo] of getRobots()) { >numberA3 : number } for ([numberA3 = -1, ...robotAInfo] of [robotA, robotB]) { ->[numberA3 = -1, ...robotAInfo] : (number | string)[] +>[numberA3 = -1, ...robotAInfo] : (string | number)[] >numberA3 = -1 : number >numberA3 : number >-1 : number >1 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >[robotA, robotB] : [number, string, string][] >robotA : [number, string, string] >robotB : [number, string, string] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types index 9c695f1c0dd77..aab0b3cf5c73e 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPattern.types @@ -62,7 +62,7 @@ function foo3([numberA2, nameA2, skillA2]: Robot) { function foo4([numberA3, ...robotAInfo]: Robot) { >foo4 : ([numberA3, ...robotAInfo]: [number, string, string]) => void >numberA3 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >Robot : [number, string, string] console.log(robotAInfo); @@ -70,7 +70,7 @@ function foo4([numberA3, ...robotAInfo]: Robot) { >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] } foo1(robotA); diff --git a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types index 366c538dda745..43420fdd58773 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringParametertArrayBindingPatternDefaultValues.types @@ -86,7 +86,7 @@ function foo4([numberA3 = -1, ...robotAInfo]: Robot = [-1, "name", "skill"]) { >numberA3 : number >-1 : number >1 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >Robot : [number, string, string] >[-1, "name", "skill"] : [number, string, string] >-1 : number @@ -99,7 +99,7 @@ function foo4([numberA3 = -1, ...robotAInfo]: Robot = [-1, "name", "skill"]) { >console.log : (msg: any) => void >console : { log(msg: any): void; } >log : (msg: any) => void ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] } foo1(robotA); diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern.types index 73006f4ec4544..db6e57258d764 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern.types @@ -59,7 +59,7 @@ let [numberC, nameC, skillC] = [3, "edging", "Trimming edges"]; let [numberA3, ...robotAInfo] = robotA; >numberA3 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >robotA : [number, string, string] if (nameA == nameA2) { diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3.types index 5ca93029977d1..14a8c18c051ef 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPattern3.types @@ -53,7 +53,7 @@ let nameA: string, numberB: number, nameB: string, skillB: string; >skillB : string let robotAInfo: (number | string)[]; ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] let multiSkillB: [string, string], nameMB: string, primarySkillB: string, secondarySkillB: string; >multiSkillB : [string, string] @@ -222,27 +222,27 @@ let multiRobotAInfo: (string | [string, string])[]; [numberB, ...robotAInfo] = robotB; >[numberB, ...robotAInfo] = robotB : [number, string, string] ->[numberB, ...robotAInfo] : (number | string)[] +>[numberB, ...robotAInfo] : (string | number)[] >numberB : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >robotB : [number, string, string] [numberB, ...robotAInfo] = getRobotB(); >[numberB, ...robotAInfo] = getRobotB() : [number, string, string] ->[numberB, ...robotAInfo] : (number | string)[] +>[numberB, ...robotAInfo] : (string | number)[] >numberB : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >getRobotB() : [number, string, string] >getRobotB : () => [number, string, string] [numberB, ...robotAInfo] = [2, "trimmer", "trimming"]; >[numberB, ...robotAInfo] = [2, "trimmer", "trimming"] : [number, string, string] ->[numberB, ...robotAInfo] : (number | string)[] +>[numberB, ...robotAInfo] : (string | number)[] >numberB : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >[2, "trimmer", "trimming"] : [number, string, string] >Robot : [number, string, string] >[2, "trimmer", "trimming"] : [number, string, string] diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues.types index 2dad459725eaf..be5b47f2eaaf5 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues.types @@ -73,7 +73,7 @@ let [numberA3 = -1, ...robotAInfo] = robotA; >numberA3 : number >-1 : number >1 : number ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] >robotA : [number, string, string] if (nameA == nameA2) { diff --git a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues3.types b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues3.types index 7edf6c63e4aed..0b1454bdf3b82 100644 --- a/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues3.types +++ b/tests/baselines/reference/sourceMapValidationDestructuringVariableStatementArrayBindingPatternDefaultValues3.types @@ -53,7 +53,7 @@ let nameA: string, numberB: number, nameB: string, skillB: string; >skillB : string let robotAInfo: (number | string)[]; ->robotAInfo : (number | string)[] +>robotAInfo : (string | number)[] let multiSkillB: string[], nameMB: string, primarySkillB: string, secondarySkillB: string; >multiSkillB : string[] @@ -296,36 +296,36 @@ let multiRobotAInfo: (string | string[])[]; [numberB = -1, ...robotAInfo] = robotB; >[numberB = -1, ...robotAInfo] = robotB : [number, string, string] ->[numberB = -1, ...robotAInfo] : (number | string)[] +>[numberB = -1, ...robotAInfo] : (string | number)[] >numberB = -1 : number >numberB : number >-1 : number >1 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >robotB : [number, string, string] [numberB = -1, ...robotAInfo] = getRobotB(); >[numberB = -1, ...robotAInfo] = getRobotB() : [number, string, string] ->[numberB = -1, ...robotAInfo] : (number | string)[] +>[numberB = -1, ...robotAInfo] : (string | number)[] >numberB = -1 : number >numberB : number >-1 : number >1 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >getRobotB() : [number, string, string] >getRobotB : () => [number, string, string] [numberB = -1, ...robotAInfo] = [2, "trimmer", "trimming"]; >[numberB = -1, ...robotAInfo] = [2, "trimmer", "trimming"] : [number, string, string] ->[numberB = -1, ...robotAInfo] : (number | string)[] +>[numberB = -1, ...robotAInfo] : (string | number)[] >numberB = -1 : number >numberB : number >-1 : number >1 : number ->...robotAInfo : number | string ->robotAInfo : (number | string)[] +>...robotAInfo : string | number +>robotAInfo : (string | number)[] >[2, "trimmer", "trimming"] : [number, string, string] >Robot : [number, string, string] >[2, "trimmer", "trimming"] : [number, string, string] diff --git a/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.types b/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.types index 7140935cb913c..e13ac6a64e8e6 100644 --- a/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.types +++ b/tests/baselines/reference/staticAnonymousTypeNotReferencingTypeParameter.types @@ -662,9 +662,9 @@ class ListWrapper { >l : T[] >T : T >JSON.stringify(l) : string ->JSON.stringify : { (value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (number | string)[], space?: string | number): string; } +>JSON.stringify : { (value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; } >JSON : JSON ->stringify : { (value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (number | string)[], space?: string | number): string; } +>stringify : { (value: any, replacer?: (key: string, value: any) => any, space?: string | number): string; (value: any, replacer?: (string | number)[], space?: string | number): string; } >l : T[] static maximum(dit: typeof ListWrapper, list: T[], predicate: (t: T) => number): T { diff --git a/tests/baselines/reference/strictNullLogicalAndOr.types b/tests/baselines/reference/strictNullLogicalAndOr.types index ac02ec1378b30..ba25c57fe1d20 100644 --- a/tests/baselines/reference/strictNullLogicalAndOr.types +++ b/tests/baselines/reference/strictNullLogicalAndOr.types @@ -14,7 +14,7 @@ let sinOrCos = Math.random() < .5; let choice = sinOrCos && Math.sin || Math.cos; >choice : (x: number) => number >sinOrCos && Math.sin || Math.cos : (x: number) => number ->sinOrCos && Math.sin : ((x: number) => number) | false +>sinOrCos && Math.sin : false | ((x: number) => number) >sinOrCos : boolean >Math.sin : (x: number) => number >Math : Math diff --git a/tests/baselines/reference/stringLiteralCheckedInIf01.types b/tests/baselines/reference/stringLiteralCheckedInIf01.types index 23db9900231c8..12da51f2b24e4 100644 --- a/tests/baselines/reference/stringLiteralCheckedInIf01.types +++ b/tests/baselines/reference/stringLiteralCheckedInIf01.types @@ -4,18 +4,18 @@ type S = "a" | "b"; >S : "a" | "b" type T = S[] | S; ->T : ("a" | "b")[] | "a" | "b" +>T : "a" | "b" | ("a" | "b")[] >S : "a" | "b" >S : "a" | "b" function f(foo: T) { ->f : (foo: ("a" | "b")[] | "a" | "b") => "a" | "b" ->foo : ("a" | "b")[] | "a" | "b" ->T : ("a" | "b")[] | "a" | "b" +>f : (foo: "a" | "b" | ("a" | "b")[]) => "a" | "b" +>foo : "a" | "b" | ("a" | "b")[] +>T : "a" | "b" | ("a" | "b")[] if (foo === "a") { >foo === "a" : boolean ->foo : ("a" | "b")[] | "a" | "b" +>foo : "a" | "b" | ("a" | "b")[] >"a" : "a" return foo; @@ -23,7 +23,7 @@ function f(foo: T) { } else if (foo === "b") { >foo === "b" : boolean ->foo : ("a" | "b")[] | "b" +>foo : "b" | ("a" | "b")[] >"b" : "b" return foo; diff --git a/tests/baselines/reference/stringLiteralCheckedInIf02.types b/tests/baselines/reference/stringLiteralCheckedInIf02.types index b287400b21dcd..a75cbaab248fb 100644 --- a/tests/baselines/reference/stringLiteralCheckedInIf02.types +++ b/tests/baselines/reference/stringLiteralCheckedInIf02.types @@ -4,36 +4,36 @@ type S = "a" | "b"; >S : "a" | "b" type T = S[] | S; ->T : ("a" | "b")[] | "a" | "b" +>T : "a" | "b" | ("a" | "b")[] >S : "a" | "b" >S : "a" | "b" function isS(t: T): t is S { ->isS : (t: ("a" | "b")[] | "a" | "b") => t is "a" | "b" ->t : ("a" | "b")[] | "a" | "b" ->T : ("a" | "b")[] | "a" | "b" +>isS : (t: "a" | "b" | ("a" | "b")[]) => t is "a" | "b" +>t : "a" | "b" | ("a" | "b")[] +>T : "a" | "b" | ("a" | "b")[] >t : any >S : "a" | "b" return t === "a" || t === "b"; >t === "a" || t === "b" : boolean >t === "a" : boolean ->t : ("a" | "b")[] | "a" | "b" +>t : "a" | "b" | ("a" | "b")[] >"a" : "a" >t === "b" : boolean ->t : ("a" | "b")[] | "b" +>t : "b" | ("a" | "b")[] >"b" : "b" } function f(foo: T) { ->f : (foo: ("a" | "b")[] | "a" | "b") => "a" | "b" ->foo : ("a" | "b")[] | "a" | "b" ->T : ("a" | "b")[] | "a" | "b" +>f : (foo: "a" | "b" | ("a" | "b")[]) => "a" | "b" +>foo : "a" | "b" | ("a" | "b")[] +>T : "a" | "b" | ("a" | "b")[] if (isS(foo)) { >isS(foo) : boolean ->isS : (t: ("a" | "b")[] | "a" | "b") => t is "a" | "b" ->foo : ("a" | "b")[] | "a" | "b" +>isS : (t: "a" | "b" | ("a" | "b")[]) => t is "a" | "b" +>foo : "a" | "b" | ("a" | "b")[] return foo; >foo : "a" | "b" diff --git a/tests/baselines/reference/stringLiteralMatchedInSwitch01.types b/tests/baselines/reference/stringLiteralMatchedInSwitch01.types index 21b7029eea653..e5a1fd5486e04 100644 --- a/tests/baselines/reference/stringLiteralMatchedInSwitch01.types +++ b/tests/baselines/reference/stringLiteralMatchedInSwitch01.types @@ -4,16 +4,16 @@ type S = "a" | "b"; >S : "a" | "b" type T = S[] | S; ->T : ("a" | "b")[] | "a" | "b" +>T : "a" | "b" | ("a" | "b")[] >S : "a" | "b" >S : "a" | "b" var foo: T; ->foo : ("a" | "b")[] | "a" | "b" ->T : ("a" | "b")[] | "a" | "b" +>foo : "a" | "b" | ("a" | "b")[] +>T : "a" | "b" | ("a" | "b")[] switch (foo) { ->foo : ("a" | "b")[] | "a" | "b" +>foo : "a" | "b" | ("a" | "b")[] case "a": >"a" : "a" @@ -25,7 +25,7 @@ switch (foo) { default: foo = (foo as S[])[0]; >foo = (foo as S[])[0] : "a" | "b" ->foo : ("a" | "b")[] | "a" | "b" +>foo : "a" | "b" | ("a" | "b")[] >(foo as S[])[0] : "a" | "b" >(foo as S[]) : ("a" | "b")[] >foo as S[] : ("a" | "b")[] diff --git a/tests/baselines/reference/stringLiteralTypeAssertion01.types b/tests/baselines/reference/stringLiteralTypeAssertion01.types index f70313f834700..6ec5bfff237c8 100644 --- a/tests/baselines/reference/stringLiteralTypeAssertion01.types +++ b/tests/baselines/reference/stringLiteralTypeAssertion01.types @@ -4,7 +4,7 @@ type S = "a" | "b"; >S : "a" | "b" type T = S[] | S; ->T : ("a" | "b")[] | "a" | "b" +>T : "a" | "b" | ("a" | "b")[] >S : "a" | "b" >S : "a" | "b" @@ -13,8 +13,8 @@ var s: S; >S : "a" | "b" var t: T; ->t : ("a" | "b")[] | "a" | "b" ->T : ("a" | "b")[] | "a" | "b" +>t : "a" | "b" | ("a" | "b")[] +>T : "a" | "b" | ("a" | "b")[] var str: string; >str : string @@ -26,13 +26,13 @@ s = t; >s : "a" | "b" >t : "a" | "b" >S : "a" | "b" ->t : ("a" | "b")[] | "a" | "b" +>t : "a" | "b" | ("a" | "b")[] s = t as S; >s = t as S : "a" | "b" >s : "a" | "b" >t as S : "a" | "b" ->t : ("a" | "b")[] | "a" | "b" +>t : "a" | "b" | ("a" | "b")[] >S : "a" | "b" s = str; @@ -52,32 +52,32 @@ s = str as S; //////////////// t = s; ->t = s : ("a" | "b")[] | "a" | "b" ->t : ("a" | "b")[] | "a" | "b" ->s : ("a" | "b")[] | "a" | "b" ->T : ("a" | "b")[] | "a" | "b" +>t = s : "a" | "b" | ("a" | "b")[] +>t : "a" | "b" | ("a" | "b")[] +>s : "a" | "b" | ("a" | "b")[] +>T : "a" | "b" | ("a" | "b")[] >s : "a" | "b" t = s as T; ->t = s as T : ("a" | "b")[] | "a" | "b" ->t : ("a" | "b")[] | "a" | "b" ->s as T : ("a" | "b")[] | "a" | "b" +>t = s as T : "a" | "b" | ("a" | "b")[] +>t : "a" | "b" | ("a" | "b")[] +>s as T : "a" | "b" | ("a" | "b")[] >s : "a" | "b" ->T : ("a" | "b")[] | "a" | "b" +>T : "a" | "b" | ("a" | "b")[] t = str; ->t = str : ("a" | "b")[] | "a" | "b" ->t : ("a" | "b")[] | "a" | "b" ->str : ("a" | "b")[] | "a" | "b" ->T : ("a" | "b")[] | "a" | "b" +>t = str : "a" | "b" | ("a" | "b")[] +>t : "a" | "b" | ("a" | "b")[] +>str : "a" | "b" | ("a" | "b")[] +>T : "a" | "b" | ("a" | "b")[] >str : string t = str as T; ->t = str as T : ("a" | "b")[] | "a" | "b" ->t : ("a" | "b")[] | "a" | "b" ->str as T : ("a" | "b")[] | "a" | "b" +>t = str as T : "a" | "b" | ("a" | "b")[] +>t : "a" | "b" | ("a" | "b")[] +>str as T : "a" | "b" | ("a" | "b")[] >str : string ->T : ("a" | "b")[] | "a" | "b" +>T : "a" | "b" | ("a" | "b")[] //////////////// @@ -97,11 +97,11 @@ str = t; >str = t : string >str : string >t : string ->t : ("a" | "b")[] | "a" | "b" +>t : "a" | "b" | ("a" | "b")[] str = t as string; >str = t as string : string >str : string >t as string : string ->t : ("a" | "b")[] | "a" | "b" +>t : "a" | "b" | ("a" | "b")[] diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types index 2d997c93ccbdf..96ec536f82fef 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types @@ -27,8 +27,8 @@ else if (x !== "bar") { >"bar" : "bar" let b = x || y; ->b : "baz" | "foo" | "bar" ->x || y : "baz" | "foo" | "bar" +>b : "foo" | "bar" | "baz" +>x || y : "foo" | "bar" | "baz" >x : "baz" >y : "foo" | "bar" | "baz" } @@ -42,10 +42,10 @@ else { >y : "foo" | "bar" | "baz" let e: (typeof x) | (typeof y) = c || d; ->e : "bar" | "foo" | "baz" +>e : "foo" | "bar" | "baz" >x : "bar" >y : "foo" | "bar" | "baz" ->c || d : "bar" | "foo" | "baz" +>c || d : "foo" | "bar" | "baz" >c : "bar" >d : "foo" | "bar" | "baz" } diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types index 2b8bbbcca9c19..ab63a9e2fab36 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types @@ -4,7 +4,7 @@ type T = string | "foo" | "bar" | "baz"; >T : string | "foo" | "bar" | "baz" var x: "foo" | "bar" | "baz" | string = undefined; ->x : "foo" | "bar" | "baz" | string +>x : string | "foo" | "bar" | "baz" >undefined : undefined var y: T = undefined; @@ -14,49 +14,49 @@ var y: T = undefined; if (x === "foo") { >x === "foo" : boolean ->x : "foo" | "bar" | "baz" | string +>x : string | "foo" | "bar" | "baz" >"foo" : "foo" let a = x; ->a : "foo" | string ->x : "foo" | string +>a : string | "foo" +>x : string | "foo" } else if (x !== "bar") { >x !== "bar" : boolean ->x : "bar" | "baz" | string +>x : string | "bar" | "baz" >"bar" : "bar" let b = x || y; >b : string >x || y : string ->x : "baz" | string +>x : string | "baz" >y : string | "foo" | "bar" | "baz" } else { let c = x; ->c : "bar" | string ->x : "bar" | string +>c : string | "bar" +>x : string | "bar" let d = y; >d : string | "foo" | "bar" | "baz" >y : string | "foo" | "bar" | "baz" let e: (typeof x) | (typeof y) = c || d; ->e : "bar" | string | "foo" | "baz" ->x : "bar" | string +>e : string | "foo" | "bar" | "baz" +>x : string | "bar" >y : string | "foo" | "bar" | "baz" >c || d : string ->c : "bar" | string +>c : string | "bar" >d : string | "foo" | "bar" | "baz" } x = y; >x = y : string | "foo" | "bar" | "baz" ->x : "foo" | "bar" | "baz" | string +>x : string | "foo" | "bar" | "baz" >y : string | "foo" | "bar" | "baz" y = x; ->y = x : "foo" | "bar" | "baz" | string +>y = x : string | "foo" | "bar" | "baz" >y : string | "foo" | "bar" | "baz" ->x : "foo" | "bar" | "baz" | string +>x : string | "foo" | "bar" | "baz" diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types index 73560ac177430..99a729c7cf9c6 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types @@ -4,7 +4,7 @@ type T = number | "foo" | "bar"; >T : number | "foo" | "bar" var x: "foo" | "bar" | number; ->x : "foo" | "bar" | number +>x : number | "foo" | "bar" var y: T = undefined; >y : number | "foo" | "bar" @@ -13,7 +13,7 @@ var y: T = undefined; if (x === "foo") { >x === "foo" : boolean ->x : "foo" | "bar" | number +>x : number | "foo" | "bar" >"foo" : "foo" let a = x; @@ -22,7 +22,7 @@ if (x === "foo") { } else if (x !== "bar") { >x !== "bar" : boolean ->x : "bar" | number +>x : number | "bar" >"bar" : "bar" let b = x || y; @@ -41,21 +41,21 @@ else { >y : number | "foo" | "bar" let e: (typeof x) | (typeof y) = c || d; ->e : "bar" | number | "foo" +>e : number | "foo" | "bar" >x : "bar" >y : number | "foo" | "bar" ->c || d : "bar" | number | "foo" +>c || d : number | "foo" | "bar" >c : "bar" >d : number | "foo" | "bar" } x = y; >x = y : number | "foo" | "bar" ->x : "foo" | "bar" | number +>x : number | "foo" | "bar" >y : number | "foo" | "bar" y = x; ->y = x : "foo" | "bar" | number +>y = x : number | "foo" | "bar" >y : number | "foo" | "bar" ->x : "foo" | "bar" | number +>x : number | "foo" | "bar" diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types index bf1cc61175f15..963ba4239db94 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types @@ -35,7 +35,7 @@ if (x !== "") { if (x == "") { >x == "" : boolean ->x : "foo" | "" +>x : "" | "foo" >"" : "" let c = x; @@ -54,7 +54,7 @@ if (x != "") { } if (x) { ->x : "foo" | "" +>x : "" | "foo" let e = x; >e : "foo" @@ -63,17 +63,17 @@ if (x) { if (!x) { >!x : boolean ->x : "foo" | "" +>x : "" | "foo" let f = x; ->f : "foo" | "" ->x : "foo" | "" +>f : "" | "foo" +>x : "" | "foo" } if (!!x) { >!!x : boolean >!x : boolean ->x : "foo" | "" +>x : "" | "foo" let g = x; >g : "foo" @@ -84,9 +84,9 @@ if (!!!x) { >!!!x : boolean >!!x : boolean >!x : boolean ->x : "foo" | "" +>x : "" | "foo" let h = x; ->h : "foo" | "" ->x : "foo" | "" +>h : "" | "foo" +>x : "" | "foo" } diff --git a/tests/baselines/reference/stringLiteralTypesOverloads01.js b/tests/baselines/reference/stringLiteralTypesOverloads01.js index f3331c9f717d6..ef441a4098566 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads01.js +++ b/tests/baselines/reference/stringLiteralTypesOverloads01.js @@ -109,6 +109,6 @@ declare const boolean: "boolean"; declare const stringOrNumber: "string" | "number"; declare const stringOrBoolean: "string" | "boolean"; declare const booleanOrNumber: "number" | "boolean"; -declare const stringOrBooleanOrNumber: "string" | "boolean" | "number"; +declare const stringOrBooleanOrNumber: "string" | "number" | "boolean"; declare namespace Consts2 { } diff --git a/tests/baselines/reference/stringLiteralTypesOverloads01.types b/tests/baselines/reference/stringLiteralTypesOverloads01.types index 71a73222ba688..dff55fc08fb54 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads01.types +++ b/tests/baselines/reference/stringLiteralTypesOverloads01.types @@ -4,35 +4,35 @@ type PrimitiveName = 'string' | 'number' | 'boolean'; >PrimitiveName : "string" | "number" | "boolean" function getFalsyPrimitive(x: "string"): string; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >x : "string" function getFalsyPrimitive(x: "number"): number; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >x : "number" function getFalsyPrimitive(x: "boolean"): boolean; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >x : "boolean" function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } ->x : "boolean" | "string" +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>x : "string" | "boolean" function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } ->x : "boolean" | "number" +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>x : "number" | "boolean" function getFalsyPrimitive(x: "number" | "string"): number | string; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } ->x : "number" | "string" +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>x : "string" | "number" function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } ->x : "number" | "string" | "boolean" +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>x : "string" | "number" | "boolean" function getFalsyPrimitive(x: PrimitiveName): number | string | boolean { ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >x : "string" | "number" | "boolean" >PrimitiveName : "string" | "number" | "boolean" @@ -72,19 +72,19 @@ namespace Consts1 { const EMPTY_STRING = getFalsyPrimitive("string"); >EMPTY_STRING : string >getFalsyPrimitive("string") : string ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >"string" : "string" const ZERO = getFalsyPrimitive('number'); >ZERO : number >getFalsyPrimitive('number') : number ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >'number' : "number" const FALSE = getFalsyPrimitive("boolean"); >FALSE : boolean >getFalsyPrimitive("boolean") : boolean ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >"boolean" : "boolean" } @@ -119,8 +119,8 @@ const booleanOrNumber = number || boolean; >boolean : "boolean" const stringOrBooleanOrNumber = stringOrBoolean || number; ->stringOrBooleanOrNumber : "string" | "boolean" | "number" ->stringOrBoolean || number : "string" | "boolean" | "number" +>stringOrBooleanOrNumber : "string" | "number" | "boolean" +>stringOrBoolean || number : "string" | "number" | "boolean" >stringOrBoolean : "string" | "boolean" >number : "number" @@ -130,44 +130,44 @@ namespace Consts2 { const EMPTY_STRING = getFalsyPrimitive(string); >EMPTY_STRING : string >getFalsyPrimitive(string) : string ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >string : "string" const ZERO = getFalsyPrimitive(number); >ZERO : number >getFalsyPrimitive(number) : number ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >number : "number" const FALSE = getFalsyPrimitive(boolean); >FALSE : boolean >getFalsyPrimitive(boolean) : boolean ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >boolean : "boolean" const a = getFalsyPrimitive(stringOrNumber); ->a : number | string ->getFalsyPrimitive(stringOrNumber) : number | string ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>a : string | number +>getFalsyPrimitive(stringOrNumber) : string | number +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >stringOrNumber : "string" | "number" const b = getFalsyPrimitive(stringOrBoolean); ->b : boolean | string ->getFalsyPrimitive(stringOrBoolean) : boolean | string ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>b : string | boolean +>getFalsyPrimitive(stringOrBoolean) : string | boolean +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >stringOrBoolean : "string" | "boolean" const c = getFalsyPrimitive(booleanOrNumber); ->c : boolean | number ->getFalsyPrimitive(booleanOrNumber) : boolean | number ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } +>c : number | boolean +>getFalsyPrimitive(booleanOrNumber) : number | boolean +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } >booleanOrNumber : "number" | "boolean" const d = getFalsyPrimitive(stringOrBooleanOrNumber); ->d : number | string | boolean ->getFalsyPrimitive(stringOrBooleanOrNumber) : number | string | boolean ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "boolean" | "string"): boolean | string; (x: "boolean" | "number"): boolean | number; (x: "number" | "string"): number | string; (x: "number" | "string" | "boolean"): number | string | boolean; } ->stringOrBooleanOrNumber : "string" | "boolean" | "number" +>d : string | number | boolean +>getFalsyPrimitive(stringOrBooleanOrNumber) : string | number | boolean +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>stringOrBooleanOrNumber : "string" | "number" | "boolean" } diff --git a/tests/baselines/reference/stringLiteralTypesOverloads02.js b/tests/baselines/reference/stringLiteralTypesOverloads02.js index 3c53f9380a88b..45443ea6a8fa3 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads02.js +++ b/tests/baselines/reference/stringLiteralTypesOverloads02.js @@ -106,6 +106,6 @@ declare const boolean: "boolean"; declare const stringOrNumber: "string" | "number"; declare const stringOrBoolean: "string" | "boolean"; declare const booleanOrNumber: "number" | "boolean"; -declare const stringOrBooleanOrNumber: "string" | "boolean" | "number"; +declare const stringOrBooleanOrNumber: "string" | "number" | "boolean"; declare namespace Consts2 { } diff --git a/tests/baselines/reference/stringLiteralTypesWithVariousOperators01.types b/tests/baselines/reference/stringLiteralTypesWithVariousOperators01.types index 90cb538b800d1..d55d5ab92948d 100644 --- a/tests/baselines/reference/stringLiteralTypesWithVariousOperators01.types +++ b/tests/baselines/reference/stringLiteralTypesWithVariousOperators01.types @@ -15,8 +15,8 @@ let abcOrXyz: "ABC" | "XYZ" = abc || xyz; >xyz : "XYZ" let abcOrXyzOrNumber: "ABC" | "XYZ" | number = abcOrXyz || 100; ->abcOrXyzOrNumber : "ABC" | "XYZ" | number ->abcOrXyz || 100 : "ABC" | "XYZ" | number +>abcOrXyzOrNumber : number | "ABC" | "XYZ" +>abcOrXyz || 100 : number | "ABC" | "XYZ" >abcOrXyz : "ABC" | "XYZ" >100 : number @@ -95,47 +95,47 @@ let l = -abcOrXyz; let m = abcOrXyzOrNumber + ""; >m : string >abcOrXyzOrNumber + "" : string ->abcOrXyzOrNumber : "ABC" | "XYZ" | number +>abcOrXyzOrNumber : number | "ABC" | "XYZ" >"" : string let n = "" + abcOrXyzOrNumber; >n : string >"" + abcOrXyzOrNumber : string >"" : string ->abcOrXyzOrNumber : "ABC" | "XYZ" | number +>abcOrXyzOrNumber : number | "ABC" | "XYZ" let o = abcOrXyzOrNumber + abcOrXyz; >o : string >abcOrXyzOrNumber + abcOrXyz : string ->abcOrXyzOrNumber : "ABC" | "XYZ" | number +>abcOrXyzOrNumber : number | "ABC" | "XYZ" >abcOrXyz : "ABC" | "XYZ" let p = abcOrXyz + abcOrXyzOrNumber; >p : string >abcOrXyz + abcOrXyzOrNumber : string >abcOrXyz : "ABC" | "XYZ" ->abcOrXyzOrNumber : "ABC" | "XYZ" | number +>abcOrXyzOrNumber : number | "ABC" | "XYZ" let q = !abcOrXyzOrNumber; >q : boolean >!abcOrXyzOrNumber : boolean ->abcOrXyzOrNumber : "ABC" | "XYZ" | number +>abcOrXyzOrNumber : number | "ABC" | "XYZ" let r = ~abcOrXyzOrNumber; >r : number >~abcOrXyzOrNumber : number ->abcOrXyzOrNumber : "ABC" | "XYZ" | number +>abcOrXyzOrNumber : number | "ABC" | "XYZ" let s = abcOrXyzOrNumber < abcOrXyzOrNumber; >s : boolean >abcOrXyzOrNumber < abcOrXyzOrNumber : boolean ->abcOrXyzOrNumber : "ABC" | "XYZ" | number ->abcOrXyzOrNumber : "ABC" | "XYZ" | number +>abcOrXyzOrNumber : number | "ABC" | "XYZ" +>abcOrXyzOrNumber : number | "ABC" | "XYZ" let t = abcOrXyzOrNumber >= abcOrXyz; >t : boolean >abcOrXyzOrNumber >= abcOrXyz : boolean ->abcOrXyzOrNumber : "ABC" | "XYZ" | number +>abcOrXyzOrNumber : number | "ABC" | "XYZ" >abcOrXyz : "ABC" | "XYZ" let u = abc === abcOrXyz; @@ -148,5 +148,5 @@ let v = abcOrXyz === abcOrXyzOrNumber; >v : boolean >abcOrXyz === abcOrXyzOrNumber : boolean >abcOrXyz : "ABC" | "XYZ" ->abcOrXyzOrNumber : "ABC" | "XYZ" | number +>abcOrXyzOrNumber : number | "ABC" | "XYZ" diff --git a/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt b/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt index 92afe67df0c62..ad02604cc4cf6 100644 --- a/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(7,9): error TS2365: Operator '+' cannot be applied to types '"ABC" | "XYZ" | number' and 'number'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(8,9): error TS2365: Operator '+' cannot be applied to types 'number' and '"ABC" | "XYZ" | number'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(9,9): error TS2365: Operator '+' cannot be applied to types '"ABC" | "XYZ" | number' and '"ABC" | "XYZ" | number'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(10,9): error TS2365: Operator '+' cannot be applied to types '"ABC" | "XYZ" | number' and 'boolean'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(11,9): error TS2365: Operator '+' cannot be applied to types 'boolean' and '"ABC" | "XYZ" | number'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(7,9): error TS2365: Operator '+' cannot be applied to types 'number | "ABC" | "XYZ"' and 'number'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(8,9): error TS2365: Operator '+' cannot be applied to types 'number' and 'number | "ABC" | "XYZ"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(9,9): error TS2365: Operator '+' cannot be applied to types 'number | "ABC" | "XYZ"' and 'number | "ABC" | "XYZ"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(10,9): error TS2365: Operator '+' cannot be applied to types 'number | "ABC" | "XYZ"' and 'boolean'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(11,9): error TS2365: Operator '+' cannot be applied to types 'boolean' and 'number | "ABC" | "XYZ"'. tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(12,9): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(13,11): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(14,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. @@ -21,19 +21,19 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperato let a = abcOrXyzOrNumber + 100; ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types '"ABC" | "XYZ" | number' and 'number'. +!!! error TS2365: Operator '+' cannot be applied to types 'number | "ABC" | "XYZ"' and 'number'. let b = 100 + abcOrXyzOrNumber; ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'number' and '"ABC" | "XYZ" | number'. +!!! error TS2365: Operator '+' cannot be applied to types 'number' and 'number | "ABC" | "XYZ"'. let c = abcOrXyzOrNumber + abcOrXyzOrNumber; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types '"ABC" | "XYZ" | number' and '"ABC" | "XYZ" | number'. +!!! error TS2365: Operator '+' cannot be applied to types 'number | "ABC" | "XYZ"' and 'number | "ABC" | "XYZ"'. let d = abcOrXyzOrNumber + true; ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types '"ABC" | "XYZ" | number' and 'boolean'. +!!! error TS2365: Operator '+' cannot be applied to types 'number | "ABC" | "XYZ"' and 'boolean'. let e = false + abcOrXyzOrNumber; ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '+' cannot be applied to types 'boolean' and '"ABC" | "XYZ" | number'. +!!! error TS2365: Operator '+' cannot be applied to types 'boolean' and 'number | "ABC" | "XYZ"'. let f = abcOrXyzOrNumber++; ~~~~~~~~~~~~~~~~ !!! error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.types b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.types index 39c50bde35569..4059a1b0b5114 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.types +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.types @@ -244,7 +244,7 @@ function f5(x: T) { var r1 = true ? x : 1; // ok >r1 : number | T ->true ? x : 1 : T | number +>true ? x : 1 : number | T >true : boolean >x : T >1 : number @@ -266,7 +266,7 @@ function f6(x: T) { var r2 = true ? x : ''; // ok >r2 : string | T ->true ? x : '' : T | string +>true ? x : '' : string | T >true : boolean >x : T >'' : string @@ -288,7 +288,7 @@ function f7(x: T) { var r3 = true ? x : true; // ok >r3 : boolean | T ->true ? x : true : T | boolean +>true ? x : true : boolean | T >true : boolean >x : T >true : boolean @@ -506,14 +506,14 @@ function f16(x: T) { >T : T var r13 = true ? E : x; // ok ->r13 : typeof E | T ->true ? E : x : typeof E | T +>r13 : T | typeof E +>true ? E : x : T | typeof E >true : boolean >E : typeof E >x : T var r13 = true ? x : E; // ok ->r13 : typeof E | T +>r13 : T | typeof E >true ? x : E : T | typeof E >true : boolean >x : T diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.types b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.types index 88c589982646f..f0f075a37ce16 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.types +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints3.types @@ -39,21 +39,21 @@ function f(t: T, u: U, v: V) { var r2 = true ? v : t; >r2 : T | V ->true ? v : t : V | T +>true ? v : t : T | V >true : boolean >v : V >t : T // ok var r3 = true ? v : u; ->r3 : V | U ->true ? v : u : V | U +>r3 : U | V +>true ? v : u : U | V >true : boolean >v : V >u : U var r3 = true ? u : v; ->r3 : V | U +>r3 : U | V >true ? u : v : U | V >true : boolean >u : U diff --git a/tests/baselines/reference/subtypesOfUnion.errors.txt b/tests/baselines/reference/subtypesOfUnion.errors.txt index 7c2e88ec8fd14..fade5377814f4 100644 --- a/tests/baselines/reference/subtypesOfUnion.errors.txt +++ b/tests/baselines/reference/subtypesOfUnion.errors.txt @@ -12,21 +12,21 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(28,5): error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'string | number'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(29,5): error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'string | number'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(30,5): error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'string | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(35,5): error TS2411: Property 'foo2' of type 'string' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(37,5): error TS2411: Property 'foo4' of type 'boolean' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(39,5): error TS2411: Property 'foo6' of type 'Date' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(40,5): error TS2411: Property 'foo7' of type 'RegExp' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(41,5): error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(42,5): error TS2411: Property 'foo9' of type 'I8' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(43,5): error TS2411: Property 'foo10' of type 'A' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(44,5): error TS2411: Property 'foo11' of type 'A2' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(45,5): error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(46,5): error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(47,5): error TS2411: Property 'foo14' of type 'typeof f' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(48,5): error TS2411: Property 'foo15' of type 'typeof c' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(49,5): error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(50,5): error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'E | number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(51,5): error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'E | number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(35,5): error TS2411: Property 'foo2' of type 'string' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(37,5): error TS2411: Property 'foo4' of type 'boolean' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(39,5): error TS2411: Property 'foo6' of type 'Date' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(40,5): error TS2411: Property 'foo7' of type 'RegExp' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(41,5): error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(42,5): error TS2411: Property 'foo9' of type 'I8' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(43,5): error TS2411: Property 'foo10' of type 'A' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(44,5): error TS2411: Property 'foo11' of type 'A2' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(45,5): error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(46,5): error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(47,5): error TS2411: Property 'foo14' of type 'typeof f' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(48,5): error TS2411: Property 'foo15' of type 'typeof c' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(49,5): error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(50,5): error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'number | E'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts(51,5): error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'number | E'. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOfUnion.ts (29 errors) ==== @@ -94,49 +94,49 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/subtypesOf foo: any; // ok foo2: string; // error ~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'string' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo2' of type 'string' is not assignable to string index type 'number | E'. foo3: number; // ok foo4: boolean; // error ~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo4' of type 'boolean' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo4' of type 'boolean' is not assignable to string index type 'number | E'. foo5: E; // ok foo6: Date; // error ~~~~~~~~~~~ -!!! error TS2411: Property 'foo6' of type 'Date' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo6' of type 'Date' is not assignable to string index type 'number | E'. foo7: RegExp; // error ~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo7' of type 'RegExp' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo7' of type 'RegExp' is not assignable to string index type 'number | E'. foo8: { bar: number }; // error ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo8' of type '{ bar: number; }' is not assignable to string index type 'number | E'. foo9: I8; // error ~~~~~~~~~ -!!! error TS2411: Property 'foo9' of type 'I8' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo9' of type 'I8' is not assignable to string index type 'number | E'. foo10: A; // error ~~~~~~~~~ -!!! error TS2411: Property 'foo10' of type 'A' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo10' of type 'A' is not assignable to string index type 'number | E'. foo11: A2; // error ~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo11' of type 'A2' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo11' of type 'A2' is not assignable to string index type 'number | E'. foo12: (x) => number; //error ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo12' of type '(x: any) => number' is not assignable to string index type 'number | E'. foo13: (x: T) => T; // error ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo13' of type '(x: T) => T' is not assignable to string index type 'number | E'. foo14: typeof f; // error ~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo14' of type 'typeof f' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo14' of type 'typeof f' is not assignable to string index type 'number | E'. foo15: typeof c; // error ~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo15' of type 'typeof c' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo15' of type 'typeof c' is not assignable to string index type 'number | E'. foo16: T; // error ~~~~~~~~~ -!!! error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo16' of type 'T' is not assignable to string index type 'number | E'. foo17: Object; // error ~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo17' of type 'Object' is not assignable to string index type 'number | E'. foo18: {}; // error ~~~~~~~~~~ -!!! error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'E | number'. +!!! error TS2411: Property 'foo18' of type '{}' is not assignable to string index type 'number | E'. } \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithCallSignatures2.types b/tests/baselines/reference/subtypingWithCallSignatures2.types index b72993e7bea1c..8a56e05a9c212 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures2.types +++ b/tests/baselines/reference/subtypingWithCallSignatures2.types @@ -371,8 +371,8 @@ var r2a = [r2arg1, r2arg2]; >r2arg2 : (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : ((x: number) => string[])[] ->[r2arg2, r2arg1] : ((x: number) => string[])[] +>r2b : ((x: T) => string[])[] +>[r2arg2, r2arg1] : ((x: T) => string[])[] >r2arg2 : (x: number) => string[] >r2arg1 : (x: T) => string[] @@ -402,8 +402,8 @@ var r3a = [r3arg1, r3arg2]; >r3arg2 : (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : ((x: number) => void)[] ->[r3arg2, r3arg1] : ((x: number) => void)[] +>r3b : ((x: T) => T)[] +>[r3arg2, r3arg1] : ((x: T) => T)[] >r3arg2 : (x: number) => void >r3arg1 : (x: T) => T @@ -814,8 +814,8 @@ var r12a = [r12arg1, r12arg2]; >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : ((x: Base[], y: Derived2[]) => Derived[])[] ->[r12arg2, r12arg1] : ((x: Base[], y: Derived2[]) => Derived[])[] +>r12b : ((x: Base[], y: T) => Derived[])[] +>[r12arg2, r12arg1] : ((x: Base[], y: T) => Derived[])[] >r12arg2 : (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : (x: Base[], y: T) => Derived[] diff --git a/tests/baselines/reference/subtypingWithCallSignatures3.types b/tests/baselines/reference/subtypingWithCallSignatures3.types index 2d4c6e9fda572..379810b2541f0 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures3.types +++ b/tests/baselines/reference/subtypingWithCallSignatures3.types @@ -349,8 +349,8 @@ module Errors { >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U var r3a = [r3arg2, r3arg]; ->r3a : (((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived) | ((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U))[] ->[r3arg2, r3arg] : (((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived) | ((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U))[] +>r3a : (((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] +>[r3arg2, r3arg] : (((x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] >r3arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >r3arg : (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U @@ -553,8 +553,8 @@ module Errors { >r7arg3 : (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : ((x: { a: T; b: T; }) => number)[] ->[r7arg3, r7arg2] : ((x: { a: T; b: T; }) => number)[] +>r7e : ((x: { a: string; b: number; }) => number)[] +>[r7arg3, r7arg2] : ((x: { a: string; b: number; }) => number)[] >r7arg3 : (x: { a: T; b: T; }) => number >r7arg2 : (x: { a: string; b: number; }) => number diff --git a/tests/baselines/reference/subtypingWithCallSignatures4.types b/tests/baselines/reference/subtypingWithCallSignatures4.types index f490f78787823..e76d36114e961 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures4.types +++ b/tests/baselines/reference/subtypingWithCallSignatures4.types @@ -323,8 +323,8 @@ var r3a = [r3arg, r3arg2]; >r3arg2 : (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : ((x: T) => void)[] ->[r3arg2, r3arg] : ((x: T) => void)[] +>r3b : ((x: T) => T)[] +>[r3arg2, r3arg] : ((x: T) => T)[] >r3arg2 : (x: T) => void >r3arg : (x: T) => T @@ -453,8 +453,8 @@ var r6a = [r6arg, r6arg2]; >r6arg2 : (x: (arg: T) => Derived) => T var r6b = [r6arg2, r6arg]; ->r6b : ((x: (arg: T) => Derived) => T)[] ->[r6arg2, r6arg] : ((x: (arg: T) => Derived) => T)[] +>r6b : ((x: (arg: T) => U) => T)[] +>[r6arg2, r6arg] : ((x: (arg: T) => U) => T)[] >r6arg2 : (x: (arg: T) => Derived) => T >r6arg : (x: (arg: T) => U) => T @@ -504,8 +504,8 @@ var r11a = [r11arg, r11arg2]; >r11arg2 : (x: { foo: T; }, y: { foo: T; bar: T; }) => Base var r11b = [r11arg2, r11arg]; ->r11b : ((x: { foo: T; }, y: { foo: T; bar: T; }) => Base)[] ->[r11arg2, r11arg] : ((x: { foo: T; }, y: { foo: T; bar: T; }) => Base)[] +>r11b : ((x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] +>[r11arg2, r11arg] : ((x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] >r11arg2 : (x: { foo: T; }, y: { foo: T; bar: T; }) => Base >r11arg : (x: { foo: T; }, y: { foo: U; bar: U; }) => Base @@ -549,8 +549,8 @@ var r15a = [r15arg, r15arg2]; >r15arg2 : (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : ((x: { a: T; b: T; }) => T[])[] ->[r15arg2, r15arg] : ((x: { a: T; b: T; }) => T[])[] +>r15b : ((x: { a: U; b: V; }) => U[])[] +>[r15arg2, r15arg] : ((x: { a: U; b: V; }) => U[])[] >r15arg2 : (x: { a: T; b: T; }) => T[] >r15arg : (x: { a: U; b: V; }) => U[] diff --git a/tests/baselines/reference/subtypingWithConstructSignatures2.types b/tests/baselines/reference/subtypingWithConstructSignatures2.types index c66d6055558ad..d723a367ecb3d 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures2.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures2.types @@ -360,8 +360,8 @@ var r2a = [r2arg1, r2arg2]; >r2arg2 : new (x: number) => string[] var r2b = [r2arg2, r2arg1]; ->r2b : (new (x: number) => string[])[] ->[r2arg2, r2arg1] : (new (x: number) => string[])[] +>r2b : (new (x: T) => string[])[] +>[r2arg2, r2arg1] : (new (x: T) => string[])[] >r2arg2 : new (x: number) => string[] >r2arg1 : new (x: T) => string[] @@ -389,8 +389,8 @@ var r3a = [r3arg1, r3arg2]; >r3arg2 : new (x: number) => void var r3b = [r3arg2, r3arg1]; ->r3b : (new (x: number) => void)[] ->[r3arg2, r3arg1] : (new (x: number) => void)[] +>r3b : (new (x: T) => T)[] +>[r3arg2, r3arg1] : (new (x: T) => T)[] >r3arg2 : new (x: number) => void >r3arg1 : new (x: T) => T @@ -636,8 +636,8 @@ var r9a = [r9arg1, r9arg2]; >r9arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived var r9b = [r9arg2, r9arg1]; ->r9b : ((new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived) | (new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U))[] ->[r9arg2, r9arg1] : ((new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived) | (new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U))[] +>r9b : ((new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U) | (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] +>[r9arg2, r9arg1] : ((new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U) | (new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] >r9arg2 : new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r9arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => new (r: T) => U @@ -747,8 +747,8 @@ var r12a = [r12arg1, r12arg2]; >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] var r12b = [r12arg2, r12arg1]; ->r12b : (new (x: Base[], y: Derived2[]) => Derived[])[] ->[r12arg2, r12arg1] : (new (x: Base[], y: Derived2[]) => Derived[])[] +>r12b : (new (x: Base[], y: T) => Derived[])[] +>[r12arg2, r12arg1] : (new (x: Base[], y: T) => Derived[])[] >r12arg2 : new (x: Base[], y: Derived2[]) => Derived[] >r12arg1 : new (x: Base[], y: T) => Derived[] diff --git a/tests/baselines/reference/subtypingWithConstructSignatures3.types b/tests/baselines/reference/subtypingWithConstructSignatures3.types index 741db4f4ba6aa..b0f0680c7a088 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures3.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures3.types @@ -318,8 +318,8 @@ module Errors { >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U var r3a = [r3arg2, r3arg1]; ->r3a : ((new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived) | (new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U))[] ->[r3arg2, r3arg1] : ((new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived) | (new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U))[] +>r3a : ((new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U) | (new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] +>[r3arg2, r3arg1] : ((new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U) | (new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived))[] >r3arg2 : new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived >r3arg1 : new (x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U @@ -497,8 +497,8 @@ module Errors { >r7arg3 : new (x: { a: T; b: T; }) => number var r7e = [r7arg3, r7arg2]; ->r7e : (new (x: { a: T; b: T; }) => number)[] ->[r7arg3, r7arg2] : (new (x: { a: T; b: T; }) => number)[] +>r7e : (new (x: { a: string; b: number; }) => number)[] +>[r7arg3, r7arg2] : (new (x: { a: string; b: number; }) => number)[] >r7arg3 : new (x: { a: T; b: T; }) => number >r7arg2 : new (x: { a: string; b: number; }) => number diff --git a/tests/baselines/reference/subtypingWithConstructSignatures4.types b/tests/baselines/reference/subtypingWithConstructSignatures4.types index 932adcb7368fa..21a40ecf7fcc1 100644 --- a/tests/baselines/reference/subtypingWithConstructSignatures4.types +++ b/tests/baselines/reference/subtypingWithConstructSignatures4.types @@ -307,8 +307,8 @@ var r3a = [r3arg, r3arg2]; >r3arg2 : new (x: T) => void var r3b = [r3arg2, r3arg]; ->r3b : (new (x: T) => void)[] ->[r3arg2, r3arg] : (new (x: T) => void)[] +>r3b : (new (x: T) => T)[] +>[r3arg2, r3arg] : (new (x: T) => T)[] >r3arg2 : new (x: T) => void >r3arg : new (x: T) => T @@ -421,8 +421,8 @@ var r6a = [r6arg, r6arg2]; >r6arg2 : new (x: new (arg: T) => Derived) => T var r6b = [r6arg2, r6arg]; ->r6b : (new (x: new (arg: T) => Derived) => T)[] ->[r6arg2, r6arg] : (new (x: new (arg: T) => Derived) => T)[] +>r6b : (new (x: new (arg: T) => U) => T)[] +>[r6arg2, r6arg] : (new (x: new (arg: T) => U) => T)[] >r6arg2 : new (x: new (arg: T) => Derived) => T >r6arg : new (x: new (arg: T) => U) => T @@ -466,8 +466,8 @@ var r11a = [r11arg, r11arg2]; >r11arg2 : new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base var r11b = [r11arg2, r11arg]; ->r11b : (new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base)[] ->[r11arg2, r11arg] : (new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base)[] +>r11b : (new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] +>[r11arg2, r11arg] : (new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base)[] >r11arg2 : new (x: { foo: T; }, y: { foo: T; bar: T; }) => Base >r11arg : new (x: { foo: T; }, y: { foo: U; bar: U; }) => Base @@ -505,8 +505,8 @@ var r15a = [r15arg, r15arg2]; >r15arg2 : new (x: { a: T; b: T; }) => T[] var r15b = [r15arg2, r15arg]; ->r15b : (new (x: { a: T; b: T; }) => T[])[] ->[r15arg2, r15arg] : (new (x: { a: T; b: T; }) => T[])[] +>r15b : (new (x: { a: U; b: V; }) => U[])[] +>[r15arg2, r15arg] : (new (x: { a: U; b: V; }) => U[])[] >r15arg2 : new (x: { a: T; b: T; }) => T[] >r15arg : new (x: { a: U; b: V; }) => U[] diff --git a/tests/baselines/reference/symbolType11.types b/tests/baselines/reference/symbolType11.types index b251db4330106..903c4ec0ecc2b 100644 --- a/tests/baselines/reference/symbolType11.types +++ b/tests/baselines/reference/symbolType11.types @@ -28,7 +28,7 @@ s || s; >s : symbol s || 1; ->s || 1 : symbol | number +>s || 1 : number | symbol >s : symbol >1 : number diff --git a/tests/baselines/reference/targetTypeTest2.types b/tests/baselines/reference/targetTypeTest2.types index 53381b9de43e8..25b36f948c6c0 100644 --- a/tests/baselines/reference/targetTypeTest2.types +++ b/tests/baselines/reference/targetTypeTest2.types @@ -4,7 +4,7 @@ var a : any[] = [1,2,"3"]; >a : any[] ->[1,2,"3"] : (number | string)[] +>[1,2,"3"] : (string | number)[] >1 : number >2 : number >"3" : string diff --git a/tests/baselines/reference/targetTypeTest3.errors.txt b/tests/baselines/reference/targetTypeTest3.errors.txt index 935a9b9e68eb5..f5dab732ed346 100644 --- a/tests/baselines/reference/targetTypeTest3.errors.txt +++ b/tests/baselines/reference/targetTypeTest3.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '(number | string)[]' is not assignable to type 'string[]'. - Type 'number | string' is not assignable to type 'string'. +tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '(string | number)[]' is not assignable to type 'string[]'. + Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. @@ -9,8 +9,8 @@ tests/cases/compiler/targetTypeTest3.ts(4,5): error TS2322: Type '(number | stri var a : string[] = [1,2,"3"]; // should produce an error ~ -!!! error TS2322: Type '(number | string)[]' is not assignable to type 'string[]'. -!!! error TS2322: Type 'number | string' is not assignable to type 'string'. +!!! error TS2322: Type '(string | number)[]' is not assignable to type 'string[]'. +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. diff --git a/tests/baselines/reference/templateStringInArray.types b/tests/baselines/reference/templateStringInArray.types index aec30c02e002a..04cc09a1005e7 100644 --- a/tests/baselines/reference/templateStringInArray.types +++ b/tests/baselines/reference/templateStringInArray.types @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/templates/templateStringInArray.ts === var x = [1, 2, `abc${ 123 }def`]; ->x : (number | string)[] ->[1, 2, `abc${ 123 }def`] : (number | string)[] +>x : (string | number)[] +>[1, 2, `abc${ 123 }def`] : (string | number)[] >1 : number >2 : number >`abc${ 123 }def` : string diff --git a/tests/baselines/reference/templateStringWithEmbeddedConditional.types b/tests/baselines/reference/templateStringWithEmbeddedConditional.types index 2a741dc271b10..7ec1ef97a3015 100644 --- a/tests/baselines/reference/templateStringWithEmbeddedConditional.types +++ b/tests/baselines/reference/templateStringWithEmbeddedConditional.types @@ -2,7 +2,7 @@ var x = `abc${ true ? false : " " }def`; >x : string >`abc${ true ? false : " " }def` : string ->true ? false : " " : boolean | string +>true ? false : " " : string | boolean >true : boolean >false : boolean >" " : string diff --git a/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.types b/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.types index d0a228ee6735f..5453880ce16d1 100644 --- a/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.types +++ b/tests/baselines/reference/templateStringWithEmbeddedConditionalES6.types @@ -2,7 +2,7 @@ var x = `abc${ true ? false : " " }def`; >x : string >`abc${ true ? false : " " }def` : string ->true ? false : " " : boolean | string +>true ? false : " " : string | boolean >true : boolean >false : boolean >" " : string diff --git a/tests/baselines/reference/thisTypeInTuples.types b/tests/baselines/reference/thisTypeInTuples.types index e0268840317b9..d2d70ad8e098f 100644 --- a/tests/baselines/reference/thisTypeInTuples.types +++ b/tests/baselines/reference/thisTypeInTuples.types @@ -16,24 +16,24 @@ let t: [number, string] = [42, "hello"]; let a = t.slice(); >a : [number, string] >t.slice() : [number, string] ->t.slice : { (start?: number, end?: number): (number | string)[]; (): [number, string]; } +>t.slice : { (start?: number, end?: number): (string | number)[]; (): [number, string]; } >t : [number, string] ->slice : { (start?: number, end?: number): (number | string)[]; (): [number, string]; } +>slice : { (start?: number, end?: number): (string | number)[]; (): [number, string]; } let b = t.slice(1); ->b : (number | string)[] ->t.slice(1) : (number | string)[] ->t.slice : { (start?: number, end?: number): (number | string)[]; (): [number, string]; } +>b : (string | number)[] +>t.slice(1) : (string | number)[] +>t.slice : { (start?: number, end?: number): (string | number)[]; (): [number, string]; } >t : [number, string] ->slice : { (start?: number, end?: number): (number | string)[]; (): [number, string]; } +>slice : { (start?: number, end?: number): (string | number)[]; (): [number, string]; } >1 : number let c = t.slice(0, 1); ->c : (number | string)[] ->t.slice(0, 1) : (number | string)[] ->t.slice : { (start?: number, end?: number): (number | string)[]; (): [number, string]; } +>c : (string | number)[] +>t.slice(0, 1) : (string | number)[] +>t.slice : { (start?: number, end?: number): (string | number)[]; (): [number, string]; } >t : [number, string] ->slice : { (start?: number, end?: number): (number | string)[]; (): [number, string]; } +>slice : { (start?: number, end?: number): (string | number)[]; (): [number, string]; } >0 : number >1 : number diff --git a/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt b/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt index 498e74ce35022..b502eaad7e58d 100644 --- a/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt +++ b/tests/baselines/reference/trailingCommaInHeterogenousArrayLiteral1.errors.txt @@ -1,8 +1,8 @@ -tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(5,19): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. - Type 'number | string' is not assignable to type 'number'. +tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(5,19): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. - Type 'number | string' is not assignable to type 'number'. +tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. @@ -13,13 +13,13 @@ tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS // these two should give the same error this.test([1, 2, "hi", 5, ]); ~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type 'number | string' is not assignable to type 'number'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number'. !!! error TS2345: Type 'string' is not assignable to type 'number'. this.test([1, 2, "hi", 5]); ~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(number | string)[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type 'number | string' is not assignable to type 'number'. +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number'. !!! error TS2345: Type 'string' is not assignable to type 'number'. } } diff --git a/tests/baselines/reference/tupleTypes.errors.txt b/tests/baselines/reference/tupleTypes.errors.txt index 8f418f9815761..75f413eb170f4 100644 --- a/tests/baselines/reference/tupleTypes.errors.txt +++ b/tests/baselines/reference/tupleTypes.errors.txt @@ -9,8 +9,8 @@ tests/cases/compiler/tupleTypes.ts(17,1): error TS2322: Type '[string, number]' tests/cases/compiler/tupleTypes.ts(41,1): error TS2322: Type 'undefined[]' is not assignable to type '[number, string]'. tests/cases/compiler/tupleTypes.ts(47,1): error TS2322: Type '[number, string]' is not assignable to type 'number[]'. Types of property 'pop' are incompatible. - Type '() => number | string' is not assignable to type '() => number'. - Type 'number | string' is not assignable to type 'number'. + Type '() => string | number' is not assignable to type '() => number'. + Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/compiler/tupleTypes.ts(49,1): error TS2322: Type '[number, {}]' is not assignable to type 'number[]'. Types of property 'pop' are incompatible. @@ -90,8 +90,8 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n ~ !!! error TS2322: Type '[number, string]' is not assignable to type 'number[]'. !!! error TS2322: Types of property 'pop' are incompatible. -!!! error TS2322: Type '() => number | string' is not assignable to type '() => number'. -!!! error TS2322: Type 'number | string' is not assignable to type 'number'. +!!! error TS2322: Type '() => string | number' is not assignable to type '() => number'. +!!! error TS2322: Type 'string | number' is not assignable to type 'number'. !!! error TS2322: Type 'string' is not assignable to type 'number'. a = a2; a = a3; // Error diff --git a/tests/baselines/reference/typeAliasDoesntMakeModuleInstantiated.types b/tests/baselines/reference/typeAliasDoesntMakeModuleInstantiated.types index eb0fcdcbbcae6..45ddf8cd949a4 100644 --- a/tests/baselines/reference/typeAliasDoesntMakeModuleInstantiated.types +++ b/tests/baselines/reference/typeAliasDoesntMakeModuleInstantiated.types @@ -4,7 +4,7 @@ declare module m { // type alias declaration here shouldnt make the module declaration instantiated type Selector = string| string[] |Function; ->Selector : string | string[] | Function +>Selector : string | Function | string[] >Function : Function export interface IStatic { diff --git a/tests/baselines/reference/typeAssertions.errors.txt b/tests/baselines/reference/typeAssertions.errors.txt index e330c23d737c3..c840e01608319 100644 --- a/tests/baselines/reference/typeAssertions.errors.txt +++ b/tests/baselines/reference/typeAssertions.errors.txt @@ -13,7 +13,7 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,14): err tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,17): error TS1005: ')' expected. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,17): error TS2304: Cannot find name 'string'. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,48): error TS1005: ';' expected. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(45,2): error TS2322: Type 'number | string' is not assignable to type 'string'. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(45,2): error TS2322: Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,32): error TS2304: Cannot find name 'numOrStr'. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,41): error TS1005: ')' expected. @@ -96,7 +96,7 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,50): err !!! error TS1005: ';' expected. str = numOrStr; // Error, no narrowing occurred ~~~ -!!! error TS2322: Type 'number | string' is not assignable to type 'string'. +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. } diff --git a/tests/baselines/reference/typeGuardEnums.types b/tests/baselines/reference/typeGuardEnums.types index f106896c52fe7..f9d5cb1754e8a 100644 --- a/tests/baselines/reference/typeGuardEnums.types +++ b/tests/baselines/reference/typeGuardEnums.types @@ -6,14 +6,14 @@ enum V {} >V : V let x: number|string|E|V; ->x : number | string | E | V +>x : string | number | E | V >E : E >V : V if (typeof x === "number") { >typeof x === "number" : boolean >typeof x : string ->x : number | string | E | V +>x : string | number | E | V >"number" : "number" x; // number|E|V @@ -27,7 +27,7 @@ else { if (typeof x !== "number") { >typeof x !== "number" : boolean >typeof x : string ->x : number | E | V | string +>x : string | number | E | V >"number" : "number" x; // string diff --git a/tests/baselines/reference/typeGuardFunction.types b/tests/baselines/reference/typeGuardFunction.types index 7f60bbc0a3bd6..1e2be413a2b4d 100644 --- a/tests/baselines/reference/typeGuardFunction.types +++ b/tests/baselines/reference/typeGuardFunction.types @@ -216,7 +216,7 @@ acceptingTypeGuardFunction(isA); // Binary expressions let union2: C | B; ->union2 : C | B +>union2 : B | C >C : C >B : B @@ -226,6 +226,6 @@ let union3: boolean | B = isA(union2) || union2; >isA(union2) || union2 : true | B >isA(union2) : boolean >isA : (p1: any) => p1 is A ->union2 : C | B +>union2 : B | C >union2 : B diff --git a/tests/baselines/reference/typeGuardNesting.types b/tests/baselines/reference/typeGuardNesting.types index 0532e4d253697..6c2df126df122 100644 --- a/tests/baselines/reference/typeGuardNesting.types +++ b/tests/baselines/reference/typeGuardNesting.types @@ -23,7 +23,7 @@ if ((typeof strOrBool === 'boolean' && !strOrBool) || typeof strOrBool === 'stri >(typeof strOrBool === 'string') : boolean >typeof strOrBool === 'string' : boolean >typeof strOrBool : string ->strOrBool : boolean | string +>strOrBool : string | boolean >'string' : "string" >strOrBool : string >"string" : string @@ -45,7 +45,7 @@ if ((typeof strOrBool === 'boolean' && !strOrBool) || typeof strOrBool === 'stri >(typeof strOrBool !== 'boolean') : boolean >typeof strOrBool !== 'boolean' : boolean >typeof strOrBool : string ->strOrBool : boolean | string +>strOrBool : string | boolean >'boolean' : "boolean" >strOrBool : string >"string" : string @@ -68,7 +68,7 @@ if ((typeof strOrBool !== 'string' && !strOrBool) || typeof strOrBool !== 'boole >typeof strOrBool !== 'string' && !strOrBool : boolean >typeof strOrBool !== 'string' : boolean >typeof strOrBool : string ->strOrBool : boolean | string +>strOrBool : string | boolean >'string' : "string" >!strOrBool : boolean >strOrBool : boolean @@ -83,7 +83,7 @@ if ((typeof strOrBool !== 'string' && !strOrBool) || typeof strOrBool !== 'boole >(typeof strOrBool === 'string') : boolean >typeof strOrBool === 'string' : boolean >typeof strOrBool : string ->strOrBool : boolean | string +>strOrBool : string | boolean >'string' : "string" >strOrBool : string >"string" : string @@ -105,7 +105,7 @@ if ((typeof strOrBool !== 'string' && !strOrBool) || typeof strOrBool !== 'boole >(typeof strOrBool !== 'boolean') : boolean >typeof strOrBool !== 'boolean' : boolean >typeof strOrBool : string ->strOrBool : boolean | string +>strOrBool : string | boolean >'boolean' : "boolean" >strOrBool : string >"string" : string diff --git a/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types b/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types index 0b1661820d5f1..b24b63f61dc44 100644 --- a/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types +++ b/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types @@ -26,7 +26,7 @@ var c: C; >C : C var cOrBool: C| boolean; ->cOrBool : C | boolean +>cOrBool : boolean | C >C : C var strOrNumOrBoolOrC: string | number | boolean | C; @@ -95,11 +95,11 @@ if (typeof strOrNumOrBoolOrC !== "string" && typeof strOrNumOrBoolOrC !== "numbe >typeof strOrNumOrBoolOrC !== "string" && typeof strOrNumOrBoolOrC !== "number" : boolean >typeof strOrNumOrBoolOrC !== "string" : boolean >typeof strOrNumOrBoolOrC : string ->strOrNumOrBoolOrC : C | string | number | boolean +>strOrNumOrBoolOrC : string | number | boolean | C >"string" : "string" >typeof strOrNumOrBoolOrC !== "number" : boolean >typeof strOrNumOrBoolOrC : string ->strOrNumOrBoolOrC : C | number | boolean +>strOrNumOrBoolOrC : number | boolean | C >"number" : "number" >typeof strOrNumOrBool === "boolean" : boolean >typeof strOrNumOrBool : string @@ -107,9 +107,9 @@ if (typeof strOrNumOrBoolOrC !== "string" && typeof strOrNumOrBoolOrC !== "numbe >"boolean" : "boolean" cOrBool = strOrNumOrBoolOrC; // C | boolean ->cOrBool = strOrNumOrBoolOrC : C | boolean ->cOrBool : C | boolean ->strOrNumOrBoolOrC : C | boolean +>cOrBool = strOrNumOrBoolOrC : boolean | C +>cOrBool : boolean | C +>strOrNumOrBoolOrC : boolean | C bool = strOrNumOrBool; // boolean >bool = strOrNumOrBool : boolean @@ -120,7 +120,7 @@ else { var r1: string | number | boolean | C = strOrNumOrBoolOrC; // string | number | boolean | C >r1 : string | number | boolean | C >C : C ->strOrNumOrBoolOrC : string | number | C | boolean +>strOrNumOrBoolOrC : string | number | boolean | C var r2: string | number | boolean = strOrNumOrBool; >r2 : string | number | boolean diff --git a/tests/baselines/reference/typeGuardOfFormExpr1OrExpr2.types b/tests/baselines/reference/typeGuardOfFormExpr1OrExpr2.types index b576630c1cf16..eb428bcb6795d 100644 --- a/tests/baselines/reference/typeGuardOfFormExpr1OrExpr2.types +++ b/tests/baselines/reference/typeGuardOfFormExpr1OrExpr2.types @@ -26,7 +26,7 @@ var c: C; >C : C var cOrBool: C| boolean; ->cOrBool : C | boolean +>cOrBool : boolean | C >C : C var strOrNumOrBoolOrC: string | number | boolean | C; @@ -118,7 +118,7 @@ if (typeof strOrNumOrBoolOrC === "string" || typeof strOrNumOrBoolOrC === "numbe else { cOrBool = strOrNumOrBoolOrC; // C | boolean >cOrBool = strOrNumOrBoolOrC : boolean | C ->cOrBool : C | boolean +>cOrBool : boolean | C >strOrNumOrBoolOrC : boolean | C bool = strOrNumOrBool; // boolean diff --git a/tests/baselines/reference/typeGuardOfFormInstanceOf.types b/tests/baselines/reference/typeGuardOfFormInstanceOf.types index 98f627866a86a..8fec2d488f641 100644 --- a/tests/baselines/reference/typeGuardOfFormInstanceOf.types +++ b/tests/baselines/reference/typeGuardOfFormInstanceOf.types @@ -60,7 +60,7 @@ num = ctor1 instanceof C2 && ctor1.p2; // C2 >num : number >ctor1 instanceof C2 && ctor1.p2 : number >ctor1 instanceof C2 : boolean ->ctor1 : C2 | C1 +>ctor1 : C1 | C2 >C2 : typeof C2 >ctor1.p2 : number >ctor1 : C2 @@ -109,7 +109,7 @@ num = ctor2 instanceof D1 && ctor2.p3; // D1 >num : number >ctor2 instanceof D1 && ctor2.p3 : number >ctor2 instanceof D1 : boolean ->ctor2 : D1 | C2 +>ctor2 : C2 | D1 >D1 : typeof D1 >ctor2.p3 : number >ctor2 : D1 @@ -127,7 +127,7 @@ str = ctor2 instanceof D1 && ctor2.p1; // D1 >p1 : string var r2: D1 | C2 = ctor2 instanceof C1 && ctor2; // C2 | D1 ->r2 : D1 | C2 +>r2 : C2 | D1 >D1 : D1 >C2 : C2 >ctor2 instanceof C1 && ctor2 : D1 @@ -192,14 +192,14 @@ else { } var ctor5: C1 | D1 | C2; ->ctor5 : C1 | D1 | C2 +>ctor5 : C1 | C2 | D1 >C1 : C1 >D1 : D1 >C2 : C2 if (ctor5 instanceof C1) { >ctor5 instanceof C1 : boolean ->ctor5 : C1 | D1 | C2 +>ctor5 : C1 | C2 | D1 >C1 : typeof C1 ctor5.p1; // C1 diff --git a/tests/baselines/reference/typeGuardOfFormInstanceOfOnInterface.types b/tests/baselines/reference/typeGuardOfFormInstanceOfOnInterface.types index a5387e66d4401..fe23d6d303e6f 100644 --- a/tests/baselines/reference/typeGuardOfFormInstanceOfOnInterface.types +++ b/tests/baselines/reference/typeGuardOfFormInstanceOfOnInterface.types @@ -84,7 +84,7 @@ num = c1Orc2 instanceof c2 && c1Orc2.p2; // C2 >num : number >c1Orc2 instanceof c2 && c1Orc2.p2 : number >c1Orc2 instanceof c2 : boolean ->c1Orc2 : C2 | C1 +>c1Orc2 : C1 | C2 >c2 : C2 >c1Orc2.p2 : number >c1Orc2 : C2 @@ -133,7 +133,7 @@ num = c2Ord1 instanceof d1 && c2Ord1.p3; // D1 >num : number >c2Ord1 instanceof d1 && c2Ord1.p3 : number >c2Ord1 instanceof d1 : boolean ->c2Ord1 : D1 | C2 +>c2Ord1 : C2 | D1 >d1 : D1 >c2Ord1.p3 : number >c2Ord1 : D1 @@ -151,7 +151,7 @@ str = c2Ord1 instanceof d1 && c2Ord1.p1; // D1 >p1 : string var r2: D1 | C2 = c2Ord1 instanceof c1 && c2Ord1; // C2 | D1 ->r2 : D1 | C2 +>r2 : C2 | D1 >D1 : D1 >C2 : C2 >c2Ord1 instanceof c1 && c2Ord1 : D1 diff --git a/tests/baselines/reference/typeGuardOfFormIsType.types b/tests/baselines/reference/typeGuardOfFormIsType.types index 23ce38732cdbf..e2059be7b637e 100644 --- a/tests/baselines/reference/typeGuardOfFormIsType.types +++ b/tests/baselines/reference/typeGuardOfFormIsType.types @@ -80,7 +80,7 @@ num = isC2(c1Orc2) && c1Orc2.p2; // C2 >isC2(c1Orc2) && c1Orc2.p2 : number >isC2(c1Orc2) : boolean >isC2 : (x: any) => x is C2 ->c1Orc2 : C2 | C1 +>c1Orc2 : C1 | C2 >c1Orc2.p2 : number >c1Orc2 : C2 >p2 : number @@ -129,7 +129,7 @@ num = isD1(c2Ord1) && c2Ord1.p3; // D1 >isD1(c2Ord1) && c2Ord1.p3 : number >isD1(c2Ord1) : boolean >isD1 : (x: any) => x is D1 ->c2Ord1 : D1 | C2 +>c2Ord1 : C2 | D1 >c2Ord1.p3 : number >c2Ord1 : D1 >p3 : number diff --git a/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.types b/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.types index 728d3dc0e38fb..ea169e954138c 100644 --- a/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.types +++ b/tests/baselines/reference/typeGuardOfFormIsTypeOnInterfaces.types @@ -111,7 +111,7 @@ num = isC2(c1Orc2) && c1Orc2.p2; // C2 >isC2(c1Orc2) && c1Orc2.p2 : number >isC2(c1Orc2) : boolean >isC2 : (x: any) => x is C2 ->c1Orc2 : C2 | C1 +>c1Orc2 : C1 | C2 >c1Orc2.p2 : number >c1Orc2 : C2 >p2 : number @@ -160,7 +160,7 @@ num = isD1(c2Ord1) && c2Ord1.p3; // D1 >isD1(c2Ord1) && c2Ord1.p3 : number >isD1(c2Ord1) : boolean >isD1 : (x: any) => x is D1 ->c2Ord1 : D1 | C2 +>c2Ord1 : C2 | D1 >c2Ord1.p3 : number >c2Ord1 : D1 >p3 : number diff --git a/tests/baselines/reference/typeGuardOfFormNotExpr.types b/tests/baselines/reference/typeGuardOfFormNotExpr.types index 6989fa663c841..e4490d42dae3c 100644 --- a/tests/baselines/reference/typeGuardOfFormNotExpr.types +++ b/tests/baselines/reference/typeGuardOfFormNotExpr.types @@ -73,13 +73,13 @@ if (!(typeof strOrNumOrBool !== "string") || !(typeof strOrNumOrBool !== "number >(typeof strOrNumOrBool !== "string") : boolean >typeof strOrNumOrBool !== "string" : boolean >typeof strOrNumOrBool : string ->strOrNumOrBool : boolean | string | number +>strOrNumOrBool : string | number | boolean >"string" : "string" >!(typeof strOrNumOrBool !== "number") : boolean >(typeof strOrNumOrBool !== "number") : boolean >typeof strOrNumOrBool !== "number" : boolean >typeof strOrNumOrBool : string ->strOrNumOrBool : boolean | number +>strOrNumOrBool : number | boolean >"number" : "number" strOrNum = strOrNumOrBool; // string | number @@ -152,19 +152,19 @@ if (!(typeof strOrNumOrBool === "string") && numOrBool !== strOrNumOrBool) { >(typeof strOrNumOrBool === "string") : boolean >typeof strOrNumOrBool === "string" : boolean >typeof strOrNumOrBool : string ->strOrNumOrBool : boolean | string | number +>strOrNumOrBool : string | number | boolean >"string" : "string" >numOrBool !== strOrNumOrBool : boolean >numOrBool : number | boolean ->strOrNumOrBool : boolean | number +>strOrNumOrBool : number | boolean numOrBool = strOrNumOrBool; // number | boolean ->numOrBool = strOrNumOrBool : boolean | number +>numOrBool = strOrNumOrBool : number | boolean >numOrBool : number | boolean ->strOrNumOrBool : boolean | number +>strOrNumOrBool : number | boolean } else { var r1: string | number | boolean = strOrNumOrBool; // string | number | boolean >r1 : string | number | boolean ->strOrNumOrBool : string | boolean | number +>strOrNumOrBool : string | number | boolean } diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types b/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types index 9166b00386ac3..c06c16e331dea 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types @@ -136,7 +136,7 @@ else { if (typeof strOrBool !== "boolean") { >typeof strOrBool !== "boolean" : boolean >typeof strOrBool : string ->strOrBool : boolean | string +>strOrBool : string | boolean >"boolean" : "boolean" str = strOrBool; // string @@ -153,7 +153,7 @@ else { if (typeof numOrBool !== "boolean") { >typeof numOrBool !== "boolean" : boolean >typeof numOrBool : string ->numOrBool : boolean | number +>numOrBool : number | boolean >"boolean" : "boolean" num = numOrBool; // number @@ -170,7 +170,7 @@ else { if (typeof strOrNumOrBool !== "boolean") { >typeof strOrNumOrBool !== "boolean" : boolean >typeof strOrNumOrBool : string ->strOrNumOrBool : boolean | string | number +>strOrNumOrBool : string | number | boolean >"boolean" : "boolean" strOrNum = strOrNumOrBool; // string | number diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types b/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types index 736cd14e88e8e..17787d06486ca 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types @@ -134,7 +134,7 @@ else { if (typeof strOrNum !== "number") { >typeof strOrNum !== "number" : boolean >typeof strOrNum : string ->strOrNum : number | string +>strOrNum : string | number >"number" : "number" str === strOrNum; // string @@ -167,7 +167,7 @@ else { if (typeof strOrNumOrBool !== "number") { >typeof strOrNumOrBool !== "number" : boolean >typeof strOrNumOrBool : string ->strOrNumOrBool : number | string | boolean +>strOrNumOrBool : string | number | boolean >"number" : "number" strOrBool = strOrNumOrBool; // string | boolean diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfOther.types b/tests/baselines/reference/typeGuardOfFormTypeOfOther.types index 3dfb720d88016..b87f6a2a004b3 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfOther.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfOther.types @@ -119,7 +119,7 @@ else { if (typeof strOrC !== "Object") { >typeof strOrC !== "Object" : boolean >typeof strOrC : string ->strOrC : C | string +>strOrC : string | C >"Object" : "Object" var r2: string = strOrC; // string @@ -135,7 +135,7 @@ else { if (typeof numOrC !== "Object") { >typeof numOrC !== "Object" : boolean >typeof numOrC : string ->numOrC : C | number +>numOrC : number | C >"Object" : "Object" var r3: number = numOrC; // number @@ -151,7 +151,7 @@ else { if (typeof boolOrC !== "Object") { >typeof boolOrC !== "Object" : boolean >typeof boolOrC : string ->boolOrC : C | boolean +>boolOrC : boolean | C >"Object" : "Object" var r4: boolean = boolOrC; // boolean diff --git a/tests/baselines/reference/typeGuardRedundancy.types b/tests/baselines/reference/typeGuardRedundancy.types index e028b4d11eb37..80de5f54acea7 100644 --- a/tests/baselines/reference/typeGuardRedundancy.types +++ b/tests/baselines/reference/typeGuardRedundancy.types @@ -22,8 +22,8 @@ var r1 = typeof x === "string" && typeof x === "string" ? x.substr : x.toFixed; >toFixed : (fractionDigits?: number) => string var r2 = !(typeof x === "string" && typeof x === "string") ? x.toFixed : x.substr; ->r2 : (fractionDigits?: number) => string ->!(typeof x === "string" && typeof x === "string") ? x.toFixed : x.substr : (fractionDigits?: number) => string +>r2 : (from: number, length?: number) => string +>!(typeof x === "string" && typeof x === "string") ? x.toFixed : x.substr : (from: number, length?: number) => string >!(typeof x === "string" && typeof x === "string") : boolean >(typeof x === "string" && typeof x === "string") : boolean >typeof x === "string" && typeof x === "string" : boolean @@ -48,7 +48,7 @@ var r3 = typeof x === "string" || typeof x === "string" ? x.substr : x.toFixed; >typeof x === "string" || typeof x === "string" : boolean >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" >typeof x === "string" : boolean >typeof x : string @@ -62,8 +62,8 @@ var r3 = typeof x === "string" || typeof x === "string" ? x.substr : x.toFixed; >toFixed : (fractionDigits?: number) => string var r4 = !(typeof x === "string" || typeof x === "string") ? x.toFixed : x.substr; ->r4 : (fractionDigits?: number) => string ->!(typeof x === "string" || typeof x === "string") ? x.toFixed : x.substr : (fractionDigits?: number) => string +>r4 : (from: number, length?: number) => string +>!(typeof x === "string" || typeof x === "string") ? x.toFixed : x.substr : (from: number, length?: number) => string >!(typeof x === "string" || typeof x === "string") : boolean >(typeof x === "string" || typeof x === "string") : boolean >typeof x === "string" || typeof x === "string" : boolean diff --git a/tests/baselines/reference/typeGuardTypeOfUndefined.types b/tests/baselines/reference/typeGuardTypeOfUndefined.types index d20eca99ca17a..8e9928896a19d 100644 --- a/tests/baselines/reference/typeGuardTypeOfUndefined.types +++ b/tests/baselines/reference/typeGuardTypeOfUndefined.types @@ -217,19 +217,19 @@ function test8(a: boolean | void) { } function test9(a: boolean | number) { ->test9 : (a: boolean | number) => void ->a : boolean | number +>test9 : (a: number | boolean) => void +>a : number | boolean if (typeof a !== "undefined") { >typeof a !== "undefined" : boolean >typeof a : string ->a : boolean | number +>a : number | boolean >"undefined" : "undefined" if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string ->a : boolean | number +>a : number | boolean >"boolean" : "boolean" a; @@ -242,24 +242,24 @@ function test9(a: boolean | number) { } else { a; ->a : boolean | number +>a : number | boolean } } function test10(a: boolean | number) { ->test10 : (a: boolean | number) => void ->a : boolean | number +>test10 : (a: number | boolean) => void +>a : number | boolean if (typeof a === "undefined") { >typeof a === "undefined" : boolean >typeof a : string ->a : boolean | number +>a : number | boolean >"undefined" : "undefined" if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string ->a : boolean | number +>a : number | boolean >"boolean" : "boolean" a; @@ -272,27 +272,27 @@ function test10(a: boolean | number) { } else { a; ->a : boolean | number +>a : number | boolean } } function test11(a: boolean | number) { ->test11 : (a: boolean | number) => void ->a : boolean | number +>test11 : (a: number | boolean) => void +>a : number | boolean if (typeof a === "undefined" || typeof a === "boolean") { >typeof a === "undefined" || typeof a === "boolean" : boolean >typeof a === "undefined" : boolean >typeof a : string ->a : boolean | number +>a : number | boolean >"undefined" : "undefined" >typeof a === "boolean" : boolean >typeof a : string ->a : boolean | number +>a : number | boolean >"boolean" : "boolean" a; ->a : boolean | number +>a : number | boolean } else { a; @@ -301,18 +301,18 @@ function test11(a: boolean | number) { } function test12(a: boolean | number) { ->test12 : (a: boolean | number) => void ->a : boolean | number +>test12 : (a: number | boolean) => void +>a : number | boolean if (typeof a !== "undefined" && typeof a === "boolean") { >typeof a !== "undefined" && typeof a === "boolean" : boolean >typeof a !== "undefined" : boolean >typeof a : string ->a : boolean | number +>a : number | boolean >"undefined" : "undefined" >typeof a === "boolean" : boolean >typeof a : string ->a : boolean | number +>a : number | boolean >"boolean" : "boolean" a; @@ -320,24 +320,24 @@ function test12(a: boolean | number) { } else { a; ->a : boolean | number +>a : number | boolean } } function test13(a: boolean | number | void) { ->test13 : (a: boolean | number | void) => void ->a : boolean | number | void +>test13 : (a: number | boolean | void) => void +>a : number | boolean | void if (typeof a !== "undefined") { >typeof a !== "undefined" : boolean >typeof a : string ->a : boolean | number | void +>a : number | boolean | void >"undefined" : "undefined" if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string ->a : boolean | number +>a : number | boolean >"boolean" : "boolean" a; @@ -350,24 +350,24 @@ function test13(a: boolean | number | void) { } else { a; ->a : boolean | number | void +>a : number | boolean | void } } function test14(a: boolean | number | void) { ->test14 : (a: boolean | number | void) => void ->a : boolean | number | void +>test14 : (a: number | boolean | void) => void +>a : number | boolean | void if (typeof a === "undefined") { >typeof a === "undefined" : boolean >typeof a : string ->a : boolean | number | void +>a : number | boolean | void >"undefined" : "undefined" if (typeof a === "boolean") { >typeof a === "boolean" : boolean >typeof a : string ->a : boolean | number | void +>a : number | boolean | void >"boolean" : "boolean" a; @@ -380,27 +380,27 @@ function test14(a: boolean | number | void) { } else { a; ->a : boolean | number +>a : number | boolean } } function test15(a: boolean | number | void) { ->test15 : (a: boolean | number | void) => void ->a : boolean | number | void +>test15 : (a: number | boolean | void) => void +>a : number | boolean | void if (typeof a === "undefined" || typeof a === "boolean") { >typeof a === "undefined" || typeof a === "boolean" : boolean >typeof a === "undefined" : boolean >typeof a : string ->a : boolean | number | void +>a : number | boolean | void >"undefined" : "undefined" >typeof a === "boolean" : boolean >typeof a : string ->a : boolean | number +>a : number | boolean >"boolean" : "boolean" a; ->a : boolean | number | void +>a : number | boolean | void } else { a; @@ -409,18 +409,18 @@ function test15(a: boolean | number | void) { } function test16(a: boolean | number | void) { ->test16 : (a: boolean | number | void) => void ->a : boolean | number | void +>test16 : (a: number | boolean | void) => void +>a : number | boolean | void if (typeof a !== "undefined" && typeof a === "boolean") { >typeof a !== "undefined" && typeof a === "boolean" : boolean >typeof a !== "undefined" : boolean >typeof a : string ->a : boolean | number | void +>a : number | boolean | void >"undefined" : "undefined" >typeof a === "boolean" : boolean >typeof a : string ->a : boolean | number +>a : number | boolean >"boolean" : "boolean" a; @@ -428,7 +428,7 @@ function test16(a: boolean | number | void) { } else { a; ->a : boolean | number | void +>a : number | boolean | void } } diff --git a/tests/baselines/reference/typeGuardsAsAssertions.types b/tests/baselines/reference/typeGuardsAsAssertions.types index 3ea84efa1c932..f24929a534869 100644 --- a/tests/baselines/reference/typeGuardsAsAssertions.types +++ b/tests/baselines/reference/typeGuardsAsAssertions.types @@ -30,9 +30,9 @@ export const none : None = { none: '' }; >'' : string export function isSome(value: Optional): value is Some { ->isSome : (value: Some | None) => value is Some +>isSome : (value: None | Some) => value is Some >a : a ->value : Some | None +>value : None | Some >Optional : Some | None >a : a >value : any @@ -42,7 +42,7 @@ export function isSome(value: Optional): value is Some { return 'some' in value; >'some' in value : boolean >'some' : string ->value : Some | None +>value : None | Some } function someFrom(some: a) { @@ -63,7 +63,7 @@ export function fn(makeSome: () => r): void { >r : r let result: Optional = none; ->result : Some | None +>result : None | Some >Optional : Some | None >r : r >none : None @@ -79,12 +79,12 @@ export function fn(makeSome: () => r): void { result = someFrom(isSome(result) ? result.some : makeSome()); >result = someFrom(isSome(result) ? result.some : makeSome()) : { some: r; } ->result : Some | None +>result : None | Some >someFrom(isSome(result) ? result.some : makeSome()) : { some: r; } >someFrom : (some: a) => { some: a; } >isSome(result) ? result.some : makeSome() : r >isSome(result) : boolean ->isSome : (value: Some | None) => value is Some +>isSome : (value: None | Some) => value is Some >result : None | Some >result.some : r >result : Some @@ -111,7 +111,7 @@ function foo1() { >cond : boolean x; // number, then string | number ->x : number | string +>x : string | number x = typeof x === "string" ? x.slice() : "abc"; >x = typeof x === "string" ? x.slice() : "abc" : string @@ -119,7 +119,7 @@ function foo1() { >typeof x === "string" ? x.slice() : "abc" : string >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" >x.slice() : string >x.slice : (start?: number | undefined, end?: number | undefined) => string @@ -131,7 +131,7 @@ function foo1() { >x : string } x; ->x : number | string +>x : string | number } function foo2() { @@ -148,12 +148,12 @@ function foo2() { >cond : boolean x; // number, then string | number ->x : number | string +>x : string | number if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" x = x.slice(); @@ -174,7 +174,7 @@ function foo2() { >x : string } x; ->x : number | string +>x : string | number } // Type guards as assertions @@ -285,10 +285,10 @@ function f5(x: string | number) { } else { x; // string | number ->x : number | string +>x : string | number } x; // string | number ->x : number | string +>x : string | number } function f6() { diff --git a/tests/baselines/reference/typeGuardsInConditionalExpression.types b/tests/baselines/reference/typeGuardsInConditionalExpression.types index 3224dc48b5b3b..8d5da1329e643 100644 --- a/tests/baselines/reference/typeGuardsInConditionalExpression.types +++ b/tests/baselines/reference/typeGuardsInConditionalExpression.types @@ -7,14 +7,14 @@ // provided the false expression contains no assignments to the variable or parameter. function foo(x: number | string) { ->foo : (x: number | string) => number ->x : number | string +>foo : (x: string | number) => number +>x : string | number return typeof x === "string" >typeof x === "string" ? x.length // string : x++ : number >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" ? x.length // string @@ -27,14 +27,14 @@ function foo(x: number | string) { >x : number } function foo2(x: number | string) { ->foo2 : (x: number | string) => string | number ->x : number | string +>foo2 : (x: string | number) => string | number +>x : string | number return typeof x === "string" >typeof x === "string" ? ((x = "hello") && x) // string : x : string | number >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" ? ((x = "hello") && x) // string @@ -42,7 +42,7 @@ function foo2(x: number | string) { >(x = "hello") && x : string >(x = "hello") : string >x = "hello" : string ->x : number | string +>x : string | number >"hello" : string >x : string @@ -50,14 +50,14 @@ function foo2(x: number | string) { >x : number } function foo3(x: number | string) { ->foo3 : (x: number | string) => number ->x : number | string +>foo3 : (x: string | number) => number +>x : string | number return typeof x === "string" >typeof x === "string" ? ((x = 10) && x) // number : x : number >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" ? ((x = 10) && x) // number @@ -65,7 +65,7 @@ function foo3(x: number | string) { >(x = 10) && x : number >(x = 10) : number >x = 10 : number ->x : number | string +>x : string | number >10 : number >x : number @@ -73,14 +73,14 @@ function foo3(x: number | string) { >x : number } function foo4(x: number | string) { ->foo4 : (x: number | string) => string | number ->x : number | string +>foo4 : (x: string | number) => string | number +>x : string | number return typeof x === "string" >typeof x === "string" ? x // string : ((x = 10) && x) : string | number >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" ? x // string @@ -91,19 +91,19 @@ function foo4(x: number | string) { >(x = 10) && x : number >(x = 10) : number >x = 10 : number ->x : number | string +>x : string | number >10 : number >x : number } function foo5(x: number | string) { ->foo5 : (x: number | string) => string ->x : number | string +>foo5 : (x: string | number) => string +>x : string | number return typeof x === "string" >typeof x === "string" ? x // string : ((x = "hello") && x) : string >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" ? x // string @@ -114,20 +114,20 @@ function foo5(x: number | string) { >(x = "hello") && x : string >(x = "hello") : string >x = "hello" : string ->x : number | string +>x : string | number >"hello" : string >x : string } function foo6(x: number | string) { ->foo6 : (x: number | string) => number | string ->x : number | string +>foo6 : (x: string | number) => string | number +>x : string | number // Modify in both branches return typeof x === "string" ->typeof x === "string" ? ((x = 10) && x) // number : ((x = "hello") && x) : number | string +>typeof x === "string" ? ((x = 10) && x) // number : ((x = "hello") && x) : string | number >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" ? ((x = 10) && x) // number @@ -135,7 +135,7 @@ function foo6(x: number | string) { >(x = 10) && x : number >(x = 10) : number >x = 10 : number ->x : number | string +>x : string | number >10 : number >x : number @@ -144,19 +144,19 @@ function foo6(x: number | string) { >(x = "hello") && x : string >(x = "hello") : string >x = "hello" : string ->x : number | string +>x : string | number >"hello" : string >x : string } function foo7(x: number | string | boolean) { ->foo7 : (x: number | string | boolean) => boolean ->x : number | string | boolean +>foo7 : (x: string | number | boolean) => boolean +>x : string | number | boolean return typeof x === "string" >typeof x === "string" ? x === "hello" // boolean : typeof x === "boolean" ? x // boolean : x == 10 : boolean >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" ? x === "hello" // boolean @@ -180,8 +180,8 @@ function foo7(x: number | string | boolean) { >10 : 10 } function foo8(x: number | string | boolean) { ->foo8 : (x: number | string | boolean) => boolean ->x : number | string | boolean +>foo8 : (x: string | number | boolean) => boolean +>x : string | number | boolean var b: number | boolean; >b : number | boolean @@ -190,7 +190,7 @@ function foo8(x: number | string | boolean) { >typeof x === "string" ? x === "hello" : ((b = x) && // number | boolean (typeof x === "boolean" ? x // boolean : x == 10)) : boolean >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" ? x === "hello" @@ -223,8 +223,8 @@ function foo8(x: number | string | boolean) { >10 : 10 } function foo9(x: number | string) { ->foo9 : (x: number | string) => boolean ->x : number | string +>foo9 : (x: string | number) => boolean +>x : string | number var y = 10; >y : number @@ -235,7 +235,7 @@ function foo9(x: number | string) { >typeof x === "string" ? ((y = x.length) && x === "hello") // boolean : x === 10 : boolean >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" ? ((y = x.length) && x === "hello") // boolean @@ -257,18 +257,18 @@ function foo9(x: number | string) { >10 : 10 } function foo10(x: number | string | boolean) { ->foo10 : (x: number | string | boolean) => string ->x : number | string | boolean +>foo10 : (x: string | number | boolean) => string +>x : string | number | boolean // Mixing typeguards var b: boolean | number; ->b : boolean | number +>b : number | boolean return typeof x === "string" >typeof x === "string" ? x // string : ((b = x) // x is number | boolean && typeof x === "number" && x.toString()) : string >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" ? x // string @@ -280,7 +280,7 @@ function foo10(x: number | string | boolean) { >(b = x) // x is number | boolean && typeof x === "number" : boolean >(b = x) : number | boolean >b = x : number | boolean ->b : boolean | number +>b : number | boolean >x : number | boolean && typeof x === "number" @@ -296,18 +296,18 @@ function foo10(x: number | string | boolean) { >toString : (radix?: number) => string } function foo11(x: number | string | boolean) { ->foo11 : (x: number | string | boolean) => string | number ->x : number | string | boolean +>foo11 : (x: string | number | boolean) => string | number +>x : string | number | boolean // Mixing typeguards var b: number | boolean | string; ->b : number | boolean | string +>b : string | number | boolean return typeof x === "string" >typeof x === "string" ? x // string : ((b = x) // x is number | boolean && typeof x === "number" && (x = 10) // assignment to x && x) : string | number >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" ? x // string @@ -320,7 +320,7 @@ function foo11(x: number | string | boolean) { >(b = x) // x is number | boolean && typeof x === "number" : boolean >(b = x) : number | boolean >b = x : number | boolean ->b : number | boolean | string +>b : string | number | boolean >x : number | boolean && typeof x === "number" @@ -332,25 +332,25 @@ function foo11(x: number | string | boolean) { && (x = 10) // assignment to x >(x = 10) : number >x = 10 : number ->x : number | string | boolean +>x : string | number | boolean >10 : number && x); // x is number >x : number } function foo12(x: number | string | boolean) { ->foo12 : (x: number | string | boolean) => number ->x : number | string | boolean +>foo12 : (x: string | number | boolean) => number +>x : string | number | boolean // Mixing typeguards var b: number | boolean | string; ->b : number | boolean | string +>b : string | number | boolean return typeof x === "string" >typeof x === "string" ? ((x = 10) && x.toString().length) // number : ((b = x) // x is number | boolean && typeof x === "number" && x) : number >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" ? ((x = 10) && x.toString().length) // number @@ -358,7 +358,7 @@ function foo12(x: number | string | boolean) { >(x = 10) && x.toString().length : number >(x = 10) : number >x = 10 : number ->x : number | string | boolean +>x : string | number | boolean >10 : number >x.toString().length : number >x.toString() : string @@ -373,7 +373,7 @@ function foo12(x: number | string | boolean) { >(b = x) // x is number | boolean && typeof x === "number" : boolean >(b = x) : number | boolean >b = x : number | boolean ->b : number | boolean | string +>b : string | number | boolean >x : number | boolean && typeof x === "number" diff --git a/tests/baselines/reference/typeGuardsInDoStatement.types b/tests/baselines/reference/typeGuardsInDoStatement.types index 3000764051dc2..58b6343a2f5a0 100644 --- a/tests/baselines/reference/typeGuardsInDoStatement.types +++ b/tests/baselines/reference/typeGuardsInDoStatement.types @@ -13,7 +13,7 @@ function a(x: string | number | boolean) { do { x; // boolean | string ->x : boolean | string +>x : string | boolean x = undefined; >x = undefined : undefined @@ -40,7 +40,7 @@ function b(x: string | number | boolean) { do { x; // boolean | string ->x : boolean | string +>x : string | boolean if (cond) continue; >cond : boolean diff --git a/tests/baselines/reference/typeGuardsInForStatement.types b/tests/baselines/reference/typeGuardsInForStatement.types index 6a7561bb436a6..1d600d52d132e 100644 --- a/tests/baselines/reference/typeGuardsInForStatement.types +++ b/tests/baselines/reference/typeGuardsInForStatement.types @@ -72,6 +72,6 @@ function c(x: string | number) { >cond : boolean } x; // string | number ->x : number | string +>x : string | number } diff --git a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types index 946ac9d71ed72..0cb312ffb1a86 100644 --- a/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types +++ b/tests/baselines/reference/typeGuardsInFunctionAndModuleBlock.types @@ -2,14 +2,14 @@ // typeguards are scoped in function/module block function foo(x: number | string | boolean) { ->foo : (x: number | string | boolean) => string ->x : number | string | boolean +>foo : (x: string | number | boolean) => string +>x : string | number | boolean return typeof x === "string" >typeof x === "string" ? x : function f() { var b = x; // number | boolean return typeof x === "boolean" ? x.toString() // boolean : x.toString(); // number } () : string >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" ? x @@ -46,14 +46,14 @@ function foo(x: number | string | boolean) { } (); } function foo2(x: number | string | boolean) { ->foo2 : (x: number | string | boolean) => string ->x : number | string | boolean +>foo2 : (x: string | number | boolean) => string +>x : string | number | boolean return typeof x === "string" >typeof x === "string" ? x : function f(a: number | boolean) { var b = x; // new scope - number | boolean return typeof x === "boolean" ? x.toString() // boolean : x.toString(); // number } (x) : string >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" ? x @@ -92,14 +92,14 @@ function foo2(x: number | string | boolean) { >x : number | boolean } function foo3(x: number | string | boolean) { ->foo3 : (x: number | string | boolean) => string ->x : number | string | boolean +>foo3 : (x: string | number | boolean) => string +>x : string | number | boolean return typeof x === "string" >typeof x === "string" ? x : (() => { var b = x; // new scope - number | boolean return typeof x === "boolean" ? x.toString() // boolean : x.toString(); // number })() : string >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" ? x @@ -136,14 +136,14 @@ function foo3(x: number | string | boolean) { })(); } function foo4(x: number | string | boolean) { ->foo4 : (x: number | string | boolean) => string ->x : number | string | boolean +>foo4 : (x: string | number | boolean) => string +>x : string | number | boolean return typeof x === "string" >typeof x === "string" ? x : ((a: number | boolean) => { var b = x; // new scope - number | boolean return typeof x === "boolean" ? x.toString() // boolean : x.toString(); // number })(x) : string >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" ? x @@ -183,13 +183,13 @@ function foo4(x: number | string | boolean) { } // Type guards do not affect nested function declarations function foo5(x: number | string | boolean) { ->foo5 : (x: number | string | boolean) => void ->x : number | string | boolean +>foo5 : (x: string | number | boolean) => void +>x : string | number | boolean if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" var y = x; // string; @@ -200,8 +200,8 @@ function foo5(x: number | string | boolean) { >foo : () => void var z = x; // string ->z : number | string | boolean ->x : number | string | boolean +>z : string | number | boolean +>x : string | number | boolean } } } @@ -209,14 +209,14 @@ module m { >m : typeof m var x: number | string | boolean; ->x : number | string | boolean +>x : string | number | boolean module m2 { >m2 : typeof m2 var b = x; // new scope - number | boolean | string ->b : number | string | boolean ->x : number | string | boolean +>b : string | number | boolean +>x : string | number | boolean var y: string; >y : string @@ -224,7 +224,7 @@ module m { if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" y = x // string; @@ -260,15 +260,15 @@ module m1 { >m1 : typeof m1 var x: number | string | boolean; ->x : number | string | boolean +>x : string | number | boolean module m2.m3 { >m2 : typeof m2 >m3 : typeof m3 var b = x; // new scope - number | boolean | string ->b : number | string | boolean ->x : number | string | boolean +>b : string | number | boolean +>x : string | number | boolean var y: string; >y : string @@ -276,7 +276,7 @@ module m1 { if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" y = x // string; diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types index 379e26fbb7e9b..9d22f63e7647a 100644 --- a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types +++ b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types @@ -2,14 +2,14 @@ // In the right operand of a && operation, // the type of a variable or parameter is narrowed by any type guard in the left operand when true. function foo(x: number | string) { ->foo : (x: number | string) => boolean ->x : number | string +>foo : (x: string | number) => boolean +>x : string | number return typeof x === "string" && x.length === 10; // string >typeof x === "string" && x.length === 10 : boolean >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" >x.length === 10 : boolean >x.length : number @@ -18,53 +18,53 @@ function foo(x: number | string) { >10 : 10 } function foo2(x: number | string) { ->foo2 : (x: number | string) => number ->x : number | string +>foo2 : (x: string | number) => number +>x : string | number // modify x in right hand operand return typeof x === "string" && ((x = 10) && x); // string | number >typeof x === "string" && ((x = 10) && x) : number >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" >((x = 10) && x) : number >(x = 10) && x : number >(x = 10) : number >x = 10 : number ->x : number | string +>x : string | number >10 : number >x : number } function foo3(x: number | string) { ->foo3 : (x: number | string) => string ->x : number | string +>foo3 : (x: string | number) => string +>x : string | number // modify x in right hand operand with string type itself return typeof x === "string" && ((x = "hello") && x); // string | number >typeof x === "string" && ((x = "hello") && x) : string >typeof x === "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" >((x = "hello") && x) : string >(x = "hello") && x : string >(x = "hello") : string >x = "hello" : string ->x : number | string +>x : string | number >"hello" : string >x : string } function foo4(x: number | string | boolean) { ->foo4 : (x: number | string | boolean) => boolean ->x : number | string | boolean +>foo4 : (x: string | number | boolean) => boolean +>x : string | number | boolean return typeof x !== "string" // string | number | boolean >typeof x !== "string" // string | number | boolean && typeof x !== "number" // number | boolean && x : boolean >typeof x !== "string" // string | number | boolean && typeof x !== "number" : boolean >typeof x !== "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" && typeof x !== "number" // number | boolean @@ -77,8 +77,8 @@ function foo4(x: number | string | boolean) { >x : boolean } function foo5(x: number | string | boolean) { ->foo5 : (x: number | string | boolean) => boolean ->x : number | string | boolean +>foo5 : (x: string | number | boolean) => boolean +>x : string | number | boolean // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop var b: number | boolean; @@ -88,7 +88,7 @@ function foo5(x: number | string | boolean) { >typeof x !== "string" // string | number | boolean && ((b = x) && (typeof x !== "number" // number | boolean && x)) : boolean >typeof x !== "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" && ((b = x) && (typeof x !== "number" // number | boolean @@ -109,15 +109,15 @@ function foo5(x: number | string | boolean) { >x : boolean } function foo6(x: number | string | boolean) { ->foo6 : (x: number | string | boolean) => boolean ->x : number | string | boolean +>foo6 : (x: string | number | boolean) => boolean +>x : string | number | boolean // Mixing typeguard narrowing in if statement with conditional expression typeguard return typeof x !== "string" // string | number | boolean >typeof x !== "string" // string | number | boolean && (typeof x !== "number" // number | boolean ? x // boolean : x === 10) : boolean >typeof x !== "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" && (typeof x !== "number" // number | boolean @@ -137,21 +137,21 @@ function foo6(x: number | string | boolean) { >10 : 10 } function foo7(x: number | string | boolean) { ->foo7 : (x: number | string | boolean) => string ->x : number | string | boolean +>foo7 : (x: string | number | boolean) => string +>x : string | number | boolean var y: number| boolean | string; ->y : number | boolean | string +>y : string | number | boolean var z: number| boolean | string; ->z : number | boolean | string +>z : string | number | boolean // Mixing typeguard narrowing return typeof x !== "string" >typeof x !== "string" && ((z = x) // number | boolean && (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // x is number // do not change value : ((y = x) && x.toString()))) : string >typeof x !== "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" && ((z = x) // number | boolean @@ -159,7 +159,7 @@ function foo7(x: number | string | boolean) { >(z = x) // number | boolean && (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // x is number // do not change value : ((y = x) && x.toString())) : string >(z = x) : number | boolean >z = x : number | boolean ->z : number | boolean | string +>z : string | number | boolean >x : number | boolean && (typeof x === "number" @@ -176,7 +176,7 @@ function foo7(x: number | string | boolean) { >(x = 10) && x.toString() : string >(x = 10) : number >x = 10 : number ->x : number | string | boolean +>x : string | number | boolean >10 : number >x.toString() : string >x.toString : (radix?: number) => string @@ -189,7 +189,7 @@ function foo7(x: number | string | boolean) { >(y = x) && x.toString() : string >(y = x) : boolean >y = x : boolean ->y : number | boolean | string +>y : string | number | boolean >x : boolean >x.toString() : string >x.toString : () => string diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types index 141fab13b3d92..0cb70c8c2d6d0 100644 --- a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types +++ b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types @@ -3,14 +3,14 @@ // the type of a variable or parameter is narrowed by any type guard in the left operand when false, // provided the right operand contains no assignments to the variable or parameter. function foo(x: number | string) { ->foo : (x: number | string) => boolean ->x : number | string +>foo : (x: string | number) => boolean +>x : string | number return typeof x !== "string" || x.length === 10; // string >typeof x !== "string" || x.length === 10 : boolean >typeof x !== "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" >x.length === 10 : boolean >x.length : number @@ -19,53 +19,53 @@ function foo(x: number | string) { >10 : 10 } function foo2(x: number | string) { ->foo2 : (x: number | string) => true | number ->x : number | string +>foo2 : (x: string | number) => number | true +>x : string | number // modify x in right hand operand return typeof x !== "string" || ((x = 10) || x); // string | number ->typeof x !== "string" || ((x = 10) || x) : true | number +>typeof x !== "string" || ((x = 10) || x) : number | true >typeof x !== "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" >((x = 10) || x) : number >(x = 10) || x : number >(x = 10) : number >x = 10 : number ->x : number | string +>x : string | number >10 : number >x : number } function foo3(x: number | string) { ->foo3 : (x: number | string) => true | string ->x : number | string +>foo3 : (x: string | number) => string | true +>x : string | number // modify x in right hand operand with string type itself return typeof x !== "string" || ((x = "hello") || x); // string | number ->typeof x !== "string" || ((x = "hello") || x) : true | string +>typeof x !== "string" || ((x = "hello") || x) : string | true >typeof x !== "string" : boolean >typeof x : string ->x : number | string +>x : string | number >"string" : "string" >((x = "hello") || x) : string >(x = "hello") || x : string >(x = "hello") : string >x = "hello" : string ->x : number | string +>x : string | number >"hello" : string >x : string } function foo4(x: number | string | boolean) { ->foo4 : (x: number | string | boolean) => boolean ->x : number | string | boolean +>foo4 : (x: string | number | boolean) => boolean +>x : string | number | boolean return typeof x === "string" // string | number | boolean >typeof x === "string" // string | number | boolean || typeof x === "number" // number | boolean || x : boolean >typeof x === "string" // string | number | boolean || typeof x === "number" : boolean >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" || typeof x === "number" // number | boolean @@ -78,18 +78,18 @@ function foo4(x: number | string | boolean) { >x : boolean } function foo5(x: number | string | boolean) { ->foo5 : (x: number | string | boolean) => boolean | number ->x : number | string | boolean +>foo5 : (x: string | number | boolean) => number | boolean +>x : string | number | boolean // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop var b: number | boolean; >b : number | boolean return typeof x === "string" // string | number | boolean ->typeof x === "string" // string | number | boolean || ((b = x) || (typeof x === "number" // number | boolean || x)) : boolean | number +>typeof x === "string" // string | number | boolean || ((b = x) || (typeof x === "number" // number | boolean || x)) : number | boolean >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" || ((b = x) || (typeof x === "number" // number | boolean @@ -110,15 +110,15 @@ function foo5(x: number | string | boolean) { >x : boolean } function foo6(x: number | string | boolean) { ->foo6 : (x: number | string | boolean) => boolean ->x : number | string | boolean +>foo6 : (x: string | number | boolean) => boolean +>x : string | number | boolean // Mixing typeguard return typeof x === "string" // string | number | boolean >typeof x === "string" // string | number | boolean || (typeof x !== "number" // number | boolean ? x // boolean : x === 10) : boolean >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" || (typeof x !== "number" // number | boolean @@ -138,29 +138,29 @@ function foo6(x: number | string | boolean) { >10 : 10 } function foo7(x: number | string | boolean) { ->foo7 : (x: number | string | boolean) => true | number | string ->x : number | string | boolean +>foo7 : (x: string | number | boolean) => string | number | true +>x : string | number | boolean var y: number| boolean | string; ->y : number | boolean | string +>y : string | number | boolean var z: number| boolean | string; ->z : number | boolean | string +>z : string | number | boolean // Mixing typeguard narrowing return typeof x === "string" ->typeof x === "string" || ((z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString()))) : true | number | string +>typeof x === "string" || ((z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString()))) : string | number | true >typeof x === "string" : boolean >typeof x : string ->x : number | string | boolean +>x : string | number | boolean >"string" : "string" || ((z = x) // number | boolean ->((z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString()))) : number | true | string ->(z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString())) : number | true | string +>((z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString()))) : string | number | true +>(z = x) // number | boolean || (typeof x === "number" // change value of x ? ((x = 10) && x.toString()) // number | boolean | string // do not change value : ((y = x) && x.toString())) : string | number | true >(z = x) : number | boolean >z = x : number | boolean ->z : number | boolean | string +>z : string | number | boolean >x : number | boolean || (typeof x === "number" @@ -177,7 +177,7 @@ function foo7(x: number | string | boolean) { >(x = 10) && x.toString() : string >(x = 10) : number >x = 10 : number ->x : number | string | boolean +>x : string | number | boolean >10 : number >x.toString() : string >x.toString : (radix?: number) => string @@ -190,7 +190,7 @@ function foo7(x: number | string | boolean) { >(y = x) && x.toString() : string >(y = x) : boolean >y = x : boolean ->y : number | boolean | string +>y : string | number | boolean >x : boolean >x.toString() : string >x.toString : () => string diff --git a/tests/baselines/reference/typeGuardsInWhileStatement.types b/tests/baselines/reference/typeGuardsInWhileStatement.types index 1786871f814de..b0ea7959ec59c 100644 --- a/tests/baselines/reference/typeGuardsInWhileStatement.types +++ b/tests/baselines/reference/typeGuardsInWhileStatement.types @@ -69,6 +69,6 @@ function c(x: string | number) { >undefined : undefined } x; // string | number ->x : number | string +>x : string | number } diff --git a/tests/baselines/reference/typeGuardsOnClassProperty.types b/tests/baselines/reference/typeGuardsOnClassProperty.types index b4ca9c0b1221a..85af4540fb9c0 100644 --- a/tests/baselines/reference/typeGuardsOnClassProperty.types +++ b/tests/baselines/reference/typeGuardsOnClassProperty.types @@ -58,13 +58,13 @@ class D { } var o: { ->o : { prop1: number | string; prop2: boolean | string; } +>o : { prop1: string | number; prop2: string | boolean; } prop1: number|string; ->prop1 : number | string +>prop1 : string | number prop2: boolean|string; ->prop2 : boolean | string +>prop2 : string | boolean } = { >{ prop1: "string" , prop2: true } : { prop1: string; prop2: boolean; } @@ -82,28 +82,28 @@ if (typeof o.prop1 === "string" && o.prop1.toLowerCase()) {} >typeof o.prop1 === "string" && o.prop1.toLowerCase() : string >typeof o.prop1 === "string" : boolean >typeof o.prop1 : string ->o.prop1 : number | string ->o : { prop1: number | string; prop2: boolean | string; } ->prop1 : number | string +>o.prop1 : string | number +>o : { prop1: string | number; prop2: string | boolean; } +>prop1 : string | number >"string" : "string" >o.prop1.toLowerCase() : string >o.prop1.toLowerCase : () => string >o.prop1 : string ->o : { prop1: number | string; prop2: boolean | string; } +>o : { prop1: string | number; prop2: string | boolean; } >prop1 : string >toLowerCase : () => string var prop1 = o.prop1; ->prop1 : number | string ->o.prop1 : number | string ->o : { prop1: number | string; prop2: boolean | string; } ->prop1 : number | string +>prop1 : string | number +>o.prop1 : string | number +>o : { prop1: string | number; prop2: string | boolean; } +>prop1 : string | number if (typeof prop1 === "string" && prop1.toLocaleLowerCase()) { } >typeof prop1 === "string" && prop1.toLocaleLowerCase() : string >typeof prop1 === "string" : boolean >typeof prop1 : string ->prop1 : number | string +>prop1 : string | number >"string" : "string" >prop1.toLocaleLowerCase() : string >prop1.toLocaleLowerCase : () => string diff --git a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt index 63b9de2aedafd..c574118f91dc3 100644 --- a/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt +++ b/tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt @@ -4,8 +4,8 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(66,10): error TS2339: Property 'bar2' does not exist on type 'C1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(85,10): error TS2339: Property 'bar' does not exist on type 'D'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(112,10): error TS2339: Property 'bar2' does not exist on type 'E1'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(134,11): error TS2339: Property 'foo' does not exist on type 'F | string'. -tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(135,11): error TS2339: Property 'bar' does not exist on type 'F | string'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(134,11): error TS2339: Property 'foo' does not exist on type 'string | F'. +tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(135,11): error TS2339: Property 'bar' does not exist on type 'string | F'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(160,11): error TS2339: Property 'foo2' does not exist on type 'G1'. tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstructorSignature.ts(182,11): error TS2339: Property 'bar' does not exist on type 'H'. @@ -158,10 +158,10 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsWithInstanceOfByConstru if (obj11 instanceof F) { // can't type narrowing, construct signature returns any. obj11.foo; ~~~ -!!! error TS2339: Property 'foo' does not exist on type 'F | string'. +!!! error TS2339: Property 'foo' does not exist on type 'string | F'. obj11.bar; ~~~ -!!! error TS2339: Property 'bar' does not exist on type 'F | string'. +!!! error TS2339: Property 'bar' does not exist on type 'string | F'. } var obj12: any; diff --git a/tests/baselines/reference/typeParameterAsElementType.types b/tests/baselines/reference/typeParameterAsElementType.types index 3b145b7f3cf33..10e6787ae31ee 100644 --- a/tests/baselines/reference/typeParameterAsElementType.types +++ b/tests/baselines/reference/typeParameterAsElementType.types @@ -8,8 +8,8 @@ function fee() { >T : T var arr = [t, ""]; ->arr : (T | string)[] ->[t, ""] : (T | string)[] +>arr : (string | T)[] +>[t, ""] : (string | T)[] >t : T >"" : string } diff --git a/tests/baselines/reference/underscoreTest1.types b/tests/baselines/reference/underscoreTest1.types index fcb329193f29f..a1fd2888bf396 100644 --- a/tests/baselines/reference/underscoreTest1.types +++ b/tests/baselines/reference/underscoreTest1.types @@ -235,7 +235,7 @@ _.all([true, 1, null, 'yes'], _.identity); >_.all : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } >_ : Underscore.Static >all : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } ->[true, 1, null, 'yes'] : (boolean | number | string)[] +>[true, 1, null, 'yes'] : (string | number | boolean)[] >true : boolean >1 : number >null : null @@ -249,7 +249,7 @@ _.any([null, 0, 'yes', false]); >_.any : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } >_ : Underscore.Static >any : { (list: T[], iterator?: Iterator, context?: any): boolean; (list: Dictionary, iterator?: Iterator, context?: any): boolean; } ->[null, 0, 'yes', false] : (number | string | boolean)[] +>[null, 0, 'yes', false] : (string | number | boolean)[] >null : null >0 : number >'yes' : string @@ -508,11 +508,11 @@ _.rest([5, 4, 3, 2, 1]); >1 : number _.compact([0, 1, false, 2, '', 3]); ->_.compact([0, 1, false, 2, '', 3]) : (number | boolean | string)[] +>_.compact([0, 1, false, 2, '', 3]) : (string | number | boolean)[] >_.compact : (list: T[]) => T[] >_ : Underscore.Static >compact : (list: T[]) => T[] ->[0, 1, false, 2, '', 3] : (number | boolean | string)[] +>[0, 1, false, 2, '', 3] : (string | number | boolean)[] >0 : number >1 : number >false : boolean diff --git a/tests/baselines/reference/unionAndIntersectionInference1.types b/tests/baselines/reference/unionAndIntersectionInference1.types index 5d23688f0b7c3..f3cf3611d7586 100644 --- a/tests/baselines/reference/unionAndIntersectionInference1.types +++ b/tests/baselines/reference/unionAndIntersectionInference1.types @@ -13,12 +13,12 @@ var y: Y = undefined; >undefined : undefined function destructure( ->destructure : (something: a | Y, haveValue: (value: a) => r, haveY: (value: Y) => r) => r +>destructure : (something: Y | a, haveValue: (value: a) => r, haveY: (value: Y) => r) => r >a : a >r : r something: a | Y, ->something : a | Y +>something : Y | a >a : a >Y : Y @@ -40,7 +40,7 @@ function destructure( return something === y ? haveY(y) : haveValue(something); >something === y ? haveY(y) : haveValue(something) : r >something === y : boolean ->something : a | Y +>something : Y | a >y : Y >haveY(y) : r >haveY : (value: Y) => r @@ -49,7 +49,7 @@ function destructure( >haveValue : (value: a) => r >something : a >a : a ->something : a | Y +>something : Y | a } var value = Math.random() > 0.5 ? 'hey!' : undefined; @@ -69,7 +69,7 @@ var value = Math.random() > 0.5 ? 'hey!' : undefined; var result = destructure(value, text => 'string', y => 'other one'); // text: string, y: Y >result : string >destructure(value, text => 'string', y => 'other one') : string ->destructure : (something: a | Y, haveValue: (value: a) => r, haveY: (value: Y) => r) => r +>destructure : (something: Y | a, haveValue: (value: a) => r, haveY: (value: Y) => r) => r >value : string | Y >text => 'string' : (text: string) => string >text : string @@ -146,14 +146,14 @@ function baz1(value: void|a): void { // Repro from #5417 type Maybe = T | void; ->Maybe : T | void +>Maybe : void | T >T : T >T : T function get(x: U | void): U { ->get : (x: U | void) => U +>get : (x: void | U) => U >U : U ->x : U | void +>x : void | U >U : U >U : U @@ -163,13 +163,13 @@ function get(x: U | void): U { let foo: Maybe; >foo : string | void ->Maybe : T | void +>Maybe : void | T get(foo).toUpperCase(); // Ok >get(foo).toUpperCase() : string >get(foo).toUpperCase : () => string >get(foo) : string ->get : (x: U | void) => U +>get : (x: void | U) => U >foo : string | void >toUpperCase : () => string diff --git a/tests/baselines/reference/unionAndIntersectionInference2.types b/tests/baselines/reference/unionAndIntersectionInference2.types index beeb2a261f3ec..afe569e6d0257 100644 --- a/tests/baselines/reference/unionAndIntersectionInference2.types +++ b/tests/baselines/reference/unionAndIntersectionInference2.types @@ -1,8 +1,8 @@ === tests/cases/conformance/types/typeRelationships/typeInference/unionAndIntersectionInference2.ts === declare function f1(x: T | string): T; ->f1 : (x: T | string) => T +>f1 : (x: string | T) => T >T : T ->x : T | string +>x : string | T >T : T >T : T @@ -13,39 +13,39 @@ var b1: string | string[]; >b1 : string | string[] var c1: string[] | string; ->c1 : string[] | string +>c1 : string | string[] var d1: string | { name: string }; >d1 : string | { name: string; } >name : string var e1: number | string | boolean; ->e1 : number | string | boolean +>e1 : string | number | boolean f1(a1); // string >f1(a1) : string ->f1 : (x: T | string) => T +>f1 : (x: string | T) => T >a1 : string f1(b1); // string[] >f1(b1) : string[] ->f1 : (x: T | string) => T +>f1 : (x: string | T) => T >b1 : string | string[] f1(c1); // string[] >f1(c1) : string[] ->f1 : (x: T | string) => T ->c1 : string[] | string +>f1 : (x: string | T) => T +>c1 : string | string[] f1(d1); // { name: string } >f1(d1) : { name: string; } ->f1 : (x: T | string) => T +>f1 : (x: string | T) => T >d1 : string | { name: string; } f1(e1); // number | boolean >f1(e1) : number | boolean ->f1 : (x: T | string) => T ->e1 : number | string | boolean +>f1 : (x: string | T) => T +>e1 : string | number | boolean declare function f2(x: T & { name: string }): T; >f2 : (x: T & { name: string; }) => T diff --git a/tests/baselines/reference/unionSubtypeIfEveryConstituentTypeIsSubtype.errors.txt b/tests/baselines/reference/unionSubtypeIfEveryConstituentTypeIsSubtype.errors.txt index 7916c82c59b90..013b5d9a9909d 100644 --- a/tests/baselines/reference/unionSubtypeIfEveryConstituentTypeIsSubtype.errors.txt +++ b/tests/baselines/reference/unionSubtypeIfEveryConstituentTypeIsSubtype.errors.txt @@ -1,34 +1,34 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(15,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'number'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(21,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'string'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(22,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'string'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(22,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'string'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(28,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'boolean'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(29,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'boolean'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(29,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'boolean'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(35,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'Date'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(36,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'Date'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(36,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'Date'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(42,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'RegExp'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(43,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'RegExp'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(43,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'RegExp'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(49,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type '{ bar: number; }'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(50,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type '{ bar: number; }'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(50,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type '{ bar: number; }'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(56,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'number[]'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(57,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'number[]'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(57,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'number[]'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(63,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'I8'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(64,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'I8'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(64,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'I8'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(70,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'A'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(71,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'A'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(71,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'A'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(77,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'A2'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(78,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'A2'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(78,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'A2'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(84,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type '(x: any) => number'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(85,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type '(x: any) => number'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(85,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type '(x: any) => number'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(91,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type '(x: T) => T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(92,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type '(x: T) => T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(92,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type '(x: T) => T'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(99,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'E2'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(100,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'E2'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(100,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'E2'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(110,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'typeof f'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(111,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'typeof f'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(111,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'typeof f'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(121,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'typeof c'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(122,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'typeof c'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(122,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'typeof c'. tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(128,5): error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'T'. -tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(129,5): error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'T'. +tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts(129,5): error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'T'. ==== tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubtypeIfEveryConstituentTypeIsSubtype.ts (31 errors) ==== @@ -59,7 +59,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'string'. foo2: e | number; // error e and number both not subtype of string ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'string'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'string'. } // error cases @@ -70,7 +70,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'boolean'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'boolean'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'boolean'. } @@ -81,7 +81,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'Date'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'Date'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'Date'. } @@ -92,7 +92,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'RegExp'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'RegExp'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'RegExp'. } @@ -103,7 +103,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type '{ bar: number; }'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type '{ bar: number; }'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type '{ bar: number; }'. } @@ -114,7 +114,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'number[]'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'number[]'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'number[]'. } @@ -125,7 +125,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'I8'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'I8'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'I8'. } class A { foo: number; } @@ -136,7 +136,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'A'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'A'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'A'. } class A2 { foo: T; } @@ -147,7 +147,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'A2'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'A2'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'A2'. } @@ -158,7 +158,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type '(x: any) => number'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type '(x: any) => number'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type '(x: any) => number'. } @@ -169,7 +169,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type '(x: T) => T'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type '(x: T) => T'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type '(x: T) => T'. } @@ -181,7 +181,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'E2'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'E2'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'E2'. } @@ -196,7 +196,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'typeof f'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'typeof f'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'typeof f'. } @@ -211,7 +211,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'typeof c'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'typeof c'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'typeof c'. } @@ -222,7 +222,7 @@ tests/cases/conformance/types/typeRelationships/subtypesAndSuperTypes/unionSubty !!! error TS2411: Property 'foo' of type 'string | number' is not assignable to string index type 'T'. foo2: e | number; ~~~~~~~~~~~~~~~~~ -!!! error TS2411: Property 'foo2' of type 'e | number' is not assignable to string index type 'T'. +!!! error TS2411: Property 'foo2' of type 'number | e' is not assignable to string index type 'T'. } interface I19 { diff --git a/tests/baselines/reference/unionTypeCallSignatures2.types b/tests/baselines/reference/unionTypeCallSignatures2.types index 64295c1b4529e..ce49e9ba1c7c1 100644 --- a/tests/baselines/reference/unionTypeCallSignatures2.types +++ b/tests/baselines/reference/unionTypeCallSignatures2.types @@ -71,8 +71,8 @@ var n1 = f1(42); // number >42 : number var s1 = f1("abc"); // boolean | string | number ->s1 : boolean | string | number ->f1("abc") : boolean | string | number +>s1 : string | number | boolean +>f1("abc") : string | number | boolean >f1 : A | B | C >"abc" : string @@ -85,7 +85,7 @@ var a1 = f1([true, false]); // boolean[] >false : boolean var f2: C | B | A; ->f2 : C | B | A +>f2 : A | B | C >C : C >B : B >A : A @@ -93,25 +93,25 @@ var f2: C | B | A; var n2 = f2(42); // number >n2 : number >f2(42) : number ->f2 : C | B | A +>f2 : A | B | C >42 : number var s2 = f2("abc"); // number | string | boolean ->s2 : number | string | boolean ->f2("abc") : number | string | boolean ->f2 : C | B | A +>s2 : string | number | boolean +>f2("abc") : string | number | boolean +>f2 : A | B | C >"abc" : string var a2 = f2([true, false]); // boolean[] >a2 : boolean[] >f2([true, false]) : boolean[] ->f2 : C | B | A +>f2 : A | B | C >[true, false] : boolean[] >true : boolean >false : boolean var f3: B | A | C; ->f3 : B | A | C +>f3 : A | B | C >B : B >A : A >C : C @@ -119,19 +119,19 @@ var f3: B | A | C; var n3 = f3(42); // number >n3 : number >f3(42) : number ->f3 : B | A | C +>f3 : A | B | C >42 : number var s3 = f3("abc"); // string | boolean | number ->s3 : string | boolean | number ->f3("abc") : string | boolean | number ->f3 : B | A | C +>s3 : string | number | boolean +>f3("abc") : string | number | boolean +>f3 : A | B | C >"abc" : string var a3 = f3([true, false]); // boolean[] >a3 : boolean[] >f3([true, false]) : boolean[] ->f3 : B | A | C +>f3 : A | B | C >[true, false] : boolean[] >true : boolean >false : boolean diff --git a/tests/baselines/reference/unionTypeIndexSignature.types b/tests/baselines/reference/unionTypeIndexSignature.types index 953a5f434fa31..6360e4b7b6141 100644 --- a/tests/baselines/reference/unionTypeIndexSignature.types +++ b/tests/baselines/reference/unionTypeIndexSignature.types @@ -30,21 +30,21 @@ numOrDate = unionOfDifferentReturnType[10]; // number | Date >10 : number var unionOfTypesWithAndWithoutStringSignature: { [a: string]: number; } | boolean; ->unionOfTypesWithAndWithoutStringSignature : { [a: string]: number; } | boolean +>unionOfTypesWithAndWithoutStringSignature : boolean | { [a: string]: number; } >a : string anyVar = unionOfTypesWithAndWithoutStringSignature["hello"]; // any >anyVar = unionOfTypesWithAndWithoutStringSignature["hello"] : any >anyVar : number >unionOfTypesWithAndWithoutStringSignature["hello"] : any ->unionOfTypesWithAndWithoutStringSignature : { [a: string]: number; } | boolean +>unionOfTypesWithAndWithoutStringSignature : boolean | { [a: string]: number; } >"hello" : string anyVar = unionOfTypesWithAndWithoutStringSignature[10]; // any >anyVar = unionOfTypesWithAndWithoutStringSignature[10] : any >anyVar : number >unionOfTypesWithAndWithoutStringSignature[10] : any ->unionOfTypesWithAndWithoutStringSignature : { [a: string]: number; } | boolean +>unionOfTypesWithAndWithoutStringSignature : boolean | { [a: string]: number; } >10 : number // If each type in U has a numeric index signature, @@ -70,20 +70,20 @@ numOrDate = unionOfDifferentReturnType1[10]; // number | Date >10 : number var unionOfTypesWithAndWithoutStringSignature1: { [a: number]: number; } | boolean; ->unionOfTypesWithAndWithoutStringSignature1 : { [a: number]: number; } | boolean +>unionOfTypesWithAndWithoutStringSignature1 : boolean | { [a: number]: number; } >a : number anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"]; // any >anyVar = unionOfTypesWithAndWithoutStringSignature1["hello"] : any >anyVar : number >unionOfTypesWithAndWithoutStringSignature1["hello"] : any ->unionOfTypesWithAndWithoutStringSignature1 : { [a: number]: number; } | boolean +>unionOfTypesWithAndWithoutStringSignature1 : boolean | { [a: number]: number; } >"hello" : string anyVar = unionOfTypesWithAndWithoutStringSignature1[10]; // any >anyVar = unionOfTypesWithAndWithoutStringSignature1[10] : any >anyVar : number >unionOfTypesWithAndWithoutStringSignature1[10] : any ->unionOfTypesWithAndWithoutStringSignature1 : { [a: number]: number; } | boolean +>unionOfTypesWithAndWithoutStringSignature1 : boolean | { [a: number]: number; } >10 : number diff --git a/tests/baselines/reference/unionTypeInference.types b/tests/baselines/reference/unionTypeInference.types index ff204cfdac9a9..efc150da91803 100644 --- a/tests/baselines/reference/unionTypeInference.types +++ b/tests/baselines/reference/unionTypeInference.types @@ -43,7 +43,7 @@ var a3 = f(1, a1 || "hello"); >f(1, a1 || "hello") : number >f : (x: T, y: string | T) => T >1 : number ->a1 || "hello" : number | string +>a1 || "hello" : string | number >a1 : number >"hello" : string diff --git a/tests/baselines/reference/unionTypePropertyAccessibility.errors.txt b/tests/baselines/reference/unionTypePropertyAccessibility.errors.txt index 33b20183b5eda..52ce842a90454 100644 --- a/tests/baselines/reference/unionTypePropertyAccessibility.errors.txt +++ b/tests/baselines/reference/unionTypePropertyAccessibility.errors.txt @@ -8,8 +8,8 @@ tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(42,5): err tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(43,5): error TS2339: Property 'member' does not exist on type 'Default | Public | Protected'. tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(44,5): error TS2339: Property 'member' does not exist on type 'Default | Public | Private'. tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(45,5): error TS2339: Property 'member' does not exist on type 'Default | Protected | Private'. -tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(46,5): error TS2339: Property 'member' does not exist on type 'Public | Private | Protected'. -tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(47,5): error TS2339: Property 'member' does not exist on type 'Default | Public | Private | Protected'. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(46,5): error TS2339: Property 'member' does not exist on type 'Public | Protected | Private'. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(47,5): error TS2339: Property 'member' does not exist on type 'Default | Public | Protected | Private'. ==== tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts (12 errors) ==== @@ -80,8 +80,8 @@ tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(47,5): err !!! error TS2339: Property 'member' does not exist on type 'Default | Protected | Private'. v14.member; ~~~~~~ -!!! error TS2339: Property 'member' does not exist on type 'Public | Private | Protected'. +!!! error TS2339: Property 'member' does not exist on type 'Public | Protected | Private'. v15.member; ~~~~~~ -!!! error TS2339: Property 'member' does not exist on type 'Default | Public | Private | Protected'. +!!! error TS2339: Property 'member' does not exist on type 'Default | Public | Protected | Private'. \ No newline at end of file diff --git a/tests/baselines/reference/unionTypeWithRecursiveSubtypeReduction1.types b/tests/baselines/reference/unionTypeWithRecursiveSubtypeReduction1.types index f609301c19c2f..361a3e90535bf 100644 --- a/tests/baselines/reference/unionTypeWithRecursiveSubtypeReduction1.types +++ b/tests/baselines/reference/unionTypeWithRecursiveSubtypeReduction1.types @@ -39,7 +39,7 @@ var t: Class | Property; >Property : Property t.parent; ->t.parent : Namespace | Module | Class +>t.parent : Module | Class | Namespace >t : Class | Property ->parent : Namespace | Module | Class +>parent : Module | Class | Namespace diff --git a/tests/baselines/reference/unionTypesAssignability.errors.txt b/tests/baselines/reference/unionTypesAssignability.errors.txt index 5be1ff3d246fa..7397105d317af 100644 --- a/tests/baselines/reference/unionTypesAssignability.errors.txt +++ b/tests/baselines/reference/unionTypesAssignability.errors.txt @@ -7,10 +7,10 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/unionTyp tests/cases/conformance/types/typeRelationships/assignmentCompatibility/unionTypesAssignability.ts(22,1): error TS2322: Type 'D | E' is not assignable to type 'E'. Type 'D' is not assignable to type 'E'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/unionTypesAssignability.ts(24,1): error TS2322: Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/typeRelationships/assignmentCompatibility/unionTypesAssignability.ts(25,1): error TS2322: Type 'number | string' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/unionTypesAssignability.ts(25,1): error TS2322: Type 'string | number' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/unionTypesAssignability.ts(26,1): error TS2322: Type 'number' is not assignable to type 'string'. -tests/cases/conformance/types/typeRelationships/assignmentCompatibility/unionTypesAssignability.ts(28,1): error TS2322: Type 'number | string' is not assignable to type 'string'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/unionTypesAssignability.ts(28,1): error TS2322: Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/unionTypesAssignability.ts(31,1): error TS2322: Type 'C' is not assignable to type 'D'. Property 'foo1' is missing in type 'C'. @@ -71,7 +71,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/unionTyp !!! error TS2322: Type 'string' is not assignable to type 'number'. num = unionNumberString; // error string is not assignable to number ~~~ -!!! error TS2322: Type 'number | string' is not assignable to type 'number'. +!!! error TS2322: Type 'string | number' is not assignable to type 'number'. !!! error TS2322: Type 'string' is not assignable to type 'number'. str = num; ~~~ @@ -79,7 +79,7 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/unionTyp str = str; str = unionNumberString; // error since number is not assignable to string ~~~ -!!! error TS2322: Type 'number | string' is not assignable to type 'string'. +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. !!! error TS2322: Type 'number' is not assignable to type 'string'. // A type T is assignable to a union type U if T is assignable to any type in U diff --git a/tests/baselines/reference/unusedLocalsAndParametersTypeAliases.types b/tests/baselines/reference/unusedLocalsAndParametersTypeAliases.types index 82c87deb7d07c..3dd7b3d1b2dbd 100644 --- a/tests/baselines/reference/unusedLocalsAndParametersTypeAliases.types +++ b/tests/baselines/reference/unusedLocalsAndParametersTypeAliases.types @@ -43,7 +43,7 @@ var x: handler5; >handler5 : (() => void) | (() => number) x(); ->x() : void | number +>x() : number | void >x : (() => void) | (() => number) // used as type argument From a17bd026e535b5ff2c359fc5e793269c6742b23f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 18 Jul 2016 17:31:17 -0700 Subject: [PATCH 35/55] Associate type alias names with union, intersection and literal types --- src/compiler/checker.ts | 51 ++++++++++++++++++++++++++--------------- src/compiler/types.ts | 3 +++ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 641b96bf6c45d..33c6e750f16c4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2133,6 +2133,10 @@ namespace ts { else if (type.flags & TypeFlags.Tuple) { writeTupleType(type); } + else if (type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol) { + const typeArguments = type.aliasTypeArguments; + writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, flags); + } else if (type.flags & TypeFlags.UnionOrIntersection) { writeUnionOrIntersectionType(type, flags); } @@ -3704,8 +3708,9 @@ namespace ts { return unknownType; } - let type: Type; + const typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); let declaration: JSDocTypedefTag | TypeAliasDeclaration = getDeclarationOfKind(symbol, SyntaxKind.JSDocTypedefTag); + let type: Type; if (declaration) { if (declaration.jsDocTypeLiteral) { type = getTypeFromTypeNode(declaration.jsDocTypeLiteral); @@ -3716,12 +3721,12 @@ namespace ts { } else { declaration = getDeclarationOfKind(symbol, SyntaxKind.TypeAliasDeclaration); - type = getTypeFromTypeNode(declaration.type); + type = getTypeFromTypeNode(declaration.type, symbol, typeParameters); } if (popTypeResolution()) { - links.typeParameters = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); - if (links.typeParameters) { + links.typeParameters = typeParameters; + if (typeParameters) { // Initialize the instantiation cache for generic type aliases. The declared type corresponds to // an instantiation of the type alias with the type parameters supplied as type arguments. links.instantiations = {}; @@ -5226,7 +5231,7 @@ namespace ts { // literals and the || and ?: operators). Named types can circularly reference themselves and therefore // cannot be deduplicated during their declaration. For example, "type Item = string | (() => Item" is // a named type that circularly references itself. - function getUnionType(types: Type[], noSubtypeReduction?: boolean): Type { + function getUnionType(types: Type[], noSubtypeReduction?: boolean, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { if (types.length === 0) { return neverType; } @@ -5260,14 +5265,16 @@ namespace ts { const propagatedFlags = getPropagatingFlagsOfTypes(typeSet, /*excludeKinds*/ TypeFlags.Nullable); type = unionTypes[id] = createObjectType(TypeFlags.Union | propagatedFlags); type.types = typeSet; + type.aliasSymbol = aliasSymbol; + type.aliasTypeArguments = aliasTypeArguments; } return type; } - function getTypeFromUnionTypeNode(node: UnionTypeNode): Type { + function getTypeFromUnionTypeNode(node: UnionTypeNode, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { const links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*noSubtypeReduction*/ true); + links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*noSubtypeReduction*/ true, aliasSymbol, aliasTypeArguments); } return links.resolvedType; } @@ -5277,7 +5284,7 @@ namespace ts { // a type alias of the form "type List = T & { next: List }" cannot be reduced during its declaration. // Also, unlike union types, the order of the constituent types is preserved in order that overload resolution // for intersections of types with signatures can be deterministic. - function getIntersectionType(types: Type[]): Type { + function getIntersectionType(types: Type[], aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { if (types.length === 0) { return emptyObjectType; } @@ -5299,23 +5306,28 @@ namespace ts { const propagatedFlags = getPropagatingFlagsOfTypes(typeSet, /*excludeKinds*/ TypeFlags.Nullable); type = intersectionTypes[id] = createObjectType(TypeFlags.Intersection | propagatedFlags); type.types = typeSet; + type.aliasSymbol = aliasSymbol; + type.aliasTypeArguments = aliasTypeArguments; } return type; } - function getTypeFromIntersectionTypeNode(node: IntersectionTypeNode): Type { + function getTypeFromIntersectionTypeNode(node: IntersectionTypeNode, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { const links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = getIntersectionType(map(node.types, getTypeFromTypeNode)); + links.resolvedType = getIntersectionType(map(node.types, getTypeFromTypeNode), aliasSymbol, aliasTypeArguments); } return links.resolvedType; } - function getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node: Node): Type { + function getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node: Node, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { const links = getNodeLinks(node); if (!links.resolvedType) { // Deferred resolution of members is handled by resolveObjectTypeMembers - links.resolvedType = createObjectType(TypeFlags.Anonymous, node.symbol); + const type = createObjectType(TypeFlags.Anonymous, node.symbol); + type.aliasSymbol = aliasSymbol; + type.aliasTypeArguments = aliasTypeArguments; + links.resolvedType = type; } return links.resolvedType; } @@ -5378,7 +5390,7 @@ namespace ts { return links.resolvedType; } - function getTypeFromTypeNode(node: TypeNode): Type { + function getTypeFromTypeNode(node: TypeNode, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { switch (node.kind) { case SyntaxKind.AnyKeyword: case SyntaxKind.JSDocAllType: @@ -5421,9 +5433,9 @@ namespace ts { return getTypeFromTupleTypeNode(node); case SyntaxKind.UnionType: case SyntaxKind.JSDocUnionType: - return getTypeFromUnionTypeNode(node); + return getTypeFromUnionTypeNode(node, aliasSymbol, aliasTypeArguments); case SyntaxKind.IntersectionType: - return getTypeFromIntersectionTypeNode(node); + return getTypeFromIntersectionTypeNode(node, aliasSymbol, aliasTypeArguments); case SyntaxKind.ParenthesizedType: case SyntaxKind.JSDocNullableType: case SyntaxKind.JSDocNonNullableType: @@ -5437,7 +5449,7 @@ namespace ts { case SyntaxKind.JSDocTypeLiteral: case SyntaxKind.JSDocFunctionType: case SyntaxKind.JSDocRecordType: - return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node); + return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node, aliasSymbol, aliasTypeArguments); // This function assumes that an identifier or qualified name is a type expression // Callers should first ensure this by calling isTypeNode case SyntaxKind.Identifier: @@ -5490,6 +5502,7 @@ namespace ts { count == 2 ? createBinaryTypeMapper(sources[0], targets ? targets[0] : anyType, sources[1], targets ? targets[1] : anyType) : createArrayTypeMapper(sources, targets); mapper.mappedTypes = sources; + mapper.targetTypes = targets; return mapper; } @@ -5615,6 +5628,8 @@ namespace ts { const result = createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol); result.target = type; result.mapper = mapper; + result.aliasSymbol = type.aliasSymbol; + result.aliasTypeArguments = mapper.targetTypes; mapper.instantiations[type.id] = result; return result; } @@ -5692,10 +5707,10 @@ namespace ts { return createTupleType(instantiateList((type).elementTypes, mapper, instantiateType)); } if (type.flags & TypeFlags.Union && !(type.flags & TypeFlags.Primitive)) { - return getUnionType(instantiateList((type).types, mapper, instantiateType), /*noSubtypeReduction*/ true); + return getUnionType(instantiateList((type).types, mapper, instantiateType), /*noSubtypeReduction*/ true, type.aliasSymbol, mapper.targetTypes); } if (type.flags & TypeFlags.Intersection) { - return getIntersectionType(instantiateList((type).types, mapper, instantiateType)); + return getIntersectionType(instantiateList((type).types, mapper, instantiateType), type.aliasSymbol, mapper.targetTypes); } } return type; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3d1962826d16c..e9ffb8bff72a0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2283,6 +2283,8 @@ namespace ts { /* @internal */ id: number; // Unique ID symbol?: Symbol; // Symbol associated with type (if any) pattern?: DestructuringPattern; // Destructuring pattern represented by type (if any) + aliasSymbol?: Symbol; // Alias associated with type + aliasTypeArguments?: Type[]; // Alias type arguments (if any) } /* @internal */ @@ -2446,6 +2448,7 @@ namespace ts { export interface TypeMapper { (t: TypeParameter): Type; mappedTypes?: Type[]; // Types mapped by this mapper + targetTypes?: Type[]; // Types substituted for mapped types instantiations?: Type[]; // Cache of instantiations created using this type mapper. context?: InferenceContext; // The inference context this mapper was created from. // Only inference mappers have this set (in createInferenceMapper). From a53a53f1797db1a6a7bf624275f7f5402f7ffb4b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 18 Jul 2016 17:31:48 -0700 Subject: [PATCH 36/55] Accept new baselines --- .../reference/booleanLiteralTypes1.types | 18 +- .../reference/booleanLiteralTypes2.types | 18 +- .../circularTypeAliasForUnionWithClass.types | 26 +-- ...rcularTypeAliasForUnionWithInterface.types | 42 ++--- .../classDoesNotDependOnBaseTypes.types | 14 +- .../controlFlowBinaryOrExpression.types | 12 +- .../declFileTypeAnnotationTypeAlias.types | 14 +- ...ecoratedDefaultExportsGetExportedAmd.types | 12 +- ...tedDefaultExportsGetExportedCommonjs.types | 12 +- ...ratedDefaultExportsGetExportedSystem.types | 12 +- ...ecoratedDefaultExportsGetExportedUmd.types | 12 +- .../reference/decoratorMetadataPromise.types | 10 +- .../destructureOptionalParameter.types | 2 +- .../destructuringInFunctionType.types | 10 +- ...estructuringParameterDeclaration3ES5.types | 2 +- ...estructuringParameterDeclaration3ES6.types | 2 +- .../emitDecoratorMetadata_restArgs.types | 16 +- .../reference/enumLiteralTypes1.types | 170 +++++++++--------- .../reference/enumLiteralTypes2.types | 168 ++++++++--------- .../reference/enumLiteralTypes3.errors.txt | 36 ++-- ...ssPropertyErrorForFunctionTypes.errors.txt | 8 +- .../reference/genericTypeAliases.types | 118 ++++++------ .../interfaceDoesNotDependOnBaseTypes.types | 18 +- .../reference/intersectionTypeMembers.types | 14 +- .../intersectionTypeOverloading.types | 20 +-- tests/baselines/reference/literalTypes1.types | 12 +- ...eLibrary_NoErrorDuplicateLibOptions1.types | 4 +- ...eLibrary_NoErrorDuplicateLibOptions2.types | 4 +- ...dularizeLibrary_TargetES5UsingES6Lib.types | 4 +- ...dularizeLibrary_TargetES6UsingES6Lib.types | 4 +- ...Library_UsingES5LibAndES6FeatureLibs.types | 6 +- .../reference/narrowTypeByInstanceof.types | 18 +- .../reference/numericLiteralTypes1.types | 36 ++-- .../reference/numericLiteralTypes2.types | 36 ++-- .../reference/numericLiteralTypes3.errors.txt | 96 +++++----- .../operatorsAndIntersectionTypes.types | 64 +++---- .../parenthesizedContexualTyping2.types | 52 +++--- .../recursiveGenericUnionType1.types | 40 ++--- .../recursiveGenericUnionType2.types | 40 ++--- .../recursiveIntersectionTypes.errors.txt | 12 +- .../stringLiteralCheckedInIf01.types | 28 +-- .../stringLiteralCheckedInIf02.types | 36 ++-- .../stringLiteralMatchedInSwitch01.types | 28 +-- .../stringLiteralTypeAssertion01.types | 96 +++++----- .../stringLiteralTypesAndTuples01.js | 2 +- .../stringLiteralTypesAndTuples01.types | 16 +- .../stringLiteralTypesAsTags01.types | 32 ++-- .../stringLiteralTypesAsTags02.types | 16 +- .../stringLiteralTypesAsTags03.types | 16 +- .../stringLiteralTypesInUnionTypes04.types | 34 ++-- .../stringLiteralTypesOverloads01.js | 2 +- .../stringLiteralTypesOverloads01.types | 52 +++--- .../stringLiteralTypesTypePredicates01.types | 40 ++--- .../taggedTemplateContextualTyping1.types | 28 +-- .../taggedTemplateContextualTyping2.types | 28 +-- .../reference/typeAliasDeclarationEmit.types | 6 +- ...ypeAliasDoesntMakeModuleInstantiated.types | 2 +- tests/baselines/reference/typeAliases.types | 4 +- ...lyReferencedTypeAliasToTypeLiteral01.types | 22 +-- ...lyReferencedTypeAliasToTypeLiteral02.types | 28 +-- .../reference/typeGuardsAsAssertions.types | 22 +-- .../unionAndIntersectionInference1.types | 8 +- ...unusedLocalsAndParametersTypeAliases.types | 34 ++-- 63 files changed, 897 insertions(+), 897 deletions(-) diff --git a/tests/baselines/reference/booleanLiteralTypes1.types b/tests/baselines/reference/booleanLiteralTypes1.types index 3ea81df09c385..704eba4055b00 100644 --- a/tests/baselines/reference/booleanLiteralTypes1.types +++ b/tests/baselines/reference/booleanLiteralTypes1.types @@ -246,7 +246,7 @@ function f13(x: true | false) { } type Item = ->Item : { kind: true; a: string; } | { kind: false; b: string; } +>Item : Item { kind: true, a: string } | >kind : true @@ -259,13 +259,13 @@ type Item = >b : string function f20(x: Item) { ->f20 : (x: { kind: true; a: string; } | { kind: false; b: string; }) => string ->x : { kind: true; a: string; } | { kind: false; b: string; } ->Item : { kind: true; a: string; } | { kind: false; b: string; } +>f20 : (x: Item) => string +>x : Item +>Item : Item switch (x.kind) { >x.kind : boolean ->x : { kind: true; a: string; } | { kind: false; b: string; } +>x : Item >kind : boolean case true: return x.a; @@ -283,13 +283,13 @@ function f20(x: Item) { } function f21(x: Item) { ->f21 : (x: { kind: true; a: string; } | { kind: false; b: string; }) => string ->x : { kind: true; a: string; } | { kind: false; b: string; } ->Item : { kind: true; a: string; } | { kind: false; b: string; } +>f21 : (x: Item) => string +>x : Item +>Item : Item switch (x.kind) { >x.kind : boolean ->x : { kind: true; a: string; } | { kind: false; b: string; } +>x : Item >kind : boolean case true: return x.a; diff --git a/tests/baselines/reference/booleanLiteralTypes2.types b/tests/baselines/reference/booleanLiteralTypes2.types index 7b6d16c35d2e2..76cca9481d4a0 100644 --- a/tests/baselines/reference/booleanLiteralTypes2.types +++ b/tests/baselines/reference/booleanLiteralTypes2.types @@ -247,7 +247,7 @@ function f13(x: true | false) { } type Item = ->Item : { kind: true; a: string; } | { kind: false; b: string; } +>Item : Item { kind: true, a: string } | >kind : true @@ -260,13 +260,13 @@ type Item = >b : string function f20(x: Item) { ->f20 : (x: { kind: true; a: string; } | { kind: false; b: string; }) => string ->x : { kind: true; a: string; } | { kind: false; b: string; } ->Item : { kind: true; a: string; } | { kind: false; b: string; } +>f20 : (x: Item) => string +>x : Item +>Item : Item switch (x.kind) { >x.kind : boolean ->x : { kind: true; a: string; } | { kind: false; b: string; } +>x : Item >kind : boolean case true: return x.a; @@ -284,13 +284,13 @@ function f20(x: Item) { } function f21(x: Item) { ->f21 : (x: { kind: true; a: string; } | { kind: false; b: string; }) => string ->x : { kind: true; a: string; } | { kind: false; b: string; } ->Item : { kind: true; a: string; } | { kind: false; b: string; } +>f21 : (x: Item) => string +>x : Item +>Item : Item switch (x.kind) { >x.kind : boolean ->x : { kind: true; a: string; } | { kind: false; b: string; } +>x : Item >kind : boolean case true: return x.a; diff --git a/tests/baselines/reference/circularTypeAliasForUnionWithClass.types b/tests/baselines/reference/circularTypeAliasForUnionWithClass.types index 99a05f3d66a50..8735c19875e38 100644 --- a/tests/baselines/reference/circularTypeAliasForUnionWithClass.types +++ b/tests/baselines/reference/circularTypeAliasForUnionWithClass.types @@ -1,26 +1,26 @@ === tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithClass.ts === var v0: T0; ->v0 : string | I0 ->T0 : string | I0 +>v0 : T0 +>T0 : T0 type T0 = string | I0; ->T0 : string | I0 +>T0 : T0 >I0 : I0 class I0 { >I0 : I0 x: T0; ->x : string | I0 ->T0 : string | I0 +>x : T0 +>T0 : T0 } var v3: T3; ->v3 : string | I3 ->T3 : string | I3 +>v3 : T3 +>T3 : T3 type T3 = string | I3; ->T3 : string | I3 +>T3 : T3 >I3 : I3 class I3 { @@ -28,15 +28,15 @@ class I3 { [x: number]: T3; >x : number ->T3 : string | I3 +>T3 : T3 } var v4: T4; ->v4 : string | I4 ->T4 : string | I4 +>v4 : T4 +>T4 : T4 type T4 = string | I4; ->T4 : string | I4 +>T4 : T4 >I4 : I4 class I4 { @@ -44,6 +44,6 @@ class I4 { [x: string]: T4; >x : string ->T4 : string | I4 +>T4 : T4 } diff --git a/tests/baselines/reference/circularTypeAliasForUnionWithInterface.types b/tests/baselines/reference/circularTypeAliasForUnionWithInterface.types index 4325f9c774ab5..941c23f866474 100644 --- a/tests/baselines/reference/circularTypeAliasForUnionWithInterface.types +++ b/tests/baselines/reference/circularTypeAliasForUnionWithInterface.types @@ -1,56 +1,56 @@ === tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithInterface.ts === var v0: T0; ->v0 : string | I0 ->T0 : string | I0 +>v0 : T0 +>T0 : T0 type T0 = string | I0; ->T0 : string | I0 +>T0 : T0 >I0 : I0 interface I0 { >I0 : I0 x: T0; ->x : string | I0 ->T0 : string | I0 +>x : T0 +>T0 : T0 } var v1: T1; ->v1 : string | I1 ->T1 : string | I1 +>v1 : T1 +>T1 : T1 type T1 = string | I1; ->T1 : string | I1 +>T1 : T1 >I1 : I1 interface I1 { >I1 : I1 (): T1; ->T1 : string | I1 +>T1 : T1 } var v2: T2; ->v2 : string | I2 ->T2 : string | I2 +>v2 : T2 +>T2 : T2 type T2 = string | I2; ->T2 : string | I2 +>T2 : T2 >I2 : I2 interface I2 { >I2 : I2 new (): T2; ->T2 : string | I2 +>T2 : T2 } var v3: T3; ->v3 : string | I3 ->T3 : string | I3 +>v3 : T3 +>T3 : T3 type T3 = string | I3; ->T3 : string | I3 +>T3 : T3 >I3 : I3 interface I3 { @@ -58,15 +58,15 @@ interface I3 { [x: number]: T3; >x : number ->T3 : string | I3 +>T3 : T3 } var v4: T4; ->v4 : string | I4 ->T4 : string | I4 +>v4 : T4 +>T4 : T4 type T4 = string | I4; ->T4 : string | I4 +>T4 : T4 >I4 : I4 interface I4 { @@ -74,6 +74,6 @@ interface I4 { [x: string]: T4; >x : string ->T4 : string | I4 +>T4 : T4 } diff --git a/tests/baselines/reference/classDoesNotDependOnBaseTypes.types b/tests/baselines/reference/classDoesNotDependOnBaseTypes.types index f8e510230e2ca..529be3c66353f 100644 --- a/tests/baselines/reference/classDoesNotDependOnBaseTypes.types +++ b/tests/baselines/reference/classDoesNotDependOnBaseTypes.types @@ -1,24 +1,24 @@ === tests/cases/conformance/types/typeAliases/classDoesNotDependOnBaseTypes.ts === var x: StringTree; ->x : string | StringTreeCollection ->StringTree : string | StringTreeCollection +>x : StringTree +>StringTree : StringTree if (typeof x !== "string") { >typeof x !== "string" : boolean >typeof x : string ->x : string | StringTreeCollection +>x : StringTree >"string" : "string" x[0] = ""; >x[0] = "" : string ->x[0] : string | StringTreeCollection +>x[0] : StringTree >x : StringTreeCollection >0 : number >"" : string x[0] = new StringTreeCollection; >x[0] = new StringTreeCollection : StringTreeCollection ->x[0] : string | StringTreeCollection +>x[0] : StringTree >x : StringTreeCollection >0 : number >new StringTreeCollection : StringTreeCollection @@ -26,7 +26,7 @@ if (typeof x !== "string") { } type StringTree = string | StringTreeCollection; ->StringTree : string | StringTreeCollection +>StringTree : StringTree >StringTreeCollection : StringTreeCollection class StringTreeCollectionBase { @@ -34,7 +34,7 @@ class StringTreeCollectionBase { [n: number]: StringTree; >n : number ->StringTree : string | StringTreeCollection +>StringTree : StringTree } class StringTreeCollection extends StringTreeCollectionBase { } diff --git a/tests/baselines/reference/controlFlowBinaryOrExpression.types b/tests/baselines/reference/controlFlowBinaryOrExpression.types index 11f28b3df19ed..0bf5ab524b906 100644 --- a/tests/baselines/reference/controlFlowBinaryOrExpression.types +++ b/tests/baselines/reference/controlFlowBinaryOrExpression.types @@ -62,21 +62,21 @@ declare function isHTMLCollection(sourceObj: any): sourceObj is HTMLCollection; >HTMLCollection : HTMLCollection type EventTargetLike = {a: string} | HTMLCollection | NodeList; ->EventTargetLike : NodeList | HTMLCollection | { a: string; } +>EventTargetLike : EventTargetLike >a : string >HTMLCollection : HTMLCollection >NodeList : NodeList var sourceObj: EventTargetLike = undefined; ->sourceObj : NodeList | HTMLCollection | { a: string; } ->EventTargetLike : NodeList | HTMLCollection | { a: string; } +>sourceObj : EventTargetLike +>EventTargetLike : EventTargetLike >undefined : any >undefined : undefined if (isNodeList(sourceObj)) { >isNodeList(sourceObj) : boolean >isNodeList : (sourceObj: any) => sourceObj is NodeList ->sourceObj : NodeList | HTMLCollection | { a: string; } +>sourceObj : EventTargetLike sourceObj.length; >sourceObj.length : number @@ -87,7 +87,7 @@ if (isNodeList(sourceObj)) { if (isHTMLCollection(sourceObj)) { >isHTMLCollection(sourceObj) : boolean >isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection ->sourceObj : NodeList | HTMLCollection | { a: string; } +>sourceObj : EventTargetLike sourceObj.length; >sourceObj.length : number @@ -99,7 +99,7 @@ if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) { >isNodeList(sourceObj) || isHTMLCollection(sourceObj) : boolean >isNodeList(sourceObj) : boolean >isNodeList : (sourceObj: any) => sourceObj is NodeList ->sourceObj : NodeList | HTMLCollection | { a: string; } +>sourceObj : EventTargetLike >isHTMLCollection(sourceObj) : boolean >isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection >sourceObj : { a: string; } diff --git a/tests/baselines/reference/declFileTypeAnnotationTypeAlias.types b/tests/baselines/reference/declFileTypeAnnotationTypeAlias.types index beef88c0ca25c..53db7a54d0d46 100644 --- a/tests/baselines/reference/declFileTypeAnnotationTypeAlias.types +++ b/tests/baselines/reference/declFileTypeAnnotationTypeAlias.types @@ -4,11 +4,11 @@ module M { >M : typeof M export type Value = string | number | boolean; ->Value : string | number | boolean +>Value : Value export var x: Value; ->x : string | number | boolean ->Value : string | number | boolean +>x : Value +>Value : Value export class c { >c : c @@ -32,7 +32,7 @@ module M { >c : m.c export type fc = () => c; ->fc : () => c +>fc : fc >c : c } @@ -47,7 +47,7 @@ module M { >M : typeof M export type W = Window | string; ->W : string | Window +>W : W >Window : Window export module N { @@ -57,7 +57,7 @@ module M { >Window : Window export var p: W; ->p : string | Window ->W : string | Window +>p : W +>W : W } } diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.types b/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.types index 8e42146b8242b..1bac7896d0515 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.types +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedAmd.types @@ -1,21 +1,21 @@ === tests/cases/conformance/es6/moduleExportsAmd/a.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => void | TFunction ->ClassDecorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator +>ClassDecorator : ClassDecorator @decorator ->decorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator export default class Foo {} >Foo : Foo === tests/cases/conformance/es6/moduleExportsAmd/b.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => void | TFunction ->ClassDecorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator +>ClassDecorator : ClassDecorator @decorator ->decorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator export default class {} diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.types b/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.types index ec4bd9f5476ae..304bf75cd5ce8 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.types +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedCommonjs.types @@ -1,21 +1,21 @@ === tests/cases/conformance/es6/moduleExportsCommonjs/a.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => void | TFunction ->ClassDecorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator +>ClassDecorator : ClassDecorator @decorator ->decorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator export default class Foo {} >Foo : Foo === tests/cases/conformance/es6/moduleExportsCommonjs/b.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => void | TFunction ->ClassDecorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator +>ClassDecorator : ClassDecorator @decorator ->decorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator export default class {} diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.types b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.types index 0577559b7d9df..ee77e08dd671e 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.types +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedSystem.types @@ -1,20 +1,20 @@ === tests/cases/conformance/es6/moduleExportsSystem/a.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => void | TFunction ->ClassDecorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator +>ClassDecorator : ClassDecorator @decorator ->decorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator export default class Foo {} >Foo : Foo === tests/cases/conformance/es6/moduleExportsSystem/b.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => void | TFunction ->ClassDecorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator +>ClassDecorator : ClassDecorator @decorator ->decorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator export default class {} diff --git a/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.types b/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.types index 399c0a79ee259..c47f7960f652d 100644 --- a/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.types +++ b/tests/baselines/reference/decoratedDefaultExportsGetExportedUmd.types @@ -1,21 +1,21 @@ === tests/cases/conformance/es6/moduleExportsUmd/a.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => void | TFunction ->ClassDecorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator +>ClassDecorator : ClassDecorator @decorator ->decorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator export default class Foo {} >Foo : Foo === tests/cases/conformance/es6/moduleExportsUmd/b.ts === var decorator: ClassDecorator; ->decorator : (target: TFunction) => void | TFunction ->ClassDecorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator +>ClassDecorator : ClassDecorator @decorator ->decorator : (target: TFunction) => void | TFunction +>decorator : ClassDecorator export default class {} diff --git a/tests/baselines/reference/decoratorMetadataPromise.types b/tests/baselines/reference/decoratorMetadataPromise.types index 953458ca5fe8d..dc07cdc1fe634 100644 --- a/tests/baselines/reference/decoratorMetadataPromise.types +++ b/tests/baselines/reference/decoratorMetadataPromise.types @@ -1,20 +1,20 @@ === tests/cases/compiler/decoratorMetadataPromise.ts === declare const decorator: MethodDecorator; ->decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor ->MethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor +>decorator : MethodDecorator +>MethodDecorator : MethodDecorator class A { >A : A @decorator ->decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor +>decorator : MethodDecorator async foo() {} >foo : () => Promise @decorator ->decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor +>decorator : MethodDecorator async bar(): Promise { return 0; } >bar : () => Promise @@ -22,7 +22,7 @@ class A { >0 : number @decorator ->decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor +>decorator : MethodDecorator baz(n: Promise): Promise { return n; } >baz : (n: Promise) => Promise diff --git a/tests/baselines/reference/destructureOptionalParameter.types b/tests/baselines/reference/destructureOptionalParameter.types index ea0e8c4b754e2..9baffd5f8faa5 100644 --- a/tests/baselines/reference/destructureOptionalParameter.types +++ b/tests/baselines/reference/destructureOptionalParameter.types @@ -52,7 +52,7 @@ interface QueryMetadataFactory { >read : any }): ParameterDecorator; ->ParameterDecorator : (target: Object, propertyKey: string | symbol, parameterIndex: number) => void +>ParameterDecorator : ParameterDecorator new (selector: Type | string, {descendants, read}?: { >selector : string | Type diff --git a/tests/baselines/reference/destructuringInFunctionType.types b/tests/baselines/reference/destructuringInFunctionType.types index 0cf057e06a301..5292ea989ddc1 100644 --- a/tests/baselines/reference/destructuringInFunctionType.types +++ b/tests/baselines/reference/destructuringInFunctionType.types @@ -19,7 +19,7 @@ type T1 = ([a, b, c]); >c : c type F1 = ([a, b, c]) => void; ->F1 : ([a, b, c]: [any, any, any]) => void +>F1 : F1 >a : any >b : any >c : any @@ -29,7 +29,7 @@ type T2 = ({ a }); >a : any type F2 = ({ a }) => void; ->F2 : ({a}: { a: any; }) => void +>F2 : F2 >a : any type T3 = ([{ a: b }, { b: a }]); @@ -40,7 +40,7 @@ type T3 = ([{ a: b }, { b: a }]); >a : a type F3 = ([{ a: b }, { b: a }]) => void; ->F3 : ([{a: b}, {b: a}]: [{ a: any; }, { b: any; }]) => void +>F3 : F3 >a : any >b : any >b : any @@ -53,13 +53,13 @@ type T4 = ([{ a: [b, c] }]); >c : c type F4 = ([{ a: [b, c] }]) => void; ->F4 : ([{a: [b, c]}]: [{ a: [any, any]; }]) => void +>F4 : F4 >a : any >b : any >c : any type C1 = new ([{ a: [b, c] }]) => void; ->C1 : new ([{a: [b, c]}]: [{ a: [any, any]; }]) => void +>C1 : C1 >a : any >b : any >c : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5.types b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types index d51a0e32dc8c8..2ab9c9330d6db 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES5.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types @@ -12,7 +12,7 @@ type arrayString = Array >String : String type someArray = Array | number[]; ->someArray : String[] | number[] +>someArray : someArray >Array : T[] >String : String diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types index 63d5d074a8d65..55a26cfe58e34 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types @@ -12,7 +12,7 @@ type arrayString = Array >String : String type someArray = Array | number[]; ->someArray : String[] | number[] +>someArray : someArray >Array : T[] >String : String diff --git a/tests/baselines/reference/emitDecoratorMetadata_restArgs.types b/tests/baselines/reference/emitDecoratorMetadata_restArgs.types index 96605d0e7f288..0b033351dc7d0 100644 --- a/tests/baselines/reference/emitDecoratorMetadata_restArgs.types +++ b/tests/baselines/reference/emitDecoratorMetadata_restArgs.types @@ -1,15 +1,15 @@ === tests/cases/compiler/emitDecoratorMetadata_restArgs.ts === declare const MyClassDecorator: ClassDecorator; ->MyClassDecorator : (target: TFunction) => void | TFunction ->ClassDecorator : (target: TFunction) => void | TFunction +>MyClassDecorator : ClassDecorator +>ClassDecorator : ClassDecorator declare const MyMethodDecorator: MethodDecorator; ->MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor ->MethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor +>MyMethodDecorator : MethodDecorator +>MethodDecorator : MethodDecorator @MyClassDecorator ->MyClassDecorator : (target: TFunction) => void | TFunction +>MyClassDecorator : ClassDecorator class A { >A : A @@ -18,7 +18,7 @@ class A { >args : any[] @MyMethodDecorator ->MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor +>MyMethodDecorator : MethodDecorator method(...args) {} >method : (...args: any[]) => void @@ -26,7 +26,7 @@ class A { } @MyClassDecorator ->MyClassDecorator : (target: TFunction) => void | TFunction +>MyClassDecorator : ClassDecorator class B { >B : B @@ -35,7 +35,7 @@ class B { >args : number[] @MyMethodDecorator ->MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => void | TypedPropertyDescriptor +>MyMethodDecorator : MethodDecorator method(...args: string[]) {} >method : (...args: string[]) => void diff --git a/tests/baselines/reference/enumLiteralTypes1.types b/tests/baselines/reference/enumLiteralTypes1.types index f73f98e405bff..6344cc5f39a98 100644 --- a/tests/baselines/reference/enumLiteralTypes1.types +++ b/tests/baselines/reference/enumLiteralTypes1.types @@ -6,21 +6,21 @@ const enum Choice { Unknown, Yes, No }; >No : Choice type YesNo = Choice.Yes | Choice.No; ->YesNo : Choice.Yes | Choice.No +>YesNo : YesNo >Choice : any >Yes : Choice.Yes >Choice : any >No : Choice.No type NoYes = Choice.No | Choice.Yes; ->NoYes : Choice.Yes | Choice.No +>NoYes : YesNo >Choice : any >No : Choice.No >Choice : any >Yes : Choice.Yes type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; ->UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown +>UnknownYesNo : UnknownYesNo >Choice : any >Unknown : Choice.Unknown >Choice : any @@ -32,22 +32,22 @@ function f1() { >f1 : () => void var a: YesNo; ->a : Choice.Yes | Choice.No ->YesNo : Choice.Yes | Choice.No +>a : YesNo +>YesNo : YesNo var a: NoYes; ->a : Choice.Yes | Choice.No ->NoYes : Choice.Yes | Choice.No +>a : YesNo +>NoYes : YesNo var a: Choice.Yes | Choice.No; ->a : Choice.Yes | Choice.No +>a : YesNo >Choice : any >Yes : Choice.Yes >Choice : any >No : Choice.No var a: Choice.No | Choice.Yes; ->a : Choice.Yes | Choice.No +>a : YesNo >Choice : any >No : Choice.No >Choice : any @@ -55,157 +55,157 @@ function f1() { } function f2(a: YesNo, b: UnknownYesNo, c: Choice) { ->f2 : (a: Choice.Yes | Choice.No, b: Choice.Yes | Choice.No | Choice.Unknown, c: Choice) => void ->a : Choice.Yes | Choice.No ->YesNo : Choice.Yes | Choice.No ->b : Choice.Yes | Choice.No | Choice.Unknown ->UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown +>f2 : (a: YesNo, b: UnknownYesNo, c: Choice) => void +>a : YesNo +>YesNo : YesNo +>b : UnknownYesNo +>UnknownYesNo : UnknownYesNo >c : Choice >Choice : Choice b = a; ->b = a : Choice.Yes | Choice.No ->b : Choice.Yes | Choice.No | Choice.Unknown ->a : Choice.Yes | Choice.No +>b = a : YesNo +>b : UnknownYesNo +>a : YesNo c = a; ->c = a : Choice.Yes | Choice.No +>c = a : YesNo >c : Choice ->a : Choice.Yes | Choice.No +>a : YesNo c = b; ->c = b : Choice.Yes | Choice.No +>c = b : YesNo >c : Choice ->b : Choice.Yes | Choice.No +>b : YesNo } function f3(a: Choice.Yes, b: YesNo) { ->f3 : (a: Choice.Yes, b: Choice.Yes | Choice.No) => void +>f3 : (a: Choice.Yes, b: YesNo) => void >a : Choice.Yes >Choice : any >Yes : Choice.Yes ->b : Choice.Yes | Choice.No ->YesNo : Choice.Yes | Choice.No +>b : YesNo +>YesNo : YesNo var x = a + b; >x : number >a + b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var x = a - b; >x : number >a - b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var x = a * b; >x : number >a * b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var x = a / b; >x : number >a / b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var x = a % b; >x : number >a % b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var x = a | b; >x : number >a | b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var x = a & b; >x : number >a & b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var x = a ^ b; >x : number >a ^ b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var x = -b; >x : number >-b : number ->b : Choice.Yes | Choice.No +>b : YesNo var x = ~b; >x : number >~b : number ->b : Choice.Yes | Choice.No +>b : YesNo var y = a == b; >y : boolean >a == b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var y = a != b; >y : boolean >a != b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var y = a === b; >y : boolean >a === b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var y = a !== b; >y : boolean >a !== b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var y = a > b; >y : boolean >a > b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var y = a < b; >y : boolean >a < b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var y = a >= b; >y : boolean >a >= b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var y = a <= b; >y : boolean >a <= b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No +>b : YesNo var y = !b; >y : boolean >!b : boolean ->b : Choice.Yes | Choice.No +>b : YesNo } function f4(a: Choice.Yes, b: YesNo) { ->f4 : (a: Choice.Yes, b: Choice.Yes | Choice.No) => void +>f4 : (a: Choice.Yes, b: YesNo) => void >a : Choice.Yes >Choice : any >Yes : Choice.Yes ->b : Choice.Yes | Choice.No ->YesNo : Choice.Yes | Choice.No +>b : YesNo +>YesNo : YesNo a++; >a++ : number @@ -213,7 +213,7 @@ function f4(a: Choice.Yes, b: YesNo) { b++; >b++ : number ->b : Choice.Yes | Choice.No +>b : YesNo } declare function g(x: Choice.Yes): string; @@ -234,11 +234,11 @@ declare function g(x: Choice): number; >Choice : Choice function f5(a: YesNo, b: UnknownYesNo, c: Choice) { ->f5 : (a: Choice.Yes | Choice.No, b: Choice.Yes | Choice.No | Choice.Unknown, c: Choice) => void ->a : Choice.Yes | Choice.No ->YesNo : Choice.Yes | Choice.No ->b : Choice.Yes | Choice.No | Choice.Unknown ->UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown +>f5 : (a: YesNo, b: UnknownYesNo, c: Choice) => void +>a : YesNo +>YesNo : YesNo +>b : UnknownYesNo +>UnknownYesNo : UnknownYesNo >c : Choice >Choice : Choice @@ -262,13 +262,13 @@ function f5(a: YesNo, b: UnknownYesNo, c: Choice) { >z3 : number >g(a) : number >g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } ->a : Choice.Yes | Choice.No +>a : YesNo var z4 = g(b); >z4 : number >g(b) : number >g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var z5 = g(c); >z5 : number @@ -288,12 +288,12 @@ function assertNever(x: never): never { } function f10(x: YesNo) { ->f10 : (x: Choice.Yes | Choice.No) => string ->x : Choice.Yes | Choice.No ->YesNo : Choice.Yes | Choice.No +>f10 : (x: YesNo) => string +>x : YesNo +>YesNo : YesNo switch (x) { ->x : Choice.Yes | Choice.No +>x : YesNo case Choice.Yes: return "true"; >Choice.Yes : Choice.Yes @@ -310,12 +310,12 @@ function f10(x: YesNo) { } function f11(x: YesNo) { ->f11 : (x: Choice.Yes | Choice.No) => string ->x : Choice.Yes | Choice.No ->YesNo : Choice.Yes | Choice.No +>f11 : (x: YesNo) => string +>x : YesNo +>YesNo : YesNo switch (x) { ->x : Choice.Yes | Choice.No +>x : YesNo case Choice.Yes: return "true"; >Choice.Yes : Choice.Yes @@ -336,30 +336,30 @@ function f11(x: YesNo) { } function f12(x: UnknownYesNo) { ->f12 : (x: Choice.Yes | Choice.No | Choice.Unknown) => void ->x : Choice.Yes | Choice.No | Choice.Unknown ->UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown +>f12 : (x: UnknownYesNo) => void +>x : UnknownYesNo +>UnknownYesNo : UnknownYesNo if (x) { ->x : Choice.Yes | Choice.No | Choice.Unknown +>x : UnknownYesNo x; ->x : Choice.Yes | Choice.No +>x : YesNo } else { x; ->x : Choice.Yes | Choice.No | Choice.Unknown +>x : UnknownYesNo } } function f13(x: UnknownYesNo) { ->f13 : (x: Choice.Yes | Choice.No | Choice.Unknown) => void ->x : Choice.Yes | Choice.No | Choice.Unknown ->UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown +>f13 : (x: UnknownYesNo) => void +>x : UnknownYesNo +>UnknownYesNo : UnknownYesNo if (x === Choice.Yes) { >x === Choice.Yes : boolean ->x : Choice.Yes | Choice.No | Choice.Unknown +>x : UnknownYesNo >Choice.Yes : Choice.Yes >Choice : typeof Choice >Yes : Choice.Yes @@ -374,7 +374,7 @@ function f13(x: UnknownYesNo) { } type Item = ->Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>Item : Item { kind: Choice.Yes, a: string } | >kind : Choice.Yes @@ -389,14 +389,14 @@ type Item = >b : string function f20(x: Item) { ->f20 : (x: { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; }) => string ->x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } ->Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>f20 : (x: Item) => string +>x : Item +>Item : Item switch (x.kind) { ->x.kind : Choice.Yes | Choice.No ->x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } ->kind : Choice.Yes | Choice.No +>x.kind : YesNo +>x : Item +>kind : YesNo case Choice.Yes: return x.a; >Choice.Yes : Choice.Yes @@ -417,14 +417,14 @@ function f20(x: Item) { } function f21(x: Item) { ->f21 : (x: { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; }) => string ->x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } ->Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>f21 : (x: Item) => string +>x : Item +>Item : Item switch (x.kind) { ->x.kind : Choice.Yes | Choice.No ->x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } ->kind : Choice.Yes | Choice.No +>x.kind : YesNo +>x : Item +>kind : YesNo case Choice.Yes: return x.a; >Choice.Yes : Choice.Yes diff --git a/tests/baselines/reference/enumLiteralTypes2.types b/tests/baselines/reference/enumLiteralTypes2.types index 45f5853d14080..ac493598ac1d5 100644 --- a/tests/baselines/reference/enumLiteralTypes2.types +++ b/tests/baselines/reference/enumLiteralTypes2.types @@ -7,21 +7,21 @@ const enum Choice { Unknown, Yes, No }; >No : Choice type YesNo = Choice.Yes | Choice.No; ->YesNo : Choice.Yes | Choice.No +>YesNo : YesNo >Choice : any >Yes : Choice.Yes >Choice : any >No : Choice.No type NoYes = Choice.No | Choice.Yes; ->NoYes : Choice.Yes | Choice.No +>NoYes : YesNo >Choice : any >No : Choice.No >Choice : any >Yes : Choice.Yes type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; ->UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown +>UnknownYesNo : UnknownYesNo >Choice : any >Unknown : Choice.Unknown >Choice : any @@ -33,22 +33,22 @@ function f1() { >f1 : () => void var a: YesNo; ->a : Choice.Yes | Choice.No ->YesNo : Choice.Yes | Choice.No +>a : YesNo +>YesNo : YesNo var a: NoYes; ->a : Choice.Yes | Choice.No ->NoYes : Choice.Yes | Choice.No +>a : YesNo +>NoYes : YesNo var a: Choice.Yes | Choice.No; ->a : Choice.Yes | Choice.No +>a : YesNo >Choice : any >Yes : Choice.Yes >Choice : any >No : Choice.No var a: Choice.No | Choice.Yes; ->a : Choice.Yes | Choice.No +>a : YesNo >Choice : any >No : Choice.No >Choice : any @@ -56,157 +56,157 @@ function f1() { } function f2(a: YesNo, b: UnknownYesNo, c: Choice) { ->f2 : (a: Choice.Yes | Choice.No, b: Choice.Yes | Choice.No | Choice.Unknown, c: Choice) => void ->a : Choice.Yes | Choice.No ->YesNo : Choice.Yes | Choice.No ->b : Choice.Yes | Choice.No | Choice.Unknown ->UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown +>f2 : (a: YesNo, b: UnknownYesNo, c: Choice) => void +>a : YesNo +>YesNo : YesNo +>b : UnknownYesNo +>UnknownYesNo : UnknownYesNo >c : Choice >Choice : Choice b = a; ->b = a : Choice.Yes | Choice.No ->b : Choice.Yes | Choice.No | Choice.Unknown ->a : Choice.Yes | Choice.No +>b = a : YesNo +>b : UnknownYesNo +>a : YesNo c = a; ->c = a : Choice.Yes | Choice.No +>c = a : YesNo >c : Choice ->a : Choice.Yes | Choice.No +>a : YesNo c = b; ->c = b : Choice.Yes | Choice.No +>c = b : YesNo >c : Choice ->b : Choice.Yes | Choice.No +>b : YesNo } function f3(a: Choice.Yes, b: UnknownYesNo) { ->f3 : (a: Choice.Yes, b: Choice.Yes | Choice.No | Choice.Unknown) => void +>f3 : (a: Choice.Yes, b: UnknownYesNo) => void >a : Choice.Yes >Choice : any >Yes : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown ->UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo +>UnknownYesNo : UnknownYesNo var x = a + b; >x : number >a + b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var x = a - b; >x : number >a - b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var x = a * b; >x : number >a * b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var x = a / b; >x : number >a / b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var x = a % b; >x : number >a % b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var x = a | b; >x : number >a | b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var x = a & b; >x : number >a & b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var x = a ^ b; >x : number >a ^ b : number >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var x = -b; >x : number >-b : number ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var x = ~b; >x : number >~b : number ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var y = a == b; >y : boolean >a == b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var y = a != b; >y : boolean >a != b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var y = a === b; >y : boolean >a === b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var y = a !== b; >y : boolean >a !== b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var y = a > b; >y : boolean >a > b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var y = a < b; >y : boolean >a < b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var y = a >= b; >y : boolean >a >= b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var y = a <= b; >y : boolean >a <= b : boolean >a : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var y = !b; >y : boolean >!b : boolean ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo } function f4(a: Choice.Yes, b: UnknownYesNo) { ->f4 : (a: Choice.Yes, b: Choice.Yes | Choice.No | Choice.Unknown) => void +>f4 : (a: Choice.Yes, b: UnknownYesNo) => void >a : Choice.Yes >Choice : any >Yes : Choice.Yes ->b : Choice.Yes | Choice.No | Choice.Unknown ->UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo +>UnknownYesNo : UnknownYesNo a++; >a++ : number @@ -214,7 +214,7 @@ function f4(a: Choice.Yes, b: UnknownYesNo) { b++; >b++ : number ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo } declare function g(x: Choice.Yes): string; @@ -235,11 +235,11 @@ declare function g(x: Choice): number; >Choice : Choice function f5(a: YesNo, b: UnknownYesNo, c: Choice) { ->f5 : (a: Choice.Yes | Choice.No, b: Choice.Yes | Choice.No | Choice.Unknown, c: Choice) => void ->a : Choice.Yes | Choice.No ->YesNo : Choice.Yes | Choice.No ->b : Choice.Yes | Choice.No | Choice.Unknown ->UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown +>f5 : (a: YesNo, b: UnknownYesNo, c: Choice) => void +>a : YesNo +>YesNo : YesNo +>b : UnknownYesNo +>UnknownYesNo : UnknownYesNo >c : Choice >Choice : Choice @@ -263,13 +263,13 @@ function f5(a: YesNo, b: UnknownYesNo, c: Choice) { >z3 : number >g(a) : number >g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } ->a : Choice.Yes | Choice.No +>a : YesNo var z4 = g(b); >z4 : number >g(b) : number >g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } ->b : Choice.Yes | Choice.No | Choice.Unknown +>b : UnknownYesNo var z5 = g(c); >z5 : number @@ -289,12 +289,12 @@ function assertNever(x: never): never { } function f10(x: YesNo) { ->f10 : (x: Choice.Yes | Choice.No) => string ->x : Choice.Yes | Choice.No ->YesNo : Choice.Yes | Choice.No +>f10 : (x: YesNo) => string +>x : YesNo +>YesNo : YesNo switch (x) { ->x : Choice.Yes | Choice.No +>x : YesNo case Choice.Yes: return "true"; >Choice.Yes : Choice.Yes @@ -311,12 +311,12 @@ function f10(x: YesNo) { } function f11(x: YesNo) { ->f11 : (x: Choice.Yes | Choice.No) => string ->x : Choice.Yes | Choice.No ->YesNo : Choice.Yes | Choice.No +>f11 : (x: YesNo) => string +>x : YesNo +>YesNo : YesNo switch (x) { ->x : Choice.Yes | Choice.No +>x : YesNo case Choice.Yes: return "true"; >Choice.Yes : Choice.Yes @@ -337,15 +337,15 @@ function f11(x: YesNo) { } function f12(x: UnknownYesNo) { ->f12 : (x: Choice.Yes | Choice.No | Choice.Unknown) => void ->x : Choice.Yes | Choice.No | Choice.Unknown ->UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown +>f12 : (x: UnknownYesNo) => void +>x : UnknownYesNo +>UnknownYesNo : UnknownYesNo if (x) { ->x : Choice.Yes | Choice.No | Choice.Unknown +>x : UnknownYesNo x; ->x : Choice.Yes | Choice.No +>x : YesNo } else { x; @@ -354,13 +354,13 @@ function f12(x: UnknownYesNo) { } function f13(x: UnknownYesNo) { ->f13 : (x: Choice.Yes | Choice.No | Choice.Unknown) => void ->x : Choice.Yes | Choice.No | Choice.Unknown ->UnknownYesNo : Choice.Yes | Choice.No | Choice.Unknown +>f13 : (x: UnknownYesNo) => void +>x : UnknownYesNo +>UnknownYesNo : UnknownYesNo if (x === Choice.Yes) { >x === Choice.Yes : boolean ->x : Choice.Yes | Choice.No | Choice.Unknown +>x : UnknownYesNo >Choice.Yes : Choice.Yes >Choice : typeof Choice >Yes : Choice.Yes @@ -375,7 +375,7 @@ function f13(x: UnknownYesNo) { } type Item = ->Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>Item : Item { kind: Choice.Yes, a: string } | >kind : Choice.Yes @@ -390,14 +390,14 @@ type Item = >b : string function f20(x: Item) { ->f20 : (x: { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; }) => string ->x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } ->Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>f20 : (x: Item) => string +>x : Item +>Item : Item switch (x.kind) { ->x.kind : Choice.Yes | Choice.No ->x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } ->kind : Choice.Yes | Choice.No +>x.kind : YesNo +>x : Item +>kind : YesNo case Choice.Yes: return x.a; >Choice.Yes : Choice.Yes @@ -418,14 +418,14 @@ function f20(x: Item) { } function f21(x: Item) { ->f21 : (x: { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; }) => string ->x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } ->Item : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } +>f21 : (x: Item) => string +>x : Item +>Item : Item switch (x.kind) { ->x.kind : Choice.Yes | Choice.No ->x : { kind: Choice.Yes; a: string; } | { kind: Choice.No; b: string; } ->kind : Choice.Yes | Choice.No +>x.kind : YesNo +>x : Item +>kind : YesNo case Choice.Yes: return x.a; >Choice.Yes : Choice.Yes diff --git a/tests/baselines/reference/enumLiteralTypes3.errors.txt b/tests/baselines/reference/enumLiteralTypes3.errors.txt index bfc8d5ac0d013..5517a4affe396 100644 --- a/tests/baselines/reference/enumLiteralTypes3.errors.txt +++ b/tests/baselines/reference/enumLiteralTypes3.errors.txt @@ -1,21 +1,21 @@ -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(10,5): error TS2322: Type 'Yes | No' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(10,5): error TS2322: Type 'YesNo' is not assignable to type 'Yes'. Type 'No' is not assignable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(11,5): error TS2322: Type 'Yes | No | Unknown' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(11,5): error TS2322: Type 'UnknownYesNo' is not assignable to type 'Yes'. Type 'No' is not assignable to type 'Yes'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(12,5): error TS2322: Type 'Choice' is not assignable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(18,5): error TS2322: Type 'Yes | No | Unknown' is not assignable to type 'Yes | No'. - Type 'Unknown' is not assignable to type 'Yes | No'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(19,5): error TS2322: Type 'Choice' is not assignable to type 'Yes | No'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(26,5): error TS2322: Type 'Choice' is not assignable to type 'Yes | No | Unknown'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(18,5): error TS2322: Type 'UnknownYesNo' is not assignable to type 'YesNo'. + Type 'Unknown' is not assignable to type 'YesNo'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(19,5): error TS2322: Type 'Choice' is not assignable to type 'YesNo'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(26,5): error TS2322: Type 'Choice' is not assignable to type 'UnknownYesNo'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(37,5): error TS2322: Type 'Unknown' is not assignable to type 'Yes'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(39,5): error TS2322: Type 'No' is not assignable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(40,5): error TS2322: Type 'Unknown' is not assignable to type 'Yes | No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(40,5): error TS2322: Type 'Unknown' is not assignable to type 'YesNo'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(52,5): error TS2365: Operator '===' cannot be applied to types 'Yes' and 'Unknown'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(54,5): error TS2365: Operator '===' cannot be applied to types 'Yes' and 'No'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(55,5): error TS2365: Operator '===' cannot be applied to types 'Yes | No' and 'Unknown'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(55,5): error TS2365: Operator '===' cannot be applied to types 'YesNo' and 'Unknown'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(87,14): error TS2678: Type 'Unknown' is not comparable to type 'Yes'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(89,14): error TS2678: Type 'No' is not comparable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: Type 'Unknown' is not comparable to type 'Yes | No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: Type 'Unknown' is not comparable to type 'YesNo'. ==== tests/cases/conformance/types/literal/enumLiteralTypes3.ts (15 errors) ==== @@ -30,11 +30,11 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: a = a; a = b; ~ -!!! error TS2322: Type 'Yes | No' is not assignable to type 'Yes'. +!!! error TS2322: Type 'YesNo' is not assignable to type 'Yes'. !!! error TS2322: Type 'No' is not assignable to type 'Yes'. a = c; ~ -!!! error TS2322: Type 'Yes | No | Unknown' is not assignable to type 'Yes'. +!!! error TS2322: Type 'UnknownYesNo' is not assignable to type 'Yes'. !!! error TS2322: Type 'No' is not assignable to type 'Yes'. a = d; ~ @@ -46,11 +46,11 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: b = b; b = c; ~ -!!! error TS2322: Type 'Yes | No | Unknown' is not assignable to type 'Yes | No'. -!!! error TS2322: Type 'Unknown' is not assignable to type 'Yes | No'. +!!! error TS2322: Type 'UnknownYesNo' is not assignable to type 'YesNo'. +!!! error TS2322: Type 'Unknown' is not assignable to type 'YesNo'. b = d; ~ -!!! error TS2322: Type 'Choice' is not assignable to type 'Yes | No'. +!!! error TS2322: Type 'Choice' is not assignable to type 'YesNo'. } function f3(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { @@ -59,7 +59,7 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: c = c; c = d; ~ -!!! error TS2322: Type 'Choice' is not assignable to type 'Yes | No | Unknown'. +!!! error TS2322: Type 'Choice' is not assignable to type 'UnknownYesNo'. } function f4(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { @@ -79,7 +79,7 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: !!! error TS2322: Type 'No' is not assignable to type 'Yes'. b = Choice.Unknown; ~ -!!! error TS2322: Type 'Unknown' is not assignable to type 'Yes | No'. +!!! error TS2322: Type 'Unknown' is not assignable to type 'YesNo'. b = Choice.Yes; b = Choice.No; c = Choice.Unknown; @@ -100,7 +100,7 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: !!! error TS2365: Operator '===' cannot be applied to types 'Yes' and 'No'. b === Choice.Unknown; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'Yes | No' and 'Unknown'. +!!! error TS2365: Operator '===' cannot be applied to types 'YesNo' and 'Unknown'. b === Choice.Yes; b === Choice.No; c === Choice.Unknown; @@ -147,7 +147,7 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: switch (x) { case Choice.Unknown: return x; ~~~~~~~~~~~~~~ -!!! error TS2678: Type 'Unknown' is not comparable to type 'Yes | No'. +!!! error TS2678: Type 'Unknown' is not comparable to type 'YesNo'. case Choice.Yes: return x; case Choice.No: return x; } diff --git a/tests/baselines/reference/excessPropertyErrorForFunctionTypes.errors.txt b/tests/baselines/reference/excessPropertyErrorForFunctionTypes.errors.txt index dc9d6821e5545..961308059bac7 100644 --- a/tests/baselines/reference/excessPropertyErrorForFunctionTypes.errors.txt +++ b/tests/baselines/reference/excessPropertyErrorForFunctionTypes.errors.txt @@ -1,5 +1,5 @@ -tests/cases/compiler/excessPropertyErrorForFunctionTypes.ts(4,44): error TS2322: Type '{ a: number; c: number; d: number; }' is not assignable to type '{ a: number; c: number; } | (() => any)'. - Object literal may only specify known properties, and 'd' does not exist in type '{ a: number; c: number; } | (() => any)'. +tests/cases/compiler/excessPropertyErrorForFunctionTypes.ts(4,44): error TS2322: Type '{ a: number; c: number; d: number; }' is not assignable to type 'DoesntWork'. + Object literal may only specify known properties, and 'd' does not exist in type 'DoesntWork'. ==== tests/cases/compiler/excessPropertyErrorForFunctionTypes.ts (1 errors) ==== @@ -8,5 +8,5 @@ tests/cases/compiler/excessPropertyErrorForFunctionTypes.ts(4,44): error TS2322: let doesntWork: DoesntWork = { a: 1, c: 2, d: 3 } ~~~~ -!!! error TS2322: Type '{ a: number; c: number; d: number; }' is not assignable to type '{ a: number; c: number; } | (() => any)'. -!!! error TS2322: Object literal may only specify known properties, and 'd' does not exist in type '{ a: number; c: number; } | (() => any)'. \ No newline at end of file +!!! error TS2322: Type '{ a: number; c: number; d: number; }' is not assignable to type 'DoesntWork'. +!!! error TS2322: Object literal may only specify known properties, and 'd' does not exist in type 'DoesntWork'. \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeAliases.types b/tests/baselines/reference/genericTypeAliases.types index b43e2610725a5..929ecf7d7e134 100644 --- a/tests/baselines/reference/genericTypeAliases.types +++ b/tests/baselines/reference/genericTypeAliases.types @@ -1,18 +1,18 @@ === tests/cases/conformance/types/typeAliases/genericTypeAliases.ts === type Tree = T | { left: Tree, right: Tree }; ->Tree : T | { left: T | any; right: T | any; } +>Tree : Tree >T : T >T : T ->left : T | { left: T | any; right: T | any; } ->Tree : T | { left: T | any; right: T | any; } +>left : Tree +>Tree : Tree >T : T ->right : T | { left: T | any; right: T | any; } ->Tree : T | { left: T | any; right: T | any; } +>right : Tree +>Tree : Tree >T : T var tree: Tree = { ->tree : number | { left: number | any; right: number | any; } ->Tree : T | { left: T | any; right: T | any; } +>tree : Tree +>Tree : Tree >{ left: { left: 0, right: { left: 1, right: 2 }, }, right: 3} : { left: { left: number; right: { left: number; right: number; }; }; right: number; } left: { @@ -44,76 +44,76 @@ var tree: Tree = { }; type Lazy = T | (() => T); ->Lazy : T | (() => T) +>Lazy : Lazy >T : T >T : T >T : T var ls: Lazy; ->ls : string | (() => string) ->Lazy : T | (() => T) +>ls : Lazy +>Lazy : Lazy ls = "eager"; >ls = "eager" : string ->ls : string | (() => string) +>ls : Lazy >"eager" : string ls = () => "lazy"; >ls = () => "lazy" : () => string ->ls : string | (() => string) +>ls : Lazy >() => "lazy" : () => string >"lazy" : string type Foo = T | { x: Foo }; ->Foo : T | { x: T | any; } +>Foo : Foo >T : T >T : T ->x : T | { x: T | any; } ->Foo : T | { x: T | any; } +>x : Foo +>Foo : Foo >T : T type Bar = U | { x: Bar }; ->Bar : U | { x: U | any; } +>Bar : Bar >U : U >U : U ->x : U | { x: U | any; } ->Bar : U | { x: U | any; } +>x : Bar +>Bar : Bar >U : U // Deeply instantiated generics var x: Foo; ->x : string | { x: string | any; } ->Foo : T | { x: T | any; } +>x : Foo +>Foo : Foo var y: Bar; ->y : string | { x: string | any; } ->Bar : U | { x: U | any; } +>y : Bar +>Bar : Bar x = y; ->x = y : string | { x: string | any; } ->x : string | { x: string | any; } ->y : string | { x: string | any; } +>x = y : Bar +>x : Foo +>y : Bar y = x; ->y = x : string | { x: string | any; } ->y : string | { x: string | any; } ->x : string | { x: string | any; } +>y = x : Foo +>y : Bar +>x : Foo x = "string"; >x = "string" : string ->x : string | { x: string | any; } +>x : Foo >"string" : string x = { x: "hello" }; >x = { x: "hello" } : { x: string; } ->x : string | { x: string | any; } +>x : Foo >{ x: "hello" } : { x: string; } >x : string >"hello" : string x = { x: { x: "world" } }; >x = { x: { x: "world" } } : { x: { x: string; }; } ->x : string | { x: string | any; } +>x : Foo >{ x: { x: "world" } } : { x: { x: string; }; } >x : { x: string; } >{ x: "world" } : { x: string; } @@ -121,24 +121,24 @@ x = { x: { x: "world" } }; >"world" : string var z: Foo; ->z : number | { x: number | any; } ->Foo : T | { x: T | any; } +>z : Foo +>Foo : Foo z = 42; >z = 42 : number ->z : number | { x: number | any; } +>z : Foo >42 : number z = { x: 42 }; >z = { x: 42 } : { x: number; } ->z : number | { x: number | any; } +>z : Foo >{ x: 42 } : { x: number; } >x : number >42 : number z = { x: { x: 42 } }; >z = { x: { x: 42 } } : { x: { x: number; }; } ->z : number | { x: number | any; } +>z : Foo >{ x: { x: 42 } } : { x: { x: number; }; } >x : { x: number; } >{ x: 42 } : { x: number; } @@ -215,60 +215,60 @@ p.tag = "test"; >"test" : string function f() { ->f : () => A[] | { x: A[] | any; } +>f : () => Foo >A : A type Foo = T | { x: Foo }; ->Foo : T | { x: T | any; } +>Foo : Foo >T : T >T : T ->x : T | { x: T | any; } ->Foo : T | { x: T | any; } +>x : Foo +>Foo : Foo >T : T var x: Foo; ->x : A[] | { x: A[] | any; } ->Foo : T | { x: T | any; } +>x : Foo +>Foo : Foo >A : A return x; ->x : A[] | { x: A[] | any; } +>x : Foo } function g() { ->g : () => B[] | { x: B[] | any; } +>g : () => Bar >B : B type Bar = U | { x: Bar }; ->Bar : U | { x: U | any; } +>Bar : Bar >U : U >U : U ->x : U | { x: U | any; } ->Bar : U | { x: U | any; } +>x : Bar +>Bar : Bar >U : U var x: Bar; ->x : B[] | { x: B[] | any; } ->Bar : U | { x: U | any; } +>x : Bar +>Bar : Bar >B : B return x; ->x : B[] | { x: B[] | any; } +>x : Bar } // Deeply instantiated generics var a = f(); ->a : string[] | { x: string[] | any; } ->f() : string[] | { x: string[] | any; } ->f : () => A[] | { x: A[] | any; } +>a : Foo +>f() : Foo +>f : () => Foo var b = g(); ->b : string[] | { x: string[] | any; } ->g() : string[] | { x: string[] | any; } ->g : () => B[] | { x: B[] | any; } +>b : Bar +>g() : Bar +>g : () => Bar a = b; ->a = b : string[] | { x: string[] | any; } ->a : string[] | { x: string[] | any; } ->b : string[] | { x: string[] | any; } +>a = b : Bar +>a : Foo +>b : Bar diff --git a/tests/baselines/reference/interfaceDoesNotDependOnBaseTypes.types b/tests/baselines/reference/interfaceDoesNotDependOnBaseTypes.types index cdfa40910127e..65a7ec60168dd 100644 --- a/tests/baselines/reference/interfaceDoesNotDependOnBaseTypes.types +++ b/tests/baselines/reference/interfaceDoesNotDependOnBaseTypes.types @@ -1,36 +1,36 @@ === tests/cases/conformance/types/typeAliases/interfaceDoesNotDependOnBaseTypes.ts === var x: StringTree; ->x : string | StringTreeArray ->StringTree : string | StringTreeArray +>x : StringTree +>StringTree : StringTree if (typeof x !== "string") { >typeof x !== "string" : boolean >typeof x : string ->x : string | StringTreeArray +>x : StringTree >"string" : "string" x.push(""); >x.push("") : number ->x.push : (...items: (string | StringTreeArray)[]) => number +>x.push : (...items: StringTree[]) => number >x : StringTreeArray ->push : (...items: (string | StringTreeArray)[]) => number +>push : (...items: StringTree[]) => number >"" : string x.push([""]); >x.push([""]) : number ->x.push : (...items: (string | StringTreeArray)[]) => number +>x.push : (...items: StringTree[]) => number >x : StringTreeArray ->push : (...items: (string | StringTreeArray)[]) => number +>push : (...items: StringTree[]) => number >[""] : string[] >"" : string } type StringTree = string | StringTreeArray; ->StringTree : string | StringTreeArray +>StringTree : StringTree >StringTreeArray : StringTreeArray interface StringTreeArray extends Array { } >StringTreeArray : StringTreeArray >Array : T[] ->StringTree : string | StringTreeArray +>StringTree : StringTree diff --git a/tests/baselines/reference/intersectionTypeMembers.types b/tests/baselines/reference/intersectionTypeMembers.types index 2c4fbcc5fc113..6c3217698b8fa 100644 --- a/tests/baselines/reference/intersectionTypeMembers.types +++ b/tests/baselines/reference/intersectionTypeMembers.types @@ -90,28 +90,28 @@ xyz.x.c = "hello"; >"hello" : string type F1 = (x: string) => string; ->F1 : (x: string) => string +>F1 : F1 >x : string type F2 = (x: number) => number; ->F2 : (x: number) => number +>F2 : F2 >x : number var f: F1 & F2; ->f : ((x: string) => string) & ((x: number) => number) ->F1 : (x: string) => string ->F2 : (x: number) => number +>f : F1 & F2 +>F1 : F1 +>F2 : F2 var s = f("hello"); >s : string >f("hello") : string ->f : ((x: string) => string) & ((x: number) => number) +>f : F1 & F2 >"hello" : string var n = f(42); >n : number >f(42) : number ->f : ((x: string) => string) & ((x: number) => number) +>f : F1 & F2 >42 : number interface D { diff --git a/tests/baselines/reference/intersectionTypeOverloading.types b/tests/baselines/reference/intersectionTypeOverloading.types index c478b6a08cb74..f301ef6e4b722 100644 --- a/tests/baselines/reference/intersectionTypeOverloading.types +++ b/tests/baselines/reference/intersectionTypeOverloading.types @@ -3,27 +3,27 @@ // overload resolution type F = (s: string) => string; ->F : (s: string) => string +>F : F >s : string type G = (x: any) => any; ->G : (x: any) => any +>G : G >x : any var fg: F & G; ->fg : ((s: string) => string) & ((x: any) => any) ->F : (s: string) => string ->G : (x: any) => any +>fg : F & G +>F : F +>G : G var gf: G & F; ->gf : ((x: any) => any) & ((s: string) => string) ->G : (x: any) => any ->F : (s: string) => string +>gf : G & F +>G : G +>F : F var x = fg("abc"); >x : string >fg("abc") : string ->fg : ((s: string) => string) & ((x: any) => any) +>fg : F & G >"abc" : string var x: string; @@ -32,7 +32,7 @@ var x: string; var y = gf("abc"); >y : any >gf("abc") : any ->gf : ((x: any) => any) & ((s: string) => string) +>gf : G & F >"abc" : string var y: any; diff --git a/tests/baselines/reference/literalTypes1.types b/tests/baselines/reference/literalTypes1.types index d34b5aebf9c79..faff485d45adb 100644 --- a/tests/baselines/reference/literalTypes1.types +++ b/tests/baselines/reference/literalTypes1.types @@ -79,24 +79,24 @@ function f2(x: 0 | 1 | 2) { } type Falsy = false | 0 | "" | null | undefined; ->Falsy : false | "" | 0 | null | undefined +>Falsy : Falsy >false : false >null : null function f3(x: Falsy) { ->f3 : (x: false | "" | 0 | null | undefined) => void ->x : false | "" | 0 | null | undefined ->Falsy : false | "" | 0 | null | undefined +>f3 : (x: Falsy) => void +>x : Falsy +>Falsy : Falsy if (x) { ->x : false | "" | 0 | null | undefined +>x : Falsy x; >x : never } else { x; ->x : false | "" | 0 | null | undefined +>x : Falsy } } diff --git a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.types b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.types index e0d0c492f4ddb..3851714cad8fc 100644 --- a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.types +++ b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions1.types @@ -124,9 +124,9 @@ var o = { }; o.hasOwnProperty(Symbol.hasInstance); >o.hasOwnProperty(Symbol.hasInstance) : boolean ->o.hasOwnProperty : { (v: string | number | symbol): boolean; (v: string): boolean; } +>o.hasOwnProperty : { (v: PropertyKey): boolean; (v: string): boolean; } >o : { a: number; [Symbol.hasInstance](value: any): boolean; } ->hasOwnProperty : { (v: string | number | symbol): boolean; (v: string): boolean; } +>hasOwnProperty : { (v: PropertyKey): boolean; (v: string): boolean; } >Symbol.hasInstance : symbol >Symbol : SymbolConstructor >hasInstance : symbol diff --git a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.types b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.types index 21e658e29ce44..f9c1894f86f19 100644 --- a/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.types +++ b/tests/baselines/reference/modularizeLibrary_NoErrorDuplicateLibOptions2.types @@ -124,9 +124,9 @@ var o = { }; o.hasOwnProperty(Symbol.hasInstance); >o.hasOwnProperty(Symbol.hasInstance) : boolean ->o.hasOwnProperty : { (v: string | number | symbol): boolean; (v: string): boolean; } +>o.hasOwnProperty : { (v: PropertyKey): boolean; (v: string): boolean; } >o : { a: number; [Symbol.hasInstance](value: any): boolean; } ->hasOwnProperty : { (v: string | number | symbol): boolean; (v: string): boolean; } +>hasOwnProperty : { (v: PropertyKey): boolean; (v: string): boolean; } >Symbol.hasInstance : symbol >Symbol : SymbolConstructor >hasInstance : symbol diff --git a/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.types b/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.types index 24ff905f1660f..8728176c2c1d0 100644 --- a/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.types +++ b/tests/baselines/reference/modularizeLibrary_TargetES5UsingES6Lib.types @@ -124,9 +124,9 @@ var o = { }; o.hasOwnProperty(Symbol.hasInstance); >o.hasOwnProperty(Symbol.hasInstance) : boolean ->o.hasOwnProperty : { (v: string | number | symbol): boolean; (v: string): boolean; } +>o.hasOwnProperty : { (v: PropertyKey): boolean; (v: string): boolean; } >o : { a: number; [Symbol.hasInstance](value: any): boolean; } ->hasOwnProperty : { (v: string | number | symbol): boolean; (v: string): boolean; } +>hasOwnProperty : { (v: PropertyKey): boolean; (v: string): boolean; } >Symbol.hasInstance : symbol >Symbol : SymbolConstructor >hasInstance : symbol diff --git a/tests/baselines/reference/modularizeLibrary_TargetES6UsingES6Lib.types b/tests/baselines/reference/modularizeLibrary_TargetES6UsingES6Lib.types index 7af40d3684cdb..248364f8d5513 100644 --- a/tests/baselines/reference/modularizeLibrary_TargetES6UsingES6Lib.types +++ b/tests/baselines/reference/modularizeLibrary_TargetES6UsingES6Lib.types @@ -79,9 +79,9 @@ var o = { }; o.hasOwnProperty(Symbol.hasInstance); >o.hasOwnProperty(Symbol.hasInstance) : boolean ->o.hasOwnProperty : { (v: string): boolean; (v: string | number | symbol): boolean; } +>o.hasOwnProperty : { (v: string): boolean; (v: PropertyKey): boolean; } >o : { a: number; [Symbol.hasInstance](value: any): boolean; } ->hasOwnProperty : { (v: string): boolean; (v: string | number | symbol): boolean; } +>hasOwnProperty : { (v: string): boolean; (v: PropertyKey): boolean; } >Symbol.hasInstance : symbol >Symbol : SymbolConstructor >hasInstance : symbol diff --git a/tests/baselines/reference/modularizeLibrary_UsingES5LibAndES6FeatureLibs.types b/tests/baselines/reference/modularizeLibrary_UsingES5LibAndES6FeatureLibs.types index 820c2f6dc8a93..cee8d3fb96b4e 100644 --- a/tests/baselines/reference/modularizeLibrary_UsingES5LibAndES6FeatureLibs.types +++ b/tests/baselines/reference/modularizeLibrary_UsingES5LibAndES6FeatureLibs.types @@ -17,10 +17,10 @@ var p = new Proxy(t, {}); >{} : {} Reflect.ownKeys({}); ->Reflect.ownKeys({}) : (string | number | symbol)[] ->Reflect.ownKeys : (target: any) => (string | number | symbol)[] +>Reflect.ownKeys({}) : PropertyKey[] +>Reflect.ownKeys : (target: any) => PropertyKey[] >Reflect : typeof Reflect ->ownKeys : (target: any) => (string | number | symbol)[] +>ownKeys : (target: any) => PropertyKey[] >{} : {} function* idGen() { diff --git a/tests/baselines/reference/narrowTypeByInstanceof.types b/tests/baselines/reference/narrowTypeByInstanceof.types index b98b1e4d234e0..2d4936f38079a 100644 --- a/tests/baselines/reference/narrowTypeByInstanceof.types +++ b/tests/baselines/reference/narrowTypeByInstanceof.types @@ -22,24 +22,24 @@ } type FileMatchOrMatch = FileMatch | Match; ->FileMatchOrMatch : Match | FileMatch +>FileMatchOrMatch : FileMatchOrMatch >FileMatch : FileMatch >Match : Match let elementA: FileMatchOrMatch, elementB: FileMatchOrMatch; ->elementA : Match | FileMatch ->FileMatchOrMatch : Match | FileMatch ->elementB : Match | FileMatch ->FileMatchOrMatch : Match | FileMatch +>elementA : FileMatchOrMatch +>FileMatchOrMatch : FileMatchOrMatch +>elementB : FileMatchOrMatch +>FileMatchOrMatch : FileMatchOrMatch if (elementA instanceof FileMatch && elementB instanceof FileMatch) { >elementA instanceof FileMatch && elementB instanceof FileMatch : boolean >elementA instanceof FileMatch : boolean ->elementA : Match | FileMatch +>elementA : FileMatchOrMatch >FileMatch : typeof FileMatch >elementB instanceof FileMatch : boolean ->elementB : Match | FileMatch +>elementB : FileMatchOrMatch >FileMatch : typeof FileMatch let a = elementA.resource().path; @@ -63,10 +63,10 @@ if (elementA instanceof FileMatch && elementB instanceof FileMatch) { } else if (elementA instanceof Match && elementB instanceof Match) { >elementA instanceof Match && elementB instanceof Match : boolean >elementA instanceof Match : boolean ->elementA : Match | FileMatch +>elementA : FileMatchOrMatch >Match : typeof Match >elementB instanceof Match : boolean ->elementB : Match | FileMatch +>elementB : FileMatchOrMatch >Match : typeof Match let a = elementA.range(); diff --git a/tests/baselines/reference/numericLiteralTypes1.types b/tests/baselines/reference/numericLiteralTypes1.types index 277148b1afbb8..38912e05365ef 100644 --- a/tests/baselines/reference/numericLiteralTypes1.types +++ b/tests/baselines/reference/numericLiteralTypes1.types @@ -44,17 +44,17 @@ function f1() { } type B1 = -1 | 0 | 1; ->B1 : 0 | 1 | -1 +>B1 : B1 >-1 : -1 >1 : number type B2 = 1 | 0 | -1; ->B2 : 0 | 1 | -1 +>B2 : B1 >-1 : -1 >1 : number type B3 = 0 | -1 | 1; ->B3 : 0 | 1 | -1 +>B3 : B1 >-1 : -1 >1 : number @@ -62,19 +62,19 @@ function f2() { >f2 : () => void var b: B1 = -1; ->b : 0 | 1 | -1 ->B1 : 0 | 1 | -1 +>b : B1 +>B1 : B1 >-1 : -1 >1 : number var b: B2 = 0; ->b : 0 | 1 | -1 ->B2 : 0 | 1 | -1 +>b : B1 +>B2 : B1 >0 : 0 var b: B3 = 1; ->b : 0 | 1 | -1 ->B3 : 0 | 1 | -1 +>b : B1 +>B3 : B1 >1 : 1 } @@ -418,7 +418,7 @@ function f15(x: 0 | false, y: 1 | "one") { } type Item = ->Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>Item : Item { kind: 0, a: string } | >kind : 0 @@ -433,13 +433,13 @@ type Item = >c : string function f20(x: Item) { ->f20 : (x: { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; }) => string ->x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } ->Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>f20 : (x: Item) => string +>x : Item +>Item : Item switch (x.kind) { >x.kind : 0 | 1 | 2 ->x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>x : Item >kind : 0 | 1 | 2 case 0: return x.a; @@ -463,13 +463,13 @@ function f20(x: Item) { } function f21(x: Item) { ->f21 : (x: { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; }) => string ->x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } ->Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>f21 : (x: Item) => string +>x : Item +>Item : Item switch (x.kind) { >x.kind : 0 | 1 | 2 ->x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>x : Item >kind : 0 | 1 | 2 case 0: return x.a; diff --git a/tests/baselines/reference/numericLiteralTypes2.types b/tests/baselines/reference/numericLiteralTypes2.types index d71c55fd5a2c3..13292e5f75c07 100644 --- a/tests/baselines/reference/numericLiteralTypes2.types +++ b/tests/baselines/reference/numericLiteralTypes2.types @@ -45,17 +45,17 @@ function f1() { } type B1 = -1 | 0 | 1; ->B1 : 0 | 1 | -1 +>B1 : B1 >-1 : -1 >1 : number type B2 = 1 | 0 | -1; ->B2 : 0 | 1 | -1 +>B2 : B1 >-1 : -1 >1 : number type B3 = 0 | -1 | 1; ->B3 : 0 | 1 | -1 +>B3 : B1 >-1 : -1 >1 : number @@ -63,19 +63,19 @@ function f2() { >f2 : () => void var b: B1 = -1; ->b : 0 | 1 | -1 ->B1 : 0 | 1 | -1 +>b : B1 +>B1 : B1 >-1 : -1 >1 : number var b: B2 = 0; ->b : 0 | 1 | -1 ->B2 : 0 | 1 | -1 +>b : B1 +>B2 : B1 >0 : 0 var b: B3 = 1; ->b : 0 | 1 | -1 ->B3 : 0 | 1 | -1 +>b : B1 +>B3 : B1 >1 : 1 } @@ -419,7 +419,7 @@ function f15(x: 0 | false, y: 1 | "one") { } type Item = ->Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>Item : Item { kind: 0, a: string } | >kind : 0 @@ -434,13 +434,13 @@ type Item = >c : string function f20(x: Item) { ->f20 : (x: { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; }) => string ->x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } ->Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>f20 : (x: Item) => string +>x : Item +>Item : Item switch (x.kind) { >x.kind : 0 | 1 | 2 ->x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>x : Item >kind : 0 | 1 | 2 case 0: return x.a; @@ -464,13 +464,13 @@ function f20(x: Item) { } function f21(x: Item) { ->f21 : (x: { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; }) => string ->x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } ->Item : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>f21 : (x: Item) => string +>x : Item +>Item : Item switch (x.kind) { >x.kind : 0 | 1 | 2 ->x : { kind: 0; a: string; } | { kind: 1; b: string; } | { kind: 2; c: string; } +>x : Item >kind : 0 | 1 | 2 case 0: return x.a; diff --git a/tests/baselines/reference/numericLiteralTypes3.errors.txt b/tests/baselines/reference/numericLiteralTypes3.errors.txt index 19a61bce78670..f89ea2ff10b0d 100644 --- a/tests/baselines/reference/numericLiteralTypes3.errors.txt +++ b/tests/baselines/reference/numericLiteralTypes3.errors.txt @@ -1,36 +1,36 @@ -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(8,5): error TS2322: Type '2 | 3' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(8,5): error TS2322: Type 'B' is not assignable to type '1'. Type '2' is not assignable to type '1'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(9,5): error TS2322: Type '1 | 2 | 3' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(9,5): error TS2322: Type 'C' is not assignable to type '1'. Type '2' is not assignable to type '1'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(10,5): error TS2322: Type '0 | 1 | 2' is not assignable to type '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(10,5): error TS2322: Type 'D' is not assignable to type '1'. Type '0' is not assignable to type '1'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(14,5): error TS2322: Type '1' is not assignable to type '2 | 3'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(16,5): error TS2322: Type '1 | 2 | 3' is not assignable to type '2 | 3'. - Type '1' is not assignable to type '2 | 3'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(17,5): error TS2322: Type '0 | 1 | 2' is not assignable to type '2 | 3'. - Type '0' is not assignable to type '2 | 3'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(24,5): error TS2322: Type '0 | 1 | 2' is not assignable to type '1 | 2 | 3'. - Type '0' is not assignable to type '1 | 2 | 3'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(29,5): error TS2322: Type '2 | 3' is not assignable to type '0 | 1 | 2'. - Type '3' is not assignable to type '0 | 1 | 2'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(30,5): error TS2322: Type '1 | 2 | 3' is not assignable to type '0 | 1 | 2'. - Type '3' is not assignable to type '0 | 1 | 2'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(14,5): error TS2322: Type '1' is not assignable to type 'B'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(16,5): error TS2322: Type 'C' is not assignable to type 'B'. + Type '1' is not assignable to type 'B'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(17,5): error TS2322: Type 'D' is not assignable to type 'B'. + Type '0' is not assignable to type 'B'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(24,5): error TS2322: Type 'D' is not assignable to type 'C'. + Type '0' is not assignable to type 'C'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(29,5): error TS2322: Type 'B' is not assignable to type 'D'. + Type '3' is not assignable to type 'D'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(30,5): error TS2322: Type 'C' is not assignable to type 'D'. + Type '3' is not assignable to type 'D'. tests/cases/conformance/types/literal/numericLiteralTypes3.ts(35,5): error TS2322: Type '0' is not assignable to type '1'. tests/cases/conformance/types/literal/numericLiteralTypes3.ts(37,5): error TS2322: Type '2' is not assignable to type '1'. tests/cases/conformance/types/literal/numericLiteralTypes3.ts(38,5): error TS2322: Type '3' is not assignable to type '1'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(39,5): error TS2322: Type '0' is not assignable to type '2 | 3'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(40,5): error TS2322: Type '1' is not assignable to type '2 | 3'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(43,5): error TS2322: Type '0' is not assignable to type '1 | 2 | 3'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(50,5): error TS2322: Type '3' is not assignable to type '0 | 1 | 2'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(39,5): error TS2322: Type '0' is not assignable to type 'B'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(40,5): error TS2322: Type '1' is not assignable to type 'B'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(43,5): error TS2322: Type '0' is not assignable to type 'C'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(50,5): error TS2322: Type '3' is not assignable to type 'D'. tests/cases/conformance/types/literal/numericLiteralTypes3.ts(54,5): error TS2365: Operator '===' cannot be applied to types '1' and '0'. tests/cases/conformance/types/literal/numericLiteralTypes3.ts(56,5): error TS2365: Operator '===' cannot be applied to types '1' and '2'. tests/cases/conformance/types/literal/numericLiteralTypes3.ts(57,5): error TS2365: Operator '===' cannot be applied to types '1' and '3'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(58,5): error TS2365: Operator '===' cannot be applied to types '2 | 3' and '0'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(59,5): error TS2365: Operator '===' cannot be applied to types '2 | 3' and '1'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(62,5): error TS2365: Operator '===' cannot be applied to types '1 | 2 | 3' and '0'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(69,5): error TS2365: Operator '===' cannot be applied to types '0 | 1 | 2' and '3'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(74,5): error TS2365: Operator '===' cannot be applied to types '1' and '2 | 3'. -tests/cases/conformance/types/literal/numericLiteralTypes3.ts(77,5): error TS2365: Operator '===' cannot be applied to types '2 | 3' and '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(58,5): error TS2365: Operator '===' cannot be applied to types 'B' and '0'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(59,5): error TS2365: Operator '===' cannot be applied to types 'B' and '1'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(62,5): error TS2365: Operator '===' cannot be applied to types 'C' and '0'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(69,5): error TS2365: Operator '===' cannot be applied to types 'D' and '3'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(74,5): error TS2365: Operator '===' cannot be applied to types '1' and 'B'. +tests/cases/conformance/types/literal/numericLiteralTypes3.ts(77,5): error TS2365: Operator '===' cannot be applied to types 'B' and '1'. tests/cases/conformance/types/literal/numericLiteralTypes3.ts(94,14): error TS2678: Type '1' is not comparable to type '0 | 2 | 4'. tests/cases/conformance/types/literal/numericLiteralTypes3.ts(96,14): error TS2678: Type '3' is not comparable to type '0 | 2 | 4'. tests/cases/conformance/types/literal/numericLiteralTypes3.ts(98,14): error TS2678: Type '5' is not comparable to type '0 | 2 | 4'. @@ -46,31 +46,31 @@ tests/cases/conformance/types/literal/numericLiteralTypes3.ts(98,14): error TS26 a = a; a = b; ~ -!!! error TS2322: Type '2 | 3' is not assignable to type '1'. +!!! error TS2322: Type 'B' is not assignable to type '1'. !!! error TS2322: Type '2' is not assignable to type '1'. a = c; ~ -!!! error TS2322: Type '1 | 2 | 3' is not assignable to type '1'. +!!! error TS2322: Type 'C' is not assignable to type '1'. !!! error TS2322: Type '2' is not assignable to type '1'. a = d; ~ -!!! error TS2322: Type '0 | 1 | 2' is not assignable to type '1'. +!!! error TS2322: Type 'D' is not assignable to type '1'. !!! error TS2322: Type '0' is not assignable to type '1'. } function f2(a: A, b: B, c: C, d: D) { b = a; ~ -!!! error TS2322: Type '1' is not assignable to type '2 | 3'. +!!! error TS2322: Type '1' is not assignable to type 'B'. b = b; b = c; ~ -!!! error TS2322: Type '1 | 2 | 3' is not assignable to type '2 | 3'. -!!! error TS2322: Type '1' is not assignable to type '2 | 3'. +!!! error TS2322: Type 'C' is not assignable to type 'B'. +!!! error TS2322: Type '1' is not assignable to type 'B'. b = d; ~ -!!! error TS2322: Type '0 | 1 | 2' is not assignable to type '2 | 3'. -!!! error TS2322: Type '0' is not assignable to type '2 | 3'. +!!! error TS2322: Type 'D' is not assignable to type 'B'. +!!! error TS2322: Type '0' is not assignable to type 'B'. } function f3(a: A, b: B, c: C, d: D) { @@ -79,20 +79,20 @@ tests/cases/conformance/types/literal/numericLiteralTypes3.ts(98,14): error TS26 c = c; c = d; ~ -!!! error TS2322: Type '0 | 1 | 2' is not assignable to type '1 | 2 | 3'. -!!! error TS2322: Type '0' is not assignable to type '1 | 2 | 3'. +!!! error TS2322: Type 'D' is not assignable to type 'C'. +!!! error TS2322: Type '0' is not assignable to type 'C'. } function f4(a: A, b: B, c: C, d: D) { d = a; d = b; ~ -!!! error TS2322: Type '2 | 3' is not assignable to type '0 | 1 | 2'. -!!! error TS2322: Type '3' is not assignable to type '0 | 1 | 2'. +!!! error TS2322: Type 'B' is not assignable to type 'D'. +!!! error TS2322: Type '3' is not assignable to type 'D'. d = c; ~ -!!! error TS2322: Type '1 | 2 | 3' is not assignable to type '0 | 1 | 2'. -!!! error TS2322: Type '3' is not assignable to type '0 | 1 | 2'. +!!! error TS2322: Type 'C' is not assignable to type 'D'. +!!! error TS2322: Type '3' is not assignable to type 'D'. d = d; } @@ -109,15 +109,15 @@ tests/cases/conformance/types/literal/numericLiteralTypes3.ts(98,14): error TS26 !!! error TS2322: Type '3' is not assignable to type '1'. b = 0; ~ -!!! error TS2322: Type '0' is not assignable to type '2 | 3'. +!!! error TS2322: Type '0' is not assignable to type 'B'. b = 1; ~ -!!! error TS2322: Type '1' is not assignable to type '2 | 3'. +!!! error TS2322: Type '1' is not assignable to type 'B'. b = 2; b = 3; c = 0; ~ -!!! error TS2322: Type '0' is not assignable to type '1 | 2 | 3'. +!!! error TS2322: Type '0' is not assignable to type 'C'. c = 1; c = 2; c = 3; @@ -126,7 +126,7 @@ tests/cases/conformance/types/literal/numericLiteralTypes3.ts(98,14): error TS26 d = 2; d = 3; ~ -!!! error TS2322: Type '3' is not assignable to type '0 | 1 | 2'. +!!! error TS2322: Type '3' is not assignable to type 'D'. } function f6(a: A, b: B, c: C, d: D) { @@ -142,15 +142,15 @@ tests/cases/conformance/types/literal/numericLiteralTypes3.ts(98,14): error TS26 !!! error TS2365: Operator '===' cannot be applied to types '1' and '3'. b === 0; ~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '2 | 3' and '0'. +!!! error TS2365: Operator '===' cannot be applied to types 'B' and '0'. b === 1; ~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '2 | 3' and '1'. +!!! error TS2365: Operator '===' cannot be applied to types 'B' and '1'. b === 2; b === 3; c === 0; ~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '1 | 2 | 3' and '0'. +!!! error TS2365: Operator '===' cannot be applied to types 'C' and '0'. c === 1; c === 2; c === 3; @@ -159,19 +159,19 @@ tests/cases/conformance/types/literal/numericLiteralTypes3.ts(98,14): error TS26 d === 2; d === 3; ~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '0 | 1 | 2' and '3'. +!!! error TS2365: Operator '===' cannot be applied to types 'D' and '3'. } function f7(a: A, b: B, c: C, d: D) { a === a; a === b; ~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '1' and '2 | 3'. +!!! error TS2365: Operator '===' cannot be applied to types '1' and 'B'. a === c; a === d; b === a; ~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types '2 | 3' and '1'. +!!! error TS2365: Operator '===' cannot be applied to types 'B' and '1'. b === b; b === c; b === d; diff --git a/tests/baselines/reference/operatorsAndIntersectionTypes.types b/tests/baselines/reference/operatorsAndIntersectionTypes.types index 2cf04c6549c7b..b955059fea67d 100644 --- a/tests/baselines/reference/operatorsAndIntersectionTypes.types +++ b/tests/baselines/reference/operatorsAndIntersectionTypes.types @@ -1,28 +1,28 @@ === tests/cases/conformance/types/intersection/operatorsAndIntersectionTypes.ts === type Guid = string & { $Guid }; // Tagged string type ->Guid : string & { $Guid: any; } +>Guid : Guid >$Guid : any type SerialNo = number & { $SerialNo }; // Tagged number type ->SerialNo : number & { $SerialNo: any; } +>SerialNo : SerialNo >$SerialNo : any function createGuid() { ->createGuid : () => string & { $Guid: any; } +>createGuid : () => Guid return "21EC2020-3AEA-4069-A2DD-08002B30309D" as Guid; ->"21EC2020-3AEA-4069-A2DD-08002B30309D" as Guid : string & { $Guid: any; } +>"21EC2020-3AEA-4069-A2DD-08002B30309D" as Guid : Guid >"21EC2020-3AEA-4069-A2DD-08002B30309D" : string ->Guid : string & { $Guid: any; } +>Guid : Guid } function createSerialNo() { ->createSerialNo : () => number & { $SerialNo: any; } +>createSerialNo : () => SerialNo return 12345 as SerialNo; ->12345 as SerialNo : number & { $SerialNo: any; } +>12345 as SerialNo : SerialNo >12345 : number ->SerialNo : number & { $SerialNo: any; } +>SerialNo : SerialNo } let map1: { [x: string]: number } = {}; @@ -31,15 +31,15 @@ let map1: { [x: string]: number } = {}; >{} : {} let guid = createGuid(); ->guid : string & { $Guid: any; } ->createGuid() : string & { $Guid: any; } ->createGuid : () => string & { $Guid: any; } +>guid : Guid +>createGuid() : Guid +>createGuid : () => Guid map1[guid] = 123; // Can with tagged string >map1[guid] = 123 : number >map1[guid] : number >map1 : { [x: string]: number; } ->guid : string & { $Guid: any; } +>guid : Guid >123 : number let map2: { [x: number]: string } = {}; @@ -48,15 +48,15 @@ let map2: { [x: number]: string } = {}; >{} : {} let serialNo = createSerialNo(); ->serialNo : number & { $SerialNo: any; } ->createSerialNo() : number & { $SerialNo: any; } ->createSerialNo : () => number & { $SerialNo: any; } +>serialNo : SerialNo +>createSerialNo() : SerialNo +>createSerialNo : () => SerialNo map2[serialNo] = "hello"; // Can index with tagged number >map2[serialNo] = "hello" : string >map2[serialNo] : string >map2 : { [x: number]: string; } ->serialNo : number & { $SerialNo: any; } +>serialNo : SerialNo >"hello" : string const s1 = "{" + guid + "}"; @@ -64,69 +64,69 @@ const s1 = "{" + guid + "}"; >"{" + guid + "}" : string >"{" + guid : string >"{" : string ->guid : string & { $Guid: any; } +>guid : Guid >"}" : string const s2 = guid.toLowerCase(); >s2 : string >guid.toLowerCase() : string >guid.toLowerCase : () => string ->guid : string & { $Guid: any; } +>guid : Guid >toLowerCase : () => string const s3 = guid + guid; >s3 : string >guid + guid : string ->guid : string & { $Guid: any; } ->guid : string & { $Guid: any; } +>guid : Guid +>guid : Guid const s4 = guid + serialNo; >s4 : string >guid + serialNo : string ->guid : string & { $Guid: any; } ->serialNo : number & { $SerialNo: any; } +>guid : Guid +>serialNo : SerialNo const s5 = serialNo.toPrecision(0); >s5 : string >serialNo.toPrecision(0) : string >serialNo.toPrecision : (precision?: number) => string ->serialNo : number & { $SerialNo: any; } +>serialNo : SerialNo >toPrecision : (precision?: number) => string >0 : number const n1 = serialNo * 3; >n1 : number >serialNo * 3 : number ->serialNo : number & { $SerialNo: any; } +>serialNo : SerialNo >3 : number const n2 = serialNo + serialNo; >n2 : number >serialNo + serialNo : number ->serialNo : number & { $SerialNo: any; } ->serialNo : number & { $SerialNo: any; } +>serialNo : SerialNo +>serialNo : SerialNo const b1 = guid === ""; >b1 : boolean >guid === "" : boolean ->guid : string & { $Guid: any; } +>guid : Guid >"" : "" const b2 = guid === guid; >b2 : boolean >guid === guid : boolean ->guid : string & { $Guid: any; } ->guid : string & { $Guid: any; } +>guid : Guid +>guid : Guid const b3 = serialNo === 0; >b3 : boolean >serialNo === 0 : boolean ->serialNo : number & { $SerialNo: any; } +>serialNo : SerialNo >0 : 0 const b4 = serialNo === serialNo; >b4 : boolean >serialNo === serialNo : boolean ->serialNo : number & { $SerialNo: any; } ->serialNo : number & { $SerialNo: any; } +>serialNo : SerialNo +>serialNo : SerialNo diff --git a/tests/baselines/reference/parenthesizedContexualTyping2.types b/tests/baselines/reference/parenthesizedContexualTyping2.types index a055f2f1bbd6f..aa6e1916f8144 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping2.types +++ b/tests/baselines/reference/parenthesizedContexualTyping2.types @@ -6,7 +6,7 @@ // back if contextual typing is not taking effect. type FuncType = (x: (p: T) => T) => typeof x; ->FuncType : (x: (p: T) => T) => (p: T) => T +>FuncType : FuncType >x : (p: T) => T >T : T >p : T @@ -15,27 +15,27 @@ type FuncType = (x: (p: T) => T) => typeof x; >x : (p: T) => T function fun(f: FuncType, x: T): T; ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >T : T ->f : (x: (p: T) => T) => (p: T) => T ->FuncType : (x: (p: T) => T) => (p: T) => T +>f : FuncType +>FuncType : FuncType >x : T >T : T >T : T function fun(f: FuncType, g: FuncType, x: T): T; ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >T : T ->f : (x: (p: T) => T) => (p: T) => T ->FuncType : (x: (p: T) => T) => (p: T) => T ->g : (x: (p: T) => T) => (p: T) => T ->FuncType : (x: (p: T) => T) => (p: T) => T +>f : FuncType +>FuncType : FuncType +>g : FuncType +>FuncType : FuncType >x : T >T : T >T : T function fun(...rest: any[]): T { ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >T : T >rest : any[] >T : T @@ -47,7 +47,7 @@ function fun(...rest: any[]): T { var a = fun(x => { x(undefined); return x; }, 10); >a : number >fun(x => { x(undefined); return x; }, 10) : number ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T >x(undefined) : number @@ -59,7 +59,7 @@ var a = fun(x => { x(undefined); return x; }, 10); var b = fun((x => { x(undefined); return x; }), 10); >b : number >fun((x => { x(undefined); return x; }), 10) : number ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T @@ -72,7 +72,7 @@ var b = fun((x => { x(undefined); return x; }), 10); var c = fun(((x => { x(undefined); return x; })), 10); >c : number >fun(((x => { x(undefined); return x; })), 10) : number ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T >(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T @@ -86,7 +86,7 @@ var c = fun(((x => { x(undefined); return x; })), 10); var d = fun((((x => { x(undefined); return x; }))), 10); >d : number >fun((((x => { x(undefined); return x; }))), 10) : number ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >(((x => { x(undefined); return x; }))) : (x: (p: T) => T) => (p: T) => T >((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T >(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T @@ -101,7 +101,7 @@ var d = fun((((x => { x(undefined); return x; }))), 10); var e = fun(x => { x(undefined); return x; }, x => { x(undefined); return x; }, 10); >e : number >fun(x => { x(undefined); return x; }, x => { x(undefined); return x; }, 10) : number ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T >x(undefined) : number @@ -119,7 +119,7 @@ var e = fun(x => { x(undefined); return x; }, x => { x(undefined var f = fun((x => { x(undefined); return x; }),(x => { x(undefined); return x; }), 10); >f : number >fun((x => { x(undefined); return x; }),(x => { x(undefined); return x; }), 10) : number ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T @@ -139,7 +139,7 @@ var f = fun((x => { x(undefined); return x; }),(x => { x(undefin var g = fun(((x => { x(undefined); return x; })),((x => { x(undefined); return x; })), 10); >g : number >fun(((x => { x(undefined); return x; })),((x => { x(undefined); return x; })), 10) : number ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T >(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T @@ -161,7 +161,7 @@ var g = fun(((x => { x(undefined); return x; })),((x => { x(unde var h = fun((((x => { x(undefined); return x; }))),((x => { x(undefined); return x; })), 10); >h : number >fun((((x => { x(undefined); return x; }))),((x => { x(undefined); return x; })), 10) : number ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >(((x => { x(undefined); return x; }))) : (x: (p: T) => T) => (p: T) => T >((x => { x(undefined); return x; })) : (x: (p: T) => T) => (p: T) => T >(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T @@ -185,7 +185,7 @@ var h = fun((((x => { x(undefined); return x; }))),((x => { x(un var i = fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10); >i : number >fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined), 10) : number ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >(Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined) : (x: (p: T) => T) => any >Math.random() < 0.5 ? x => { x(undefined); return x; } : x => undefined : (x: (p: T) => T) => any >Math.random() < 0.5 : boolean @@ -208,7 +208,7 @@ var i = fun((Math.random() < 0.5 ? x => { x(undefined); return x; } : x var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10); >j : number >fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), 10) : number ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >(Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)) : (x: (p: T) => T) => any >Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined) : (x: (p: T) => T) => any >Math.random() < 0.5 : boolean @@ -233,7 +233,7 @@ var j = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10); >k : number >fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)), x => { x(undefined); return x; }, 10) : number ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >(Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined)) : (x: (p: T) => T) => any >Math.random() < 0.5 ? (x => { x(undefined); return x; }) : (x => undefined) : (x: (p: T) => T) => any >Math.random() < 0.5 : boolean @@ -264,7 +264,7 @@ var k = fun((Math.random() < 0.5 ? (x => { x(undefined); return x; }) : var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10); >l : number >fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))),((x => { x(undefined); return x; })), 10) : number ->fun : { (f: (x: (p: T) => T) => (p: T) => T, x: T): T; (f: (x: (p: T) => T) => (p: T) => T, g: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>fun : { (f: FuncType, x: T): T; (f: FuncType, g: FuncType, x: T): T; } >((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)))) : (x: (p: T) => T) => any >(Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined))) : (x: (p: T) => T) => any >Math.random() < 0.5 ? ((x => { x(undefined); return x; })) : ((x => undefined)) : (x: (p: T) => T) => any @@ -298,8 +298,8 @@ var l = fun(((Math.random() < 0.5 ? ((x => { x(undefined); return x; })) >10 : number var lambda1: FuncType = x => { x(undefined); return x; }; ->lambda1 : (x: (p: T) => T) => (p: T) => T ->FuncType : (x: (p: T) => T) => (p: T) => T +>lambda1 : FuncType +>FuncType : FuncType >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T >x(undefined) : number @@ -308,8 +308,8 @@ var lambda1: FuncType = x => { x(undefined); return x; }; >x : (p: T) => T var lambda2: FuncType = (x => { x(undefined); return x; }); ->lambda2 : (x: (p: T) => T) => (p: T) => T ->FuncType : (x: (p: T) => T) => (p: T) => T +>lambda2 : FuncType +>FuncType : FuncType >(x => { x(undefined); return x; }) : (x: (p: T) => T) => (p: T) => T >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T diff --git a/tests/baselines/reference/recursiveGenericUnionType1.types b/tests/baselines/reference/recursiveGenericUnionType1.types index c153aba0e7c1e..65b1666fb4192 100644 --- a/tests/baselines/reference/recursiveGenericUnionType1.types +++ b/tests/baselines/reference/recursiveGenericUnionType1.types @@ -3,62 +3,62 @@ declare module Test1 { >Test1 : any export type Container = T | { ->Container : T | { [i: string]: T | any; } +>Container : Container >T : T >T : T [i: string]: Container; >i : string ->Container : T | { [i: string]: T | any; } +>Container : Container >T : T }; export type IStringContainer = Container; ->IStringContainer : string | { [i: string]: string | any; } ->Container : T | { [i: string]: T | any; } +>IStringContainer : Container +>Container : Container } declare module Test2 { >Test2 : any export type Container = T | { ->Container : T | { [i: string]: T | any; } +>Container : Container >T : T >T : T [i: string]: Container; >i : string ->Container : T | { [i: string]: T | any; } +>Container : Container >T : T }; export type IStringContainer = Container; ->IStringContainer : string | { [i: string]: string | any; } ->Container : T | { [i: string]: T | any; } +>IStringContainer : Container +>Container : Container } var x: Test1.Container; ->x : number | { [i: string]: number | any; } +>x : Test1.Container >Test1 : any ->Container : T | { [i: string]: T | any; } +>Container : Test1.Container var s1: Test1.IStringContainer; ->s1 : string | { [i: string]: string | any; } +>s1 : Test1.Container >Test1 : any ->IStringContainer : string | { [i: string]: string | any; } +>IStringContainer : Test1.Container var s2: Test2.IStringContainer; ->s2 : string | { [i: string]: string | any; } +>s2 : Test2.Container >Test2 : any ->IStringContainer : string | { [i: string]: string | any; } +>IStringContainer : Test2.Container s1 = s2; ->s1 = s2 : string | { [i: string]: string | any; } ->s1 : string | { [i: string]: string | any; } ->s2 : string | { [i: string]: string | any; } +>s1 = s2 : Test2.Container +>s1 : Test1.Container +>s2 : Test2.Container s2 = s1; ->s2 = s1 : string | { [i: string]: string | any; } ->s2 : string | { [i: string]: string | any; } ->s1 : string | { [i: string]: string | any; } +>s2 = s1 : Test1.Container +>s2 : Test2.Container +>s1 : Test1.Container diff --git a/tests/baselines/reference/recursiveGenericUnionType2.types b/tests/baselines/reference/recursiveGenericUnionType2.types index f98cf144780ec..2a74ba9558df0 100644 --- a/tests/baselines/reference/recursiveGenericUnionType2.types +++ b/tests/baselines/reference/recursiveGenericUnionType2.types @@ -3,62 +3,62 @@ declare module Test1 { >Test1 : any export type Container = T | { ->Container : T | { [i: string]: (T | any)[]; } +>Container : Container >T : T >T : T [i: string]: Container[]; >i : string ->Container : T | { [i: string]: (T | any)[]; } +>Container : Container >T : T }; export type IStringContainer = Container; ->IStringContainer : string | { [i: string]: (string | any)[]; } ->Container : T | { [i: string]: (T | any)[]; } +>IStringContainer : Container +>Container : Container } declare module Test2 { >Test2 : any export type Container = T | { ->Container : T | { [i: string]: (T | any)[]; } +>Container : Container >T : T >T : T [i: string]: Container[]; >i : string ->Container : T | { [i: string]: (T | any)[]; } +>Container : Container >T : T }; export type IStringContainer = Container; ->IStringContainer : string | { [i: string]: (string | any)[]; } ->Container : T | { [i: string]: (T | any)[]; } +>IStringContainer : Container +>Container : Container } var x: Test1.Container; ->x : number | { [i: string]: (number | any)[]; } +>x : Test1.Container >Test1 : any ->Container : T | { [i: string]: (T | any)[]; } +>Container : Test1.Container var s1: Test1.IStringContainer; ->s1 : string | { [i: string]: (string | any)[]; } +>s1 : Test1.Container >Test1 : any ->IStringContainer : string | { [i: string]: (string | any)[]; } +>IStringContainer : Test1.Container var s2: Test2.IStringContainer; ->s2 : string | { [i: string]: (string | any)[]; } +>s2 : Test2.Container >Test2 : any ->IStringContainer : string | { [i: string]: (string | any)[]; } +>IStringContainer : Test2.Container s1 = s2; ->s1 = s2 : string | { [i: string]: (string | any)[]; } ->s1 : string | { [i: string]: (string | any)[]; } ->s2 : string | { [i: string]: (string | any)[]; } +>s1 = s2 : Test2.Container +>s1 : Test1.Container +>s2 : Test2.Container s2 = s1; ->s2 = s1 : string | { [i: string]: (string | any)[]; } ->s2 : string | { [i: string]: (string | any)[]; } ->s1 : string | { [i: string]: (string | any)[]; } +>s2 = s1 : Test1.Container +>s2 : Test2.Container +>s1 : Test1.Container diff --git a/tests/baselines/reference/recursiveIntersectionTypes.errors.txt b/tests/baselines/reference/recursiveIntersectionTypes.errors.txt index 34a25c19712ad..84762c2cec6e8 100644 --- a/tests/baselines/reference/recursiveIntersectionTypes.errors.txt +++ b/tests/baselines/reference/recursiveIntersectionTypes.errors.txt @@ -1,6 +1,6 @@ -tests/cases/conformance/types/intersection/recursiveIntersectionTypes.ts(19,1): error TS2322: Type 'Entity & { next: Entity & any; }' is not assignable to type 'Product & { next: Product & any; }'. - Type 'Entity & { next: Entity & any; }' is not assignable to type 'Product'. - Property 'price' is missing in type 'Entity & { next: Entity & any; }'. +tests/cases/conformance/types/intersection/recursiveIntersectionTypes.ts(19,1): error TS2322: Type 'LinkedList' is not assignable to type 'LinkedList'. + Type 'LinkedList' is not assignable to type 'Product'. + Property 'price' is missing in type 'LinkedList'. ==== tests/cases/conformance/types/intersection/recursiveIntersectionTypes.ts (1 errors) ==== @@ -24,7 +24,7 @@ tests/cases/conformance/types/intersection/recursiveIntersectionTypes.ts(19,1): entityList = productList; productList = entityList; // Error ~~~~~~~~~~~ -!!! error TS2322: Type 'Entity & { next: Entity & any; }' is not assignable to type 'Product & { next: Product & any; }'. -!!! error TS2322: Type 'Entity & { next: Entity & any; }' is not assignable to type 'Product'. -!!! error TS2322: Property 'price' is missing in type 'Entity & { next: Entity & any; }'. +!!! error TS2322: Type 'LinkedList' is not assignable to type 'LinkedList'. +!!! error TS2322: Type 'LinkedList' is not assignable to type 'Product'. +!!! error TS2322: Property 'price' is missing in type 'LinkedList'. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralCheckedInIf01.types b/tests/baselines/reference/stringLiteralCheckedInIf01.types index 12da51f2b24e4..bbf83ebdaa6c7 100644 --- a/tests/baselines/reference/stringLiteralCheckedInIf01.types +++ b/tests/baselines/reference/stringLiteralCheckedInIf01.types @@ -1,21 +1,21 @@ === tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf01.ts === type S = "a" | "b"; ->S : "a" | "b" +>S : S type T = S[] | S; ->T : "a" | "b" | ("a" | "b")[] ->S : "a" | "b" ->S : "a" | "b" +>T : T +>S : S +>S : S function f(foo: T) { ->f : (foo: "a" | "b" | ("a" | "b")[]) => "a" | "b" ->foo : "a" | "b" | ("a" | "b")[] ->T : "a" | "b" | ("a" | "b")[] +>f : (foo: T) => S +>foo : T +>T : T if (foo === "a") { >foo === "a" : boolean ->foo : "a" | "b" | ("a" | "b")[] +>foo : T >"a" : "a" return foo; @@ -23,7 +23,7 @@ function f(foo: T) { } else if (foo === "b") { >foo === "b" : boolean ->foo : "b" | ("a" | "b")[] +>foo : "b" | S[] >"b" : "b" return foo; @@ -31,11 +31,11 @@ function f(foo: T) { } else { return (foo as S[])[0]; ->(foo as S[])[0] : "a" | "b" ->(foo as S[]) : ("a" | "b")[] ->foo as S[] : ("a" | "b")[] ->foo : ("a" | "b")[] ->S : "a" | "b" +>(foo as S[])[0] : S +>(foo as S[]) : S[] +>foo as S[] : S[] +>foo : S[] +>S : S >0 : number } } diff --git a/tests/baselines/reference/stringLiteralCheckedInIf02.types b/tests/baselines/reference/stringLiteralCheckedInIf02.types index a75cbaab248fb..d8e0be2f0d9cf 100644 --- a/tests/baselines/reference/stringLiteralCheckedInIf02.types +++ b/tests/baselines/reference/stringLiteralCheckedInIf02.types @@ -1,47 +1,47 @@ === tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf02.ts === type S = "a" | "b"; ->S : "a" | "b" +>S : S type T = S[] | S; ->T : "a" | "b" | ("a" | "b")[] ->S : "a" | "b" ->S : "a" | "b" +>T : T +>S : S +>S : S function isS(t: T): t is S { ->isS : (t: "a" | "b" | ("a" | "b")[]) => t is "a" | "b" ->t : "a" | "b" | ("a" | "b")[] ->T : "a" | "b" | ("a" | "b")[] +>isS : (t: T) => t is S +>t : T +>T : T >t : any ->S : "a" | "b" +>S : S return t === "a" || t === "b"; >t === "a" || t === "b" : boolean >t === "a" : boolean ->t : "a" | "b" | ("a" | "b")[] +>t : T >"a" : "a" >t === "b" : boolean ->t : "b" | ("a" | "b")[] +>t : "b" | S[] >"b" : "b" } function f(foo: T) { ->f : (foo: "a" | "b" | ("a" | "b")[]) => "a" | "b" ->foo : "a" | "b" | ("a" | "b")[] ->T : "a" | "b" | ("a" | "b")[] +>f : (foo: T) => S +>foo : T +>T : T if (isS(foo)) { >isS(foo) : boolean ->isS : (t: "a" | "b" | ("a" | "b")[]) => t is "a" | "b" ->foo : "a" | "b" | ("a" | "b")[] +>isS : (t: T) => t is S +>foo : T return foo; ->foo : "a" | "b" +>foo : S } else { return foo[0]; ->foo[0] : "a" | "b" ->foo : ("a" | "b")[] +>foo[0] : S +>foo : S[] >0 : number } } diff --git a/tests/baselines/reference/stringLiteralMatchedInSwitch01.types b/tests/baselines/reference/stringLiteralMatchedInSwitch01.types index e5a1fd5486e04..a0147779fd006 100644 --- a/tests/baselines/reference/stringLiteralMatchedInSwitch01.types +++ b/tests/baselines/reference/stringLiteralMatchedInSwitch01.types @@ -1,19 +1,19 @@ === tests/cases/conformance/types/stringLiteral/stringLiteralMatchedInSwitch01.ts === type S = "a" | "b"; ->S : "a" | "b" +>S : S type T = S[] | S; ->T : "a" | "b" | ("a" | "b")[] ->S : "a" | "b" ->S : "a" | "b" +>T : T +>S : S +>S : S var foo: T; ->foo : "a" | "b" | ("a" | "b")[] ->T : "a" | "b" | ("a" | "b")[] +>foo : T +>T : T switch (foo) { ->foo : "a" | "b" | ("a" | "b")[] +>foo : T case "a": >"a" : "a" @@ -24,13 +24,13 @@ switch (foo) { break; default: foo = (foo as S[])[0]; ->foo = (foo as S[])[0] : "a" | "b" ->foo : "a" | "b" | ("a" | "b")[] ->(foo as S[])[0] : "a" | "b" ->(foo as S[]) : ("a" | "b")[] ->foo as S[] : ("a" | "b")[] ->foo : ("a" | "b")[] ->S : "a" | "b" +>foo = (foo as S[])[0] : S +>foo : T +>(foo as S[])[0] : S +>(foo as S[]) : S[] +>foo as S[] : S[] +>foo : S[] +>S : S >0 : number break; diff --git a/tests/baselines/reference/stringLiteralTypeAssertion01.types b/tests/baselines/reference/stringLiteralTypeAssertion01.types index 6ec5bfff237c8..051b8ffc573f3 100644 --- a/tests/baselines/reference/stringLiteralTypeAssertion01.types +++ b/tests/baselines/reference/stringLiteralTypeAssertion01.types @@ -1,20 +1,20 @@ === tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts === type S = "a" | "b"; ->S : "a" | "b" +>S : S type T = S[] | S; ->T : "a" | "b" | ("a" | "b")[] ->S : "a" | "b" ->S : "a" | "b" +>T : T +>S : S +>S : S var s: S; ->s : "a" | "b" ->S : "a" | "b" +>s : S +>S : S var t: T; ->t : "a" | "b" | ("a" | "b")[] ->T : "a" | "b" | ("a" | "b")[] +>t : T +>T : T var str: string; >str : string @@ -22,62 +22,62 @@ var str: string; //////////////// s = t; ->s = t : "a" | "b" ->s : "a" | "b" ->t : "a" | "b" ->S : "a" | "b" ->t : "a" | "b" | ("a" | "b")[] +>s = t : S +>s : S +>t : S +>S : S +>t : T s = t as S; ->s = t as S : "a" | "b" ->s : "a" | "b" ->t as S : "a" | "b" ->t : "a" | "b" | ("a" | "b")[] ->S : "a" | "b" +>s = t as S : S +>s : S +>t as S : S +>t : T +>S : S s = str; ->s = str : "a" | "b" ->s : "a" | "b" ->str : "a" | "b" ->S : "a" | "b" +>s = str : S +>s : S +>str : S +>S : S >str : string s = str as S; ->s = str as S : "a" | "b" ->s : "a" | "b" ->str as S : "a" | "b" +>s = str as S : S +>s : S +>str as S : S >str : string ->S : "a" | "b" +>S : S //////////////// t = s; ->t = s : "a" | "b" | ("a" | "b")[] ->t : "a" | "b" | ("a" | "b")[] ->s : "a" | "b" | ("a" | "b")[] ->T : "a" | "b" | ("a" | "b")[] ->s : "a" | "b" +>t = s : T +>t : T +>s : T +>T : T +>s : S t = s as T; ->t = s as T : "a" | "b" | ("a" | "b")[] ->t : "a" | "b" | ("a" | "b")[] ->s as T : "a" | "b" | ("a" | "b")[] ->s : "a" | "b" ->T : "a" | "b" | ("a" | "b")[] +>t = s as T : T +>t : T +>s as T : T +>s : S +>T : T t = str; ->t = str : "a" | "b" | ("a" | "b")[] ->t : "a" | "b" | ("a" | "b")[] ->str : "a" | "b" | ("a" | "b")[] ->T : "a" | "b" | ("a" | "b")[] +>t = str : T +>t : T +>str : T +>T : T >str : string t = str as T; ->t = str as T : "a" | "b" | ("a" | "b")[] ->t : "a" | "b" | ("a" | "b")[] ->str as T : "a" | "b" | ("a" | "b")[] +>t = str as T : T +>t : T +>str as T : T >str : string ->T : "a" | "b" | ("a" | "b")[] +>T : T //////////////// @@ -85,23 +85,23 @@ str = s; >str = s : string >str : string >s : string ->s : "a" | "b" +>s : S str = s as string; >str = s as string : string >str : string >s as string : string ->s : "a" | "b" +>s : S str = t; >str = t : string >str : string >t : string ->t : "a" | "b" | ("a" | "b")[] +>t : T str = t as string; >str = t as string : string >str : string >t as string : string ->t : "a" | "b" | ("a" | "b")[] +>t : T diff --git a/tests/baselines/reference/stringLiteralTypesAndTuples01.js b/tests/baselines/reference/stringLiteralTypesAndTuples01.js index ae02d12429a39..b887213c8f6ad 100644 --- a/tests/baselines/reference/stringLiteralTypesAndTuples01.js +++ b/tests/baselines/reference/stringLiteralTypesAndTuples01.js @@ -38,5 +38,5 @@ function rawr(dino) { //// [stringLiteralTypesAndTuples01.d.ts] declare let hello: string, brave: string, newish: string, world: string; declare type RexOrRaptor = "t-rex" | "raptor"; -declare let im: "I'm", a: "a", dinosaur: "t-rex" | "raptor"; +declare let im: "I'm", a: "a", dinosaur: RexOrRaptor; declare function rawr(dino: RexOrRaptor): string; diff --git a/tests/baselines/reference/stringLiteralTypesAndTuples01.types b/tests/baselines/reference/stringLiteralTypesAndTuples01.types index 59057b85f54b1..0900d9fc745af 100644 --- a/tests/baselines/reference/stringLiteralTypesAndTuples01.types +++ b/tests/baselines/reference/stringLiteralTypesAndTuples01.types @@ -13,13 +13,13 @@ let [hello, brave, newish, world] = ["Hello", "Brave", "New", "World"]; >"World" : string type RexOrRaptor = "t-rex" | "raptor" ->RexOrRaptor : "t-rex" | "raptor" +>RexOrRaptor : RexOrRaptor let [im, a, dinosaur]: ["I'm", "a", RexOrRaptor] = ['I\'m', 'a', 't-rex']; >im : "I'm" >a : "a" ->dinosaur : "t-rex" | "raptor" ->RexOrRaptor : "t-rex" | "raptor" +>dinosaur : RexOrRaptor +>RexOrRaptor : RexOrRaptor >['I\'m', 'a', 't-rex'] : ["I'm", "a", "t-rex"] >'I\'m' : "I'm" >'a' : "a" @@ -27,17 +27,17 @@ let [im, a, dinosaur]: ["I'm", "a", RexOrRaptor] = ['I\'m', 'a', 't-rex']; rawr(dinosaur); >rawr(dinosaur) : string ->rawr : (dino: "t-rex" | "raptor") => string +>rawr : (dino: RexOrRaptor) => string >dinosaur : "t-rex" function rawr(dino: RexOrRaptor) { ->rawr : (dino: "t-rex" | "raptor") => string ->dino : "t-rex" | "raptor" ->RexOrRaptor : "t-rex" | "raptor" +>rawr : (dino: RexOrRaptor) => string +>dino : RexOrRaptor +>RexOrRaptor : RexOrRaptor if (dino === "t-rex") { >dino === "t-rex" : boolean ->dino : "t-rex" | "raptor" +>dino : RexOrRaptor >"t-rex" : "t-rex" return "ROAAAAR!"; diff --git a/tests/baselines/reference/stringLiteralTypesAsTags01.types b/tests/baselines/reference/stringLiteralTypesAsTags01.types index 64b099b34f2fa..e00fd18163dd6 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags01.types +++ b/tests/baselines/reference/stringLiteralTypesAsTags01.types @@ -1,14 +1,14 @@ === tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags01.ts === type Kind = "A" | "B" ->Kind : "A" | "B" +>Kind : Kind interface Entity { >Entity : Entity kind: Kind; ->kind : "A" | "B" ->Kind : "A" | "B" +>kind : Kind +>Kind : Kind } interface A extends Entity { @@ -34,7 +34,7 @@ interface B extends Entity { } function hasKind(entity: Entity, kind: "A"): entity is A; ->hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; } +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: Kind): entity is Entity; } >entity : Entity >Entity : Entity >kind : "A" @@ -42,7 +42,7 @@ function hasKind(entity: Entity, kind: "A"): entity is A; >A : A function hasKind(entity: Entity, kind: "B"): entity is B; ->hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; } +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: Kind): entity is Entity; } >entity : Entity >Entity : Entity >kind : "B" @@ -50,27 +50,27 @@ function hasKind(entity: Entity, kind: "B"): entity is B; >B : B function hasKind(entity: Entity, kind: Kind): entity is Entity; ->hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; } +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: Kind): entity is Entity; } >entity : Entity >Entity : Entity ->kind : "A" | "B" ->Kind : "A" | "B" +>kind : Kind +>Kind : Kind >entity : any >Entity : Entity function hasKind(entity: Entity, kind: Kind): boolean { ->hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; } +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: Kind): entity is Entity; } >entity : Entity >Entity : Entity ->kind : "A" | "B" ->Kind : "A" | "B" +>kind : Kind +>Kind : Kind return entity.kind === kind; >entity.kind === kind : boolean ->entity.kind : "A" | "B" +>entity.kind : Kind >entity : Entity ->kind : "A" | "B" ->kind : "A" | "B" +>kind : Kind +>kind : Kind } let x: A = { @@ -89,7 +89,7 @@ let x: A = { if (hasKind(x, "A")) { >hasKind(x, "A") : boolean ->hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; } +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: Kind): entity is Entity; } >x : A >"A" : "A" @@ -106,7 +106,7 @@ else { if (!hasKind(x, "B")) { >!hasKind(x, "B") : boolean >hasKind(x, "B") : boolean ->hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: "A" | "B"): entity is Entity; } +>hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; (entity: Entity, kind: Kind): entity is Entity; } >x : A >"B" : "B" diff --git a/tests/baselines/reference/stringLiteralTypesAsTags02.types b/tests/baselines/reference/stringLiteralTypesAsTags02.types index 92b294a249895..fb1632559ea90 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags02.types +++ b/tests/baselines/reference/stringLiteralTypesAsTags02.types @@ -1,14 +1,14 @@ === tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts === type Kind = "A" | "B" ->Kind : "A" | "B" +>Kind : Kind interface Entity { >Entity : Entity kind: Kind; ->kind : "A" | "B" ->Kind : "A" | "B" +>kind : Kind +>Kind : Kind } interface A extends Entity { @@ -53,18 +53,18 @@ function hasKind(entity: Entity, kind: Kind): entity is (A | B) { >hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; } >entity : Entity >Entity : Entity ->kind : "A" | "B" ->Kind : "A" | "B" +>kind : Kind +>Kind : Kind >entity : any >A : A >B : B return entity.kind === kind; >entity.kind === kind : boolean ->entity.kind : "A" | "B" +>entity.kind : Kind >entity : Entity ->kind : "A" | "B" ->kind : "A" | "B" +>kind : Kind +>kind : Kind } let x: A = { diff --git a/tests/baselines/reference/stringLiteralTypesAsTags03.types b/tests/baselines/reference/stringLiteralTypesAsTags03.types index 49ae3da4be033..05be633813b49 100644 --- a/tests/baselines/reference/stringLiteralTypesAsTags03.types +++ b/tests/baselines/reference/stringLiteralTypesAsTags03.types @@ -1,14 +1,14 @@ === tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags03.ts === type Kind = "A" | "B" ->Kind : "A" | "B" +>Kind : Kind interface Entity { >Entity : Entity kind: Kind; ->kind : "A" | "B" ->Kind : "A" | "B" +>kind : Kind +>Kind : Kind } interface A extends Entity { @@ -57,17 +57,17 @@ function hasKind(entity: Entity, kind: Kind): entity is Entity { >hasKind : { (entity: Entity, kind: "A"): entity is A; (entity: Entity, kind: "B"): entity is B; } >entity : Entity >Entity : Entity ->kind : "A" | "B" ->Kind : "A" | "B" +>kind : Kind +>Kind : Kind >entity : any >Entity : Entity return entity.kind === kind; >entity.kind === kind : boolean ->entity.kind : "A" | "B" +>entity.kind : Kind >entity : Entity ->kind : "A" | "B" ->kind : "A" | "B" +>kind : Kind +>kind : Kind } let x: A = { diff --git a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types index 963ba4239db94..05b6b9b9b7aed 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types @@ -1,21 +1,21 @@ === tests/cases/conformance/types/stringLiteral/stringLiteralTypesInUnionTypes04.ts === type T = "" | "foo"; ->T : "" | "foo" +>T : T let x: T = undefined; ->x : "" | "foo" ->T : "" | "foo" +>x : T +>T : T >undefined : undefined let y: T = undefined; ->y : "" | "foo" ->T : "" | "foo" +>y : T +>T : T >undefined : undefined if (x === "") { >x === "" : boolean ->x : "" | "foo" +>x : T >"" : "" let a = x; @@ -25,7 +25,7 @@ if (x === "") { if (x !== "") { >x !== "" : boolean ->x : "" | "foo" +>x : T >"" : "" let b = x; @@ -35,7 +35,7 @@ if (x !== "") { if (x == "") { >x == "" : boolean ->x : "" | "foo" +>x : T >"" : "" let c = x; @@ -45,7 +45,7 @@ if (x == "") { if (x != "") { >x != "" : boolean ->x : "" | "foo" +>x : T >"" : "" let d = x; @@ -54,7 +54,7 @@ if (x != "") { } if (x) { ->x : "" | "foo" +>x : T let e = x; >e : "foo" @@ -63,17 +63,17 @@ if (x) { if (!x) { >!x : boolean ->x : "" | "foo" +>x : T let f = x; ->f : "" | "foo" ->x : "" | "foo" +>f : T +>x : T } if (!!x) { >!!x : boolean >!x : boolean ->x : "" | "foo" +>x : T let g = x; >g : "foo" @@ -84,9 +84,9 @@ if (!!!x) { >!!!x : boolean >!!x : boolean >!x : boolean ->x : "" | "foo" +>x : T let h = x; ->h : "" | "foo" ->x : "" | "foo" +>h : T +>x : T } diff --git a/tests/baselines/reference/stringLiteralTypesOverloads01.js b/tests/baselines/reference/stringLiteralTypesOverloads01.js index ef441a4098566..dd050b5e4646c 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads01.js +++ b/tests/baselines/reference/stringLiteralTypesOverloads01.js @@ -109,6 +109,6 @@ 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 stringOrBooleanOrNumber: PrimitiveName; declare namespace Consts2 { } diff --git a/tests/baselines/reference/stringLiteralTypesOverloads01.types b/tests/baselines/reference/stringLiteralTypesOverloads01.types index dff55fc08fb54..3b9df5c006675 100644 --- a/tests/baselines/reference/stringLiteralTypesOverloads01.types +++ b/tests/baselines/reference/stringLiteralTypesOverloads01.types @@ -1,44 +1,44 @@ === tests/cases/conformance/types/stringLiteral/stringLiteralTypesOverloads01.ts === type PrimitiveName = 'string' | 'number' | 'boolean'; ->PrimitiveName : "string" | "number" | "boolean" +>PrimitiveName : PrimitiveName function getFalsyPrimitive(x: "string"): string; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >x : "string" function getFalsyPrimitive(x: "number"): number; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >x : "number" function getFalsyPrimitive(x: "boolean"): boolean; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >x : "boolean" function getFalsyPrimitive(x: "boolean" | "string"): boolean | string; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >x : "string" | "boolean" function getFalsyPrimitive(x: "boolean" | "number"): boolean | number; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >x : "number" | "boolean" function getFalsyPrimitive(x: "number" | "string"): number | string; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >x : "string" | "number" function getFalsyPrimitive(x: "number" | "string" | "boolean"): number | string | boolean; ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } ->x : "string" | "number" | "boolean" +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } +>x : PrimitiveName function getFalsyPrimitive(x: PrimitiveName): number | string | boolean { ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } ->x : "string" | "number" | "boolean" ->PrimitiveName : "string" | "number" | "boolean" +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } +>x : PrimitiveName +>PrimitiveName : PrimitiveName if (x === "string") { >x === "string" : boolean ->x : "string" | "number" | "boolean" +>x : PrimitiveName >"string" : "string" return ""; @@ -72,19 +72,19 @@ namespace Consts1 { const EMPTY_STRING = getFalsyPrimitive("string"); >EMPTY_STRING : string >getFalsyPrimitive("string") : string ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >"string" : "string" const ZERO = getFalsyPrimitive('number'); >ZERO : number >getFalsyPrimitive('number') : number ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >'number' : "number" const FALSE = getFalsyPrimitive("boolean"); >FALSE : boolean >getFalsyPrimitive("boolean") : boolean ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >"boolean" : "boolean" } @@ -119,8 +119,8 @@ const booleanOrNumber = number || boolean; >boolean : "boolean" const stringOrBooleanOrNumber = stringOrBoolean || number; ->stringOrBooleanOrNumber : "string" | "number" | "boolean" ->stringOrBoolean || number : "string" | "number" | "boolean" +>stringOrBooleanOrNumber : PrimitiveName +>stringOrBoolean || number : PrimitiveName >stringOrBoolean : "string" | "boolean" >number : "number" @@ -130,44 +130,44 @@ namespace Consts2 { const EMPTY_STRING = getFalsyPrimitive(string); >EMPTY_STRING : string >getFalsyPrimitive(string) : string ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >string : "string" const ZERO = getFalsyPrimitive(number); >ZERO : number >getFalsyPrimitive(number) : number ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >number : "number" const FALSE = getFalsyPrimitive(boolean); >FALSE : boolean >getFalsyPrimitive(boolean) : boolean ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >boolean : "boolean" const a = getFalsyPrimitive(stringOrNumber); >a : string | number >getFalsyPrimitive(stringOrNumber) : string | number ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >stringOrNumber : "string" | "number" const b = getFalsyPrimitive(stringOrBoolean); >b : string | boolean >getFalsyPrimitive(stringOrBoolean) : string | boolean ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >stringOrBoolean : "string" | "boolean" const c = getFalsyPrimitive(booleanOrNumber); >c : number | boolean >getFalsyPrimitive(booleanOrNumber) : number | boolean ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } >booleanOrNumber : "number" | "boolean" const d = getFalsyPrimitive(stringOrBooleanOrNumber); >d : string | number | boolean >getFalsyPrimitive(stringOrBooleanOrNumber) : string | number | boolean ->getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: "string" | "number" | "boolean"): string | number | boolean; } ->stringOrBooleanOrNumber : "string" | "number" | "boolean" +>getFalsyPrimitive : { (x: "string"): string; (x: "number"): number; (x: "boolean"): boolean; (x: "string" | "boolean"): string | boolean; (x: "number" | "boolean"): number | boolean; (x: "string" | "number"): string | number; (x: PrimitiveName): string | number | boolean; } +>stringOrBooleanOrNumber : PrimitiveName } diff --git a/tests/baselines/reference/stringLiteralTypesTypePredicates01.types b/tests/baselines/reference/stringLiteralTypesTypePredicates01.types index 4a765ea531295..822103b86f571 100644 --- a/tests/baselines/reference/stringLiteralTypesTypePredicates01.types +++ b/tests/baselines/reference/stringLiteralTypesTypePredicates01.types @@ -1,44 +1,44 @@ === tests/cases/conformance/types/stringLiteral/stringLiteralTypesTypePredicates01.ts === type Kind = "A" | "B" ->Kind : "A" | "B" +>Kind : Kind function kindIs(kind: Kind, is: "A"): kind is "A"; ->kindIs : { (kind: "A" | "B", is: "A"): kind is "A"; (kind: "A" | "B", is: "B"): kind is "B"; } ->kind : "A" | "B" ->Kind : "A" | "B" +>kindIs : { (kind: Kind, is: "A"): kind is "A"; (kind: Kind, is: "B"): kind is "B"; } +>kind : Kind +>Kind : Kind >is : "A" >kind : any function kindIs(kind: Kind, is: "B"): kind is "B"; ->kindIs : { (kind: "A" | "B", is: "A"): kind is "A"; (kind: "A" | "B", is: "B"): kind is "B"; } ->kind : "A" | "B" ->Kind : "A" | "B" +>kindIs : { (kind: Kind, is: "A"): kind is "A"; (kind: Kind, is: "B"): kind is "B"; } +>kind : Kind +>Kind : Kind >is : "B" >kind : any function kindIs(kind: Kind, is: Kind): boolean { ->kindIs : { (kind: "A" | "B", is: "A"): kind is "A"; (kind: "A" | "B", is: "B"): kind is "B"; } ->kind : "A" | "B" ->Kind : "A" | "B" ->is : "A" | "B" ->Kind : "A" | "B" +>kindIs : { (kind: Kind, is: "A"): kind is "A"; (kind: Kind, is: "B"): kind is "B"; } +>kind : Kind +>Kind : Kind +>is : Kind +>Kind : Kind return kind === is; >kind === is : boolean ->kind : "A" | "B" ->is : "A" | "B" +>kind : Kind +>is : Kind } var x: Kind = undefined; ->x : "A" | "B" ->Kind : "A" | "B" +>x : Kind +>Kind : Kind >undefined : undefined if (kindIs(x, "A")) { >kindIs(x, "A") : boolean ->kindIs : { (kind: "A" | "B", is: "A"): kind is "A"; (kind: "A" | "B", is: "B"): kind is "B"; } ->x : "A" | "B" +>kindIs : { (kind: Kind, is: "A"): kind is "A"; (kind: Kind, is: "B"): kind is "B"; } +>x : Kind >"A" : "A" let a = x; @@ -54,8 +54,8 @@ else { if (!kindIs(x, "B")) { >!kindIs(x, "B") : boolean >kindIs(x, "B") : boolean ->kindIs : { (kind: "A" | "B", is: "A"): kind is "A"; (kind: "A" | "B", is: "B"): kind is "B"; } ->x : "A" | "B" +>kindIs : { (kind: Kind, is: "A"): kind is "A"; (kind: Kind, is: "B"): kind is "B"; } +>x : Kind >"B" : "B" let c = x; diff --git a/tests/baselines/reference/taggedTemplateContextualTyping1.types b/tests/baselines/reference/taggedTemplateContextualTyping1.types index 93ca81f8446fb..2ccf8798dfd79 100644 --- a/tests/baselines/reference/taggedTemplateContextualTyping1.types +++ b/tests/baselines/reference/taggedTemplateContextualTyping1.types @@ -1,7 +1,7 @@ === tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping1.ts === type FuncType = (x: (p: T) => T) => typeof x; ->FuncType : (x: (p: T) => T) => (p: T) => T +>FuncType : FuncType >x : (p: T) => T >T : T >p : T @@ -10,31 +10,31 @@ type FuncType = (x: (p: T) => T) => typeof x; >x : (p: T) => T function tempTag1(templateStrs: TemplateStringsArray, f: FuncType, x: T): T; ->tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>tempTag1 : { (templateStrs: TemplateStringsArray, f: FuncType, x: T): T; (templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T; } >T : T >templateStrs : TemplateStringsArray >TemplateStringsArray : TemplateStringsArray ->f : (x: (p: T) => T) => (p: T) => T ->FuncType : (x: (p: T) => T) => (p: T) => T +>f : FuncType +>FuncType : FuncType >x : T >T : T >T : T function tempTag1(templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T; ->tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>tempTag1 : { (templateStrs: TemplateStringsArray, f: FuncType, x: T): T; (templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T; } >T : T >templateStrs : TemplateStringsArray >TemplateStringsArray : TemplateStringsArray ->f : (x: (p: T) => T) => (p: T) => T ->FuncType : (x: (p: T) => T) => (p: T) => T ->h : (x: (p: T) => T) => (p: T) => T ->FuncType : (x: (p: T) => T) => (p: T) => T +>f : FuncType +>FuncType : FuncType +>h : FuncType +>FuncType : FuncType >x : T >T : T >T : T function tempTag1(...rest: any[]): T { ->tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>tempTag1 : { (templateStrs: TemplateStringsArray, f: FuncType, x: T): T; (templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T; } >T : T >rest : any[] >T : T @@ -49,7 +49,7 @@ function tempTag1(...rest: any[]): T { // so this test will error. tempTag1 `${ x => { x(undefined); return x; } }${ 10 }`; >tempTag1 `${ x => { x(undefined); return x; } }${ 10 }` : number ->tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>tempTag1 : { (templateStrs: TemplateStringsArray, f: FuncType, x: T): T; (templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T; } >`${ x => { x(undefined); return x; } }${ 10 }` : string >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T @@ -61,7 +61,7 @@ tempTag1 `${ x => { x(undefined); return x; } }${ 10 } tempTag1 `${ x => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ 10 }`; >tempTag1 `${ x => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ 10 }` : number ->tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>tempTag1 : { (templateStrs: TemplateStringsArray, f: FuncType, x: T): T; (templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T; } >`${ x => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ 10 }` : string >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T @@ -79,7 +79,7 @@ tempTag1 `${ x => { x(undefined); return x; } }${ y => tempTag1 `${ x => { x(undefined); return x; } }${ (y: (p: T) => T) => { y(undefined); return y } }${ undefined }`; >tempTag1 `${ x => { x(undefined); return x; } }${ (y: (p: T) => T) => { y(undefined); return y } }${ undefined }` : any ->tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>tempTag1 : { (templateStrs: TemplateStringsArray, f: FuncType, x: T): T; (templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T; } >`${ x => { x(undefined); return x; } }${ (y: (p: T) => T) => { y(undefined); return y } }${ undefined }` : string >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T @@ -101,7 +101,7 @@ tempTag1 `${ x => { x(undefined); return x; } }${ (y: tempTag1 `${ (x: (p: T) => T) => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ undefined }`; >tempTag1 `${ (x: (p: T) => T) => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ undefined }` : any ->tempTag1 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: T): T; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: T): T; } +>tempTag1 : { (templateStrs: TemplateStringsArray, f: FuncType, x: T): T; (templateStrs: TemplateStringsArray, f: FuncType, h: FuncType, x: T): T; } >`${ (x: (p: T) => T) => { x(undefined); return x; } }${ y => { y(undefined); return y; } }${ undefined }` : string >(x: (p: T) => T) => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T diff --git a/tests/baselines/reference/taggedTemplateContextualTyping2.types b/tests/baselines/reference/taggedTemplateContextualTyping2.types index 8fcfc02c62b69..02dcbd2275380 100644 --- a/tests/baselines/reference/taggedTemplateContextualTyping2.types +++ b/tests/baselines/reference/taggedTemplateContextualTyping2.types @@ -1,7 +1,7 @@ === tests/cases/conformance/expressions/contextualTyping/taggedTemplateContextualTyping2.ts === type FuncType1 = (x: (p: T) => T) => typeof x; ->FuncType1 : (x: (p: T) => T) => (p: T) => T +>FuncType1 : FuncType1 >x : (p: T) => T >T : T >p : T @@ -10,7 +10,7 @@ type FuncType1 = (x: (p: T) => T) => typeof x; >x : (p: T) => T type FuncType2 = (x: (p: T) => T) => typeof x; ->FuncType2 : (x: (p: T) => T) => (p: T) => T +>FuncType2 : FuncType2 >x : (p: T) => T >S : S >T : T @@ -20,25 +20,25 @@ type FuncType2 = (x: (p: T) => T) => typeof x; >x : (p: T) => T function tempTag2(templateStrs: TemplateStringsArray, f: FuncType1, x: number): number; ->tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: string): string; } +>tempTag2 : { (templateStrs: TemplateStringsArray, f: FuncType1, x: number): number; (templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string; } >templateStrs : TemplateStringsArray >TemplateStringsArray : TemplateStringsArray ->f : (x: (p: T) => T) => (p: T) => T ->FuncType1 : (x: (p: T) => T) => (p: T) => T +>f : FuncType1 +>FuncType1 : FuncType1 >x : number function tempTag2(templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string; ->tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: string): string; } +>tempTag2 : { (templateStrs: TemplateStringsArray, f: FuncType1, x: number): number; (templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string; } >templateStrs : TemplateStringsArray >TemplateStringsArray : TemplateStringsArray ->f : (x: (p: T) => T) => (p: T) => T ->FuncType2 : (x: (p: T) => T) => (p: T) => T ->h : (x: (p: T) => T) => (p: T) => T ->FuncType2 : (x: (p: T) => T) => (p: T) => T +>f : FuncType2 +>FuncType2 : FuncType2 +>h : FuncType2 +>FuncType2 : FuncType2 >x : string function tempTag2(...rest: any[]): any { ->tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: string): string; } +>tempTag2 : { (templateStrs: TemplateStringsArray, f: FuncType1, x: number): number; (templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string; } >rest : any[] return undefined; @@ -51,7 +51,7 @@ function tempTag2(...rest: any[]): any { // so this test will error. tempTag2 `${ x => { x(undefined); return x; } }${ 0 }`; >tempTag2 `${ x => { x(undefined); return x; } }${ 0 }` : number ->tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: string): string; } +>tempTag2 : { (templateStrs: TemplateStringsArray, f: FuncType1, x: number): number; (templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string; } >`${ x => { x(undefined); return x; } }${ 0 }` : string >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T @@ -63,7 +63,7 @@ tempTag2 `${ x => { x(undefined); return x; } }${ 0 }`; tempTag2 `${ x => { x(undefined); return x; } }${ y => { y(null); return y; } }${ "hello" }`; >tempTag2 `${ x => { x(undefined); return x; } }${ y => { y(null); return y; } }${ "hello" }` : string ->tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: string): string; } +>tempTag2 : { (templateStrs: TemplateStringsArray, f: FuncType1, x: number): number; (templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string; } >`${ x => { x(undefined); return x; } }${ y => { y(null); return y; } }${ "hello" }` : string >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T @@ -81,7 +81,7 @@ tempTag2 `${ x => { x(undefined); return x; } }${ y => { y { x(undefined); return x; } }${ undefined }${ "hello" }`; >tempTag2 `${ x => { x(undefined); return x; } }${ undefined }${ "hello" }` : string ->tempTag2 : { (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, x: number): number; (templateStrs: TemplateStringsArray, f: (x: (p: T) => T) => (p: T) => T, h: (x: (p: T) => T) => (p: T) => T, x: string): string; } +>tempTag2 : { (templateStrs: TemplateStringsArray, f: FuncType1, x: number): number; (templateStrs: TemplateStringsArray, f: FuncType2, h: FuncType2, x: string): string; } >`${ x => { x(undefined); return x; } }${ undefined }${ "hello" }` : string >x => { x(undefined); return x; } : (x: (p: T) => T) => (p: T) => T >x : (p: T) => T diff --git a/tests/baselines/reference/typeAliasDeclarationEmit.types b/tests/baselines/reference/typeAliasDeclarationEmit.types index 6f9359e36f5c6..cc7d5f9a3422e 100644 --- a/tests/baselines/reference/typeAliasDeclarationEmit.types +++ b/tests/baselines/reference/typeAliasDeclarationEmit.types @@ -1,13 +1,13 @@ === tests/cases/compiler/typeAliasDeclarationEmit.ts === export type callback = () => T; ->callback : () => T +>callback : callback >T : T >T : T export type CallbackArray = () => T; ->CallbackArray : () => T +>CallbackArray : CallbackArray >T : T ->callback : () => T +>callback : callback >T : T diff --git a/tests/baselines/reference/typeAliasDoesntMakeModuleInstantiated.types b/tests/baselines/reference/typeAliasDoesntMakeModuleInstantiated.types index 45ddf8cd949a4..f112db28e7f85 100644 --- a/tests/baselines/reference/typeAliasDoesntMakeModuleInstantiated.types +++ b/tests/baselines/reference/typeAliasDoesntMakeModuleInstantiated.types @@ -4,7 +4,7 @@ declare module m { // type alias declaration here shouldnt make the module declaration instantiated type Selector = string| string[] |Function; ->Selector : string | Function | string[] +>Selector : Selector >Function : Function export interface IStatic { diff --git a/tests/baselines/reference/typeAliases.types b/tests/baselines/reference/typeAliases.types index c762a568b3228..d6bce143c9b26 100644 --- a/tests/baselines/reference/typeAliases.types +++ b/tests/baselines/reference/typeAliases.types @@ -94,14 +94,14 @@ var x8: T8; >T8 : string | boolean type T9 = () => string; ->T9 : () => string +>T9 : T9 var x9: () => string; >x9 : () => string var x9: T9; >x9 : () => string ->T9 : () => string +>T9 : T9 type T10 = { x: number }; >T10 : { x: number; } diff --git a/tests/baselines/reference/typeArgumentInferenceWithRecursivelyReferencedTypeAliasToTypeLiteral01.types b/tests/baselines/reference/typeArgumentInferenceWithRecursivelyReferencedTypeAliasToTypeLiteral01.types index ea821607211d0..5269bd9b5186c 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithRecursivelyReferencedTypeAliasToTypeLiteral01.types +++ b/tests/baselines/reference/typeArgumentInferenceWithRecursivelyReferencedTypeAliasToTypeLiteral01.types @@ -1,27 +1,27 @@ === tests/cases/compiler/typeArgumentInferenceWithRecursivelyReferencedTypeAliasToTypeLiteral01.ts === type TreeNode = { ->TreeNode : { name: string; parent: TreeNode; } +>TreeNode : TreeNode name: string; >name : string parent: TreeNode; ->parent : { name: string; parent: TreeNode; } ->TreeNode : { name: string; parent: TreeNode; } +>parent : TreeNode +>TreeNode : TreeNode } var nodes: TreeNode[]; ->nodes : { name: string; parent: TreeNode; }[] ->TreeNode : { name: string; parent: TreeNode; } +>nodes : TreeNode[] +>TreeNode : TreeNode nodes.map(n => n.name); >nodes.map(n => n.name) : string[] ->nodes.map : (callbackfn: (value: { name: string; parent: TreeNode; }, index: number, array: { name: string; parent: TreeNode; }[]) => U, thisArg?: any) => U[] ->nodes : { name: string; parent: TreeNode; }[] ->map : (callbackfn: (value: { name: string; parent: TreeNode; }, index: number, array: { name: string; parent: TreeNode; }[]) => U, thisArg?: any) => U[] ->n => n.name : (n: { name: string; parent: TreeNode; }) => string ->n : { name: string; parent: TreeNode; } +>nodes.map : (callbackfn: (value: TreeNode, index: number, array: TreeNode[]) => U, thisArg?: any) => U[] +>nodes : TreeNode[] +>map : (callbackfn: (value: TreeNode, index: number, array: TreeNode[]) => U, thisArg?: any) => U[] +>n => n.name : (n: TreeNode) => string +>n : TreeNode >n.name : string ->n : { name: string; parent: TreeNode; } +>n : TreeNode >name : string diff --git a/tests/baselines/reference/typeArgumentInferenceWithRecursivelyReferencedTypeAliasToTypeLiteral02.types b/tests/baselines/reference/typeArgumentInferenceWithRecursivelyReferencedTypeAliasToTypeLiteral02.types index d18cf3a2b1dc2..fec665f3f616a 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithRecursivelyReferencedTypeAliasToTypeLiteral02.types +++ b/tests/baselines/reference/typeArgumentInferenceWithRecursivelyReferencedTypeAliasToTypeLiteral02.types @@ -1,38 +1,38 @@ === tests/cases/compiler/typeArgumentInferenceWithRecursivelyReferencedTypeAliasToTypeLiteral02.ts === type TreeNode = { ->TreeNode : { name: string; parent: TreeNode; } +>TreeNode : TreeNode name: string; >name : string parent: TreeNode; ->parent : { name: string; parent: TreeNode; } ->TreeNode : { name: string; parent: TreeNode; } +>parent : TreeNode +>TreeNode : TreeNode } type TreeNodeMiddleman = { ->TreeNodeMiddleman : { name: string; parent: { name: string; parent: TreeNode; }; } +>TreeNodeMiddleman : { name: string; parent: TreeNode; } name: string; >name : string parent: TreeNode; ->parent : { name: string; parent: TreeNode; } ->TreeNode : { name: string; parent: TreeNode; } +>parent : TreeNode +>TreeNode : TreeNode } var nodes: TreeNodeMiddleman[]; ->nodes : { name: string; parent: { name: string; parent: TreeNode; }; }[] ->TreeNodeMiddleman : { name: string; parent: { name: string; parent: TreeNode; }; } +>nodes : { name: string; parent: TreeNode; }[] +>TreeNodeMiddleman : { name: string; parent: TreeNode; } nodes.map(n => n.name); >nodes.map(n => n.name) : string[] ->nodes.map : (callbackfn: (value: { name: string; parent: { name: string; parent: TreeNode; }; }, index: number, array: { name: string; parent: { name: string; parent: TreeNode; }; }[]) => U, thisArg?: any) => U[] ->nodes : { name: string; parent: { name: string; parent: TreeNode; }; }[] ->map : (callbackfn: (value: { name: string; parent: { name: string; parent: TreeNode; }; }, index: number, array: { name: string; parent: { name: string; parent: TreeNode; }; }[]) => U, thisArg?: any) => U[] ->n => n.name : (n: { name: string; parent: { name: string; parent: TreeNode; }; }) => string ->n : { name: string; parent: { name: string; parent: TreeNode; }; } +>nodes.map : (callbackfn: (value: { name: string; parent: TreeNode; }, index: number, array: { name: string; parent: TreeNode; }[]) => U, thisArg?: any) => U[] +>nodes : { name: string; parent: TreeNode; }[] +>map : (callbackfn: (value: { name: string; parent: TreeNode; }, index: number, array: { name: string; parent: TreeNode; }[]) => U, thisArg?: any) => U[] +>n => n.name : (n: { name: string; parent: TreeNode; }) => string +>n : { name: string; parent: TreeNode; } >n.name : string ->n : { name: string; parent: { name: string; parent: TreeNode; }; } +>n : { name: string; parent: TreeNode; } >name : string diff --git a/tests/baselines/reference/typeGuardsAsAssertions.types b/tests/baselines/reference/typeGuardsAsAssertions.types index f24929a534869..34d3b296a48db 100644 --- a/tests/baselines/reference/typeGuardsAsAssertions.types +++ b/tests/baselines/reference/typeGuardsAsAssertions.types @@ -6,7 +6,7 @@ let cond: boolean; >cond : boolean export type Optional = Some | None; ->Optional : Some | None +>Optional : Optional >a : a >Some : Some >a : a @@ -30,10 +30,10 @@ export const none : None = { none: '' }; >'' : string export function isSome(value: Optional): value is Some { ->isSome : (value: None | Some) => value is Some +>isSome : (value: Optional) => value is Some >a : a ->value : None | Some ->Optional : Some | None +>value : Optional +>Optional : Optional >a : a >value : any >Some : Some @@ -42,7 +42,7 @@ export function isSome(value: Optional): value is Some { return 'some' in value; >'some' in value : boolean >'some' : string ->value : None | Some +>value : Optional } function someFrom(some: a) { @@ -63,8 +63,8 @@ export function fn(makeSome: () => r): void { >r : r let result: Optional = none; ->result : None | Some ->Optional : Some | None +>result : Optional +>Optional : Optional >r : r >none : None @@ -75,17 +75,17 @@ export function fn(makeSome: () => r): void { >cond : boolean result; // Some | None ->result : None | Some +>result : Optional result = someFrom(isSome(result) ? result.some : makeSome()); >result = someFrom(isSome(result) ? result.some : makeSome()) : { some: r; } ->result : None | Some +>result : Optional >someFrom(isSome(result) ? result.some : makeSome()) : { some: r; } >someFrom : (some: a) => { some: a; } >isSome(result) ? result.some : makeSome() : r >isSome(result) : boolean ->isSome : (value: None | Some) => value is Some ->result : None | Some +>isSome : (value: Optional) => value is Some +>result : Optional >result.some : r >result : Some >some : r diff --git a/tests/baselines/reference/unionAndIntersectionInference1.types b/tests/baselines/reference/unionAndIntersectionInference1.types index f3cf3611d7586..3dc97d01a486d 100644 --- a/tests/baselines/reference/unionAndIntersectionInference1.types +++ b/tests/baselines/reference/unionAndIntersectionInference1.types @@ -146,7 +146,7 @@ function baz1(value: void|a): void { // Repro from #5417 type Maybe = T | void; ->Maybe : void | T +>Maybe : Maybe >T : T >T : T @@ -162,15 +162,15 @@ function get(x: U | void): U { } let foo: Maybe; ->foo : string | void ->Maybe : void | T +>foo : Maybe +>Maybe : Maybe get(foo).toUpperCase(); // Ok >get(foo).toUpperCase() : string >get(foo).toUpperCase : () => string >get(foo) : string >get : (x: void | U) => U ->foo : string | void +>foo : Maybe >toUpperCase : () => string // Repro from #5456 diff --git a/tests/baselines/reference/unusedLocalsAndParametersTypeAliases.types b/tests/baselines/reference/unusedLocalsAndParametersTypeAliases.types index 3dd7b3d1b2dbd..2695b9b429a86 100644 --- a/tests/baselines/reference/unusedLocalsAndParametersTypeAliases.types +++ b/tests/baselines/reference/unusedLocalsAndParametersTypeAliases.types @@ -2,28 +2,28 @@ // used in a declaration type handler1 = () => void; ->handler1 : () => void +>handler1 : handler1 export interface I1 { >I1 : I1 getHandler: handler1; ->getHandler : () => void ->handler1 : () => void +>getHandler : handler1 +>handler1 : handler1 } // exported export type handler2 = () => void; ->handler2 : () => void +>handler2 : handler2 // used in extends clause type handler3 = () => void; ->handler3 : () => void +>handler3 : handler3 export interface I3 { >I3 : I3 >T : T ->handler3 : () => void +>handler3 : handler3 getHandler: T; >getHandler : T @@ -32,32 +32,32 @@ export interface I3 { // used in another type alias declaration type handler4 = () => void; ->handler4 : () => void +>handler4 : handler4 type handler5 = handler4 | (()=>number); ->handler5 : (() => void) | (() => number) ->handler4 : () => void +>handler5 : handler5 +>handler4 : handler4 var x: handler5; ->x : (() => void) | (() => number) ->handler5 : (() => void) | (() => number) +>x : handler5 +>handler5 : handler5 x(); >x() : number | void ->x : (() => void) | (() => number) +>x : handler5 // used as type argument type handler6 = () => void; ->handler6 : () => void +>handler6 : handler6 var y: Array; ->y : (() => void)[] +>y : handler6[] >Array : T[] ->handler6 : () => void +>handler6 : handler6 y[0](); >y[0]() : void ->y[0] : () => void ->y : (() => void)[] +>y[0] : handler6 +>y : handler6[] >0 : number From 26713c8721aefe852245b191cf1db129eb881f77 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 19 Jul 2016 07:18:16 -0700 Subject: [PATCH 37/55] Expand top level of declared type in type alias declaration --- src/compiler/checker.ts | 13 +++++++------ src/compiler/types.ts | 1 + src/services/services.ts | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 33c6e750f16c4..60673b4a5881a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2110,6 +2110,7 @@ namespace ts { return writeType(type, globalFlags); function writeType(type: Type, flags: TypeFormatFlags) { + const nextFlags = flags & ~TypeFormatFlags.InTypeAlias; // Write undefined/null type as any if (type.flags & TypeFlags.Intrinsic) { // Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving @@ -2124,24 +2125,24 @@ namespace ts { writer.writeKeyword("this"); } else if (type.flags & TypeFlags.Reference) { - writeTypeReference(type, flags); + writeTypeReference(type, nextFlags); } else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { // The specified symbol flags need to be reinterpreted as type flags - buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags); + buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags); } else if (type.flags & TypeFlags.Tuple) { writeTupleType(type); } - else if (type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol) { + else if (!(flags & TypeFormatFlags.InTypeAlias) && type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol) { const typeArguments = type.aliasTypeArguments; - writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, flags); + writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags); } else if (type.flags & TypeFlags.UnionOrIntersection) { - writeUnionOrIntersectionType(type, flags); + writeUnionOrIntersectionType(type, nextFlags); } else if (type.flags & TypeFlags.Anonymous) { - writeAnonymousType(type, flags); + writeAnonymousType(type, nextFlags); } else if (type.flags & TypeFlags.StringLiteral) { writer.writeStringLiteral(`"${escapeString((type).text)}"`); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e9ffb8bff72a0..5174bc5732b37 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1913,6 +1913,7 @@ namespace ts { InElementType = 0x00000040, // Writing an array or union element type UseFullyQualifiedType = 0x00000080, // Write out the fully qualified type name (eg. Module.Type, instead of Type) InFirstTypeArgument = 0x00000100, // Writing first type argument of the instantiated type + InTypeAlias = 0x00000200, // Writing type in type alias declaration } export const enum SymbolFormatFlags { diff --git a/src/services/services.ts b/src/services/services.ts index 6586930c34347..5bcd5ee28c4b2 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4606,7 +4606,7 @@ namespace ts { displayParts.push(spacePart()); displayParts.push(operatorPart(SyntaxKind.EqualsToken)); displayParts.push(spacePart()); - addRange(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration)); + addRange(displayParts, typeToDisplayParts(typeChecker, typeChecker.getDeclaredTypeOfSymbol(symbol), enclosingDeclaration, TypeFormatFlags.InTypeAlias)); } if (symbolFlags & SymbolFlags.Enum) { addNewLineIfDisplayPartsExist(); From a2c4176ea8317249bcfa9a17132dc0244e4d3182 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 19 Jul 2016 07:18:35 -0700 Subject: [PATCH 38/55] Fix fourslash test --- tests/cases/fourslash/server/quickinfo01.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/fourslash/server/quickinfo01.ts b/tests/cases/fourslash/server/quickinfo01.ts index e04175f76bc19..9008505e4476d 100644 --- a/tests/cases/fourslash/server/quickinfo01.ts +++ b/tests/cases/fourslash/server/quickinfo01.ts @@ -21,7 +21,7 @@ verify.quickInfoIs('var x: One | Two'); goTo.marker("2"); -verify.quickInfoIs('(property) commonProperty: number | string'); +verify.quickInfoIs('(property) commonProperty: string | number'); goTo.marker("3"); verify.quickInfoIs('(method) commonFunction(): number'); From 1868f2ec83fc6b71f88cb39dbcdb46a4d23836b4 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 19 Jul 2016 07:18:55 -0700 Subject: [PATCH 39/55] Remove bizarre fourslash test --- ...sTypeParameterOfFunctionLikeInTypeAlias.ts | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 tests/cases/fourslash/quickInfoDisplayPartsTypeParameterOfFunctionLikeInTypeAlias.ts diff --git a/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterOfFunctionLikeInTypeAlias.ts b/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterOfFunctionLikeInTypeAlias.ts deleted file mode 100644 index 917358fde570b..0000000000000 --- a/tests/cases/fourslash/quickInfoDisplayPartsTypeParameterOfFunctionLikeInTypeAlias.ts +++ /dev/null @@ -1,41 +0,0 @@ -/// - -//// type jamming = new () => jamming; -//// type jamming = (new () => jamming) & { constructor: /*2*/A }; -//// type jamming = new () => jamming & { constructor: /*3*/A }; - -let typeAliashDisplayParts = [{ text: "type", kind: "keyword" }, { text: " ", kind: "space" }, { text: "jamming", kind: "aliasName" }, - { text: "<", kind: "punctuation" }, { text: "A", kind: "typeParameterName" }, { text: ">", kind: "punctuation" }]; - -let typeParameterDisplayParts = [{ text: "(", kind: "punctuation" }, { text: "type parameter", kind: "text" }, { text: ")", kind: "punctuation" }, { text: " ", kind: "space" }, - { text: "A", kind: "typeParameterName" }, { text: " ", kind: "space" }, { text: "in", kind: "keyword" }, { text: " ", kind: "space" }]; - -let constructorTypeDisplayParts = [{ text: "<", kind: "punctuation" }, { text: "A", kind: "typeParameterName" }, { text: ">", kind: "punctuation" }, - { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, { text: ":", kind: "punctuation" }, { text: " ", kind: "space" }, - { text: "new", kind: "keyword" }, { "text": " ", kind: "space" }, { text: "<", kind: "punctuation" }, { text: "A", kind: "typeParameterName" }, - { text: ">", kind: "punctuation" }, { text: "(", kind: "punctuation" }, { text: ")", kind: "punctuation" }, {"text": " ", kind: "space" }, - { text: "=>", kind: "punctuation" }, { "text": " ", kind: "space" }, { text: "jamming", kind: "aliasName" }]; - -let constructorTypeWithLongReturnTypeDisplayParts = [{ "text": "<", kind: "punctuation" }, { "text": "A", kind: "typeParameterName" }, { "text": ">", kind: "punctuation" }, - { "text": "(", kind: "punctuation" }, { "text": ")", kind: "punctuation" }, { "text": ":", kind: "punctuation" }, { "text": " ", kind: "space" }, { "text": "(", kind: "punctuation" }, - { "text": "new", kind: "keyword" }, { "text": " ", kind: "space" }, { "text": "<", kind: "punctuation" }, { "text": "A", kind: "typeParameterName" }, { "text": ">", kind: "punctuation" }, - { "text": "(", kind: "punctuation" }, { "text": ")", kind: "punctuation" }, { "text": " ", kind: "space" }, { "text": "=>", kind: "punctuation" }, { "text": " ", kind: "space" }, - { "text": "jamming", kind: "aliasName" }, { "text": ")", kind: "punctuation" }, { "text": " ", kind: "space" }, { "text": "&", kind: "punctuation" }, { "text": " ", kind: "space" }, - { "text": "{", kind: "punctuation" }, { "text": "\n", kind: "lineBreak" }, { "text": " ", kind: "space" }, { "text": "constructor", kind: "propertyName" }, { "text": ":", kind: "punctuation" }, - { "text": " ", kind: "space" }, { "text": "A", kind: "typeParameterName" }, {"text":";", kind: "punctuation" }, {"text":"\n", kind: "lineBreak" }, {"text":"}", kind: "punctuation" }]; - -goTo.marker('0'); -verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName("0").position, length: "A".length }, - typeParameterDisplayParts.concat(constructorTypeDisplayParts), []); - -goTo.marker('1'); -verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName("1").position, length: "A".length }, - typeParameterDisplayParts.concat(constructorTypeDisplayParts), []); - -goTo.marker('2'); -verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName("2").position, length: "A".length }, - typeParameterDisplayParts.concat(typeAliashDisplayParts), []); - -goTo.marker('3'); -verify.verifyQuickInfoDisplayParts("type parameter", "", { start: test.markerByName("3").position, length: "A".length }, - typeParameterDisplayParts.concat(constructorTypeWithLongReturnTypeDisplayParts), []); \ No newline at end of file From f5f8a4554aee78c119ba8186ced5c55db083291a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 20 Jul 2016 11:15:01 -0700 Subject: [PATCH 40/55] Optimize checkTypeRelatedTo --- src/compiler/checker.ts | 57 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 60673b4a5881a..666eedf4f603a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5779,23 +5779,23 @@ namespace ts { // TYPE CHECKING function isTypeIdenticalTo(source: Type, target: Type): boolean { - return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined); + return isTypeRelatedTo(source, target, identityRelation); } function compareTypesIdentical(source: Type, target: Type): Ternary { - return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined) ? Ternary.True : Ternary.False; + return isTypeRelatedTo(source, target, identityRelation) ? Ternary.True : Ternary.False; } function compareTypesAssignable(source: Type, target: Type): Ternary { - return checkTypeRelatedTo(source, target, assignableRelation, /*errorNode*/ undefined) ? Ternary.True : Ternary.False; + return isTypeRelatedTo(source, target, assignableRelation) ? Ternary.True : Ternary.False; } function isTypeSubtypeOf(source: Type, target: Type): boolean { - return checkTypeSubtypeOf(source, target, /*errorNode*/ undefined); + return isTypeRelatedTo(source, target, subtypeRelation); } function isTypeAssignableTo(source: Type, target: Type): boolean { - return checkTypeAssignableTo(source, target, /*errorNode*/ undefined); + return isTypeRelatedTo(source, target, assignableRelation); } /** @@ -5803,7 +5803,7 @@ namespace ts { * If one needs to check both directions for comparability, use a second call to this function or 'checkTypeComparableTo'. */ function isTypeComparableTo(source: Type, target: Type): boolean { - return checkTypeComparableTo(source, target, /*errorNode*/ undefined); + return isTypeRelatedTo(source, target, comparableRelation); } function areTypesComparable(type1: Type, type2: Type): boolean { @@ -5996,6 +5996,51 @@ namespace ts { } } + function isPrimtiveTypeRelatedTo(source: Type, target: Type, relation: Map) { + if (target.flags & TypeFlags.Any || source.flags & TypeFlags.Never) return true; + if (source.flags & TypeFlags.Undefined) { + if (!strictNullChecks || target.flags & (TypeFlags.Undefined | TypeFlags.Void)) return true; + } + if (source.flags & TypeFlags.Null) { + if (!strictNullChecks || target.flags & TypeFlags.Null) return true; + } + if (source.flags & TypeFlags.NumberLike && target === numberType) return true; + if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum && source.symbol.flags & SymbolFlags.EnumMember && source.symbol.parent === target.symbol) { + return true; + } + if (source.flags & TypeFlags.StringLike && target === stringType) return true; + if (relation === assignableRelation || relation === comparableRelation) { + if (source.flags & TypeFlags.Any) return true; + if (source === numberType && target.flags & TypeFlags.Enum) return true; + } + if (source.flags & TypeFlags.BooleanLike && target.flags & TypeFlags.Boolean) return true; + return false; + } + + function isTypeRelatedTo(source: Type, target: Type, relation: Map) { + if (source === target) { + return true; + } + if (relation !== identityRelation) { + if (source.flags & TypeFlags.Primitive && target.flags & TypeFlags.Primitive) { + if (isPrimtiveTypeRelatedTo(source, target, relation)) { + return true; + } + if (!(source.flags & TypeFlags.Union || target.flags & TypeFlags.Union)) { + return false; + } + } + } + if (source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType) { + const id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id; + const related = relation[id]; + if (related !== undefined) { + return related === RelationComparisonResult.Succeeded; + } + } + return checkTypeRelatedTo(source, target, relation, undefined, undefined, undefined); + } + /** * Checks if 'source' is related to 'target' (e.g.: is a assignable to). * @param source The left-hand-side of the relation. From 451f48bf828b79c135a8a80f870feef63355de24 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 21 Jul 2016 09:57:46 -0700 Subject: [PATCH 41/55] Optimize checkTypeRelatedTo, part 2 --- src/compiler/checker.ts | 120 ++++++++++++++-------------------------- src/compiler/types.ts | 1 + 2 files changed, 44 insertions(+), 77 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 666eedf4f603a..4ff284d9c944c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5832,6 +5832,8 @@ namespace ts { return compareSignaturesRelated(source, target, ignoreReturnTypes, /*reportErrors*/ false, /*errorReporter*/ undefined, compareTypesAssignable) !== Ternary.False; } + type ErrorReporter = (message: DiagnosticMessage, arg0?: string, arg1?: string) => void; + /** * See signatureRelatedTo, compareSignaturesIdentical */ @@ -5839,7 +5841,7 @@ namespace ts { target: Signature, ignoreReturnTypes: boolean, reportErrors: boolean, - errorReporter: (d: DiagnosticMessage, arg0?: string, arg1?: string) => void, + errorReporter: ErrorReporter, compareTypes: (s: Type, t: Type, reportErrors?: boolean) => Ternary): Ternary { // TODO (drosen): De-duplicate code between related functions. if (source === target) { @@ -5924,7 +5926,7 @@ namespace ts { function compareTypePredicateRelatedTo(source: TypePredicate, target: TypePredicate, reportErrors: boolean, - errorReporter: (d: DiagnosticMessage, arg0?: string, arg1?: string) => void, + errorReporter: ErrorReporter, compareTypes: (s: Type, t: Type, reportErrors?: boolean) => Ternary): Ternary { if (source.kind !== target.kind) { if (reportErrors) { @@ -5961,8 +5963,8 @@ namespace ts { const sourceReturnType = getReturnTypeOfSignature(erasedSource); const targetReturnType = getReturnTypeOfSignature(erasedTarget); if (targetReturnType === voidType - || checkTypeRelatedTo(targetReturnType, sourceReturnType, assignableRelation, /*errorNode*/ undefined) - || checkTypeRelatedTo(sourceReturnType, targetReturnType, assignableRelation, /*errorNode*/ undefined)) { + || isTypeRelatedTo(targetReturnType, sourceReturnType, assignableRelation) + || isTypeRelatedTo(sourceReturnType, targetReturnType, assignableRelation)) { return isSignatureAssignableTo(erasedSource, erasedTarget, /*ignoreReturnTypes*/ true); } @@ -5996,41 +5998,49 @@ namespace ts { } } - function isPrimtiveTypeRelatedTo(source: Type, target: Type, relation: Map) { - if (target.flags & TypeFlags.Any || source.flags & TypeFlags.Never) return true; - if (source.flags & TypeFlags.Undefined) { - if (!strictNullChecks || target.flags & (TypeFlags.Undefined | TypeFlags.Void)) return true; + function isEnumTypeRelatedTo(source: Type, target: Type, errorReporter?: ErrorReporter) { + if (source.symbol.flags & SymbolFlags.EnumMember && source.symbol.parent === target.symbol) { + return true; } - if (source.flags & TypeFlags.Null) { - if (!strictNullChecks || target.flags & TypeFlags.Null) return true; + if (source.symbol.name !== target.symbol.name || !(source.symbol.flags & SymbolFlags.RegularEnum) || !(target.symbol.flags & SymbolFlags.RegularEnum)) { + return false; } - if (source.flags & TypeFlags.NumberLike && target === numberType) return true; - if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum && source.symbol.flags & SymbolFlags.EnumMember && source.symbol.parent === target.symbol) { - return true; + const targetEnumType = getTypeOfSymbol(target.symbol); + for (const property of getPropertiesOfType(getTypeOfSymbol(source.symbol))) { + if (property.flags & SymbolFlags.EnumMember) { + const targetProperty = getPropertyOfType(targetEnumType, property.name); + if (!targetProperty || !(targetProperty.flags & SymbolFlags.EnumMember)) { + if (errorReporter) { + errorReporter(Diagnostics.Property_0_is_missing_in_type_1, property.name, + typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType)); + } + return false; + } + } } - if (source.flags & TypeFlags.StringLike && target === stringType) return true; + return true; + } + + function isSimpleTypeRelatedTo(source: Type, target: Type, relation: Map, errorReporter?: ErrorReporter) { + if (target.flags & TypeFlags.Never) return false; + if (target.flags & TypeFlags.Any || source.flags & TypeFlags.Never) return true; + if (source.flags & TypeFlags.StringLike && target.flags & TypeFlags.String) return true; + if (source.flags & TypeFlags.NumberLike && target.flags & TypeFlags.Number) return true; + if (source.flags & TypeFlags.BooleanLike && target.flags & TypeFlags.Boolean) return true; + if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum && isEnumTypeRelatedTo(source, target, errorReporter)) return true; + if (source.flags & TypeFlags.Undefined && (!strictNullChecks || target.flags & (TypeFlags.Undefined | TypeFlags.Void))) return true; + if (source.flags & TypeFlags.Null && (!strictNullChecks || target.flags & TypeFlags.Null)) return true; if (relation === assignableRelation || relation === comparableRelation) { if (source.flags & TypeFlags.Any) return true; - if (source === numberType && target.flags & TypeFlags.Enum) return true; + if (source.flags & TypeFlags.Number && target.flags & TypeFlags.Enum) return true; } - if (source.flags & TypeFlags.BooleanLike && target.flags & TypeFlags.Boolean) return true; return false; } function isTypeRelatedTo(source: Type, target: Type, relation: Map) { - if (source === target) { + if (source === target || relation !== identityRelation && isSimpleTypeRelatedTo(source, target, relation)) { return true; } - if (relation !== identityRelation) { - if (source.flags & TypeFlags.Primitive && target.flags & TypeFlags.Primitive) { - if (isPrimtiveTypeRelatedTo(source, target, relation)) { - return true; - } - if (!(source.flags & TypeFlags.Union || target.flags & TypeFlags.Union)) { - return false; - } - } - } if (source.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType) { const id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id; const related = relation[id]; @@ -6038,7 +6048,10 @@ namespace ts { return related === RelationComparisonResult.Succeeded; } } - return checkTypeRelatedTo(source, target, relation, undefined, undefined, undefined); + if (source.flags & TypeFlags.StructuredOrTypeParameter || target.flags & TypeFlags.StructuredOrTypeParameter) { + return checkTypeRelatedTo(source, target, relation, undefined, undefined, undefined); + } + return false; } /** @@ -6112,33 +6125,12 @@ namespace ts { let result: Ternary; // 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; + if (relation === identityRelation) { return isIdenticalTo(source, target); } - if (!(target.flags & TypeFlags.Never)) { - if (target.flags & TypeFlags.Any || source.flags & TypeFlags.Never) return Ternary.True; - if (source.flags & TypeFlags.Undefined) { - if (!strictNullChecks || target.flags & (TypeFlags.Undefined | TypeFlags.Void)) return Ternary.True; - } - if (source.flags & TypeFlags.Null) { - if (!strictNullChecks || target.flags & TypeFlags.Null) return Ternary.True; - } - if (source.flags & TypeFlags.NumberLike && target === numberType) return Ternary.True; - if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum) { - if (result = enumRelatedTo(source, target, reportErrors)) { - return result; - } - } - if (source.flags & TypeFlags.StringLike && target === stringType) return Ternary.True; - if (relation === assignableRelation || relation === comparableRelation) { - if (source.flags & TypeFlags.Any) return Ternary.True; - if (source === numberType && target.flags & TypeFlags.Enum) return Ternary.True; - } - if (source.flags & TypeFlags.BooleanLike && target.flags & TypeFlags.Boolean) { - return Ternary.True; - } - } + if (isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined)) return Ternary.True; if (source.flags & TypeFlags.FreshObjectLiteral) { if (hasExcessProperties(source, target, reportErrors)) { @@ -6772,32 +6764,6 @@ namespace ts { return Ternary.False; } - function enumRelatedTo(source: Type, target: Type, reportErrors?: boolean) { - if (source.symbol.flags & SymbolFlags.EnumMember && source.symbol.parent === target.symbol) { - return Ternary.True; - } - if (source.symbol.name !== target.symbol.name || - !(source.symbol.flags & SymbolFlags.RegularEnum) || - !(target.symbol.flags & SymbolFlags.RegularEnum)) { - return Ternary.False; - } - const targetEnumType = getTypeOfSymbol(target.symbol); - for (const property of getPropertiesOfType(getTypeOfSymbol(source.symbol))) { - if (property.flags & SymbolFlags.EnumMember) { - const targetProperty = getPropertyOfType(targetEnumType, property.name); - if (!targetProperty || !(targetProperty.flags & SymbolFlags.EnumMember)) { - if (reportErrors) { - reportError(Diagnostics.Property_0_is_missing_in_type_1, - property.name, - typeToString(target, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType)); - } - return Ternary.False; - } - } - } - return Ternary.True; - } - function constructorVisibilitiesAreCompatible(sourceSignature: Signature, targetSignature: Signature, reportErrors: boolean) { if (!sourceSignature.declaration || !targetSignature.declaration) { return true; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5174bc5732b37..bd1ba19a05427 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2265,6 +2265,7 @@ namespace ts { ObjectType = Class | Interface | Reference | Tuple | Anonymous, UnionOrIntersection = Union | Intersection, StructuredType = ObjectType | Union | Intersection, + StructuredOrTypeParameter = StructuredType | TypeParameter, // 'Narrowable' types are types where narrowing actually narrows. // This *should* be every type other than null, undefined, void, and never From afd39cccaa3bb8568f9bc815638e16b16db35760 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 22 Jul 2016 14:27:33 -0700 Subject: [PATCH 42/55] Enum type is also a union of the literal enum types it declares --- src/compiler/checker.ts | 135 ++++++++++++++++++--------- src/compiler/diagnosticMessages.json | 4 + src/compiler/types.ts | 71 ++++++++------ src/compiler/utilities.ts | 2 +- src/services/utilities.ts | 2 +- 5 files changed, 140 insertions(+), 74 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4ff284d9c944c..bea464faf2be7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2127,7 +2127,7 @@ namespace ts { else if (type.flags & TypeFlags.Reference) { writeTypeReference(type, nextFlags); } - else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { + else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.EnumLike | TypeFlags.TypeParameter)) { // The specified symbol flags need to be reinterpreted as type flags buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags); } @@ -3743,23 +3743,72 @@ namespace ts { return links.declaredType; } - function createEnumType(symbol: Symbol): Type { - const type = createType(TypeFlags.Enum); - type.symbol = symbol; - return type; + function isLiteralEnumMember(symbol: Symbol, member: EnumMember) { + const expr = member.initializer; + if (!expr) { + return !isInAmbientContext(member); + } + return expr.kind === SyntaxKind.NumericLiteral || + expr.kind === SyntaxKind.PrefixUnaryExpression && (expr).operator === SyntaxKind.MinusToken && + (expr).operand.kind === SyntaxKind.NumericLiteral || + expr.kind === SyntaxKind.Identifier && hasProperty(symbol.exports, (expr).text); } - function getEnumMemberType(symbol: Symbol): Type { - const links = getSymbolLinks(getParentOfSymbol(symbol)); - const map = links.enumMemberTypes || (links.enumMemberTypes = {}); - const value = "" + getEnumMemberValue(symbol.valueDeclaration); - return map[value] || (map[value] = createEnumType(symbol)); + function enumHasLiteralMembers(symbol: Symbol) { + for (const declaration of symbol.declarations) { + if (declaration.kind === SyntaxKind.EnumDeclaration) { + for (const member of (declaration).members) { + if (!isLiteralEnumMember(symbol, member)) { + return false; + } + } + } + } + return true; } function getDeclaredTypeOfEnum(symbol: Symbol): Type { const links = getSymbolLinks(symbol); if (!links.declaredType) { - links.declaredType = symbol.flags & SymbolFlags.EnumMember ? getEnumMemberType(symbol) : createEnumType(symbol); + const enumType = links.declaredType = createType(TypeFlags.Enum); + enumType.symbol = symbol; + if (enumHasLiteralMembers(symbol)) { + const memberTypeList: Type[] = []; + const memberTypes: Map = {}; + for (const declaration of enumType.symbol.declarations) { + if (declaration.kind === SyntaxKind.EnumDeclaration) { + computeEnumMemberValues(declaration); + for (const member of (declaration).members) { + 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; + memberTypeList.push(memberType); + } + } + } + } + enumType.memberTypes = memberTypes; + if (memberTypeList.length > 1) { + enumType.flags |= TypeFlags.Union; + (enumType).types = memberTypeList; + unionTypes[getTypeListId(memberTypeList)] = enumType; + } + } + } + return links.declaredType; + } + + function getDeclaredTypeOfEnumMember(symbol: Symbol): Type { + const links = getSymbolLinks(symbol); + if (!links.declaredType) { + const enumType = getDeclaredTypeOfEnum(getParentOfSymbol(symbol)); + links.declaredType = enumType.flags & TypeFlags.Union ? + enumType.memberTypes[getEnumMemberValue(symbol.valueDeclaration)] : + enumType; } return links.declaredType; } @@ -3793,12 +3842,15 @@ namespace ts { if (symbol.flags & SymbolFlags.TypeAlias) { return getDeclaredTypeOfTypeAlias(symbol); } - if (symbol.flags & (SymbolFlags.Enum | SymbolFlags.EnumMember)) { - return getDeclaredTypeOfEnum(symbol); - } if (symbol.flags & SymbolFlags.TypeParameter) { return getDeclaredTypeOfTypeParameter(symbol); } + if (symbol.flags & SymbolFlags.Enum) { + return getDeclaredTypeOfEnum(symbol); + } + if (symbol.flags & SymbolFlags.EnumMember) { + return getDeclaredTypeOfEnumMember(symbol); + } if (symbol.flags & SymbolFlags.Alias) { return getDeclaredTypeOfAlias(symbol); } @@ -5998,8 +6050,8 @@ namespace ts { } } - function isEnumTypeRelatedTo(source: Type, target: Type, errorReporter?: ErrorReporter) { - if (source.symbol.flags & SymbolFlags.EnumMember && source.symbol.parent === target.symbol) { + function isEnumTypeRelatedTo(source: EnumType, target: EnumType, errorReporter?: ErrorReporter) { + if (source === target) { return true; } if (source.symbol.name !== target.symbol.name || !(source.symbol.flags & SymbolFlags.RegularEnum) || !(target.symbol.flags & SymbolFlags.RegularEnum)) { @@ -6027,12 +6079,14 @@ namespace ts { if (source.flags & TypeFlags.StringLike && target.flags & TypeFlags.String) return true; if (source.flags & TypeFlags.NumberLike && target.flags & TypeFlags.Number) return true; if (source.flags & TypeFlags.BooleanLike && target.flags & TypeFlags.Boolean) return true; - if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum && isEnumTypeRelatedTo(source, target, errorReporter)) return true; + if (source.flags & TypeFlags.EnumLiteral && target.flags & TypeFlags.Enum && (source).baseType === target) return true; + if (source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum && isEnumTypeRelatedTo(source, target, errorReporter)) return true; if (source.flags & TypeFlags.Undefined && (!strictNullChecks || target.flags & (TypeFlags.Undefined | TypeFlags.Void))) return true; if (source.flags & TypeFlags.Null && (!strictNullChecks || target.flags & TypeFlags.Null)) return true; if (relation === assignableRelation || relation === comparableRelation) { if (source.flags & TypeFlags.Any) return true; - if (source.flags & TypeFlags.Number && target.flags & TypeFlags.Enum) return true; + if (source.flags & (TypeFlags.Number | TypeFlags.NumberLiteral) && target.flags & TypeFlags.Enum) return true; + if (source.flags & TypeFlags.NumberLiteral && target.flags & TypeFlags.EnumLiteral && (source).text === (target).text) return true; } return false; } @@ -6070,8 +6124,8 @@ namespace ts { relation: Map, errorNode: Node, headMessage?: DiagnosticMessage, - containingMessageChain?: DiagnosticMessageChain): boolean { - + containingMessageChain?: DiagnosticMessageChain): boolean + { let errorInfo: DiagnosticMessageChain; let sourceStack: ObjectType[]; let targetStack: ObjectType[]; @@ -7018,13 +7072,12 @@ namespace ts { } function isUnitType(type: Type): boolean { - return type.flags & (TypeFlags.Literal | TypeFlags.Undefined | TypeFlags.Null) || - type.flags & TypeFlags.Enum && type.symbol.flags & SymbolFlags.EnumMember ? true : false; + return (type.flags & (TypeFlags.Literal | TypeFlags.Undefined | TypeFlags.Null)) !== 0; } function isUnitUnionType(type: Type): boolean { return type.flags & TypeFlags.Boolean ? true : - type.flags & TypeFlags.Union ? !forEach((type).types, t => !isUnitType(t)) : + type.flags & TypeFlags.Union ? type.flags & TypeFlags.Enum ? true : !forEach((type).types, t => !isUnitType(t)) : isUnitType(type); } @@ -7032,8 +7085,8 @@ namespace ts { return type.flags & TypeFlags.StringLiteral ? stringType : type.flags & TypeFlags.NumberLiteral ? numberType : type.flags & TypeFlags.BooleanLiteral ? booleanType : - type.flags & TypeFlags.Enum && type.symbol.flags & SymbolFlags.EnumMember ? getDeclaredTypeOfSymbol(getParentOfSymbol(type.symbol)) : - type.flags & TypeFlags.Union ? getUnionType(map((type).types, getBaseTypeOfUnitType)) : + type.flags & TypeFlags.EnumLiteral ? (type).baseType : + type.flags & TypeFlags.Union && !(type.flags & TypeFlags.Enum) ? getUnionType(map((type).types, getBaseTypeOfUnitType), /*noSubtypeReduction*/ true) : type; } @@ -7330,7 +7383,7 @@ namespace ts { } function inferFromTypes(source: Type, target: Type) { - if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union || + if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union && !(source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum) || source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) { // Source and target are both unions or both intersections. If source and target // are the same type, just relate each constituent type to itself. @@ -7758,13 +7811,11 @@ namespace ts { type === emptyStringType ? TypeFacts.EmptyStringStrictFacts : TypeFacts.NonEmptyStringStrictFacts : type === emptyStringType ? TypeFacts.EmptyStringFacts : TypeFacts.NonEmptyStringFacts; } - if (flags & TypeFlags.Number || type.flags & TypeFlags.Enum && !(type.symbol.flags & SymbolFlags.EnumMember)) { + if (flags & (TypeFlags.Number | TypeFlags.Enum)) { return strictNullChecks ? TypeFacts.NumberStrictFacts : TypeFacts.NumberFacts; } - if (flags & TypeFlags.NumberLike) { - const isZero = type === zeroType || - type.flags & TypeFlags.Enum && type.symbol.flags & SymbolFlags.EnumMember && - getEnumMemberValue(type.symbol.valueDeclaration) === 0; + if (flags & (TypeFlags.NumberLiteral | TypeFlags.EnumLiteral)) { + const isZero = type === zeroType || type.flags & TypeFlags.EnumLiteral && (type).text === "0"; return strictNullChecks ? isZero ? TypeFacts.ZeroStrictFacts : TypeFacts.NonZeroStrictFacts : isZero ? TypeFacts.ZeroFacts : TypeFacts.NonZeroFacts; @@ -10459,7 +10510,7 @@ namespace ts { } let propType = getTypeOfSymbol(prop); - if (prop.flags & SymbolFlags.EnumMember && getParentOfSymbol(prop).flags & SymbolFlags.ConstEnum && isLiteralContextForType(node, propType)) { + if (prop.flags & SymbolFlags.EnumMember && isLiteralContextForType(node, propType)) { propType = getDeclaredTypeOfSymbol(prop); } @@ -13057,16 +13108,16 @@ namespace ts { return getUnionType([type1, type2]); } - function typeContainsEnumLiteral(type: Type, enumType: Type) { + function typeContainsLiteralFromEnum(type: Type, enumType: EnumType) { if (type.flags & TypeFlags.Union) { for (const t of (type).types) { - if (t.flags & TypeFlags.Enum && t.symbol.flags & SymbolFlags.EnumMember && t.symbol.parent === enumType.symbol) { + if (t.flags & TypeFlags.EnumLiteral && (t).baseType === enumType) { return true; } } } - if (type.flags & TypeFlags.Enum) { - return type.symbol.flags & SymbolFlags.EnumMember && type.symbol.parent === enumType.symbol; + if (type.flags & TypeFlags.EnumLiteral) { + return (type).baseType === enumType; } return false; } @@ -13091,13 +13142,13 @@ namespace ts { return maybeTypeOfKind(contextualType, TypeFlags.StringLiteral); } if (type.flags & TypeFlags.Number) { - return maybeTypeOfKind(contextualType, TypeFlags.NumberLiteral); + return maybeTypeOfKind(contextualType, (TypeFlags.NumberLiteral | TypeFlags.EnumLiteral)); } if (type.flags & TypeFlags.Boolean) { return maybeTypeOfKind(contextualType, TypeFlags.BooleanLiteral) && !isTypeAssignableTo(booleanType, contextualType); } - if (type.flags & TypeFlags.Enum && type.symbol.flags & SymbolFlags.ConstEnum) { - return typeContainsEnumLiteral(contextualType, type); + if (type.flags & TypeFlags.Enum) { + return typeContainsLiteralFromEnum(contextualType, type); } } return false; @@ -13889,6 +13940,9 @@ namespace ts { checkTypeArgumentConstraints(typeParameters, node.typeArguments); } } + if (type.flags & TypeFlags.Enum && !(type).memberTypes && getNodeLinks(node).resolvedSymbol.flags & SymbolFlags.EnumMember) { + error(node, Diagnostics.Enum_type_0_has_members_with_initializers_that_are_not_literals, typeToString(type)); + } } } @@ -18400,9 +18454,6 @@ namespace ts { } } - // The built-in boolean type is 'true | false', also mark 'false | true' as a boolean type - createBooleanType([falseType, trueType]); - // Setup global builtins addToSymbolTable(globals, builtinGlobals, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7996f80bd91cf..7fb3c81d70821 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1755,6 +1755,10 @@ "category": "Error", "code": 2534 }, + "Enum type '{0}' has members with initializers that are not literals.": { + "category": "Error", + "code": 2535 + }, "JSX element attributes type '{0}' may not be a union type.": { "category": "Error", "code": 2600 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index bd1ba19a05427..2dabee35f1158 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2068,7 +2068,7 @@ namespace ts { Variable = FunctionScopedVariable | BlockScopedVariable, Value = Variable | Property | EnumMember | Function | Class | Enum | ValueModule | Method | GetAccessor | SetAccessor, Type = Class | Interface | Enum | EnumMember | TypeLiteral | ObjectLiteral | TypeParameter | TypeAlias, - Namespace = ValueModule | NamespaceModule | ConstEnum, + Namespace = ValueModule | NamespaceModule | Enum, Module = ValueModule | NamespaceModule, Accessor = GetAccessor | SetAccessor, @@ -2151,7 +2151,6 @@ namespace ts { isDeclarationWithCollidingName?: boolean; // True if symbol is block scoped redeclaration bindingElement?: BindingElement; // Binding element associated with property symbol exportsSomeValue?: boolean; // True if module exports some value (not just types) - enumMemberTypes?: Map; // Enum member types indexed by enum value } /* @internal */ @@ -2218,50 +2217,52 @@ namespace ts { String = 1 << 1, Number = 1 << 2, Boolean = 1 << 3, - StringLiteral = 1 << 4, // String literal type - NumberLiteral = 1 << 5, - BooleanLiteral = 1 << 6, - ESSymbol = 1 << 7, // Type of symbol primitive introduced in ES6 - Void = 1 << 8, - Undefined = 1 << 9, - Null = 1 << 10, - Never = 1 << 11, // Never type - Enum = 1 << 12, // Enum type - TypeParameter = 1 << 13, // Type parameter - Class = 1 << 14, // Class - Interface = 1 << 15, // Interface - Reference = 1 << 16, // Generic type reference - Tuple = 1 << 17, // Tuple - Union = 1 << 18, // Union (T | U) - Intersection = 1 << 19, // Intersection (T & U) - Anonymous = 1 << 20, // Anonymous - Instantiated = 1 << 21, // Instantiated anonymous type + Enum = 1 << 4, + StringLiteral = 1 << 5, + NumberLiteral = 1 << 6, + BooleanLiteral = 1 << 7, + EnumLiteral = 1 << 8, + ESSymbol = 1 << 9, // Type of symbol primitive introduced in ES6 + Void = 1 << 10, + Undefined = 1 << 11, + Null = 1 << 12, + Never = 1 << 13, // Never type + TypeParameter = 1 << 14, // Type parameter + Class = 1 << 15, // Class + Interface = 1 << 16, // Interface + Reference = 1 << 17, // Generic type reference + Tuple = 1 << 18, // Tuple + Union = 1 << 19, // Union (T | U) + Intersection = 1 << 20, // Intersection (T & U) + Anonymous = 1 << 21, // Anonymous + Instantiated = 1 << 22, // Instantiated anonymous type /* @internal */ - ObjectLiteral = 1 << 22, // Originates in an object literal + ObjectLiteral = 1 << 23, // Originates in an object literal /* @internal */ - FreshObjectLiteral = 1 << 23, // Fresh object literal type + FreshObjectLiteral = 1 << 24, // Fresh object literal type /* @internal */ - ContainsWideningType = 1 << 24, // Type is or contains undefined or null widening type + ContainsWideningType = 1 << 25, // Type is or contains undefined or null widening type /* @internal */ - ContainsObjectLiteral = 1 << 25, // Type is or contains object literal type + ContainsObjectLiteral = 1 << 26, // Type is or contains object literal type /* @internal */ - ContainsAnyFunctionType = 1 << 26, // Type is or contains object literal type - ThisType = 1 << 27, // This type - ObjectLiteralPatternWithComputedProperties = 1 << 28, // Object literal type implied by binding pattern has computed properties + ContainsAnyFunctionType = 1 << 27, // Type is or contains object literal type + ThisType = 1 << 28, // This type + ObjectLiteralPatternWithComputedProperties = 1 << 29, // Object literal type implied by binding pattern has computed properties /* @internal */ Nullable = Undefined | Null, - Literal = StringLiteral | NumberLiteral | BooleanLiteral, + Literal = StringLiteral | NumberLiteral | BooleanLiteral | EnumLiteral, /* @internal */ DefinitelyFalsy = StringLiteral | NumberLiteral | BooleanLiteral | Void | Undefined | Null, PossiblyFalsy = DefinitelyFalsy | String | Number | Boolean, /* @internal */ Intrinsic = Any | String | Number | Boolean | BooleanLiteral | ESSymbol | Void | Undefined | Null | Never, /* @internal */ - Primitive = String | Number | Boolean | ESSymbol | Void | Undefined | Null | Literal | Enum, + Primitive = String | Number | Boolean | Enum | ESSymbol | Void | Undefined | Null | Literal, StringLike = String | StringLiteral, - NumberLike = Number | NumberLiteral | Enum, + NumberLike = Number | NumberLiteral | Enum | EnumLiteral, BooleanLike = Boolean | BooleanLiteral, + EnumLike = Enum | EnumLiteral, ObjectType = Class | Interface | Reference | Tuple | Anonymous, UnionOrIntersection = Union | Intersection, StructuredType = ObjectType | Union | Intersection, @@ -2300,6 +2301,16 @@ namespace ts { text: string; // Text of string literal } + // Enum types (TypeFlags.Enum) + export interface EnumType extends Type { + memberTypes: Map; + } + + // Enum types (TypeFlags.EnumLiteral) + export interface EnumLiteralType extends LiteralType { + baseType: EnumType; + } + // Object types (TypeFlags.ObjectType) export interface ObjectType extends Type { } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6f3a1d6d813d4..b66abf3cf38ee 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1523,7 +1523,7 @@ namespace ts { continue; } return parent.kind === SyntaxKind.BinaryExpression && - (parent).operatorToken.kind === SyntaxKind.EqualsToken && + isAssignmentOperator((parent).operatorToken.kind) && (parent).left === node || (parent.kind === SyntaxKind.ForInStatement || parent.kind === SyntaxKind.ForOfStatement) && (parent).initializer === node; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 1ed0b269921f6..7f41cdbb3a42e 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -920,7 +920,7 @@ namespace ts { if (host && host.getScriptKind) { scriptKind = host.getScriptKind(fileName); } - if (!scriptKind || scriptKind === ScriptKind.Unknown) { + if (!scriptKind) { scriptKind = getScriptKindFromFileName(fileName); } return ensureScriptKind(fileName, scriptKind); From 8c64759f756eb992a9a547a9a74611446a0d45d3 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 22 Jul 2016 14:28:09 -0700 Subject: [PATCH 43/55] Fix bug in binder uncovered by changes --- src/compiler/binder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 2c0a51cfc14d9..5e38fbff2829f 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1971,7 +1971,7 @@ namespace ts { function bindThisPropertyAssignment(node: BinaryExpression) { // Declare a 'member' in case it turns out the container was an ES5 class or ES6 constructor let assignee: Node; - if (container.kind === SyntaxKind.FunctionDeclaration || container.kind === SyntaxKind.FunctionDeclaration) { + if (container.kind === SyntaxKind.FunctionDeclaration || container.kind === SyntaxKind.FunctionExpression) { assignee = container; } else if (container.kind === SyntaxKind.Constructor) { From 9a23b11b6aad15dff9aff3757d4435944f0f61fa Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 22 Jul 2016 14:28:53 -0700 Subject: [PATCH 44/55] Change parser to use token() function for accessing current token --- src/compiler/parser.ts | 612 +++++++++++++++++++++-------------------- 1 file changed, 311 insertions(+), 301 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index e707ff6e5c1e6..b4a399e88b649 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -474,7 +474,7 @@ namespace ts { let parseDiagnostics: Diagnostic[]; let syntaxCursor: IncrementalParser.SyntaxCursor; - let token: SyntaxKind; + let currentToken: SyntaxKind; let sourceText: string; let nodeCount: number; let identifiers: Map; @@ -617,11 +617,11 @@ namespace ts { sourceFile.flags = contextFlags; // Prime the scanner. - token = nextToken(); + nextToken(); processReferenceComments(sourceFile); sourceFile.statements = parseList(ParsingContext.SourceElements, parseStatement); - Debug.assert(token === SyntaxKind.EndOfFileToken); + Debug.assert(token() === SyntaxKind.EndOfFileToken); sourceFile.endOfFileToken = parseTokenNode(); setExternalModuleIndicator(sourceFile); @@ -856,34 +856,44 @@ namespace ts { return scanner.getStartPos(); } + // Use this function to access the current token instead of reading the currentToken + // variable. Since function results aren't narrowed in control flow analysis, this ensures + // that the type checker doesn't make wrong assumptions about the type of the current + // token (e.g. a call to nextToken() changes the current token but the checker doesn't + // reason about this side effect). Mainstream VMs inline simple functions like this, so + // there is no performance penalty. + function token(): SyntaxKind { + return currentToken; + } + function nextToken(): SyntaxKind { - return token = scanner.scan(); + return currentToken = scanner.scan(); } function reScanGreaterToken(): SyntaxKind { - return token = scanner.reScanGreaterToken(); + return currentToken = scanner.reScanGreaterToken(); } function reScanSlashToken(): SyntaxKind { - return token = scanner.reScanSlashToken(); + return currentToken = scanner.reScanSlashToken(); } function reScanTemplateToken(): SyntaxKind { - return token = scanner.reScanTemplateToken(); + return currentToken = scanner.reScanTemplateToken(); } function scanJsxIdentifier(): SyntaxKind { - return token = scanner.scanJsxIdentifier(); + return currentToken = scanner.scanJsxIdentifier(); } function scanJsxText(): SyntaxKind { - return token = scanner.scanJsxToken(); + return currentToken = scanner.scanJsxToken(); } function speculationHelper(callback: () => T, isLookAhead: boolean): T { // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). - const saveToken = token; + const saveToken = currentToken; const saveParseDiagnosticsLength = parseDiagnostics.length; const saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; @@ -905,7 +915,7 @@ namespace ts { // If our callback returned something 'falsy' or we're just looking ahead, // then unconditionally restore us to where we were. if (!result || isLookAhead) { - token = saveToken; + currentToken = saveToken; parseDiagnostics.length = saveParseDiagnosticsLength; parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode; } @@ -932,27 +942,27 @@ namespace ts { // Ignore strict mode flag because we will report an error in type checker instead. function isIdentifier(): boolean { - if (token === SyntaxKind.Identifier) { + if (token() === SyntaxKind.Identifier) { return true; } // If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is // considered a keyword and is not an identifier. - if (token === SyntaxKind.YieldKeyword && inYieldContext()) { + if (token() === SyntaxKind.YieldKeyword && inYieldContext()) { return false; } // If we have a 'await' keyword, and we're in the [Await] context, then 'await' is // considered a keyword and is not an identifier. - if (token === SyntaxKind.AwaitKeyword && inAwaitContext()) { + if (token() === SyntaxKind.AwaitKeyword && inAwaitContext()) { return false; } - return token > SyntaxKind.LastReservedWord; + return token() > SyntaxKind.LastReservedWord; } function parseExpected(kind: SyntaxKind, diagnosticMessage?: DiagnosticMessage, shouldAdvance = true): boolean { - if (token === kind) { + if (token() === kind) { if (shouldAdvance) { nextToken(); } @@ -970,7 +980,7 @@ namespace ts { } function parseOptional(t: SyntaxKind): boolean { - if (token === t) { + if (token() === t) { nextToken(); return true; } @@ -978,7 +988,7 @@ namespace ts { } function parseOptionalToken(t: SyntaxKind): Node { - if (token === t) { + if (token() === t) { return parseTokenNode(); } return undefined; @@ -990,24 +1000,24 @@ namespace ts { } function parseTokenNode(): T { - const node = createNode(token); + const node = createNode(token()); nextToken(); return finishNode(node); } function canParseSemicolon() { // If there's a real semicolon, then we can always parse it out. - if (token === SyntaxKind.SemicolonToken) { + if (token() === SyntaxKind.SemicolonToken) { return true; } // We can parse out an optional semicolon in ASI cases in the following cases. - return token === SyntaxKind.CloseBraceToken || token === SyntaxKind.EndOfFileToken || scanner.hasPrecedingLineBreak(); + return token() === SyntaxKind.CloseBraceToken || token() === SyntaxKind.EndOfFileToken || scanner.hasPrecedingLineBreak(); } function parseSemicolon(): boolean { if (canParseSemicolon()) { - if (token === SyntaxKind.SemicolonToken) { + if (token() === SyntaxKind.SemicolonToken) { // consume the semicolon if it was explicitly provided. nextToken(); } @@ -1074,8 +1084,8 @@ namespace ts { const node = createNode(SyntaxKind.Identifier); // Store original token kind if it is not just an Identifier so we can report appropriate error later in type checker - if (token !== SyntaxKind.Identifier) { - node.originalKeywordKind = token; + if (token() !== SyntaxKind.Identifier) { + node.originalKeywordKind = token(); } node.text = internIdentifier(scanner.getTokenValue()); nextToken(); @@ -1090,20 +1100,20 @@ namespace ts { } function parseIdentifierName(): Identifier { - return createIdentifier(tokenIsIdentifierOrKeyword(token)); + return createIdentifier(tokenIsIdentifierOrKeyword(token())); } function isLiteralPropertyName(): boolean { - return tokenIsIdentifierOrKeyword(token) || - token === SyntaxKind.StringLiteral || - token === SyntaxKind.NumericLiteral; + return tokenIsIdentifierOrKeyword(token()) || + token() === SyntaxKind.StringLiteral || + token() === SyntaxKind.NumericLiteral; } function parsePropertyNameWorker(allowComputedPropertyNames: boolean): PropertyName { - if (token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral) { + if (token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral) { return parseLiteralNode(/*internName*/ true); } - if (allowComputedPropertyNames && token === SyntaxKind.OpenBracketToken) { + if (allowComputedPropertyNames && token() === SyntaxKind.OpenBracketToken) { return parseComputedPropertyName(); } return parseIdentifierName(); @@ -1118,7 +1128,7 @@ namespace ts { } function isSimplePropertyName() { - return token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || tokenIsIdentifierOrKeyword(token); + return token() === SyntaxKind.StringLiteral || token() === SyntaxKind.NumericLiteral || tokenIsIdentifierOrKeyword(token()); } function parseComputedPropertyName(): ComputedPropertyName { @@ -1138,7 +1148,7 @@ namespace ts { } function parseContextualModifier(t: SyntaxKind): boolean { - return token === t && tryParse(nextTokenCanFollowModifier); + return token() === t && tryParse(nextTokenCanFollowModifier); } function nextTokenIsOnSameLineAndCanFollowModifier() { @@ -1150,21 +1160,21 @@ namespace ts { } function nextTokenCanFollowModifier() { - if (token === SyntaxKind.ConstKeyword) { + if (token() === SyntaxKind.ConstKeyword) { // 'const' is only a modifier if followed by 'enum'. return nextToken() === SyntaxKind.EnumKeyword; } - if (token === SyntaxKind.ExportKeyword) { + if (token() === SyntaxKind.ExportKeyword) { nextToken(); - if (token === SyntaxKind.DefaultKeyword) { + if (token() === SyntaxKind.DefaultKeyword) { return lookAhead(nextTokenIsClassOrFunctionOrAsync); } - return token !== SyntaxKind.AsteriskToken && token !== SyntaxKind.AsKeyword && token !== SyntaxKind.OpenBraceToken && canFollowModifier(); + return token() !== SyntaxKind.AsteriskToken && token() !== SyntaxKind.AsKeyword && token() !== SyntaxKind.OpenBraceToken && canFollowModifier(); } - if (token === SyntaxKind.DefaultKeyword) { + if (token() === SyntaxKind.DefaultKeyword) { return nextTokenIsClassOrFunctionOrAsync(); } - if (token === SyntaxKind.StaticKeyword) { + if (token() === SyntaxKind.StaticKeyword) { nextToken(); return canFollowModifier(); } @@ -1173,21 +1183,21 @@ namespace ts { } function parseAnyContextualModifier(): boolean { - return isModifierKind(token) && tryParse(nextTokenCanFollowModifier); + return isModifierKind(token()) && tryParse(nextTokenCanFollowModifier); } function canFollowModifier(): boolean { - return token === SyntaxKind.OpenBracketToken - || token === SyntaxKind.OpenBraceToken - || token === SyntaxKind.AsteriskToken - || token === SyntaxKind.DotDotDotToken + return token() === SyntaxKind.OpenBracketToken + || token() === SyntaxKind.OpenBraceToken + || token() === SyntaxKind.AsteriskToken + || token() === SyntaxKind.DotDotDotToken || isLiteralPropertyName(); } function nextTokenIsClassOrFunctionOrAsync(): boolean { nextToken(); - return token === SyntaxKind.ClassKeyword || token === SyntaxKind.FunctionKeyword || - (token === SyntaxKind.AsyncKeyword && lookAhead(nextTokenIsFunctionKeywordOnSameLine)); + return token() === SyntaxKind.ClassKeyword || token() === SyntaxKind.FunctionKeyword || + (token() === SyntaxKind.AsyncKeyword && lookAhead(nextTokenIsFunctionKeywordOnSameLine)); } // True if positioned at the start of a list element @@ -1207,9 +1217,9 @@ namespace ts { // we're parsing. For example, if we have a semicolon in the middle of a class, then // we really don't want to assume the class is over and we're on a statement in the // outer module. We just want to consume and move on. - return !(token === SyntaxKind.SemicolonToken && inErrorRecovery) && isStartOfStatement(); + return !(token() === SyntaxKind.SemicolonToken && inErrorRecovery) && isStartOfStatement(); case ParsingContext.SwitchClauses: - return token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword; + return token() === SyntaxKind.CaseKeyword || token() === SyntaxKind.DefaultKeyword; case ParsingContext.TypeMembers: return lookAhead(isTypeMemberStart); case ParsingContext.ClassMembers: @@ -1217,19 +1227,19 @@ namespace ts { // not in error recovery. If we're in error recovery, we don't want an errant // semicolon to be treated as a class member (since they're almost always used // for statements. - return lookAhead(isClassMemberStart) || (token === SyntaxKind.SemicolonToken && !inErrorRecovery); + return lookAhead(isClassMemberStart) || (token() === SyntaxKind.SemicolonToken && !inErrorRecovery); case ParsingContext.EnumMembers: // Include open bracket computed properties. This technically also lets in indexers, // which would be a candidate for improved error reporting. - return token === SyntaxKind.OpenBracketToken || isLiteralPropertyName(); + return token() === SyntaxKind.OpenBracketToken || isLiteralPropertyName(); case ParsingContext.ObjectLiteralMembers: - return token === SyntaxKind.OpenBracketToken || token === SyntaxKind.AsteriskToken || isLiteralPropertyName(); + return token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.AsteriskToken || isLiteralPropertyName(); case ParsingContext.ObjectBindingElements: - return token === SyntaxKind.OpenBracketToken || isLiteralPropertyName(); + return token() === SyntaxKind.OpenBracketToken || isLiteralPropertyName(); case ParsingContext.HeritageClauseElement: // If we see { } then only consume it as an expression if it is followed by , or { // That way we won't consume the body of a class in its heritage clause. - if (token === SyntaxKind.OpenBraceToken) { + if (token() === SyntaxKind.OpenBraceToken) { return lookAhead(isValidHeritageClauseObjectLiteral); } @@ -1245,23 +1255,23 @@ namespace ts { case ParsingContext.VariableDeclarations: return isIdentifierOrPattern(); case ParsingContext.ArrayBindingElements: - return token === SyntaxKind.CommaToken || token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern(); + return token() === SyntaxKind.CommaToken || token() === SyntaxKind.DotDotDotToken || isIdentifierOrPattern(); case ParsingContext.TypeParameters: return isIdentifier(); case ParsingContext.ArgumentExpressions: case ParsingContext.ArrayLiteralMembers: - return token === SyntaxKind.CommaToken || token === SyntaxKind.DotDotDotToken || isStartOfExpression(); + return token() === SyntaxKind.CommaToken || token() === SyntaxKind.DotDotDotToken || isStartOfExpression(); case ParsingContext.Parameters: return isStartOfParameter(); case ParsingContext.TypeArguments: case ParsingContext.TupleElementTypes: - return token === SyntaxKind.CommaToken || isStartOfType(); + return token() === SyntaxKind.CommaToken || isStartOfType(); case ParsingContext.HeritageClauses: return isHeritageClause(); case ParsingContext.ImportOrExportSpecifiers: - return tokenIsIdentifierOrKeyword(token); + return tokenIsIdentifierOrKeyword(token()); case ParsingContext.JsxAttributes: - return tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.OpenBraceToken; + return tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.OpenBraceToken; case ParsingContext.JsxChildren: return true; case ParsingContext.JSDocFunctionParameters: @@ -1276,7 +1286,7 @@ namespace ts { } function isValidHeritageClauseObjectLiteral() { - Debug.assert(token === SyntaxKind.OpenBraceToken); + Debug.assert(token() === SyntaxKind.OpenBraceToken); if (nextToken() === SyntaxKind.CloseBraceToken) { // if we see "extends {}" then only treat the {} as what we're extending (and not // the class body) if we have: @@ -1300,12 +1310,12 @@ namespace ts { function nextTokenIsIdentifierOrKeyword() { nextToken(); - return tokenIsIdentifierOrKeyword(token); + return tokenIsIdentifierOrKeyword(token()); } function isHeritageClauseExtendsOrImplementsKeyword(): boolean { - if (token === SyntaxKind.ImplementsKeyword || - token === SyntaxKind.ExtendsKeyword) { + if (token() === SyntaxKind.ImplementsKeyword || + token() === SyntaxKind.ExtendsKeyword) { return lookAhead(nextTokenIsStartOfExpression); } @@ -1320,7 +1330,7 @@ namespace ts { // True if positioned at a list terminator function isListTerminator(kind: ParsingContext): boolean { - if (token === SyntaxKind.EndOfFileToken) { + if (token() === SyntaxKind.EndOfFileToken) { // Being at the end of the file ends all lists. return true; } @@ -1334,43 +1344,43 @@ namespace ts { case ParsingContext.ObjectLiteralMembers: case ParsingContext.ObjectBindingElements: case ParsingContext.ImportOrExportSpecifiers: - return token === SyntaxKind.CloseBraceToken; + return token() === SyntaxKind.CloseBraceToken; case ParsingContext.SwitchClauseStatements: - return token === SyntaxKind.CloseBraceToken || token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword; + return token() === SyntaxKind.CloseBraceToken || token() === SyntaxKind.CaseKeyword || token() === SyntaxKind.DefaultKeyword; case ParsingContext.HeritageClauseElement: - return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword; + return token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.ExtendsKeyword || token() === SyntaxKind.ImplementsKeyword; case ParsingContext.VariableDeclarations: return isVariableDeclaratorListTerminator(); case ParsingContext.TypeParameters: // Tokens other than '>' are here for better error recovery - return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.OpenBraceToken || token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword; + return token() === SyntaxKind.GreaterThanToken || token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.ExtendsKeyword || token() === SyntaxKind.ImplementsKeyword; case ParsingContext.ArgumentExpressions: // Tokens other than ')' are here for better error recovery - return token === SyntaxKind.CloseParenToken || token === SyntaxKind.SemicolonToken; + return token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.SemicolonToken; case ParsingContext.ArrayLiteralMembers: case ParsingContext.TupleElementTypes: case ParsingContext.ArrayBindingElements: - return token === SyntaxKind.CloseBracketToken; + return token() === SyntaxKind.CloseBracketToken; case ParsingContext.Parameters: // Tokens other than ')' and ']' (the latter for index signatures) are here for better error recovery - return token === SyntaxKind.CloseParenToken || token === SyntaxKind.CloseBracketToken /*|| token === SyntaxKind.OpenBraceToken*/; + return token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.CloseBracketToken /*|| token === SyntaxKind.OpenBraceToken*/; case ParsingContext.TypeArguments: // Tokens other than '>' are here for better error recovery - return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.OpenParenToken; + return token() === SyntaxKind.GreaterThanToken || token() === SyntaxKind.OpenParenToken; case ParsingContext.HeritageClauses: - return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.CloseBraceToken; + return token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.CloseBraceToken; case ParsingContext.JsxAttributes: - return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.SlashToken; + return token() === SyntaxKind.GreaterThanToken || token() === SyntaxKind.SlashToken; case ParsingContext.JsxChildren: - return token === SyntaxKind.LessThanToken && lookAhead(nextTokenIsSlash); + return token() === SyntaxKind.LessThanToken && lookAhead(nextTokenIsSlash); case ParsingContext.JSDocFunctionParameters: - return token === SyntaxKind.CloseParenToken || token === SyntaxKind.ColonToken || token === SyntaxKind.CloseBraceToken; + return token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.ColonToken || token() === SyntaxKind.CloseBraceToken; case ParsingContext.JSDocTypeArguments: - return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.CloseBraceToken; + return token() === SyntaxKind.GreaterThanToken || token() === SyntaxKind.CloseBraceToken; case ParsingContext.JSDocTupleTypes: - return token === SyntaxKind.CloseBracketToken || token === SyntaxKind.CloseBraceToken; + return token() === SyntaxKind.CloseBracketToken || token() === SyntaxKind.CloseBraceToken; case ParsingContext.JSDocRecordMembers: - return token === SyntaxKind.CloseBraceToken; + return token() === SyntaxKind.CloseBraceToken; } } @@ -1383,7 +1393,7 @@ namespace ts { // in the case where we're parsing the variable declarator of a 'for-in' statement, we // are done if we see an 'in' keyword in front of us. Same with for-of - if (isInOrOfKeyword(token)) { + if (isInOrOfKeyword(token())) { return true; } @@ -1391,7 +1401,7 @@ namespace ts { // For better error recovery, if we see an '=>' then we just stop immediately. We've got an // arrow function here and it's going to be very unlikely that we'll resynchronize and get // another variable declaration. - if (token === SyntaxKind.EqualsGreaterThanToken) { + if (token() === SyntaxKind.EqualsGreaterThanToken) { return true; } @@ -1790,7 +1800,7 @@ namespace ts { // parse errors. For example, this can happen when people do things like use // a semicolon to delimit object literal members. Note: we'll have already // reported an error when we called parseExpected above. - if (considerSemicolonAsDelimiter && token === SyntaxKind.SemicolonToken && !scanner.hasPrecedingLineBreak()) { + if (considerSemicolonAsDelimiter && token() === SyntaxKind.SemicolonToken && !scanner.hasPrecedingLineBreak()) { nextToken(); } continue; @@ -1870,7 +1880,7 @@ namespace ts { // the code would be implicitly: "name.identifierOrKeyword; identifierNameOrKeyword". // In the first case though, ASI will not take effect because there is not a // line terminator after the identifier or keyword. - if (scanner.hasPrecedingLineBreak() && tokenIsIdentifierOrKeyword(token)) { + if (scanner.hasPrecedingLineBreak() && tokenIsIdentifierOrKeyword(token())) { const matchesPattern = lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine); if (matchesPattern) { @@ -1910,7 +1920,7 @@ namespace ts { let literal: TemplateLiteralFragment; - if (token === SyntaxKind.CloseBraceToken) { + if (token() === SyntaxKind.CloseBraceToken) { reScanTemplateToken(); literal = parseTemplateLiteralFragment(); } @@ -1923,11 +1933,11 @@ namespace ts { } function parseLiteralNode(internName?: boolean): LiteralExpression { - return parseLiteralLikeNode(token, internName); + return parseLiteralLikeNode(token(), internName); } function parseTemplateLiteralFragment(): TemplateLiteralFragment { - return parseLiteralLikeNode(token, /*internName*/ false); + return parseLiteralLikeNode(token(), /*internName*/ false); } function parseLiteralLikeNode(kind: SyntaxKind, internName: boolean): LiteralLikeNode { @@ -1969,7 +1979,7 @@ namespace ts { const typeName = parseEntityName(/*allowReservedWords*/ false, Diagnostics.Type_expected); const node = createNode(SyntaxKind.TypeReference, typeName.pos); node.typeName = typeName; - if (!scanner.hasPrecedingLineBreak() && token === SyntaxKind.LessThanToken) { + if (!scanner.hasPrecedingLineBreak() && token() === SyntaxKind.LessThanToken) { node.typeArguments = parseBracketedList(ParsingContext.TypeArguments, parseType, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); } return finishNode(node); @@ -2023,7 +2033,7 @@ namespace ts { } function parseTypeParameters(): NodeArray { - if (token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.LessThanToken) { return parseBracketedList(ParsingContext.TypeParameters, parseTypeParameter, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); } } @@ -2037,7 +2047,7 @@ namespace ts { } function isStartOfParameter(): boolean { - return token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifierKind(token) || token === SyntaxKind.AtToken || token === SyntaxKind.ThisKeyword; + return token() === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifierKind(token()) || token() === SyntaxKind.AtToken || token() === SyntaxKind.ThisKeyword; } function setModifiers(node: Node, modifiers: ModifiersArray) { @@ -2049,7 +2059,7 @@ namespace ts { function parseParameter(): ParameterDeclaration { const node = createNode(SyntaxKind.Parameter); - if (token === SyntaxKind.ThisKeyword) { + if (token() === SyntaxKind.ThisKeyword) { node.name = createIdentifier(/*isIdentifier*/true, undefined); node.type = parseParameterType(); return finishNode(node); @@ -2062,7 +2072,7 @@ namespace ts { // FormalParameter [Yield,Await]: // BindingElement[?Yield,?Await] node.name = parseIdentifierOrPattern(); - if (getFullWidth(node.name) === 0 && node.flags === 0 && isModifierKind(token)) { + if (getFullWidth(node.name) === 0 && node.flags === 0 && isModifierKind(token())) { // in cases like // 'use strict' // function foo(static) @@ -2181,7 +2191,7 @@ namespace ts { } function isIndexSignature(): boolean { - if (token !== SyntaxKind.OpenBracketToken) { + if (token() !== SyntaxKind.OpenBracketToken) { return false; } @@ -2206,11 +2216,11 @@ namespace ts { // [] // nextToken(); - if (token === SyntaxKind.DotDotDotToken || token === SyntaxKind.CloseBracketToken) { + if (token() === SyntaxKind.DotDotDotToken || token() === SyntaxKind.CloseBracketToken) { return true; } - if (isModifierKind(token)) { + if (isModifierKind(token())) { nextToken(); if (isIdentifier()) { return true; @@ -2227,20 +2237,20 @@ namespace ts { // A colon signifies a well formed indexer // A comma should be a badly formed indexer because comma expressions are not allowed // in computed properties. - if (token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken) { + if (token() === SyntaxKind.ColonToken || token() === SyntaxKind.CommaToken) { return true; } // Question mark could be an indexer with an optional property, // or it could be a conditional expression in a computed property. - if (token !== SyntaxKind.QuestionToken) { + if (token() !== SyntaxKind.QuestionToken) { return false; } // If any of the following tokens are after the question mark, it cannot // be a conditional expression, so treat it as an indexer. nextToken(); - return token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBracketToken; + return token() === SyntaxKind.ColonToken || token() === SyntaxKind.CommaToken || token() === SyntaxKind.CloseBracketToken; } function parseIndexSignatureDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): IndexSignatureDeclaration { @@ -2257,7 +2267,7 @@ namespace ts { const name = parsePropertyName(); const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { const method = createNode(SyntaxKind.MethodSignature, fullStart); setModifiers(method, modifiers); method.name = name; @@ -2276,7 +2286,7 @@ namespace ts { property.questionToken = questionToken; property.type = parseTypeAnnotation(); - if (token === SyntaxKind.EqualsToken) { + if (token() === SyntaxKind.EqualsToken) { // Although type literal properties cannot not have initializers, we attempt // to parse an initializer so we can report in the checker that an interface // property or type literal property cannot have an initializer. @@ -2291,40 +2301,40 @@ namespace ts { function isTypeMemberStart(): boolean { let idToken: SyntaxKind; // Return true if we have the start of a signature member - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return true; } // Eat up all modifiers, but hold on to the last one in case it is actually an identifier - while (isModifierKind(token)) { - idToken = token; + while (isModifierKind(token())) { + idToken = token(); nextToken(); } // Index signatures and computed property names are type members - if (token === SyntaxKind.OpenBracketToken) { + if (token() === SyntaxKind.OpenBracketToken) { return true; } // Try to get the first property-like token following all modifiers if (isLiteralPropertyName()) { - idToken = token; + idToken = token(); nextToken(); } // If we were able to get any potential identifier, check that it is // the start of a member declaration if (idToken) { - return token === SyntaxKind.OpenParenToken || - token === SyntaxKind.LessThanToken || - token === SyntaxKind.QuestionToken || - token === SyntaxKind.ColonToken || + return token() === SyntaxKind.OpenParenToken || + token() === SyntaxKind.LessThanToken || + token() === SyntaxKind.QuestionToken || + token() === SyntaxKind.ColonToken || canParseSemicolon(); } return false; } function parseTypeMember(): TypeElement { - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return parseSignatureMember(SyntaxKind.CallSignature); } - if (token === SyntaxKind.NewKeyword && lookAhead(isStartOfConstructSignature)) { + if (token() === SyntaxKind.NewKeyword && lookAhead(isStartOfConstructSignature)) { return parseSignatureMember(SyntaxKind.ConstructSignature); } const fullStart = getNodePos(); @@ -2337,7 +2347,7 @@ namespace ts { function isStartOfConstructSignature() { nextToken(); - return token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken; + return token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken; } function parseTypeLiteral(): TypeLiteralNode { @@ -2384,7 +2394,7 @@ namespace ts { function parseKeywordAndNoDot(): TypeNode { const node = parseTokenNode(); - return token === SyntaxKind.DotToken ? undefined : node; + return token() === SyntaxKind.DotToken ? undefined : node; } function parseLiteralTypeNode(): LiteralTypeNode { @@ -2399,7 +2409,7 @@ namespace ts { } function parseNonArrayType(): TypeNode { - switch (token) { + switch (token()) { case SyntaxKind.AnyKeyword: case SyntaxKind.StringKeyword: case SyntaxKind.NumberKeyword: @@ -2422,7 +2432,7 @@ namespace ts { return parseTokenNode(); case SyntaxKind.ThisKeyword: { const thisKeyword = parseThisTypeNode(); - if (token === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { + if (token() === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { return parseThisTypePredicate(thisKeyword); } else { @@ -2443,7 +2453,7 @@ namespace ts { } function isStartOfType(): boolean { - switch (token) { + switch (token()) { case SyntaxKind.AnyKeyword: case SyntaxKind.StringKeyword: case SyntaxKind.NumberKeyword: @@ -2477,7 +2487,7 @@ namespace ts { function isStartOfParenthesizedOrFunctionType() { nextToken(); - return token === SyntaxKind.CloseParenToken || isStartOfParameter() || isStartOfType(); + return token() === SyntaxKind.CloseParenToken || isStartOfParameter() || isStartOfType(); } function parseArrayTypeOrHigher(): TypeNode { @@ -2493,7 +2503,7 @@ namespace ts { function parseUnionOrIntersectionType(kind: SyntaxKind, parseConstituentType: () => TypeNode, operator: SyntaxKind): TypeNode { let type = parseConstituentType(); - if (token === operator) { + if (token() === operator) { const types = >[type]; types.pos = type.pos; while (parseOptional(operator)) { @@ -2516,22 +2526,22 @@ namespace ts { } function isStartOfFunctionType(): boolean { - if (token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.LessThanToken) { return true; } - return token === SyntaxKind.OpenParenToken && lookAhead(isUnambiguouslyStartOfFunctionType); + return token() === SyntaxKind.OpenParenToken && lookAhead(isUnambiguouslyStartOfFunctionType); } function skipParameterStart(): boolean { - if (isModifierKind(token)) { + if (isModifierKind(token())) { // Skip modifiers parseModifiers(); } - if (isIdentifier() || token === SyntaxKind.ThisKeyword) { + if (isIdentifier() || token() === SyntaxKind.ThisKeyword) { nextToken(); return true; } - if (token === SyntaxKind.OpenBracketToken || token === SyntaxKind.OpenBraceToken) { + if (token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.OpenBraceToken) { // Return true if we can parse an array or object binding pattern with no errors const previousErrorCount = parseDiagnostics.length; parseIdentifierOrPattern(); @@ -2542,7 +2552,7 @@ namespace ts { function isUnambiguouslyStartOfFunctionType() { nextToken(); - if (token === SyntaxKind.CloseParenToken || token === SyntaxKind.DotDotDotToken) { + if (token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.DotDotDotToken) { // ( ) // ( ... return true; @@ -2550,17 +2560,17 @@ namespace ts { if (skipParameterStart()) { // We successfully skipped modifiers (if any) and an identifier or binding pattern, // now see if we have something that indicates a parameter declaration - if (token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken || - token === SyntaxKind.QuestionToken || token === SyntaxKind.EqualsToken) { + if (token() === SyntaxKind.ColonToken || token() === SyntaxKind.CommaToken || + token() === SyntaxKind.QuestionToken || token() === SyntaxKind.EqualsToken) { // ( xxx : // ( xxx , // ( xxx ? // ( xxx = return true; } - if (token === SyntaxKind.CloseParenToken) { + if (token() === SyntaxKind.CloseParenToken) { nextToken(); - if (token === SyntaxKind.EqualsGreaterThanToken) { + if (token() === SyntaxKind.EqualsGreaterThanToken) { // ( xxx ) => return true; } @@ -2585,7 +2595,7 @@ namespace ts { function parseTypePredicatePrefix() { const id = parseIdentifier(); - if (token === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { + if (token() === SyntaxKind.IsKeyword && !scanner.hasPrecedingLineBreak()) { nextToken(); return id; } @@ -2601,7 +2611,7 @@ namespace ts { if (isStartOfFunctionType()) { return parseFunctionOrConstructorType(SyntaxKind.FunctionType); } - if (token === SyntaxKind.NewKeyword) { + if (token() === SyntaxKind.NewKeyword) { return parseFunctionOrConstructorType(SyntaxKind.ConstructorType); } return parseUnionTypeOrHigher(); @@ -2613,7 +2623,7 @@ namespace ts { // EXPRESSIONS function isStartOfLeftHandSideExpression(): boolean { - switch (token) { + switch (token()) { case SyntaxKind.ThisKeyword: case SyntaxKind.SuperKeyword: case SyntaxKind.NullKeyword: @@ -2643,7 +2653,7 @@ namespace ts { return true; } - switch (token) { + switch (token()) { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: case SyntaxKind.TildeToken: @@ -2675,10 +2685,10 @@ namespace ts { function isStartOfExpressionStatement(): boolean { // As per the grammar, none of '{' or 'function' or 'class' can start an expression statement. - return token !== SyntaxKind.OpenBraceToken && - token !== SyntaxKind.FunctionKeyword && - token !== SyntaxKind.ClassKeyword && - token !== SyntaxKind.AtToken && + return token() !== SyntaxKind.OpenBraceToken && + token() !== SyntaxKind.FunctionKeyword && + token() !== SyntaxKind.ClassKeyword && + token() !== SyntaxKind.AtToken && isStartOfExpression(); } @@ -2706,7 +2716,7 @@ namespace ts { } function parseInitializer(inParameter: boolean): Expression { - if (token !== SyntaxKind.EqualsToken) { + if (token() !== SyntaxKind.EqualsToken) { // It's not uncommon during typing for the user to miss writing the '=' token. Check if // there is no newline after the last token and if we're on an expression. If so, parse // this as an equals-value clause with a missing equals. @@ -2715,7 +2725,7 @@ namespace ts { // it's more likely that a { would be a allowed (as an object literal). While this // is also allowed for parameters, the risk is that we consume the { as an object // literal when it really will be for the block following the parameter. - if (scanner.hasPrecedingLineBreak() || (inParameter && token === SyntaxKind.OpenBraceToken) || !isStartOfExpression()) { + if (scanner.hasPrecedingLineBreak() || (inParameter && token() === SyntaxKind.OpenBraceToken) || !isStartOfExpression()) { // preceding line break, open brace in a parameter (likely a function body) or current token is not an expression - // do not try to parse initializer return undefined; @@ -2776,7 +2786,7 @@ namespace ts { // To avoid a look-ahead, we did not handle the case of an arrow function with a single un-parenthesized // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single // identifier and the current token is an arrow. - if (expr.kind === SyntaxKind.Identifier && token === SyntaxKind.EqualsGreaterThanToken) { + if (expr.kind === SyntaxKind.Identifier && token() === SyntaxKind.EqualsGreaterThanToken) { return parseSimpleArrowFunctionExpression(expr); } @@ -2795,7 +2805,7 @@ namespace ts { } function isYieldExpression(): boolean { - if (token === SyntaxKind.YieldKeyword) { + if (token() === SyntaxKind.YieldKeyword) { // If we have a 'yield' keyword, and this is a context where yield expressions are // allowed, then definitely parse out a yield expression. if (inYieldContext()) { @@ -2837,7 +2847,7 @@ namespace ts { nextToken(); if (!scanner.hasPrecedingLineBreak() && - (token === SyntaxKind.AsteriskToken || isStartOfExpression())) { + (token() === SyntaxKind.AsteriskToken || isStartOfExpression())) { node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); node.expression = parseAssignmentExpressionOrHigher(); return finishNode(node); @@ -2850,7 +2860,7 @@ namespace ts { } function parseSimpleArrowFunctionExpression(identifier: Identifier, asyncModifier?: ModifiersArray): ArrowFunction { - Debug.assert(token === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); + Debug.assert(token() === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); let node: ArrowFunction; if (asyncModifier) { @@ -2899,7 +2909,7 @@ namespace ts { // If we have an arrow, then try to parse the body. Even if not, try to parse if we // have an opening brace, just in case we're in an error state. - const lastToken = token; + const lastToken = token(); arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, /*reportAtCurrentPosition*/false, Diagnostics._0_expected, "=>"); arrowFunction.body = (lastToken === SyntaxKind.EqualsGreaterThanToken || lastToken === SyntaxKind.OpenBraceToken) ? parseArrowFunctionExpressionBody(isAsync) @@ -2913,11 +2923,11 @@ namespace ts { // Unknown -> There *might* be a parenthesized arrow function here. // Speculatively look ahead to be sure, and rollback if not. function isParenthesizedArrowFunctionExpression(): Tristate { - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken || token === SyntaxKind.AsyncKeyword) { + if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken || token() === SyntaxKind.AsyncKeyword) { return lookAhead(isParenthesizedArrowFunctionExpressionWorker); } - if (token === SyntaxKind.EqualsGreaterThanToken) { + if (token() === SyntaxKind.EqualsGreaterThanToken) { // ERROR RECOVERY TWEAK: // If we see a standalone => try to parse it as an arrow function expression as that's // likely what the user intended to write. @@ -2928,17 +2938,17 @@ namespace ts { } function isParenthesizedArrowFunctionExpressionWorker() { - if (token === SyntaxKind.AsyncKeyword) { + if (token() === SyntaxKind.AsyncKeyword) { nextToken(); if (scanner.hasPrecedingLineBreak()) { return Tristate.False; } - if (token !== SyntaxKind.OpenParenToken && token !== SyntaxKind.LessThanToken) { + if (token() !== SyntaxKind.OpenParenToken && token() !== SyntaxKind.LessThanToken) { return Tristate.False; } } - const first = token; + const first = token(); const second = nextToken(); if (first === SyntaxKind.OpenParenToken) { @@ -3040,7 +3050,7 @@ namespace ts { function tryParseAsyncSimpleArrowFunctionExpression(): ArrowFunction { // We do a check here so that we won't be doing unnecessarily call to "lookAhead" - if (token === SyntaxKind.AsyncKeyword) { + if (token() === SyntaxKind.AsyncKeyword) { const isUnParenthesizedAsyncArrowFunction = lookAhead(isUnParenthesizedAsyncArrowFunctionWorker); if (isUnParenthesizedAsyncArrowFunction === Tristate.True) { const asyncModifier = parseModifiersForArrowFunction(); @@ -3055,16 +3065,16 @@ namespace ts { // AsyncArrowFunctionExpression: // 1) async[no LineTerminator here]AsyncArrowBindingIdentifier[?Yield][no LineTerminator here]=>AsyncConciseBody[?In] // 2) CoverCallExpressionAndAsyncArrowHead[?Yield, ?Await][no LineTerminator here]=>AsyncConciseBody[?In] - if (token === SyntaxKind.AsyncKeyword) { + if (token() === SyntaxKind.AsyncKeyword) { nextToken(); // If the "async" is followed by "=>" token then it is not a begining of an async arrow-function // but instead a simple arrow-function which will be parsed inside "parseAssignmentExpressionOrHigher" - if (scanner.hasPrecedingLineBreak() || token === SyntaxKind.EqualsGreaterThanToken) { + if (scanner.hasPrecedingLineBreak() || token() === SyntaxKind.EqualsGreaterThanToken) { return Tristate.False; } // Check for un-parenthesized AsyncArrowFunction const expr = parseBinaryExpressionOrHigher(/*precedence*/ 0); - if (!scanner.hasPrecedingLineBreak() && expr.kind === SyntaxKind.Identifier && token === SyntaxKind.EqualsGreaterThanToken) { + if (!scanner.hasPrecedingLineBreak() && expr.kind === SyntaxKind.Identifier && token() === SyntaxKind.EqualsGreaterThanToken) { return Tristate.True; } } @@ -3099,7 +3109,7 @@ namespace ts { // - "a ? (b): c" will have "(b):" parsed as a signature with a return type annotation. // // So we need just a bit of lookahead to ensure that it can only be a signature. - if (!allowAmbiguity && token !== SyntaxKind.EqualsGreaterThanToken && token !== SyntaxKind.OpenBraceToken) { + if (!allowAmbiguity && token() !== SyntaxKind.EqualsGreaterThanToken && token() !== SyntaxKind.OpenBraceToken) { // Returning undefined here will cause our caller to rewind to where we started from. return undefined; } @@ -3108,13 +3118,13 @@ namespace ts { } function parseArrowFunctionExpressionBody(isAsync: boolean): Block | Expression { - if (token === SyntaxKind.OpenBraceToken) { + if (token() === SyntaxKind.OpenBraceToken) { return parseFunctionBlock(/*allowYield*/ false, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false); } - if (token !== SyntaxKind.SemicolonToken && - token !== SyntaxKind.FunctionKeyword && - token !== SyntaxKind.ClassKeyword && + if (token() !== SyntaxKind.SemicolonToken && + token() !== SyntaxKind.FunctionKeyword && + token() !== SyntaxKind.ClassKeyword && isStartOfStatement() && !isStartOfExpressionStatement()) { // Check if we got a plain statement (i.e. no expression-statements, no function/class expressions/declarations) @@ -3196,7 +3206,7 @@ namespace ts { // ^^token; leftOperand = b. Return b ** c to the caller as a rightOperand // a ** b - c // ^token; leftOperand = b. Return b to the caller as a rightOperand - const consumeCurrentOperator = token === SyntaxKind.AsteriskAsteriskToken ? + const consumeCurrentOperator = token() === SyntaxKind.AsteriskAsteriskToken ? newPrecedence >= precedence : newPrecedence > precedence; @@ -3204,11 +3214,11 @@ namespace ts { break; } - if (token === SyntaxKind.InKeyword && inDisallowInContext()) { + if (token() === SyntaxKind.InKeyword && inDisallowInContext()) { break; } - if (token === SyntaxKind.AsKeyword) { + if (token() === SyntaxKind.AsKeyword) { // Make sure we *do* perform ASI for constructs like this: // var x = foo // as (Bar) @@ -3231,7 +3241,7 @@ namespace ts { } function isBinaryOperator() { - if (inDisallowInContext() && token === SyntaxKind.InKeyword) { + if (inDisallowInContext() && token() === SyntaxKind.InKeyword) { return false; } @@ -3239,7 +3249,7 @@ namespace ts { } function getBinaryOperatorPrecedence(): number { - switch (token) { + switch (token()) { case SyntaxKind.BarBarToken: return 1; case SyntaxKind.AmpersandAmpersandToken: @@ -3300,7 +3310,7 @@ namespace ts { function parsePrefixUnaryExpression() { const node = createNode(SyntaxKind.PrefixUnaryExpression); - node.operator = token; + node.operator = token(); nextToken(); node.operand = parseSimpleUnaryExpression(); @@ -3329,7 +3339,7 @@ namespace ts { } function isAwaitExpression(): boolean { - if (token === SyntaxKind.AwaitKeyword) { + if (token() === SyntaxKind.AwaitKeyword) { if (inAwaitContext()) { return true; } @@ -3362,14 +3372,14 @@ namespace ts { if (isIncrementExpression()) { const incrementExpression = parseIncrementExpression(); - return token === SyntaxKind.AsteriskAsteriskToken ? + return token() === SyntaxKind.AsteriskAsteriskToken ? parseBinaryExpressionRest(getBinaryOperatorPrecedence(), incrementExpression) : incrementExpression; } - const unaryOperator = token; + const unaryOperator = token(); const simpleUnaryExpression = parseSimpleUnaryExpression(); - if (token === SyntaxKind.AsteriskAsteriskToken) { + if (token() === SyntaxKind.AsteriskAsteriskToken) { const start = skipTrivia(sourceText, simpleUnaryExpression.pos); if (simpleUnaryExpression.kind === SyntaxKind.TypeAssertionExpression) { parseErrorAtPosition(start, simpleUnaryExpression.end - start, Diagnostics.A_type_assertion_expression_is_not_allowed_in_the_left_hand_side_of_an_exponentiation_expression_Consider_enclosing_the_expression_in_parentheses); @@ -3395,7 +3405,7 @@ namespace ts { * 8) ! UnaryExpression[?yield] */ function parseSimpleUnaryExpression(): UnaryExpression { - switch (token) { + switch (token()) { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: case SyntaxKind.TildeToken: @@ -3430,7 +3440,7 @@ namespace ts { function isIncrementExpression(): boolean { // This function is called inside parseUnaryExpression to decide // whether to call parseSimpleUnaryExpression or call parseIncrementExpression directly - switch (token) { + switch (token()) { case SyntaxKind.PlusToken: case SyntaxKind.MinusToken: case SyntaxKind.TildeToken: @@ -3463,14 +3473,14 @@ namespace ts { * In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression */ function parseIncrementExpression(): IncrementExpression { - if (token === SyntaxKind.PlusPlusToken || token === SyntaxKind.MinusMinusToken) { + if (token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) { const node = createNode(SyntaxKind.PrefixUnaryExpression); - node.operator = token; + node.operator = token(); nextToken(); node.operand = parseLeftHandSideExpressionOrHigher(); return finishNode(node); } - else if (sourceFile.languageVariant === LanguageVariant.JSX && token === SyntaxKind.LessThanToken && lookAhead(nextTokenIsIdentifierOrKeyword)) { + else if (sourceFile.languageVariant === LanguageVariant.JSX && token() === SyntaxKind.LessThanToken && lookAhead(nextTokenIsIdentifierOrKeyword)) { // JSXElement is part of primaryExpression return parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ true); } @@ -3478,10 +3488,10 @@ namespace ts { const expression = parseLeftHandSideExpressionOrHigher(); Debug.assert(isLeftHandSideExpression(expression)); - if ((token === SyntaxKind.PlusPlusToken || token === SyntaxKind.MinusMinusToken) && !scanner.hasPrecedingLineBreak()) { + if ((token() === SyntaxKind.PlusPlusToken || token() === SyntaxKind.MinusMinusToken) && !scanner.hasPrecedingLineBreak()) { const node = createNode(SyntaxKind.PostfixUnaryExpression, expression.pos); node.operand = expression; - node.operator = token; + node.operator = token(); nextToken(); return finishNode(node); } @@ -3520,7 +3530,7 @@ namespace ts { // the last two CallExpression productions. Or we have a MemberExpression which either // completes the LeftHandSideExpression, or starts the beginning of the first four // CallExpression productions. - const expression = token === SyntaxKind.SuperKeyword + const expression = token() === SyntaxKind.SuperKeyword ? parseSuperExpression() : parseMemberExpressionOrHigher(); @@ -3583,7 +3593,7 @@ namespace ts { function parseSuperExpression(): MemberExpression { const expression = parseTokenNode(); - if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.DotToken || token === SyntaxKind.OpenBracketToken) { + if (token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.DotToken || token() === SyntaxKind.OpenBracketToken) { return expression; } @@ -3646,7 +3656,7 @@ namespace ts { // does less damage and we can report a better error. // Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios // of one sort or another. - if (inExpressionContext && token === SyntaxKind.LessThanToken) { + if (inExpressionContext && token() === SyntaxKind.LessThanToken) { const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElement(/*inExpressionContext*/true)); if (invalidElement) { parseErrorAtCurrentToken(Diagnostics.JSX_expressions_must_have_one_parent_element); @@ -3665,12 +3675,12 @@ namespace ts { function parseJsxText(): JsxText { const node = createNode(SyntaxKind.JsxText, scanner.getStartPos()); - token = scanner.scanJsxToken(); + currentToken = scanner.scanJsxToken(); return finishNode(node); } function parseJsxChild(): JsxChild { - switch (token) { + switch (token()) { case SyntaxKind.JsxText: return parseJsxText(); case SyntaxKind.OpenBraceToken: @@ -3678,7 +3688,7 @@ namespace ts { case SyntaxKind.LessThanToken: return parseJsxElementOrSelfClosingElement(/*inExpressionContext*/ false); } - Debug.fail("Unknown JSX child kind " + token); + Debug.fail("Unknown JSX child kind " + token()); } function parseJsxChildren(openingTagName: LeftHandSideExpression): NodeArray { @@ -3688,12 +3698,12 @@ namespace ts { parsingContext |= 1 << ParsingContext.JsxChildren; while (true) { - token = scanner.reScanJsxToken(); - if (token === SyntaxKind.LessThanSlashToken) { + currentToken = scanner.reScanJsxToken(); + if (token() === SyntaxKind.LessThanSlashToken) { // Closing tag break; } - else if (token === SyntaxKind.EndOfFileToken) { + else if (token() === SyntaxKind.EndOfFileToken) { // If we hit EOF, issue the error at the tag that lacks the closing element // rather than at the end of the file (which is useless) parseErrorAtPosition(openingTagName.pos, openingTagName.end - openingTagName.pos, Diagnostics.JSX_element_0_has_no_corresponding_closing_tag, getTextOfNodeFromSourceText(sourceText, openingTagName)); @@ -3719,7 +3729,7 @@ namespace ts { const attributes = parseList(ParsingContext.JsxAttributes, parseJsxAttribute); let node: JsxOpeningLikeElement; - if (token === SyntaxKind.GreaterThanToken) { + if (token() === SyntaxKind.GreaterThanToken) { // Closing tag, so scan the immediately-following text with the JSX scanning instead // of regular scanning to avoid treating illegal characters (e.g. '#') as immediate // scanning errors @@ -3751,7 +3761,7 @@ namespace ts { // primaryExpression in the form of an identifier and "this" keyword // We can't just simply use parseLeftHandSideExpressionOrHigher because then we will start consider class,function etc as a keyword // We only want to consider "this" as a primaryExpression - let expression: JsxTagNameExpression = token === SyntaxKind.ThisKeyword ? + let expression: JsxTagNameExpression = token() === SyntaxKind.ThisKeyword ? parseTokenNode() : parseIdentifierName(); while (parseOptional(SyntaxKind.DotToken)) { const propertyAccess: PropertyAccessExpression = createNode(SyntaxKind.PropertyAccessExpression, expression.pos); @@ -3766,7 +3776,7 @@ namespace ts { const node = createNode(SyntaxKind.JsxExpression); parseExpected(SyntaxKind.OpenBraceToken); - if (token !== SyntaxKind.CloseBraceToken) { + if (token() !== SyntaxKind.CloseBraceToken) { node.expression = parseAssignmentExpressionOrHigher(); } if (inExpressionContext) { @@ -3781,7 +3791,7 @@ namespace ts { } function parseJsxAttribute(): JsxAttribute | JsxSpreadAttribute { - if (token === SyntaxKind.OpenBraceToken) { + if (token() === SyntaxKind.OpenBraceToken) { return parseJsxSpreadAttribute(); } @@ -3789,7 +3799,7 @@ namespace ts { const node = createNode(SyntaxKind.JsxAttribute); node.name = parseIdentifierName(); if (parseOptional(SyntaxKind.EqualsToken)) { - switch (token) { + switch (token()) { case SyntaxKind.StringLiteral: node.initializer = parseLiteralNode(); break; @@ -3844,7 +3854,7 @@ namespace ts { continue; } - if (token === SyntaxKind.ExclamationToken && !scanner.hasPrecedingLineBreak()) { + if (token() === SyntaxKind.ExclamationToken && !scanner.hasPrecedingLineBreak()) { nextToken(); const nonNullExpression = createNode(SyntaxKind.NonNullExpression, expression.pos); nonNullExpression.expression = expression; @@ -3859,7 +3869,7 @@ namespace ts { // It's not uncommon for a user to write: "new Type[]". // Check for that common pattern and report a better error message. - if (token !== SyntaxKind.CloseBracketToken) { + if (token() !== SyntaxKind.CloseBracketToken) { indexedAccess.argumentExpression = allowInAnd(parseExpression); if (indexedAccess.argumentExpression.kind === SyntaxKind.StringLiteral || indexedAccess.argumentExpression.kind === SyntaxKind.NumericLiteral) { const literal = indexedAccess.argumentExpression; @@ -3872,10 +3882,10 @@ namespace ts { continue; } - if (token === SyntaxKind.NoSubstitutionTemplateLiteral || token === SyntaxKind.TemplateHead) { + if (token() === SyntaxKind.NoSubstitutionTemplateLiteral || token() === SyntaxKind.TemplateHead) { const tagExpression = createNode(SyntaxKind.TaggedTemplateExpression, expression.pos); tagExpression.tag = expression; - tagExpression.template = token === SyntaxKind.NoSubstitutionTemplateLiteral + tagExpression.template = token() === SyntaxKind.NoSubstitutionTemplateLiteral ? parseLiteralNode() : parseTemplateExpression(); expression = finishNode(tagExpression); @@ -3889,7 +3899,7 @@ namespace ts { function parseCallExpressionRest(expression: LeftHandSideExpression): LeftHandSideExpression { while (true) { expression = parseMemberExpressionRest(expression); - if (token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.LessThanToken) { // See if this is the start of a generic invocation. If so, consume it and // keep checking for postfix expressions. Otherwise, it's just a '<' that's // part of an arithmetic expression. Break out so we consume it higher in the @@ -3906,7 +3916,7 @@ namespace ts { expression = finishNode(callExpr); continue; } - else if (token === SyntaxKind.OpenParenToken) { + else if (token() === SyntaxKind.OpenParenToken) { const callExpr = createNode(SyntaxKind.CallExpression, expression.pos); callExpr.expression = expression; callExpr.arguments = parseArgumentList(); @@ -3944,7 +3954,7 @@ namespace ts { } function canFollowTypeArgumentsInExpression(): boolean { - switch (token) { + switch (token()) { case SyntaxKind.OpenParenToken: // foo( // this case are the only case where this token can legally follow a type argument // list. So we definitely want to treat this as a type arg list. @@ -3984,7 +3994,7 @@ namespace ts { } function parsePrimaryExpression(): PrimaryExpression { - switch (token) { + switch (token()) { case SyntaxKind.NumericLiteral: case SyntaxKind.StringLiteral: case SyntaxKind.NoSubstitutionTemplateLiteral: @@ -4045,8 +4055,8 @@ namespace ts { } function parseArgumentOrArrayLiteralElement(): Expression { - return token === SyntaxKind.DotDotDotToken ? parseSpreadElement() : - token === SyntaxKind.CommaToken ? createNode(SyntaxKind.OmittedExpression) : + return token() === SyntaxKind.DotDotDotToken ? parseSpreadElement() : + token() === SyntaxKind.CommaToken ? createNode(SyntaxKind.OmittedExpression) : parseAssignmentExpressionOrHigher(); } @@ -4092,7 +4102,7 @@ namespace ts { // Disallowing of optional property assignments happens in the grammar checker. const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); - if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + if (asteriskToken || token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken); } @@ -4102,7 +4112,7 @@ namespace ts { // IdentifierReference[?Yield] Initializer[In, ?Yield] // this is necessary because ObjectLiteral productions are also used to cover grammar for ObjectAssignmentPattern const isShorthandPropertyAssignment = - tokenIsIdentifier && (token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBraceToken || token === SyntaxKind.EqualsToken); + tokenIsIdentifier && (token() === SyntaxKind.CommaToken || token() === SyntaxKind.CloseBraceToken || token() === SyntaxKind.EqualsToken); if (isShorthandPropertyAssignment) { const shorthandDeclaration = createNode(SyntaxKind.ShorthandPropertyAssignment, fullStart); @@ -4181,7 +4191,7 @@ namespace ts { parseExpected(SyntaxKind.NewKeyword); node.expression = parseMemberExpressionOrHigher(); node.typeArguments = tryParse(parseTypeArgumentsInExpression); - if (node.typeArguments || token === SyntaxKind.OpenParenToken) { + if (node.typeArguments || token() === SyntaxKind.OpenParenToken) { node.arguments = parseArgumentList(); } @@ -4277,8 +4287,8 @@ namespace ts { parseExpected(SyntaxKind.OpenParenToken); let initializer: VariableDeclarationList | Expression = undefined; - if (token !== SyntaxKind.SemicolonToken) { - if (token === SyntaxKind.VarKeyword || token === SyntaxKind.LetKeyword || token === SyntaxKind.ConstKeyword) { + if (token() !== SyntaxKind.SemicolonToken) { + if (token() === SyntaxKind.VarKeyword || token() === SyntaxKind.LetKeyword || token() === SyntaxKind.ConstKeyword) { initializer = parseVariableDeclarationList(/*inForStatementInitializer*/ true); } else { @@ -4304,11 +4314,11 @@ namespace ts { const forStatement = createNode(SyntaxKind.ForStatement, pos); forStatement.initializer = initializer; parseExpected(SyntaxKind.SemicolonToken); - if (token !== SyntaxKind.SemicolonToken && token !== SyntaxKind.CloseParenToken) { + if (token() !== SyntaxKind.SemicolonToken && token() !== SyntaxKind.CloseParenToken) { forStatement.condition = allowInAnd(parseExpression); } parseExpected(SyntaxKind.SemicolonToken); - if (token !== SyntaxKind.CloseParenToken) { + if (token() !== SyntaxKind.CloseParenToken) { forStatement.incrementor = allowInAnd(parseExpression); } parseExpected(SyntaxKind.CloseParenToken); @@ -4372,7 +4382,7 @@ namespace ts { } function parseCaseOrDefaultClause(): CaseOrDefaultClause { - return token === SyntaxKind.CaseKeyword ? parseCaseClause() : parseDefaultClause(); + return token() === SyntaxKind.CaseKeyword ? parseCaseClause() : parseDefaultClause(); } function parseSwitchStatement(): SwitchStatement { @@ -4411,11 +4421,11 @@ namespace ts { parseExpected(SyntaxKind.TryKeyword); node.tryBlock = parseBlock(/*ignoreMissingOpenBrace*/ false); - node.catchClause = token === SyntaxKind.CatchKeyword ? parseCatchClause() : undefined; + node.catchClause = token() === SyntaxKind.CatchKeyword ? parseCatchClause() : undefined; // If we don't have a catch clause, then we must have a finally clause. Try to parse // one out no matter what. - if (!node.catchClause || token === SyntaxKind.FinallyKeyword) { + if (!node.catchClause || token() === SyntaxKind.FinallyKeyword) { parseExpected(SyntaxKind.FinallyKeyword); node.finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false); } @@ -4465,22 +4475,22 @@ namespace ts { function nextTokenIsIdentifierOrKeywordOnSameLine() { nextToken(); - return tokenIsIdentifierOrKeyword(token) && !scanner.hasPrecedingLineBreak(); + return tokenIsIdentifierOrKeyword(token()) && !scanner.hasPrecedingLineBreak(); } function nextTokenIsFunctionKeywordOnSameLine() { nextToken(); - return token === SyntaxKind.FunctionKeyword && !scanner.hasPrecedingLineBreak(); + return token() === SyntaxKind.FunctionKeyword && !scanner.hasPrecedingLineBreak(); } function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() { nextToken(); - return (tokenIsIdentifierOrKeyword(token) || token === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak(); + return (tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak(); } function isDeclaration(): boolean { while (true) { - switch (token) { + switch (token()) { case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: case SyntaxKind.ConstKeyword: @@ -4532,17 +4542,17 @@ namespace ts { case SyntaxKind.GlobalKeyword: nextToken(); - return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.Identifier || token === SyntaxKind.ExportKeyword; + return token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.Identifier || token() === SyntaxKind.ExportKeyword; case SyntaxKind.ImportKeyword: nextToken(); - return token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBraceToken || tokenIsIdentifierOrKeyword(token); + return token() === SyntaxKind.StringLiteral || token() === SyntaxKind.AsteriskToken || + token() === SyntaxKind.OpenBraceToken || tokenIsIdentifierOrKeyword(token()); case SyntaxKind.ExportKeyword: nextToken(); - if (token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword || - token === SyntaxKind.AsKeyword) { + if (token() === SyntaxKind.EqualsToken || token() === SyntaxKind.AsteriskToken || + token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.DefaultKeyword || + token() === SyntaxKind.AsKeyword) { return true; } continue; @@ -4561,7 +4571,7 @@ namespace ts { } function isStartOfStatement(): boolean { - switch (token) { + switch (token()) { case SyntaxKind.AtToken: case SyntaxKind.SemicolonToken: case SyntaxKind.OpenBraceToken: @@ -4619,7 +4629,7 @@ namespace ts { function nextTokenIsIdentifierOrStartOfDestructuring() { nextToken(); - return isIdentifier() || token === SyntaxKind.OpenBraceToken || token === SyntaxKind.OpenBracketToken; + return isIdentifier() || token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.OpenBracketToken; } function isLetDeclaration() { @@ -4629,7 +4639,7 @@ namespace ts { } function parseStatement(): Statement { - switch (token) { + switch (token()) { case SyntaxKind.SemicolonToken: return parseEmptyStatement(); case SyntaxKind.OpenBraceToken: @@ -4703,7 +4713,7 @@ namespace ts { const fullStart = getNodePos(); const decorators = parseDecorators(); const modifiers = parseModifiers(); - switch (token) { + switch (token()) { case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: case SyntaxKind.ConstKeyword: @@ -4726,7 +4736,7 @@ namespace ts { return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); case SyntaxKind.ExportKeyword: nextToken(); - switch (token) { + switch (token()) { case SyntaxKind.DefaultKeyword: case SyntaxKind.EqualsToken: return parseExportAssignment(fullStart, decorators, modifiers); @@ -4750,11 +4760,11 @@ namespace ts { function nextTokenIsIdentifierOrStringLiteralOnSameLine() { nextToken(); - return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token === SyntaxKind.StringLiteral); + return !scanner.hasPrecedingLineBreak() && (isIdentifier() || token() === SyntaxKind.StringLiteral); } function parseFunctionBlockOrSemicolon(isGenerator: boolean, isAsync: boolean, diagnosticMessage?: DiagnosticMessage): Block { - if (token !== SyntaxKind.OpenBraceToken && canParseSemicolon()) { + if (token() !== SyntaxKind.OpenBraceToken && canParseSemicolon()) { parseSemicolon(); return; } @@ -4765,7 +4775,7 @@ namespace ts { // DECLARATIONS function parseArrayBindingElement(): BindingElement { - if (token === SyntaxKind.CommaToken) { + if (token() === SyntaxKind.CommaToken) { return createNode(SyntaxKind.OmittedExpression); } const node = createNode(SyntaxKind.BindingElement); @@ -4779,7 +4789,7 @@ namespace ts { const node = createNode(SyntaxKind.BindingElement); const tokenIsIdentifier = isIdentifier(); const propertyName = parsePropertyName(); - if (tokenIsIdentifier && token !== SyntaxKind.ColonToken) { + if (tokenIsIdentifier && token() !== SyntaxKind.ColonToken) { node.name = propertyName; } else { @@ -4808,14 +4818,14 @@ namespace ts { } function isIdentifierOrPattern() { - return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.OpenBracketToken || isIdentifier(); + return token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.OpenBracketToken || isIdentifier(); } function parseIdentifierOrPattern(): Identifier | BindingPattern { - if (token === SyntaxKind.OpenBracketToken) { + if (token() === SyntaxKind.OpenBracketToken) { return parseArrayBindingPattern(); } - if (token === SyntaxKind.OpenBraceToken) { + if (token() === SyntaxKind.OpenBraceToken) { return parseObjectBindingPattern(); } return parseIdentifier(); @@ -4825,7 +4835,7 @@ namespace ts { const node = createNode(SyntaxKind.VariableDeclaration); node.name = parseIdentifierOrPattern(); node.type = parseTypeAnnotation(); - if (!isInOrOfKeyword(token)) { + if (!isInOrOfKeyword(token())) { node.initializer = parseInitializer(/*inParameter*/ false); } return finishNode(node); @@ -4834,7 +4844,7 @@ namespace ts { function parseVariableDeclarationList(inForStatementInitializer: boolean): VariableDeclarationList { const node = createNode(SyntaxKind.VariableDeclarationList); - switch (token) { + switch (token()) { case SyntaxKind.VarKeyword: break; case SyntaxKind.LetKeyword: @@ -4858,7 +4868,7 @@ namespace ts { // So we need to look ahead to determine if 'of' should be treated as a keyword in // this context. // The checker will then give an error that there is an empty declaration list. - if (token === SyntaxKind.OfKeyword && lookAhead(canFollowContextualOfKeyword)) { + if (token() === SyntaxKind.OfKeyword && lookAhead(canFollowContextualOfKeyword)) { node.declarations = createMissingList(); } else { @@ -4956,7 +4966,7 @@ namespace ts { // Note: this is not legal as per the grammar. But we allow it in the parser and // report an error in the grammar checker. const questionToken = parseOptionalToken(SyntaxKind.QuestionToken); - if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + if (asteriskToken || token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.LessThanToken) { return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, Diagnostics.or_expected); } else { @@ -4994,13 +5004,13 @@ namespace ts { function isClassMemberStart(): boolean { let idToken: SyntaxKind; - if (token === SyntaxKind.AtToken) { + if (token() === SyntaxKind.AtToken) { return true; } // Eat up all modifiers, but hold on to the last one in case it is actually an identifier. - while (isModifierKind(token)) { - idToken = token; + while (isModifierKind(token())) { + idToken = token(); // If the idToken is a class modifier (protected, private, public, and static), it is // certain that we are starting to parse class member. This allows better error recovery // Example: @@ -5014,19 +5024,19 @@ namespace ts { nextToken(); } - if (token === SyntaxKind.AsteriskToken) { + if (token() === SyntaxKind.AsteriskToken) { return true; } // Try to get the first property-like token following all modifiers. // This can either be an identifier or the 'get' or 'set' keywords. if (isLiteralPropertyName()) { - idToken = token; + idToken = token(); nextToken(); } // Index signatures and computed properties are class members; we can parse. - if (token === SyntaxKind.OpenBracketToken) { + if (token() === SyntaxKind.OpenBracketToken) { return true; } @@ -5039,7 +5049,7 @@ namespace ts { // If it *is* a keyword, but not an accessor, check a little farther along // to see if it should actually be parsed as a class member. - switch (token) { + switch (token()) { case SyntaxKind.OpenParenToken: // Method declaration case SyntaxKind.LessThanToken: // Generic Method declaration case SyntaxKind.ColonToken: // Type Annotation for declaration @@ -5094,9 +5104,9 @@ namespace ts { let modifiers: ModifiersArray; while (true) { const modifierStart = scanner.getStartPos(); - const modifierKind = token; + const modifierKind = token(); - if (token === SyntaxKind.ConstKeyword && permitInvalidConstAsModifier) { + if (token() === SyntaxKind.ConstKeyword && permitInvalidConstAsModifier) { // We need to ensure that any subsequent modifiers appear on the same line // so that when 'const' is a standalone declaration, we don't issue an error. if (!tryParse(nextTokenIsOnSameLineAndCanFollowModifier)) { @@ -5127,9 +5137,9 @@ namespace ts { function parseModifiersForArrowFunction(): ModifiersArray { let flags = 0; let modifiers: ModifiersArray; - if (token === SyntaxKind.AsyncKeyword) { + if (token() === SyntaxKind.AsyncKeyword) { const modifierStart = scanner.getStartPos(); - const modifierKind = token; + const modifierKind = token(); nextToken(); modifiers = []; modifiers.pos = modifierStart; @@ -5143,7 +5153,7 @@ namespace ts { } function parseClassElement(): ClassElement { - if (token === SyntaxKind.SemicolonToken) { + if (token() === SyntaxKind.SemicolonToken) { const result = createNode(SyntaxKind.SemicolonClassElement); nextToken(); return finishNode(result); @@ -5158,7 +5168,7 @@ namespace ts { return accessor; } - if (token === SyntaxKind.ConstructorKeyword) { + if (token() === SyntaxKind.ConstructorKeyword) { return parseConstructorDeclaration(fullStart, decorators, modifiers); } @@ -5168,11 +5178,11 @@ namespace ts { // It is very important that we check this *after* checking indexers because // the [ token can start an index signature or a computed property name - if (tokenIsIdentifierOrKeyword(token) || - token === SyntaxKind.StringLiteral || - token === SyntaxKind.NumericLiteral || - token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBracketToken) { + if (tokenIsIdentifierOrKeyword(token()) || + token() === SyntaxKind.StringLiteral || + token() === SyntaxKind.NumericLiteral || + token() === SyntaxKind.AsteriskToken || + token() === SyntaxKind.OpenBracketToken) { return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } @@ -5233,7 +5243,7 @@ namespace ts { } function isImplementsClause() { - return token === SyntaxKind.ImplementsKeyword && lookAhead(nextTokenIsIdentifierOrKeyword); + return token() === SyntaxKind.ImplementsKeyword && lookAhead(nextTokenIsIdentifierOrKeyword); } function parseHeritageClauses(isClassHeritageClause: boolean): NodeArray { @@ -5248,9 +5258,9 @@ namespace ts { } function parseHeritageClause() { - if (token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword) { + if (token() === SyntaxKind.ExtendsKeyword || token() === SyntaxKind.ImplementsKeyword) { const node = createNode(SyntaxKind.HeritageClause); - node.token = token; + node.token = token(); nextToken(); node.types = parseDelimitedList(ParsingContext.HeritageClauseElement, parseExpressionWithTypeArguments); return finishNode(node); @@ -5262,7 +5272,7 @@ namespace ts { function parseExpressionWithTypeArguments(): ExpressionWithTypeArguments { const node = createNode(SyntaxKind.ExpressionWithTypeArguments); node.expression = parseLeftHandSideExpressionOrHigher(); - if (token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.LessThanToken) { node.typeArguments = parseBracketedList(ParsingContext.TypeArguments, parseType, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken); } @@ -5270,7 +5280,7 @@ namespace ts { } function isHeritageClause(): boolean { - return token === SyntaxKind.ExtendsKeyword || token === SyntaxKind.ImplementsKeyword; + return token() === SyntaxKind.ExtendsKeyword || token() === SyntaxKind.ImplementsKeyword; } function parseClassMembers() { @@ -5360,7 +5370,7 @@ namespace ts { const node = createNode(SyntaxKind.ModuleDeclaration, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - if (token === SyntaxKind.GlobalKeyword) { + if (token() === SyntaxKind.GlobalKeyword) { // parse 'global' as name of global scope augmentation node.name = parseIdentifier(); node.flags |= NodeFlags.GlobalAugmentation; @@ -5369,7 +5379,7 @@ namespace ts { node.name = parseLiteralNode(/*internName*/ true); } - if (token === SyntaxKind.OpenBraceToken) { + if (token() === SyntaxKind.OpenBraceToken) { node.body = parseModuleBlock(); } else { @@ -5381,7 +5391,7 @@ namespace ts { function parseModuleDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ModuleDeclaration { let flags = modifiers ? modifiers.flags : 0; - if (token === SyntaxKind.GlobalKeyword) { + if (token() === SyntaxKind.GlobalKeyword) { // global augmentation return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers); } @@ -5390,7 +5400,7 @@ namespace ts { } else { parseExpected(SyntaxKind.ModuleKeyword); - if (token === SyntaxKind.StringLiteral) { + if (token() === SyntaxKind.StringLiteral) { return parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers); } } @@ -5398,7 +5408,7 @@ namespace ts { } function isExternalModuleReference() { - return token === SyntaxKind.RequireKeyword && + return token() === SyntaxKind.RequireKeyword && lookAhead(nextTokenIsOpenParen); } @@ -5431,7 +5441,7 @@ namespace ts { let identifier: Identifier; if (isIdentifier()) { identifier = parseIdentifier(); - if (token !== SyntaxKind.CommaToken && token !== SyntaxKind.FromKeyword) { + if (token() !== SyntaxKind.CommaToken && token() !== SyntaxKind.FromKeyword) { // ImportEquals declaration of type: // import x = require("mod"); or // import x = M.x; @@ -5455,8 +5465,8 @@ namespace ts { // import ImportClause from ModuleSpecifier ; // import ModuleSpecifier; if (identifier || // import id - token === SyntaxKind.AsteriskToken || // import * - token === SyntaxKind.OpenBraceToken) { // import { + token() === SyntaxKind.AsteriskToken || // import * + token() === SyntaxKind.OpenBraceToken) { // import { importDeclaration.importClause = parseImportClause(identifier, afterImportPos); parseExpected(SyntaxKind.FromKeyword); } @@ -5485,7 +5495,7 @@ namespace ts { // parse namespace or named imports if (!importClause.name || parseOptional(SyntaxKind.CommaToken)) { - importClause.namedBindings = token === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImportsOrExports(SyntaxKind.NamedImports); + importClause.namedBindings = token() === SyntaxKind.AsteriskToken ? parseNamespaceImport() : parseNamedImportsOrExports(SyntaxKind.NamedImports); } return finishNode(importClause); @@ -5507,7 +5517,7 @@ namespace ts { } function parseModuleSpecifier(): Expression { - if (token === SyntaxKind.StringLiteral) { + if (token() === SyntaxKind.StringLiteral) { const result = parseLiteralNode(); internIdentifier((result).text); return result; @@ -5563,14 +5573,14 @@ namespace ts { // ExportSpecifier: // IdentifierName // IdentifierName as IdentifierName - let checkIdentifierIsKeyword = isKeyword(token) && !isIdentifier(); + let checkIdentifierIsKeyword = isKeyword(token()) && !isIdentifier(); let checkIdentifierStart = scanner.getTokenPos(); let checkIdentifierEnd = scanner.getTextPos(); const identifierName = parseIdentifierName(); - if (token === SyntaxKind.AsKeyword) { + if (token() === SyntaxKind.AsKeyword) { node.propertyName = identifierName; parseExpected(SyntaxKind.AsKeyword); - checkIdentifierIsKeyword = isKeyword(token) && !isIdentifier(); + checkIdentifierIsKeyword = isKeyword(token()) && !isIdentifier(); checkIdentifierStart = scanner.getTokenPos(); checkIdentifierEnd = scanner.getTextPos(); node.name = parseIdentifierName(); @@ -5599,7 +5609,7 @@ namespace ts { // It is not uncommon to accidentally omit the 'from' keyword. Additionally, in editing scenarios, // the 'from' keyword can be parsed as a named export when the export clause is unterminated (i.e. `export { from "moduleName";`) // If we don't have a 'from' keyword, see if we have a string literal such that ASI won't take effect. - if (token === SyntaxKind.FromKeyword || (token === SyntaxKind.StringLiteral && !scanner.hasPrecedingLineBreak())) { + if (token() === SyntaxKind.FromKeyword || (token() === SyntaxKind.StringLiteral && !scanner.hasPrecedingLineBreak())) { parseExpected(SyntaxKind.FromKeyword); node.moduleSpecifier = parseModuleSpecifier(); } @@ -5744,7 +5754,7 @@ namespace ts { export namespace JSDocParser { export function isJSDocType() { - switch (token) { + switch (token()) { case SyntaxKind.AsteriskToken: case SyntaxKind.QuestionToken: case SyntaxKind.OpenParenToken: @@ -5758,13 +5768,13 @@ namespace ts { return true; } - return tokenIsIdentifierOrKeyword(token); + return tokenIsIdentifierOrKeyword(token()); } export function parseJSDocTypeExpressionForTests(content: string, start: number, length: number) { initializeState("file.js", content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS); scanner.setText(content, start, length); - token = scanner.scan(); + currentToken = scanner.scan(); const jsDocTypeExpression = parseJSDocTypeExpression(); const diagnostics = parseDiagnostics; clearState(); @@ -5787,13 +5797,13 @@ namespace ts { function parseJSDocTopLevelType(): JSDocType { let type = parseJSDocType(); - if (token === SyntaxKind.BarToken) { + if (token() === SyntaxKind.BarToken) { const unionType = createNode(SyntaxKind.JSDocUnionType, type.pos); unionType.types = parseJSDocTypeList(type); type = finishNode(unionType); } - if (token === SyntaxKind.EqualsToken) { + if (token() === SyntaxKind.EqualsToken) { const optionalType = createNode(SyntaxKind.JSDocOptionalType, type.pos); nextToken(); optionalType.type = type; @@ -5807,7 +5817,7 @@ namespace ts { let type = parseBasicTypeExpression(); while (true) { - if (token === SyntaxKind.OpenBracketToken) { + if (token() === SyntaxKind.OpenBracketToken) { const arrayType = createNode(SyntaxKind.JSDocArrayType, type.pos); arrayType.elementType = type; @@ -5816,14 +5826,14 @@ namespace ts { type = finishNode(arrayType); } - else if (token === SyntaxKind.QuestionToken) { + else if (token() === SyntaxKind.QuestionToken) { const nullableType = createNode(SyntaxKind.JSDocNullableType, type.pos); nullableType.type = type; nextToken(); type = finishNode(nullableType); } - else if (token === SyntaxKind.ExclamationToken) { + else if (token() === SyntaxKind.ExclamationToken) { const nonNullableType = createNode(SyntaxKind.JSDocNonNullableType, type.pos); nonNullableType.type = type; @@ -5839,7 +5849,7 @@ namespace ts { } function parseBasicTypeExpression(): JSDocType { - switch (token) { + switch (token()) { case SyntaxKind.AsteriskToken: return parseJSDocAllType(); case SyntaxKind.QuestionToken: @@ -5905,7 +5915,7 @@ namespace ts { checkForTrailingComma(result.parameters); parseExpected(SyntaxKind.CloseParenToken); - if (token === SyntaxKind.ColonToken) { + if (token() === SyntaxKind.ColonToken) { nextToken(); result.type = parseJSDocType(); } @@ -5926,12 +5936,12 @@ namespace ts { const result = createNode(SyntaxKind.JSDocTypeReference); result.name = parseSimplePropertyName(); - if (token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.LessThanToken) { result.typeArguments = parseTypeArguments(); } else { while (parseOptional(SyntaxKind.DotToken)) { - if (token === SyntaxKind.LessThanToken) { + if (token() === SyntaxKind.LessThanToken) { result.typeArguments = parseTypeArguments(); break; } @@ -5985,7 +5995,7 @@ namespace ts { const result = createNode(SyntaxKind.JSDocRecordMember); result.name = parseSimplePropertyName(); - if (token === SyntaxKind.ColonToken) { + if (token() === SyntaxKind.ColonToken) { nextToken(); result.type = parseJSDocType(); } @@ -6063,12 +6073,12 @@ namespace ts { // Foo // Foo(?= // (?| - if (token === SyntaxKind.CommaToken || - token === SyntaxKind.CloseBraceToken || - token === SyntaxKind.CloseParenToken || - token === SyntaxKind.GreaterThanToken || - token === SyntaxKind.EqualsToken || - token === SyntaxKind.BarToken) { + if (token() === SyntaxKind.CommaToken || + token() === SyntaxKind.CloseBraceToken || + token() === SyntaxKind.CloseParenToken || + token() === SyntaxKind.GreaterThanToken || + token() === SyntaxKind.EqualsToken || + token() === SyntaxKind.BarToken) { const result = createNode(SyntaxKind.JSDocUnknownType, pos); return finishNode(result); @@ -6091,7 +6101,7 @@ namespace ts { } export function parseJSDocComment(parent: Node, start: number, length: number): JSDocComment { - const saveToken = token; + const saveToken = currentToken; const saveParseDiagnosticsLength = parseDiagnostics.length; const saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; @@ -6100,7 +6110,7 @@ namespace ts { comment.parent = parent; } - token = saveToken; + currentToken = saveToken; parseDiagnostics.length = saveParseDiagnosticsLength; parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode; @@ -6135,8 +6145,8 @@ namespace ts { let seenAsterisk = true; nextJSDocToken(); - while (token !== SyntaxKind.EndOfFileToken) { - switch (token) { + while (token() !== SyntaxKind.EndOfFileToken) { + switch (token()) { case SyntaxKind.AtToken: if (canParseTag) { parseTag(); @@ -6192,13 +6202,13 @@ namespace ts { } function skipWhitespace(): void { - while (token === SyntaxKind.WhitespaceTrivia || token === SyntaxKind.NewLineTrivia) { + while (token() === SyntaxKind.WhitespaceTrivia || token() === SyntaxKind.NewLineTrivia) { nextJSDocToken(); } } function parseTag(): void { - Debug.assert(token === SyntaxKind.AtToken); + Debug.assert(token() === SyntaxKind.AtToken); const atToken = createNode(SyntaxKind.AtToken, scanner.getTokenPos()); atToken.end = scanner.getTextPos(); nextJSDocToken(); @@ -6252,7 +6262,7 @@ namespace ts { } function tryParseTypeExpression(): JSDocTypeExpression { - if (token !== SyntaxKind.OpenBraceToken) { + if (token() !== SyntaxKind.OpenBraceToken) { return undefined; } @@ -6278,7 +6288,7 @@ namespace ts { parseExpected(SyntaxKind.CloseBracketToken); } - else if (tokenIsIdentifierOrKeyword(token)) { + else if (tokenIsIdentifierOrKeyword(token())) { name = parseJSDocIdentifierName(); } @@ -6387,9 +6397,9 @@ namespace ts { let seenAsterisk = false; let parentTagTerminated = false; - while (token !== SyntaxKind.EndOfFileToken && !parentTagTerminated) { + while (token() !== SyntaxKind.EndOfFileToken && !parentTagTerminated) { nextJSDocToken(); - switch (token) { + switch (token()) { case SyntaxKind.AtToken: if (canParseTag) { parentTagTerminated = !tryParseChildTag(jsDocTypeLiteral); @@ -6419,7 +6429,7 @@ namespace ts { } function tryParseChildTag(parentTag: JSDocTypeLiteral): boolean { - Debug.assert(token === SyntaxKind.AtToken); + Debug.assert(token() === SyntaxKind.AtToken); const atToken = createNode(SyntaxKind.AtToken, scanner.getStartPos()); atToken.end = scanner.getTextPos(); nextJSDocToken(); @@ -6471,7 +6481,7 @@ namespace ts { typeParameters.push(typeParameter); - if (token === SyntaxKind.CommaToken) { + if (token() === SyntaxKind.CommaToken) { nextJSDocToken(); } else { @@ -6489,11 +6499,11 @@ namespace ts { } function nextJSDocToken(): SyntaxKind { - return token = scanner.scanJSDocToken(); + return currentToken = scanner.scanJSDocToken(); } function parseJSDocIdentifierName(): Identifier { - return createJSDocIdentifier(tokenIsIdentifierOrKeyword(token)); + return createJSDocIdentifier(tokenIsIdentifierOrKeyword(token())); } function createJSDocIdentifier(isIdentifier: boolean): Identifier { From f7753afb2ec7c170fd41f3e959416b4554e7e301 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 22 Jul 2016 16:55:46 -0700 Subject: [PATCH 45/55] Reduce unions of enum literal types when displaying types --- src/compiler/checker.ts | 31 +++++++++++++++++++------------ src/compiler/types.ts | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bea464faf2be7..c0069878503fd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1547,8 +1547,8 @@ namespace ts { return type; } - function createBooleanType(trueFalseTypes: Type[]): IntrinsicType { - const type = getUnionType(trueFalseTypes, /*noSubtypeReduction*/ true); + function createBooleanType(trueFalseTypes: Type[]): IntrinsicType & UnionType { + const type = getUnionType(trueFalseTypes, /*noSubtypeReduction*/ true); type.flags |= TypeFlags.Boolean; type.intrinsicName = "boolean"; return type; @@ -1928,17 +1928,24 @@ namespace ts { return result; } - function replaceTrueFalseWithBoolean(types: Type[]): Type[] { - if (contains(types, trueType) && contains(types, falseType)) { - const result: Type[] = []; - for (const t of types) { - if (t !== falseType) { - result.push(t === trueType ? booleanType : t); + function reduceLiteralTypes(types: Type[]): Type[] { + let result: Type[]; + for (let i = 0; i < types.length; i++) { + const t = types[i]; + if (t.flags & (TypeFlags.BooleanLiteral | TypeFlags.EnumLiteral)) { + const baseType = t.flags & TypeFlags.BooleanLiteral ? booleanType : (t).baseType; + const count = baseType.types.length; + if (i + count <= types.length && types[i + count - 1] === baseType.types[count - 1]) { + (result || (result = types.slice(0, i))).push(baseType); + i += count - 1; + continue; } } - return result; + if (result) { + result.push(t); + } } - return types; + return result || types; } function visibilityToString(flags: NodeFlags) { @@ -2239,7 +2246,7 @@ namespace ts { writePunctuation(writer, SyntaxKind.OpenParenToken); } if (type.flags & TypeFlags.Union) { - writeTypeList(replaceTrueFalseWithBoolean(type.types), SyntaxKind.BarToken); + writeTypeList(reduceLiteralTypes(type.types), SyntaxKind.BarToken); } else { writeTypeList(type.types, SyntaxKind.AmpersandToken); @@ -3784,7 +3791,7 @@ namespace ts { if (!memberTypes[value]) { const memberType = memberTypes[value] = createType(TypeFlags.EnumLiteral); memberType.symbol = memberSymbol; - memberType.baseType = enumType; + memberType.baseType = enumType; memberType.text = "" + value; memberTypeList.push(memberType); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2dabee35f1158..f8c261cc91b82 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2308,7 +2308,7 @@ namespace ts { // Enum types (TypeFlags.EnumLiteral) export interface EnumLiteralType extends LiteralType { - baseType: EnumType; + baseType: EnumType & UnionType; } // Object types (TypeFlags.ObjectType) From d3c91e03cc0a32c612983d97b0cc2ee11b3a606a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 22 Jul 2016 16:56:33 -0700 Subject: [PATCH 46/55] Accept new baselines --- .../amdImportAsPrimaryExpression.types | 4 +- .../amdImportNotAsPrimaryExpression.types | 2 +- .../assignmentNonObjectTypeConstraints.types | 4 +- tests/baselines/reference/commentsEnums.types | 6 +- .../reference/commentsdoNotEmitComments.types | 4 +- ...commonJSImportNotAsPrimaryExpression.types | 2 +- ...isonOperatorWithSubtypeEnumAndNumber.types | 64 ++++----- ...ndAdditionAssignmentLHSCanBeAssigned.types | 6 +- tests/baselines/reference/constEnums.types | 128 +++++++++--------- .../declarationEmit_nameConflicts3.symbols | 4 +- .../reference/enumLiteralTypes1.types | 38 +++--- .../reference/enumLiteralTypes2.types | 88 ++++++------ .../reference/enumLiteralTypes3.errors.txt | 17 +-- tests/baselines/reference/enumMerging.types | 6 +- .../exportAssignmentTopLevelEnumdule.types | 4 +- .../functionExpressionContextualTyping1.types | 2 +- .../reference/instantiatedModule.types | 4 +- .../reference/internalAliasEnum.types | 4 +- ...AliasEnumInsideLocalModuleWithExport.types | 4 +- ...asEnumInsideLocalModuleWithoutExport.types | 4 +- ...asEnumInsideTopLevelModuleWithExport.types | 4 +- ...numInsideTopLevelModuleWithoutExport.types | 4 +- .../invalidImportAliasIdentifiers.errors.txt | 5 +- .../localImportNameVsGlobalName.types | 12 +- tests/baselines/reference/localTypes1.types | 24 ++-- .../logicalAndOperatorWithEveryType.types | 6 +- .../reference/validEnumAssignments.types | 28 ++-- 27 files changed, 234 insertions(+), 244 deletions(-) diff --git a/tests/baselines/reference/amdImportAsPrimaryExpression.types b/tests/baselines/reference/amdImportAsPrimaryExpression.types index 4c2f47f4d59d6..8f6e509419f68 100644 --- a/tests/baselines/reference/amdImportAsPrimaryExpression.types +++ b/tests/baselines/reference/amdImportAsPrimaryExpression.types @@ -4,11 +4,11 @@ import foo = require("./foo_0"); if(foo.E1.A === 0){ >foo.E1.A === 0 : boolean ->foo.E1.A : foo.E1 +>foo.E1.A : foo.E1.A >foo.E1 : typeof foo.E1 >foo : typeof foo >E1 : typeof foo.E1 ->A : foo.E1 +>A : foo.E1.A >0 : 0 // Should cause runtime import - interesting optimization possibility, as gets inlined to 0. diff --git a/tests/baselines/reference/amdImportNotAsPrimaryExpression.types b/tests/baselines/reference/amdImportNotAsPrimaryExpression.types index 6c3978d93aa1d..5d90a8dadc243 100644 --- a/tests/baselines/reference/amdImportNotAsPrimaryExpression.types +++ b/tests/baselines/reference/amdImportNotAsPrimaryExpression.types @@ -41,7 +41,7 @@ var e: number = 0; >0 : foo.E1 >foo : any >E1 : foo.E1 ->0 : number +>0 : 0 === tests/cases/conformance/externalModules/foo_0.ts === export class C1 { diff --git a/tests/baselines/reference/assignmentNonObjectTypeConstraints.types b/tests/baselines/reference/assignmentNonObjectTypeConstraints.types index 26c0b1724435e..e2c3176940d38 100644 --- a/tests/baselines/reference/assignmentNonObjectTypeConstraints.types +++ b/tests/baselines/reference/assignmentNonObjectTypeConstraints.types @@ -24,9 +24,9 @@ foo(5); foo(E.A); >foo(E.A) : void >foo : (x: T) => void ->E.A : E +>E.A : E.A >E : typeof E ->A : E +>A : E.A class A { a } >A : A diff --git a/tests/baselines/reference/commentsEnums.types b/tests/baselines/reference/commentsEnums.types index 64404bff2e53c..ef2c52067d1ce 100644 --- a/tests/baselines/reference/commentsEnums.types +++ b/tests/baselines/reference/commentsEnums.types @@ -20,10 +20,10 @@ var x = Colors.Cornflower; >Cornflower : Colors x = Colors.FancyPink; ->x = Colors.FancyPink : Colors +>x = Colors.FancyPink : Colors.FancyPink >x : Colors ->Colors.FancyPink : Colors +>Colors.FancyPink : Colors.FancyPink >Colors : typeof Colors ->FancyPink : Colors +>FancyPink : Colors.FancyPink diff --git a/tests/baselines/reference/commentsdoNotEmitComments.types b/tests/baselines/reference/commentsdoNotEmitComments.types index 067275f215115..465c841e20f66 100644 --- a/tests/baselines/reference/commentsdoNotEmitComments.types +++ b/tests/baselines/reference/commentsdoNotEmitComments.types @@ -165,7 +165,7 @@ const enum color { red, green, blue } var shade: color = color.green; >shade : color >color : color ->color.green : color +>color.green : color.green >color : typeof color ->green : color +>green : color.green diff --git a/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.types b/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.types index 6c3978d93aa1d..5d90a8dadc243 100644 --- a/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.types +++ b/tests/baselines/reference/commonJSImportNotAsPrimaryExpression.types @@ -41,7 +41,7 @@ var e: number = 0; >0 : foo.E1 >foo : any >E1 : foo.E1 ->0 : number +>0 : 0 === tests/cases/conformance/externalModules/foo_0.ts === export class C1 { diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.types b/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.types index fa804eada4449..0f07c158cc4e4 100644 --- a/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.types +++ b/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.types @@ -208,34 +208,34 @@ var re2 = b == a; var re3 = E.a == b; >re3 : boolean >E.a == b : boolean ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a >b : number var re4 = b == E.a; >re4 : boolean >b == E.a : boolean >b : number ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a var re5 = E.a == 0; >re5 : boolean >E.a == 0 : boolean ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a >0 : 0 var re6 = 0 == E.a; >re6 : boolean >0 == E.a : boolean >0 : 0 ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a // operator != var rf1 = a != b; @@ -253,34 +253,34 @@ var rf2 = b != a; var rf3 = E.a != b; >rf3 : boolean >E.a != b : boolean ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a >b : number var rf4 = b != E.a; >rf4 : boolean >b != E.a : boolean >b : number ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a var rf5 = E.a != 0; >rf5 : boolean >E.a != 0 : boolean ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a >0 : 0 var rf6 = 0 != E.a; >rf6 : boolean >0 != E.a : boolean >0 : 0 ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a // operator === var rg1 = a === b; @@ -298,34 +298,34 @@ var rg2 = b === a; var rg3 = E.a === b; >rg3 : boolean >E.a === b : boolean ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a >b : number var rg4 = b === E.a; >rg4 : boolean >b === E.a : boolean >b : number ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a var rg5 = E.a === 0; >rg5 : boolean >E.a === 0 : boolean ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a >0 : 0 var rg6 = 0 === E.a; >rg6 : boolean >0 === E.a : boolean >0 : 0 ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a // operator !== var rh1 = a !== b; @@ -343,32 +343,32 @@ var rh2 = b !== a; var rh3 = E.a !== b; >rh3 : boolean >E.a !== b : boolean ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a >b : number var rh4 = b !== E.a; >rh4 : boolean >b !== E.a : boolean >b : number ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a var rh5 = E.a !== 0; >rh5 : boolean >E.a !== 0 : boolean ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a >0 : 0 var rh6 = 0 !== E.a; >rh6 : boolean >0 !== E.a : boolean >0 : 0 ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a diff --git a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.types b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.types index e40422450b44f..77189e5fee233 100644 --- a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.types +++ b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.types @@ -152,14 +152,14 @@ x4 += a; x4 += 0; >x4 += 0 : number >x4 : E ->0 : number +>0 : 0 x4 += E.a; >x4 += E.a : number >x4 : E ->E.a : E +>E.a : E.a >E : typeof E ->a : E +>a : E.a x4 += null; >x4 += null : number diff --git a/tests/baselines/reference/constEnums.types b/tests/baselines/reference/constEnums.types index ba8b90314e438..83ee20100e5a2 100644 --- a/tests/baselines/reference/constEnums.types +++ b/tests/baselines/reference/constEnums.types @@ -314,16 +314,16 @@ function foo0(e: I): void { if (e === I.V1) { >e === I.V1 : boolean >e : I ->I.V1 : I.V1 +>I.V1 : I >I : typeof I ->V1 : I.V1 +>V1 : I } else if (e === I.V2) { >e === I.V2 : boolean >e : I ->I.V2 : I.V2 +>I.V2 : I >I : typeof I ->V2 : I.V2 +>V2 : I } } @@ -347,7 +347,7 @@ function foo1(e: I1.C.E): void { } else if (e === I1.C.E.V2) { >e === I1.C.E.V2 : boolean ->e : I1.C.E +>e : I1.C.E.V2 >I1.C.E.V2 : I1.C.E.V2 >I1.C.E : typeof I1.C.E >I1.C : typeof I1.C @@ -378,7 +378,7 @@ function foo2(e: I2.C.E): void { } else if (e === I2.C.E.V2) { >e === I2.C.E.V2 : boolean ->e : I2.C.E +>e : I2.C.E.V2 >I2.C.E.V2 : I2.C.E.V2 >I2.C.E : typeof I2.C.E >I2.C : typeof I2.C @@ -399,99 +399,99 @@ function foo(x: Enum1) { >x : Enum1 case Enum1.A: ->Enum1.A : Enum1.A +>Enum1.A : Enum1 >Enum1 : typeof Enum1 ->A : Enum1.A +>A : Enum1 case Enum1.B: ->Enum1.B : Enum1.B +>Enum1.B : Enum1 >Enum1 : typeof Enum1 ->B : Enum1.B +>B : Enum1 case Enum1.C: ->Enum1.C : Enum1.C +>Enum1.C : Enum1 >Enum1 : typeof Enum1 ->C : Enum1.C +>C : Enum1 case Enum1.D: ->Enum1.D : Enum1.B +>Enum1.D : Enum1 >Enum1 : typeof Enum1 ->D : Enum1.B +>D : Enum1 case Enum1.E: ->Enum1.E : Enum1.B +>Enum1.E : Enum1 >Enum1 : typeof Enum1 ->E : Enum1.B +>E : Enum1 case Enum1.F: ->Enum1.F : Enum1.B +>Enum1.F : Enum1 >Enum1 : typeof Enum1 ->F : Enum1.B +>F : Enum1 case Enum1.G: ->Enum1.G : Enum1.B +>Enum1.G : Enum1 >Enum1 : typeof Enum1 ->G : Enum1.B +>G : Enum1 case Enum1.H: ->Enum1.H : Enum1.H +>Enum1.H : Enum1 >Enum1 : typeof Enum1 ->H : Enum1.H +>H : Enum1 case Enum1.I: ->Enum1.I : Enum1.A +>Enum1.I : Enum1 >Enum1 : typeof Enum1 ->I : Enum1.A +>I : Enum1 case Enum1.J: ->Enum1.J : Enum1.A +>Enum1.J : Enum1 >Enum1 : typeof Enum1 ->J : Enum1.A +>J : Enum1 case Enum1.K: ->Enum1.K : Enum1.K +>Enum1.K : Enum1 >Enum1 : typeof Enum1 ->K : Enum1.K +>K : Enum1 case Enum1.L: ->Enum1.L : Enum1.H +>Enum1.L : Enum1 >Enum1 : typeof Enum1 ->L : Enum1.H +>L : Enum1 case Enum1.M: ->Enum1.M : Enum1.M +>Enum1.M : Enum1 >Enum1 : typeof Enum1 ->M : Enum1.M +>M : Enum1 case Enum1.N: ->Enum1.N : Enum1.M +>Enum1.N : Enum1 >Enum1 : typeof Enum1 ->N : Enum1.M +>N : Enum1 case Enum1.O: ->Enum1.O : Enum1.A +>Enum1.O : Enum1 >Enum1 : typeof Enum1 ->O : Enum1.A +>O : Enum1 case Enum1.P: ->Enum1.P : Enum1.A +>Enum1.P : Enum1 >Enum1 : typeof Enum1 ->P : Enum1.A +>P : Enum1 case Enum1.Q: ->Enum1.Q : Enum1.Q +>Enum1.Q : Enum1 >Enum1 : typeof Enum1 ->Q : Enum1.Q +>Q : Enum1 case Enum1.R: ->Enum1.R : Enum1.A +>Enum1.R : Enum1 >Enum1 : typeof Enum1 ->R : Enum1.A +>R : Enum1 case Enum1.S: ->Enum1.S : Enum1.A +>Enum1.S : Enum1 >Enum1 : typeof Enum1 ->S : Enum1.A +>S : Enum1 case Enum1["T"]: >Enum1["T"] : Enum1 @@ -499,39 +499,39 @@ function foo(x: Enum1) { >"T" : string case Enum1.U: ->Enum1.U : Enum1.U +>Enum1.U : Enum1 >Enum1 : typeof Enum1 ->U : Enum1.U +>U : Enum1 case Enum1.V: ->Enum1.V : Enum1.U +>Enum1.V : Enum1 >Enum1 : typeof Enum1 ->V : Enum1.U +>V : Enum1 case Enum1.W: ->Enum1.W : Enum1.U +>Enum1.W : Enum1 >Enum1 : typeof Enum1 ->W : Enum1.U +>W : Enum1 case Enum1.W1: ->Enum1.W1 : Enum1.W1 +>Enum1.W1 : Enum1 >Enum1 : typeof Enum1 ->W1 : Enum1.W1 +>W1 : Enum1 case Enum1.W2: ->Enum1.W2 : Enum1.W1 +>Enum1.W2 : Enum1 >Enum1 : typeof Enum1 ->W2 : Enum1.W1 +>W2 : Enum1 case Enum1.W3: ->Enum1.W3 : Enum1.W1 +>Enum1.W3 : Enum1 >Enum1 : typeof Enum1 ->W3 : Enum1.W1 +>W3 : Enum1 case Enum1.W4: ->Enum1.W4 : Enum1.U +>Enum1.W4 : Enum1 >Enum1 : typeof Enum1 ->W4 : Enum1.U +>W4 : Enum1 break; } @@ -549,7 +549,7 @@ function bar(e: A.B.C.E): number { >e : I case A.B.C.E.V1: return 1; ->A.B.C.E.V1 : I.V1 +>A.B.C.E.V1 : I >A.B.C.E : typeof I >A.B.C : typeof A.B.C >A.B : typeof A.B @@ -557,11 +557,11 @@ function bar(e: A.B.C.E): number { >B : typeof A.B >C : typeof A.B.C >E : typeof I ->V1 : I.V1 +>V1 : I >1 : number case A.B.C.E.V2: return 1; ->A.B.C.E.V2 : I.V2 +>A.B.C.E.V2 : I >A.B.C.E : typeof I >A.B.C : typeof A.B.C >A.B : typeof A.B @@ -569,11 +569,11 @@ function bar(e: A.B.C.E): number { >B : typeof A.B >C : typeof A.B.C >E : typeof I ->V2 : I.V2 +>V2 : I >1 : number case A.B.C.E.V3: return 1; ->A.B.C.E.V3 : I.V3 +>A.B.C.E.V3 : I >A.B.C.E : typeof I >A.B.C : typeof A.B.C >A.B : typeof A.B @@ -581,7 +581,7 @@ function bar(e: A.B.C.E): number { >B : typeof A.B >C : typeof A.B.C >E : typeof I ->V3 : I.V3 +>V3 : I >1 : number } } diff --git a/tests/baselines/reference/declarationEmit_nameConflicts3.symbols b/tests/baselines/reference/declarationEmit_nameConflicts3.symbols index 051ffe593657f..e72c4ec9ceea1 100644 --- a/tests/baselines/reference/declarationEmit_nameConflicts3.symbols +++ b/tests/baselines/reference/declarationEmit_nameConflicts3.symbols @@ -52,11 +52,11 @@ module M.P { export var w = M.D.f; // error, should be typeof M.D.f >w : Symbol(w, Decl(declarationEmit_nameConflicts3.ts, 22, 14)) ->M.D.f : Symbol(D.f, Decl(declarationEmit_nameConflicts3.ts, 2, 21)) +>M.D.f : Symbol(M.D.f, Decl(declarationEmit_nameConflicts3.ts, 2, 21)) >M.D : Symbol(D, Decl(declarationEmit_nameConflicts3.ts, 0, 10), Decl(declarationEmit_nameConflicts3.ts, 1, 26)) >M : Symbol(M, Decl(declarationEmit_nameConflicts3.ts, 0, 0), Decl(declarationEmit_nameConflicts3.ts, 11, 1)) >D : Symbol(D, Decl(declarationEmit_nameConflicts3.ts, 0, 10), Decl(declarationEmit_nameConflicts3.ts, 1, 26)) ->f : Symbol(D.f, Decl(declarationEmit_nameConflicts3.ts, 2, 21)) +>f : Symbol(M.D.f, Decl(declarationEmit_nameConflicts3.ts, 2, 21)) export var x = M.C.f; // error, should be typeof M.C.f >x : Symbol(x, Decl(declarationEmit_nameConflicts3.ts, 23, 14), Decl(declarationEmit_nameConflicts3.ts, 24, 14)) diff --git a/tests/baselines/reference/enumLiteralTypes1.types b/tests/baselines/reference/enumLiteralTypes1.types index 6344cc5f39a98..1fe3c8dd637a9 100644 --- a/tests/baselines/reference/enumLiteralTypes1.types +++ b/tests/baselines/reference/enumLiteralTypes1.types @@ -20,7 +20,7 @@ type NoYes = Choice.No | Choice.Yes; >Yes : Choice.Yes type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; ->UnknownYesNo : UnknownYesNo +>UnknownYesNo : Choice >Choice : any >Unknown : Choice.Unknown >Choice : any @@ -55,17 +55,17 @@ function f1() { } function f2(a: YesNo, b: UnknownYesNo, c: Choice) { ->f2 : (a: YesNo, b: UnknownYesNo, c: Choice) => void +>f2 : (a: YesNo, b: Choice, c: Choice) => void >a : YesNo >YesNo : YesNo ->b : UnknownYesNo ->UnknownYesNo : UnknownYesNo +>b : Choice +>UnknownYesNo : Choice >c : Choice >Choice : Choice b = a; >b = a : YesNo ->b : UnknownYesNo +>b : Choice >a : YesNo c = a; @@ -234,11 +234,11 @@ declare function g(x: Choice): number; >Choice : Choice function f5(a: YesNo, b: UnknownYesNo, c: Choice) { ->f5 : (a: YesNo, b: UnknownYesNo, c: Choice) => void +>f5 : (a: YesNo, b: Choice, c: Choice) => void >a : YesNo >YesNo : YesNo ->b : UnknownYesNo ->UnknownYesNo : UnknownYesNo +>b : Choice +>UnknownYesNo : Choice >c : Choice >Choice : Choice @@ -268,7 +268,7 @@ function f5(a: YesNo, b: UnknownYesNo, c: Choice) { >z4 : number >g(b) : number >g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } ->b : UnknownYesNo +>b : Choice var z5 = g(c); >z5 : number @@ -336,30 +336,30 @@ function f11(x: YesNo) { } function f12(x: UnknownYesNo) { ->f12 : (x: UnknownYesNo) => void ->x : UnknownYesNo ->UnknownYesNo : UnknownYesNo +>f12 : (x: Choice) => void +>x : Choice +>UnknownYesNo : Choice if (x) { ->x : UnknownYesNo +>x : Choice x; >x : YesNo } else { x; ->x : UnknownYesNo +>x : Choice } } function f13(x: UnknownYesNo) { ->f13 : (x: UnknownYesNo) => void ->x : UnknownYesNo ->UnknownYesNo : UnknownYesNo +>f13 : (x: Choice) => void +>x : Choice +>UnknownYesNo : Choice if (x === Choice.Yes) { >x === Choice.Yes : boolean ->x : UnknownYesNo +>x : Choice >Choice.Yes : Choice.Yes >Choice : typeof Choice >Yes : Choice.Yes @@ -369,7 +369,7 @@ function f13(x: UnknownYesNo) { } else { x; ->x : Choice.No | Choice.Unknown +>x : Choice.Unknown | Choice.No } } diff --git a/tests/baselines/reference/enumLiteralTypes2.types b/tests/baselines/reference/enumLiteralTypes2.types index ac493598ac1d5..36390865aec4d 100644 --- a/tests/baselines/reference/enumLiteralTypes2.types +++ b/tests/baselines/reference/enumLiteralTypes2.types @@ -21,7 +21,7 @@ type NoYes = Choice.No | Choice.Yes; >Yes : Choice.Yes type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No; ->UnknownYesNo : UnknownYesNo +>UnknownYesNo : Choice >Choice : any >Unknown : Choice.Unknown >Choice : any @@ -56,17 +56,17 @@ function f1() { } function f2(a: YesNo, b: UnknownYesNo, c: Choice) { ->f2 : (a: YesNo, b: UnknownYesNo, c: Choice) => void +>f2 : (a: YesNo, b: Choice, c: Choice) => void >a : YesNo >YesNo : YesNo ->b : UnknownYesNo ->UnknownYesNo : UnknownYesNo +>b : Choice +>UnknownYesNo : Choice >c : Choice >Choice : Choice b = a; >b = a : YesNo ->b : UnknownYesNo +>b : Choice >a : YesNo c = a; @@ -81,132 +81,132 @@ function f2(a: YesNo, b: UnknownYesNo, c: Choice) { } function f3(a: Choice.Yes, b: UnknownYesNo) { ->f3 : (a: Choice.Yes, b: UnknownYesNo) => void +>f3 : (a: Choice.Yes, b: Choice) => void >a : Choice.Yes >Choice : any >Yes : Choice.Yes ->b : UnknownYesNo ->UnknownYesNo : UnknownYesNo +>b : Choice +>UnknownYesNo : Choice var x = a + b; >x : number >a + b : number >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var x = a - b; >x : number >a - b : number >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var x = a * b; >x : number >a * b : number >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var x = a / b; >x : number >a / b : number >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var x = a % b; >x : number >a % b : number >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var x = a | b; >x : number >a | b : number >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var x = a & b; >x : number >a & b : number >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var x = a ^ b; >x : number >a ^ b : number >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var x = -b; >x : number >-b : number ->b : UnknownYesNo +>b : Choice var x = ~b; >x : number >~b : number ->b : UnknownYesNo +>b : Choice var y = a == b; >y : boolean >a == b : boolean >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var y = a != b; >y : boolean >a != b : boolean >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var y = a === b; >y : boolean >a === b : boolean >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var y = a !== b; >y : boolean >a !== b : boolean >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var y = a > b; >y : boolean >a > b : boolean >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var y = a < b; >y : boolean >a < b : boolean >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var y = a >= b; >y : boolean >a >= b : boolean >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var y = a <= b; >y : boolean >a <= b : boolean >a : Choice.Yes ->b : UnknownYesNo +>b : Choice var y = !b; >y : boolean >!b : boolean ->b : UnknownYesNo +>b : Choice } function f4(a: Choice.Yes, b: UnknownYesNo) { ->f4 : (a: Choice.Yes, b: UnknownYesNo) => void +>f4 : (a: Choice.Yes, b: Choice) => void >a : Choice.Yes >Choice : any >Yes : Choice.Yes ->b : UnknownYesNo ->UnknownYesNo : UnknownYesNo +>b : Choice +>UnknownYesNo : Choice a++; >a++ : number @@ -214,7 +214,7 @@ function f4(a: Choice.Yes, b: UnknownYesNo) { b++; >b++ : number ->b : UnknownYesNo +>b : Choice } declare function g(x: Choice.Yes): string; @@ -235,11 +235,11 @@ declare function g(x: Choice): number; >Choice : Choice function f5(a: YesNo, b: UnknownYesNo, c: Choice) { ->f5 : (a: YesNo, b: UnknownYesNo, c: Choice) => void +>f5 : (a: YesNo, b: Choice, c: Choice) => void >a : YesNo >YesNo : YesNo ->b : UnknownYesNo ->UnknownYesNo : UnknownYesNo +>b : Choice +>UnknownYesNo : Choice >c : Choice >Choice : Choice @@ -269,7 +269,7 @@ function f5(a: YesNo, b: UnknownYesNo, c: Choice) { >z4 : number >g(b) : number >g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; } ->b : UnknownYesNo +>b : Choice var z5 = g(c); >z5 : number @@ -337,12 +337,12 @@ function f11(x: YesNo) { } function f12(x: UnknownYesNo) { ->f12 : (x: UnknownYesNo) => void ->x : UnknownYesNo ->UnknownYesNo : UnknownYesNo +>f12 : (x: Choice) => void +>x : Choice +>UnknownYesNo : Choice if (x) { ->x : UnknownYesNo +>x : Choice x; >x : YesNo @@ -354,13 +354,13 @@ function f12(x: UnknownYesNo) { } function f13(x: UnknownYesNo) { ->f13 : (x: UnknownYesNo) => void ->x : UnknownYesNo ->UnknownYesNo : UnknownYesNo +>f13 : (x: Choice) => void +>x : Choice +>UnknownYesNo : Choice if (x === Choice.Yes) { >x === Choice.Yes : boolean ->x : UnknownYesNo +>x : Choice >Choice.Yes : Choice.Yes >Choice : typeof Choice >Yes : Choice.Yes @@ -370,7 +370,7 @@ function f13(x: UnknownYesNo) { } else { x; ->x : Choice.No | Choice.Unknown +>x : Choice.Unknown | Choice.No } } diff --git a/tests/baselines/reference/enumLiteralTypes3.errors.txt b/tests/baselines/reference/enumLiteralTypes3.errors.txt index 5517a4affe396..d904e35c2f9b4 100644 --- a/tests/baselines/reference/enumLiteralTypes3.errors.txt +++ b/tests/baselines/reference/enumLiteralTypes3.errors.txt @@ -1,12 +1,9 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(10,5): error TS2322: Type 'YesNo' is not assignable to type 'Yes'. Type 'No' is not assignable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(11,5): error TS2322: Type 'UnknownYesNo' is not assignable to type 'Yes'. - Type 'No' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(11,5): error TS2322: Type 'Choice' is not assignable to type 'Yes'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(12,5): error TS2322: Type 'Choice' is not assignable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(18,5): error TS2322: Type 'UnknownYesNo' is not assignable to type 'YesNo'. - Type 'Unknown' is not assignable to type 'YesNo'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(18,5): error TS2322: Type 'Choice' is not assignable to type 'YesNo'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(19,5): error TS2322: Type 'Choice' is not assignable to type 'YesNo'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(26,5): error TS2322: Type 'Choice' is not assignable to type 'UnknownYesNo'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(37,5): error TS2322: Type 'Unknown' is not assignable to type 'Yes'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(39,5): error TS2322: Type 'No' is not assignable to type 'Yes'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(40,5): error TS2322: Type 'Unknown' is not assignable to type 'YesNo'. @@ -18,7 +15,7 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(89,14): error TS2678: tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: Type 'Unknown' is not comparable to type 'YesNo'. -==== tests/cases/conformance/types/literal/enumLiteralTypes3.ts (15 errors) ==== +==== tests/cases/conformance/types/literal/enumLiteralTypes3.ts (14 errors) ==== const enum Choice { Unknown, Yes, No }; type Yes = Choice.Yes; @@ -34,8 +31,7 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: !!! error TS2322: Type 'No' is not assignable to type 'Yes'. a = c; ~ -!!! error TS2322: Type 'UnknownYesNo' is not assignable to type 'Yes'. -!!! error TS2322: Type 'No' is not assignable to type 'Yes'. +!!! error TS2322: Type 'Choice' is not assignable to type 'Yes'. a = d; ~ !!! error TS2322: Type 'Choice' is not assignable to type 'Yes'. @@ -46,8 +42,7 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: b = b; b = c; ~ -!!! error TS2322: Type 'UnknownYesNo' is not assignable to type 'YesNo'. -!!! error TS2322: Type 'Unknown' is not assignable to type 'YesNo'. +!!! error TS2322: Type 'Choice' is not assignable to type 'YesNo'. b = d; ~ !!! error TS2322: Type 'Choice' is not assignable to type 'YesNo'. @@ -58,8 +53,6 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: c = b; c = c; c = d; - ~ -!!! error TS2322: Type 'Choice' is not assignable to type 'UnknownYesNo'. } function f4(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { diff --git a/tests/baselines/reference/enumMerging.types b/tests/baselines/reference/enumMerging.types index 85eb360249fb6..1ca284702c525 100644 --- a/tests/baselines/reference/enumMerging.types +++ b/tests/baselines/reference/enumMerging.types @@ -208,12 +208,12 @@ module M6 { >Yellow : A.Color t = A.Color.Red; ->t = A.Color.Red : A.Color +>t = A.Color.Red : A.Color.Red >t : A.Color ->A.Color.Red : A.Color +>A.Color.Red : A.Color.Red >A.Color : typeof A.Color >A : typeof A >Color : typeof A.Color ->Red : A.Color +>Red : A.Color.Red } diff --git a/tests/baselines/reference/exportAssignmentTopLevelEnumdule.types b/tests/baselines/reference/exportAssignmentTopLevelEnumdule.types index d60fc87831912..fba15dc3ca848 100644 --- a/tests/baselines/reference/exportAssignmentTopLevelEnumdule.types +++ b/tests/baselines/reference/exportAssignmentTopLevelEnumdule.types @@ -9,9 +9,9 @@ var color: foo; if(color === foo.green){ >color === foo.green : boolean >color : foo ->foo.green : foo +>foo.green : foo.green >foo : typeof foo ->green : foo +>green : foo.green color = foo.answer; >color = foo.answer : number diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.types b/tests/baselines/reference/functionExpressionContextualTyping1.types index 61d16bf6a4fdd..893744c4954bd 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping1.types +++ b/tests/baselines/reference/functionExpressionContextualTyping1.types @@ -116,7 +116,7 @@ var b4: (n: E) => string = (number = 1) => { return "hello"; }; >E : E >(number = 1) => { return "hello"; } : (number?: E) => string >number : E ->1 : number +>1 : 1 >"hello" : string var b5: (n: {}) => string = (number = "string") => { return "hello"; }; diff --git a/tests/baselines/reference/instantiatedModule.types b/tests/baselines/reference/instantiatedModule.types index e9933eea80458..743c6561161fc 100644 --- a/tests/baselines/reference/instantiatedModule.types +++ b/tests/baselines/reference/instantiatedModule.types @@ -175,9 +175,9 @@ var blue: M3.Color = a3.Blue; >blue : M3.Color >M3 : any >Color : M3.Color ->a3.Blue : M3.Color +>a3.Blue : M3.Color.Blue >a3 : typeof M3.Color ->Blue : M3.Color +>Blue : M3.Color.Blue var p3: M3.Color; >p3 : M3.Color diff --git a/tests/baselines/reference/internalAliasEnum.types b/tests/baselines/reference/internalAliasEnum.types index 87cab6cc56dee..3f86d63c87946 100644 --- a/tests/baselines/reference/internalAliasEnum.types +++ b/tests/baselines/reference/internalAliasEnum.types @@ -27,8 +27,8 @@ module c { export var bVal: b = b.Sunday; >bVal : b >b : b ->b.Sunday : b +>b.Sunday : b.Sunday >b : typeof b ->Sunday : b +>Sunday : b.Sunday } diff --git a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.types b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.types index 0d09b930f9533..66d946e47b37a 100644 --- a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.types +++ b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.types @@ -27,8 +27,8 @@ export module c { export var bVal: b = b.Sunday; >bVal : b >b : b ->b.Sunday : b +>b.Sunday : b.Sunday >b : typeof b ->Sunday : b +>Sunday : b.Sunday } diff --git a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.types b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.types index 881e51324af81..f53a6fa355bf0 100644 --- a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.types +++ b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.types @@ -27,8 +27,8 @@ export module c { export var bVal: b = b.Sunday; >bVal : b >b : b ->b.Sunday : b +>b.Sunday : b.Sunday >b : typeof b ->Sunday : b +>Sunday : b.Sunday } diff --git a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.types b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.types index 8458d885738d3..437e211bf16b7 100644 --- a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.types +++ b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.types @@ -24,7 +24,7 @@ export import b = a.weekend; export var bVal: b = b.Sunday; >bVal : b >b : b ->b.Sunday : b +>b.Sunday : b.Sunday >b : typeof b ->Sunday : b +>Sunday : b.Sunday diff --git a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.types b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.types index 6e75bd81bdf89..c9b75f84266c1 100644 --- a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.types +++ b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.types @@ -24,7 +24,7 @@ import b = a.weekend; export var bVal: b = b.Sunday; >bVal : b >b : b ->b.Sunday : b +>b.Sunday : b.Sunday >b : typeof b ->Sunday : b +>Sunday : b.Sunday diff --git a/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt b/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt index fb29c8299479a..afe7472570da6 100644 --- a/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt +++ b/tests/baselines/reference/invalidImportAliasIdentifiers.errors.txt @@ -1,10 +1,9 @@ tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(5,12): error TS2503: Cannot find namespace 'V'. tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(11,12): error TS2503: Cannot find namespace 'C'. -tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(17,12): error TS2503: Cannot find namespace 'E'. tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts(23,12): error TS2503: Cannot find namespace 'I'. -==== tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts (4 errors) ==== +==== tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIdentifiers.ts (3 errors) ==== // none of these should work, since non are actually modules var V = 12; @@ -26,8 +25,6 @@ tests/cases/conformance/internalModules/importDeclarations/invalidImportAliasIde } import e = E; - ~ -!!! error TS2503: Cannot find namespace 'E'. interface I { id: number; diff --git a/tests/baselines/reference/localImportNameVsGlobalName.types b/tests/baselines/reference/localImportNameVsGlobalName.types index 7cb45208e81ee..dd7f05fc8ddf7 100644 --- a/tests/baselines/reference/localImportNameVsGlobalName.types +++ b/tests/baselines/reference/localImportNameVsGlobalName.types @@ -26,21 +26,21 @@ module App { foo(Key.UP); >foo(Key.UP) : void >foo : (key: Key) => void ->Key.UP : Key +>Key.UP : Key.UP >Key : typeof Key ->UP : Key +>UP : Key.UP foo(Key.DOWN); >foo(Key.DOWN) : void >foo : (key: Key) => void ->Key.DOWN : Key +>Key.DOWN : Key.DOWN >Key : typeof Key ->DOWN : Key +>DOWN : Key.DOWN foo(Key.LEFT); >foo(Key.LEFT) : void >foo : (key: Key) => void ->Key.LEFT : Key +>Key.LEFT : Key.LEFT >Key : typeof Key ->LEFT : Key +>LEFT : Key.LEFT } diff --git a/tests/baselines/reference/localTypes1.types b/tests/baselines/reference/localTypes1.types index 1770a36edb7cc..78e92fd832494 100644 --- a/tests/baselines/reference/localTypes1.types +++ b/tests/baselines/reference/localTypes1.types @@ -37,15 +37,15 @@ function f1() { >C : typeof C a[0].x = E.B; ->a[0].x = E.B : E +>a[0].x = E.B : E.B >a[0].x : E >a[0] : I >a : I[] >0 : number >x : E ->E.B : E +>E.B : E.B >E : typeof E ->B : E +>B : E.B return a; >a : I[] @@ -91,15 +91,15 @@ function f2() { >C : typeof C a[0].x = E.B; ->a[0].x = E.B : E +>a[0].x = E.B : E.B >a[0].x : E >a[0] : I >a : I[] >0 : number >x : E ->E.B : E +>E.B : E.B >E : typeof E ->B : E +>B : E.B return a; >a : I[] @@ -153,15 +153,15 @@ function f3(b: boolean) { >C : typeof C a[0].x = E.B; ->a[0].x = E.B : E +>a[0].x = E.B : E.B >a[0].x : E >a[0] : I >a : I[] >0 : number >x : E ->E.B : E +>E.B : E.B >E : typeof E ->B : E +>B : E.B return a; >a : I[] @@ -193,15 +193,15 @@ function f3(b: boolean) { >A : typeof A c[0].x = E.B; ->c[0].x = E.B : E +>c[0].x = E.B : E.B >c[0].x : E >c[0] : J >c : J[] >0 : number >x : E ->E.B : E +>E.B : E.B >E : typeof E ->B : E +>B : E.B return c; >c : J[] diff --git a/tests/baselines/reference/logicalAndOperatorWithEveryType.types b/tests/baselines/reference/logicalAndOperatorWithEveryType.types index 25771ede18621..22187bb16a961 100644 --- a/tests/baselines/reference/logicalAndOperatorWithEveryType.types +++ b/tests/baselines/reference/logicalAndOperatorWithEveryType.types @@ -364,10 +364,10 @@ var rf5 = a5 && a6; >a6 : E var rf6 = a6 && a6; ->rf6 : E ->a6 && a6 : E ->a6 : E +>rf6 : E.b | E.c +>a6 && a6 : E.b | E.c >a6 : E +>a6 : E.b | E.c var rf7 = a7 && a6; >rf7 : E diff --git a/tests/baselines/reference/validEnumAssignments.types b/tests/baselines/reference/validEnumAssignments.types index 5ac73b126abc3..120e4fe04bef9 100644 --- a/tests/baselines/reference/validEnumAssignments.types +++ b/tests/baselines/reference/validEnumAssignments.types @@ -54,18 +54,18 @@ e = e; >e : E e = E.A; ->e = E.A : E +>e = E.A : E.A >e : E ->E.A : E +>E.A : E.A >E : typeof E ->A : E +>A : E.A e = E.B; ->e = E.B : E +>e = E.B : E.B >e : E ->E.B : E +>E.B : E.B >E : typeof E ->B : E +>B : E.B e = n; >e = n : number @@ -83,23 +83,23 @@ e = undefined; >undefined : undefined e = 1; ->e = 1 : number +>e = 1 : 1 >e : E ->1 : number +>1 : 1 e = 1.; ->e = 1. : number +>e = 1. : 1 >e : E ->1. : number +>1. : 1 e = 1.0; ->e = 1.0 : number +>e = 1.0 : 1 >e : E ->1.0 : number +>1.0 : 1 e = -1; ->e = -1 : number +>e = -1 : -1 >e : E ->-1 : number +>-1 : -1 >1 : number From 178883a617b4843dd9dc93ee8f4fecc7279c152d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 23 Jul 2016 09:29:29 -0700 Subject: [PATCH 47/55] Fix issue in getTypeDefinitionAtPosition --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 5bcd5ee28c4b2..b6d80f835ffbd 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -5093,7 +5093,7 @@ namespace ts { return undefined; } - if (type.flags & TypeFlags.Union) { + if (type.flags & TypeFlags.Union && !(type.flags & TypeFlags.Enum)) { const result: DefinitionInfo[] = []; forEach((type).types, t => { if (t.symbol) { From 835645c5ec78da0b38214dc68b195b505bbb3941 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 23 Jul 2016 09:29:49 -0700 Subject: [PATCH 48/55] Fix fourslash test --- tests/cases/fourslash/completionListEnumMembers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/fourslash/completionListEnumMembers.ts b/tests/cases/fourslash/completionListEnumMembers.ts index 4f81af5a84537..48bda280f3f27 100644 --- a/tests/cases/fourslash/completionListEnumMembers.ts +++ b/tests/cases/fourslash/completionListEnumMembers.ts @@ -16,7 +16,7 @@ verify.memberListCount(2); goTo.marker('typeReference'); -verify.memberListCount(0); +verify.memberListCount(2); goTo.marker('enumValueReference'); verify.memberListContains("toString"); From b70132a577e8579cd0c54965861c418d3165f5bc Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 23 Jul 2016 09:30:08 -0700 Subject: [PATCH 49/55] Fix linting errors --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c0069878503fd..8113834f67d6e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3781,7 +3781,7 @@ namespace ts { enumType.symbol = symbol; if (enumHasLiteralMembers(symbol)) { const memberTypeList: Type[] = []; - const memberTypes: Map = {}; + const memberTypes: Map = {}; for (const declaration of enumType.symbol.declarations) { if (declaration.kind === SyntaxKind.EnumDeclaration) { computeEnumMemberValues(declaration); @@ -6131,8 +6131,8 @@ namespace ts { relation: Map, errorNode: Node, headMessage?: DiagnosticMessage, - containingMessageChain?: DiagnosticMessageChain): boolean - { + containingMessageChain?: DiagnosticMessageChain): boolean { + let errorInfo: DiagnosticMessageChain; let sourceStack: ObjectType[]; let targetStack: ObjectType[]; From 60cc5df2d71545fe656c5971fdd8cb98f296f456 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 23 Jul 2016 11:20:16 -0700 Subject: [PATCH 50/55] Change getUnionType to default to no subtype reduction --- src/compiler/checker.ts | 98 +++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8113834f67d6e..a14f9161c6e8e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1548,7 +1548,7 @@ namespace ts { } function createBooleanType(trueFalseTypes: Type[]): IntrinsicType & UnionType { - const type = getUnionType(trueFalseTypes, /*noSubtypeReduction*/ true); + const type = getUnionType(trueFalseTypes, /*subtypeReduction*/ true); type.flags |= TypeFlags.Boolean; type.intrinsicName = "boolean"; return type; @@ -3232,7 +3232,7 @@ namespace ts { let type: Type = undefined; // Handle module.exports = expr or this.p = expr if (declaration.kind === SyntaxKind.BinaryExpression) { - type = getUnionType(map(symbol.declarations, (decl: BinaryExpression) => checkExpressionCached(decl.right))); + type = getUnionType(map(symbol.declarations, (decl: BinaryExpression) => checkExpressionCached(decl.right)), /*subtypeReduction*/ true); } else if (declaration.kind === SyntaxKind.PropertyAccessExpression) { // Declarations only exist for property access expressions for certain @@ -4087,7 +4087,7 @@ namespace ts { } function resolveTupleTypeMembers(type: TupleType) { - const arrayElementType = getUnionType(type.elementTypes, /*noSubtypeReduction*/ true); + const arrayElementType = getUnionType(type.elementTypes); // Make the tuple type itself the 'this' type by including an extra type argument const arrayType = resolveStructuredTypeMembers(createTypeFromGenericGlobalType(globalArrayType, [arrayElementType, type])); const members = createTupleTypeMemberSymbols(type.elementTypes); @@ -4149,7 +4149,7 @@ namespace ts { if (unionSignatures.length > 1) { s = cloneSignature(signature); if (forEach(unionSignatures, sig => sig.thisParameter)) { - const thisType = getUnionType(map(unionSignatures, sig => getTypeOfSymbol(sig.thisParameter) || anyType)); + const thisType = getUnionType(map(unionSignatures, sig => getTypeOfSymbol(sig.thisParameter) || anyType), /*subtypeReduction*/ true); s.thisParameter = createTransientSymbol(signature.thisParameter, thisType); } // Clear resolved return type we possibly got from cloneSignature @@ -4175,7 +4175,7 @@ namespace ts { indexTypes.push(indexInfo.type); isAnyReadonly = isAnyReadonly || indexInfo.isReadonly; } - return createIndexInfo(getUnionType(indexTypes), isAnyReadonly); + return createIndexInfo(getUnionType(indexTypes, /*subtypeReduction*/ true), isAnyReadonly); } function resolveUnionTypeMembers(type: UnionType) { @@ -4417,7 +4417,7 @@ namespace ts { result.containingType = containingType; result.declarations = declarations; result.isReadonly = isReadonly; - result.type = containingType.flags & TypeFlags.Union ? getUnionType(propTypes, /*noSubtypeReduction*/ true) : getIntersectionType(propTypes); + result.type = containingType.flags & TypeFlags.Union ? getUnionType(propTypes) : getIntersectionType(propTypes); return result; } @@ -4509,7 +4509,7 @@ namespace ts { } } if (propTypes.length) { - return getUnionType(propTypes); + return getUnionType(propTypes, /*subtypeReduction*/ true); } } return undefined; @@ -4774,7 +4774,7 @@ namespace ts { type = instantiateType(getReturnTypeOfSignature(signature.target), signature.mapper); } else if (signature.unionSignatures) { - type = getUnionType(map(signature.unionSignatures, getReturnTypeOfSignature)); + type = getUnionType(map(signature.unionSignatures, getReturnTypeOfSignature), /*subtypeReduction*/ true); } else { type = getReturnTypeFromBody(signature.declaration); @@ -5291,7 +5291,7 @@ namespace ts { // literals and the || and ?: operators). Named types can circularly reference themselves and therefore // cannot be deduplicated during their declaration. For example, "type Item = string | (() => Item" is // a named type that circularly references itself. - function getUnionType(types: Type[], noSubtypeReduction?: boolean, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { + function getUnionType(types: Type[], subtypeReduction?: boolean, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { if (types.length === 0) { return neverType; } @@ -5308,7 +5308,7 @@ namespace ts { if (typeSet.containsNull) typeSet.push(nullType); if (typeSet.containsUndefined) typeSet.push(undefinedType); } - if (!noSubtypeReduction) { + if (subtypeReduction) { removeSubtypes(typeSet); } if (typeSet.length === 0) { @@ -5334,7 +5334,7 @@ namespace ts { function getTypeFromUnionTypeNode(node: UnionTypeNode, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { const links = getNodeLinks(node); if (!links.resolvedType) { - links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*noSubtypeReduction*/ true, aliasSymbol, aliasTypeArguments); + links.resolvedType = getUnionType(map(node.types, getTypeFromTypeNode), /*subtypeReduction*/ false, aliasSymbol, aliasTypeArguments); } return links.resolvedType; } @@ -5767,7 +5767,7 @@ namespace ts { return createTupleType(instantiateList((type).elementTypes, mapper, instantiateType)); } if (type.flags & TypeFlags.Union && !(type.flags & TypeFlags.Primitive)) { - return getUnionType(instantiateList((type).types, mapper, instantiateType), /*noSubtypeReduction*/ true, type.aliasSymbol, mapper.targetTypes); + return getUnionType(instantiateList((type).types, mapper, instantiateType), /*subtypeReduction*/ false, type.aliasSymbol, mapper.targetTypes); } if (type.flags & TypeFlags.Intersection) { return getIntersectionType(instantiateList((type).types, mapper, instantiateType), type.aliasSymbol, mapper.targetTypes); @@ -7016,7 +7016,7 @@ namespace ts { } const primaryTypes = filter(types, t => !(t.flags & TypeFlags.Nullable)); if (!primaryTypes.length) { - return getUnionType(types); + return getUnionType(types, /*subtypeReduction*/ true); } const supertype = forEach(primaryTypes, t => isSupertypeOfEach(t, primaryTypes) ? t : undefined); return supertype && includeFalsyTypes(supertype, getFalsyFlagsOfTypes(types) & TypeFlags.Nullable); @@ -7093,7 +7093,7 @@ namespace ts { type.flags & TypeFlags.NumberLiteral ? numberType : type.flags & TypeFlags.BooleanLiteral ? booleanType : type.flags & TypeFlags.EnumLiteral ? (type).baseType : - type.flags & TypeFlags.Union && !(type.flags & TypeFlags.Enum) ? getUnionType(map((type).types, getBaseTypeOfUnitType), /*noSubtypeReduction*/ true) : + type.flags & TypeFlags.Union && !(type.flags & TypeFlags.Enum) ? getUnionType(map((type).types, getBaseTypeOfUnitType)) : type; } @@ -7135,7 +7135,7 @@ namespace ts { if (flags & TypeFlags.Void) types.push(voidType); if (flags & TypeFlags.Undefined) types.push(undefinedType); if (flags & TypeFlags.Null) types.push(nullType); - return getUnionType(types); + return getUnionType(types, /*subtypeReduction*/ true); } function removeDefinitelyFalsyTypes(type: Type): Type { @@ -7232,7 +7232,7 @@ namespace ts { return getWidenedTypeOfObjectLiteral(type); } if (type.flags & TypeFlags.Union) { - return getUnionType(map((type).types, getWidenedConstituentType), /*noSubtypeReduction*/ true); + return getUnionType(map((type).types, getWidenedConstituentType)); } if (isArrayType(type)) { return createArrayType(getWidenedType((type).typeArguments[0])); @@ -7608,7 +7608,7 @@ namespace ts { reducedTypes.push(t); } } - return type.flags & TypeFlags.Union ? getUnionType(reducedTypes, /*noSubtypeReduction*/ true) : getIntersectionType(reducedTypes); + return type.flags & TypeFlags.Union ? getUnionType(reducedTypes) : getIntersectionType(reducedTypes); } function getInferenceCandidates(context: InferenceContext, index: number): Type[] { @@ -7623,7 +7623,7 @@ namespace ts { const inferences = getInferenceCandidates(context, index); if (inferences.length) { // Infer widened union or supertype, or the unknown type for no common supertype - const unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences); + const unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences, /*subtypeReduction*/ true) : getCommonSupertype(inferences); inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType; inferenceSucceeded = !!unionOrSuperType; } @@ -7794,7 +7794,7 @@ namespace ts { if (declaredType !== assignedType && declaredType.flags & TypeFlags.Union) { const reducedTypes = filter(declaredType.types, t => typeMaybeAssignableTo(assignedType, t)); if (reducedTypes.length) { - return reducedTypes.length === 1 ? reducedTypes[0] : getUnionType(reducedTypes, /*noSubtypeReduction*/ true); + return reducedTypes.length === 1 ? reducedTypes[0] : getUnionType(reducedTypes); } } return declaredType; @@ -7879,13 +7879,13 @@ namespace ts { } } } - return firstType ? types ? getUnionType(types, /*noSubtypeReduction*/ true) : firstType : neverType; + return firstType ? types ? getUnionType(types) : firstType : neverType; } function getTypeWithDefault(type: Type, defaultExpression: Expression) { if (defaultExpression) { const defaultType = checkExpression(defaultExpression); - return getUnionType([getTypeWithFacts(type, TypeFacts.NEUndefined), defaultType]); + return getUnionType([getTypeWithFacts(type, TypeFacts.NEUndefined), defaultType], /*subtypeReduction*/ true); } return type; } @@ -8031,7 +8031,7 @@ namespace ts { function filterType(type: Type, f: (t: Type) => boolean): Type { return type.flags & TypeFlags.Union ? - getUnionType(filter((type).types, f), /*noSubtypeReduction*/ true) : + getUnionType(filter((type).types, f)) : f(type) ? type : neverType; } @@ -8185,7 +8185,7 @@ namespace ts { antecedentTypes.push(type); } } - return getUnionType(antecedentTypes, /*noSubtypeReduction*/ true); + return getUnionType(antecedentTypes); } function getTypeAtFlowLoopLabel(flow: FlowLabel) { @@ -8205,7 +8205,7 @@ namespace ts { // the non-looping control flow path that leads to the top. for (let i = flowLoopStart; i < flowLoopCount; i++) { if (flowLoopNodes[i] === flow && flowLoopKeys[i] === key) { - return getUnionType(flowLoopTypes[i], /*noSubtypeReduction*/ true); + return getUnionType(flowLoopTypes[i]); } } // Add the flow loop junction and reference to the in-process stack and analyze @@ -8234,7 +8234,7 @@ namespace ts { break; } } - return cache[key] = getUnionType(antecedentTypes, /*noSubtypeReduction*/ true); + return cache[key] = getUnionType(antecedentTypes); } function isMatchingPropertyAccess(expr: Expression) { @@ -8362,13 +8362,13 @@ namespace ts { } const clauseTypes = switchTypes.slice(clauseStart, clauseEnd); const hasDefaultClause = clauseStart === clauseEnd || contains(clauseTypes, neverType); - const discriminantType = getUnionType(clauseTypes, /*noSubtypeReduction*/ true); + const discriminantType = getUnionType(clauseTypes); const caseType = discriminantType === neverType ? 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], /*noSubtypeReduction*/ true); + return caseType === neverType ? defaultType : getUnionType([caseType, defaultType]); } function narrowTypeByInstanceof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { @@ -8412,7 +8412,7 @@ namespace ts { constructSignatures = getSignaturesOfType(rightType, SignatureKind.Construct); } if (constructSignatures && constructSignatures.length) { - targetType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature))), /*noSubtypeReduction*/ true); + targetType = getUnionType(map(constructSignatures, signature => getReturnTypeOfSignature(getErasedSignature(signature)))); } } @@ -8426,7 +8426,7 @@ namespace ts { function getNarrowedType(type: Type, candidate: Type, assumeTrue: boolean) { if (!assumeTrue) { return type.flags & TypeFlags.Union ? - getUnionType(filter((type).types, t => !isTypeSubtypeOf(t, candidate)), /*noSubtypeReduction*/ true) : + getUnionType(filter((type).types, t => !isTypeSubtypeOf(t, candidate))) : type; } // If the current type is a union type, remove all constituents that aren't assignable to @@ -8434,7 +8434,7 @@ namespace ts { if (type.flags & TypeFlags.Union) { const assignableConstituents = filter((type).types, t => isTypeAssignableTo(t, candidate)); if (assignableConstituents.length) { - return getUnionType(assignableConstituents, /*noSubtypeReduction*/ true); + return getUnionType(assignableConstituents); } } // If the candidate type is assignable to the target type, narrow to the candidate type. @@ -9125,7 +9125,7 @@ namespace ts { for (let i = indexOfParameter; i < iife.arguments.length; i++) { restTypes.push(getTypeOfExpression(iife.arguments[i])); } - return createArrayType(getUnionType(restTypes)); + return createArrayType(getUnionType(restTypes, /*subtypeReduction*/ true)); } const links = getNodeLinks(iife); const cached = links.resolvedSignature; @@ -9328,7 +9328,7 @@ namespace ts { } } } - return mappedTypes ? getUnionType(mappedTypes) : mappedType; + return mappedTypes ? getUnionType(mappedTypes, /*subtypeReduction*/ true) : mappedType; } function getTypeOfPropertyOfContextualType(type: Type, name: string) { @@ -9694,7 +9694,9 @@ namespace ts { } } } - return createArrayType(elementTypes.length ? getUnionType(elementTypes) : strictNullChecks ? neverType : undefinedWideningType); + return createArrayType(elementTypes.length ? + getUnionType(elementTypes, /*subtypeReduction*/ true) : + strictNullChecks ? neverType : undefinedWideningType); } function isNumericName(name: DeclarationName): boolean { @@ -9761,7 +9763,7 @@ namespace ts { propTypes.push(getTypeOfSymbol(properties[i])); } } - const unionType = propTypes.length ? getUnionType(propTypes) : undefinedType; + const unionType = propTypes.length ? getUnionType(propTypes, /*subtypeReduction*/ true) : undefinedType; return createIndexInfo(unionType, /*isReadonly*/ false); } @@ -10072,7 +10074,7 @@ namespace ts { } } - return getUnionType(signatures.map(getReturnTypeOfSignature)); + return getUnionType(signatures.map(getReturnTypeOfSignature), /*subtypeReduction*/ true); } /// e.g. "props" for React.d.ts, @@ -10124,7 +10126,7 @@ namespace ts { const types = (elemType).types; return getUnionType(types.map(type => { return getResolvedJsxType(node, type, elemClassType); - })); + }), /*subtypeReduction*/ true); } // If the elemType is a string type, we have to return anyType to prevent an error downstream as we will try to find construct or call signature of the type @@ -12178,7 +12180,7 @@ namespace ts { } // When yield/return statements are contextually typed we allow the return type to be a union type. // Otherwise we require the yield/return expressions to have a best common supertype. - type = contextualSignature ? getUnionType(types) : getCommonSupertype(types); + type = contextualSignature ? getUnionType(types, /*subtypeReduction*/ true) : getCommonSupertype(types); if (!type) { if (funcIsGenerator) { error(func, Diagnostics.No_best_common_type_exists_among_yield_expressions); @@ -12187,7 +12189,7 @@ namespace ts { else { error(func, Diagnostics.No_best_common_type_exists_among_return_expressions); // Defer to unioning the return types so we get a) downstream errors earlier and b) better Salsa experience - return isAsync ? createPromiseReturnType(func, getUnionType(types)) : getUnionType(types); + return isAsync ? createPromiseReturnType(func, getUnionType(types, /*subtypeReduction*/ true)) : getUnionType(types, /*subtypeReduction*/ true); } } @@ -12985,7 +12987,7 @@ namespace ts { leftType; case SyntaxKind.BarBarToken: return getTypeFacts(leftType) & TypeFacts.Falsy ? - getUnionType([removeDefinitelyFalsyTypes(leftType), rightType]) : + getUnionType([removeDefinitelyFalsyTypes(leftType), rightType], /*subtypeReduction*/ true) : leftType; case SyntaxKind.EqualsToken: checkAssignmentOperator(rightType); @@ -13112,7 +13114,7 @@ namespace ts { checkExpression(node.condition); const type1 = checkExpression(node.whenTrue, contextualMapper); const type2 = checkExpression(node.whenFalse, contextualMapper); - return getUnionType([type1, type2]); + return getUnionType([type1, type2], /*subtypeReduction*/ true); } function typeContainsLiteralFromEnum(type: Type, enumType: EnumType) { @@ -14373,7 +14375,7 @@ namespace ts { return undefined; } - return getUnionType(map(onfulfilledParameterSignatures, getTypeOfFirstParameterOfSignature)); + return getUnionType(map(onfulfilledParameterSignatures, getTypeOfFirstParameterOfSignature), /*subtypeReduction*/ true); } function getTypeOfFirstParameterOfSignature(signature: Signature) { @@ -14401,7 +14403,7 @@ namespace ts { types.push(checkAwaitedTypeWorker(constituentType)); } - return getUnionType(types); + return getUnionType(types, /*subtypeReduction*/ true); } else { const promisedType = getPromisedType(type); @@ -14617,7 +14619,7 @@ namespace ts { case SyntaxKind.ClassDeclaration: const classSymbol = getSymbolOfNode(node.parent); const classConstructorType = getTypeOfSymbol(classSymbol); - expectedReturnType = getUnionType([classConstructorType, voidType]); + expectedReturnType = getUnionType([classConstructorType, voidType], /*subtypeReduction*/ true); break; case SyntaxKind.Parameter: @@ -14640,7 +14642,7 @@ namespace ts { case SyntaxKind.SetAccessor: const methodType = getTypeOfNode(node.parent); const descriptorType = createTypedPropertyDescriptorType(methodType); - expectedReturnType = getUnionType([descriptorType, voidType]); + expectedReturnType = getUnionType([descriptorType, voidType], /*subtypeReduction*/ true); break; } @@ -15614,7 +15616,7 @@ namespace ts { return undefined; } - typeAsIterable.iterableElementType = getElementTypeOfIterator(getUnionType(map(iteratorFunctionSignatures, getReturnTypeOfSignature)), errorNode); + typeAsIterable.iterableElementType = getElementTypeOfIterator(getUnionType(map(iteratorFunctionSignatures, getReturnTypeOfSignature), /*subtypeReduction*/ true), errorNode); } } @@ -15660,7 +15662,7 @@ namespace ts { return undefined; } - const iteratorNextResult = getUnionType(map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); + const iteratorNextResult = getUnionType(map(iteratorNextFunctionSignatures, getReturnTypeOfSignature), /*subtypeReduction*/ true); if (isTypeAny(iteratorNextResult)) { return undefined; } @@ -15719,7 +15721,7 @@ namespace ts { // based on whether the remaining type is the same as the initial type. let arrayType = arrayOrStringType; if (arrayOrStringType.flags & TypeFlags.Union) { - arrayType = getUnionType(filter((arrayOrStringType as UnionType).types, t => !(t.flags & TypeFlags.StringLike))); + arrayType = getUnionType(filter((arrayOrStringType as UnionType).types, t => !(t.flags & TypeFlags.StringLike)), /*subtypeReduction*/ true); } else if (arrayOrStringType.flags & TypeFlags.StringLike) { arrayType = neverType; @@ -15760,7 +15762,7 @@ namespace ts { return stringType; } - return getUnionType([arrayElementType, stringType]); + return getUnionType([arrayElementType, stringType], /*subtypeReduction*/ true); } return arrayElementType; From d7aa40d0fc45168a41f18b2c21f678fefd642308 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 23 Jul 2016 14:08:51 -0700 Subject: [PATCH 51/55] Remove unnecessary subtype reduction operations --- src/compiler/checker.ts | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a14f9161c6e8e..f169c1bfd660d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1548,7 +1548,7 @@ namespace ts { } function createBooleanType(trueFalseTypes: Type[]): IntrinsicType & UnionType { - const type = getUnionType(trueFalseTypes, /*subtypeReduction*/ true); + const type = getUnionType(trueFalseTypes); type.flags |= TypeFlags.Boolean; type.intrinsicName = "boolean"; return type; @@ -5284,13 +5284,13 @@ namespace ts { return type1.id - type2.id; } - // We reduce the constituent type set to only include types that aren't subtypes of other types, unless - // the noSubtypeReduction flag is specified, in which case we perform a simple deduplication based on - // object identity. Subtype reduction is possible only when union types are known not to circularly - // reference themselves (as is the case with union types created by expression constructs such as array - // literals and the || and ?: operators). Named types can circularly reference themselves and therefore - // cannot be deduplicated during their declaration. For example, "type Item = string | (() => Item" is - // a named type that circularly references itself. + // We 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 + // types are known not to circularly reference themselves (as is the case with union types created by + // expression constructs such as array literals and the || and ?: operators). Named types can + // circularly reference themselves and therefore cannot be deduplicated during their declaration. + // For example, "type Item = string | (() => Item" is a named type that circularly references itself. function getUnionType(types: Type[], subtypeReduction?: boolean, aliasSymbol?: Symbol, aliasTypeArguments?: Type[]): Type { if (types.length === 0) { return neverType; @@ -7885,7 +7885,7 @@ namespace ts { function getTypeWithDefault(type: Type, defaultExpression: Expression) { if (defaultExpression) { const defaultType = checkExpression(defaultExpression); - return getUnionType([getTypeWithFacts(type, TypeFacts.NEUndefined), defaultType], /*subtypeReduction*/ true); + return getUnionType([getTypeWithFacts(type, TypeFacts.NEUndefined), defaultType]); } return type; } @@ -9125,7 +9125,7 @@ namespace ts { for (let i = indexOfParameter; i < iife.arguments.length; i++) { restTypes.push(getTypeOfExpression(iife.arguments[i])); } - return createArrayType(getUnionType(restTypes, /*subtypeReduction*/ true)); + return createArrayType(getUnionType(restTypes)); } const links = getNodeLinks(iife); const cached = links.resolvedSignature; @@ -9328,7 +9328,7 @@ namespace ts { } } } - return mappedTypes ? getUnionType(mappedTypes, /*subtypeReduction*/ true) : mappedType; + return mappedTypes ? getUnionType(mappedTypes) : mappedType; } function getTypeOfPropertyOfContextualType(type: Type, name: string) { @@ -14619,7 +14619,7 @@ namespace ts { case SyntaxKind.ClassDeclaration: const classSymbol = getSymbolOfNode(node.parent); const classConstructorType = getTypeOfSymbol(classSymbol); - expectedReturnType = getUnionType([classConstructorType, voidType], /*subtypeReduction*/ true); + expectedReturnType = getUnionType([classConstructorType, voidType]); break; case SyntaxKind.Parameter: @@ -14642,7 +14642,7 @@ namespace ts { case SyntaxKind.SetAccessor: const methodType = getTypeOfNode(node.parent); const descriptorType = createTypedPropertyDescriptorType(methodType); - expectedReturnType = getUnionType([descriptorType, voidType], /*subtypeReduction*/ true); + expectedReturnType = getUnionType([descriptorType, voidType]); break; } From b673d5ff03195fc08eb6ee1dde8147754bc1a796 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sat, 23 Jul 2016 16:48:19 -0700 Subject: [PATCH 52/55] Use binary searching in union types to improve performance --- src/compiler/checker.ts | 156 ++++++++++++++++++++++------------------ 1 file changed, 88 insertions(+), 68 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f169c1bfd660d..91f305460bcb0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -118,6 +118,11 @@ namespace ts { const resolvingSymbol = createSymbol(SymbolFlags.Transient, "__resolving__"); const anyType = createIntrinsicType(TypeFlags.Any, "any"); + const unknownType = createIntrinsicType(TypeFlags.Any, "unknown"); + const undefinedType = createIntrinsicType(TypeFlags.Undefined, "undefined"); + const undefinedWideningType = strictNullChecks ? undefinedType : createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsWideningType, "undefined"); + const nullType = createIntrinsicType(TypeFlags.Null, "null"); + const nullWideningType = strictNullChecks ? nullType : createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsWideningType, "null"); const stringType = createIntrinsicType(TypeFlags.String, "string"); const numberType = createIntrinsicType(TypeFlags.Number, "number"); const trueType = createIntrinsicType(TypeFlags.BooleanLiteral, "true"); @@ -125,11 +130,6 @@ namespace ts { const booleanType = createBooleanType([trueType, falseType]); const esSymbolType = createIntrinsicType(TypeFlags.ESSymbol, "symbol"); const voidType = createIntrinsicType(TypeFlags.Void, "void"); - const undefinedType = createIntrinsicType(TypeFlags.Undefined, "undefined"); - const undefinedWideningType = strictNullChecks ? undefinedType : createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsWideningType, "undefined"); - const nullType = createIntrinsicType(TypeFlags.Null, "null"); - const nullWideningType = strictNullChecks ? nullType : createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsWideningType, "null"); - const unknownType = createIntrinsicType(TypeFlags.Any, "unknown"); const neverType = createIntrinsicType(TypeFlags.Never, "never"); const emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -1928,23 +1928,27 @@ namespace ts { return result; } - function reduceLiteralTypes(types: Type[]): Type[] { - let result: Type[]; + function formatUnionTypes(types: Type[]): Type[] { + const result: Type[] = []; + let flags: TypeFlags = 0; for (let i = 0; i < types.length; i++) { const t = types[i]; - if (t.flags & (TypeFlags.BooleanLiteral | TypeFlags.EnumLiteral)) { - const baseType = t.flags & TypeFlags.BooleanLiteral ? booleanType : (t).baseType; - const count = baseType.types.length; - if (i + count <= types.length && types[i + count - 1] === baseType.types[count - 1]) { - (result || (result = types.slice(0, i))).push(baseType); - i += count - 1; - continue; + flags |= t.flags; + if (!(t.flags & TypeFlags.Nullable)) { + if (t.flags & (TypeFlags.BooleanLiteral | TypeFlags.EnumLiteral)) { + const baseType = t.flags & TypeFlags.BooleanLiteral ? booleanType : (t).baseType; + const count = baseType.types.length; + if (i + count <= types.length && types[i + count - 1] === baseType.types[count - 1]) { + result.push(baseType); + i += count - 1; + continue; + } } - } - if (result) { result.push(t); } } + if (flags & TypeFlags.Null) result.push(nullType); + if (flags & TypeFlags.Undefined) result.push(undefinedType); return result || types; } @@ -2246,7 +2250,7 @@ namespace ts { writePunctuation(writer, SyntaxKind.OpenParenToken); } if (type.flags & TypeFlags.Union) { - writeTypeList(reduceLiteralTypes(type.types), SyntaxKind.BarToken); + writeTypeList(formatUnionTypes(type.types), SyntaxKind.BarToken); } else { writeTypeList(type.types, SyntaxKind.AmpersandToken); @@ -5228,27 +5232,58 @@ namespace ts { containsNonWideningType?: boolean; } - function addTypeToSet(typeSet: TypeSet, type: Type, typeSetKind: TypeFlags) { - if (type.flags & typeSetKind) { - addTypesToSet(typeSet, (type).types, typeSetKind); + function binarySearchTypes(types: Type[], type: Type): number { + let low = 0; + let high = types.length - 1; + const typeId = type.id; + while (low <= high) { + const middle = low + ((high - low) >> 1); + const id = types[middle].id; + if (id === typeId) { + return middle; + } + else if (id > typeId) { + high = middle - 1; + } + else { + low = middle + 1; + } + } + return ~low; + } + + function containsType(types: Type[], type: Type): boolean { + return binarySearchTypes(types, type) >= 0; + } + + function addTypeToUnion(typeSet: TypeSet, type: Type) { + if (type.flags & TypeFlags.Union) { + addTypesToUnion(typeSet, (type).types); } - else if (type.flags & (TypeFlags.Any | TypeFlags.Undefined | TypeFlags.Null)) { - if (type.flags & TypeFlags.Any) typeSet.containsAny = true; + else if (type.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 (type !== neverType && !contains(typeSet, type) && - !(type.flags & TypeFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && containsIdenticalType(typeSet, type))) { - typeSet.push(type); + else if (!(type.flags & TypeFlags.Never)) { + 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))) { + typeSet.splice(~index, 0, type); + } + } } } // Add the given types to the given type set. Order is preserved, duplicates are removed, // and nested types of the given kind are flattened into the set. - function addTypesToSet(typeSet: TypeSet, types: Type[], typeSetKind: TypeFlags) { + function addTypesToUnion(typeSet: TypeSet, types: Type[]) { for (const type of types) { - addTypeToSet(typeSet, type, typeSetKind); + addTypeToUnion(typeSet, type); } } @@ -5280,10 +5315,6 @@ namespace ts { } } - function compareTypeIds(type1: Type, type2: Type): number { - return type1.id - type2.id; - } - // We 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 @@ -5299,15 +5330,10 @@ namespace ts { return types[0]; } const typeSet = [] as TypeSet; - addTypesToSet(typeSet, types, TypeFlags.Union); + addTypesToUnion(typeSet, types); if (typeSet.containsAny) { return anyType; } - typeSet.sort(compareTypeIds); - if (strictNullChecks) { - if (typeSet.containsNull) typeSet.push(nullType); - if (typeSet.containsUndefined) typeSet.push(undefinedType); - } if (subtypeReduction) { removeSubtypes(typeSet); } @@ -5339,6 +5365,26 @@ namespace ts { return links.resolvedType; } + function addTypeToIntersection(typeSet: TypeSet, type: Type) { + if (type.flags & TypeFlags.Intersection) { + addTypesToIntersection(typeSet, (type).types); + } + else if (type.flags & TypeFlags.Any) { + typeSet.containsAny = true; + } + else if (!(type.flags & TypeFlags.Never) && (strictNullChecks || !(type.flags & TypeFlags.Nullable)) && !contains(typeSet, type)) { + typeSet.push(type); + } + } + + // Add the given types to the given type set. Order is preserved, duplicates are removed, + // and nested types of the given kind are flattened into the set. + function addTypesToIntersection(typeSet: TypeSet, types: Type[]) { + for (const type of types) { + addTypeToIntersection(typeSet, type); + } + } + // We do not perform structural deduplication on intersection types. Intersection types are created only by the & // type operator and we can't reduce those because we want to support recursive intersection types. For example, // a type alias of the form "type List = T & { next: List }" cannot be reduced during its declaration. @@ -5349,14 +5395,10 @@ namespace ts { return emptyObjectType; } const typeSet = [] as TypeSet; - addTypesToSet(typeSet, types, TypeFlags.Intersection); + addTypesToIntersection(typeSet, types); if (typeSet.containsAny) { return anyType; } - if (strictNullChecks) { - if (typeSet.containsNull) typeSet.push(nullType); - if (typeSet.containsUndefined) typeSet.push(undefinedType); - } if (typeSet.length === 1) { return typeSet[0]; } @@ -6395,21 +6437,10 @@ namespace ts { function typeRelatedToSomeType(source: Type, target: UnionOrIntersectionType, reportErrors: boolean): Ternary { const targetTypes = target.types; - if (contains(targetTypes, source)) { + if (target.flags & TypeFlags.Union && containsType(targetTypes, source)) { return Ternary.True; } - // The null and undefined types are guaranteed to be at the end of the constituent type list. In order - // to produce the best possible errors we first check the nullable types, such that the last type we - // check and report errors from is a non-nullable type if one is present. - let len = targetTypes.length; - while (len >= 2 && targetTypes[len - 1].flags & TypeFlags.Nullable) { - const related = isRelatedTo(source, targetTypes[len - 1], /*reportErrors*/ false); - if (related) { - return related; - } - len--; - } - // Now check the non-nullable types and report errors on the last one. + const len = targetTypes.length; for (let i = 0; i < len; i++) { const related = isRelatedTo(source, targetTypes[i], reportErrors && i === len - 1); if (related) { @@ -6434,21 +6465,10 @@ namespace ts { function someTypeRelatedToType(source: UnionOrIntersectionType, target: Type, reportErrors: boolean): Ternary { const sourceTypes = source.types; - if (contains(sourceTypes, target)) { + if (source.flags & TypeFlags.Union && containsType(sourceTypes, target)) { return Ternary.True; } - // The null and undefined types are guaranteed to be at the end of the constituent type list. In order - // to produce the best possible errors we first check the nullable types, such that the last type we - // check and report errors from is a non-nullable type if one is present. - let len = sourceTypes.length; - while (len >= 2 && sourceTypes[len - 1].flags & TypeFlags.Nullable) { - const related = isRelatedTo(sourceTypes[len - 1], target, /*reportErrors*/ false); - if (related) { - return related; - } - len--; - } - // Now check the non-nullable types and report errors on the last one. + const len = sourceTypes.length; for (let i = 0; i < len; i++) { const related = isRelatedTo(sourceTypes[i], target, reportErrors && i === len - 1); if (related) { From a1a87254565b6b2eec334b2a280463ee7139449a Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 25 Jul 2016 09:05:29 -0700 Subject: [PATCH 53/55] Optimize type inference --- src/compiler/checker.ts | 30 ++++++++++++++++++++++-------- src/compiler/types.ts | 4 ++-- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index db71a8461d292..730f93bab45d4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7393,6 +7393,24 @@ namespace ts { }; } + // Return true if the given type could possibly reference a type parameter for which + // we perform type inference (i.e. a type parameter of a generic function). We cache + // results for union and intersection types for performance reasons. + function couldContainTypeParameters(type: Type): boolean { + return !!(type.flags & TypeFlags.TypeParameter || + type.flags & TypeFlags.Reference && forEach((type).typeArguments, couldContainTypeParameters) || + type.flags & TypeFlags.Tuple && forEach((type).elementTypes, couldContainTypeParameters) || + type.flags & TypeFlags.Anonymous && type.symbol && type.symbol.flags & (SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.Class) || + type.flags & TypeFlags.UnionOrIntersection && couldUnionOrIntersectionContainTypeParameters(type)); + } + + function couldUnionOrIntersectionContainTypeParameters(type: UnionOrIntersectionType): boolean { + if (type.couldContainTypeParameters === undefined) { + type.couldContainTypeParameters = forEach(type.types, couldContainTypeParameters); + } + return type.couldContainTypeParameters; + } + function inferTypes(context: InferenceContext, source: Type, target: Type) { let sourceStack: Type[]; let targetStack: Type[]; @@ -7411,6 +7429,9 @@ namespace ts { } function inferFromTypes(source: Type, target: Type) { + if (!couldContainTypeParameters(target)) { + return; + } if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union && !(source.flags & TypeFlags.Enum && target.flags & TypeFlags.Enum) || source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) { // Source and target are both unions or both intersections. If source and target @@ -7521,25 +7542,18 @@ namespace ts { } else { source = getApparentType(source); - if (source.flags & TypeFlags.ObjectType && ( - target.flags & TypeFlags.Reference && (target).typeArguments || - target.flags & TypeFlags.Tuple || - target.flags & TypeFlags.Anonymous && target.symbol && target.symbol.flags & (SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.Class))) { - // If source is an object type, and target is a type reference with type arguments, a tuple type, - // the type of a method, or a type literal, infer from members + if (source.flags & TypeFlags.ObjectType) { if (isInProcess(source, target)) { return; } if (isDeeplyNestedGeneric(source, sourceStack, depth) && isDeeplyNestedGeneric(target, targetStack, depth)) { return; } - const key = source.id + "," + target.id; if (hasProperty(visited, key)) { return; } visited[key] = true; - if (depth === 0) { sourceStack = []; targetStack = []; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 8fe23739af08b..072209aa49640 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2364,9 +2364,9 @@ namespace ts { export interface UnionOrIntersectionType extends Type { types: Type[]; // Constituent types /* @internal */ - reducedType: Type; // Reduced union type (all subtypes removed) - /* @internal */ resolvedProperties: SymbolTable; // Cache of resolved properties + /* @internal */ + couldContainTypeParameters: boolean; } export interface UnionType extends UnionOrIntersectionType { } From a5fcd5f94bf528c516b30f8c71e8aef157ab763c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 27 Jul 2016 17:10:06 -0700 Subject: [PATCH 54/55] Display enum member types using qualified names --- src/compiler/checker.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 730f93bab45d4..38ce16c33f68b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2136,7 +2136,12 @@ namespace ts { else if (type.flags & TypeFlags.Reference) { writeTypeReference(type, nextFlags); } - else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.EnumLike | TypeFlags.TypeParameter)) { + else if (type.flags & TypeFlags.EnumLiteral) { + buildSymbolDisplay(getParentOfSymbol(type.symbol), writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags); + writePunctuation(writer, SyntaxKind.DotToken); + appendSymbolNameOnly(type.symbol, writer); + } + else if (type.flags & (TypeFlags.Class | TypeFlags.Interface | TypeFlags.Enum | TypeFlags.TypeParameter)) { // The specified symbol flags need to be reinterpreted as type flags buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags); } From 5ff07dc224134d20284c0ec52f703441c22b02b8 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 27 Jul 2016 17:10:14 -0700 Subject: [PATCH 55/55] Accept new baselines --- .../reference/enumLiteralTypes3.errors.txt | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/baselines/reference/enumLiteralTypes3.errors.txt b/tests/baselines/reference/enumLiteralTypes3.errors.txt index d904e35c2f9b4..62cb4644c7256 100644 --- a/tests/baselines/reference/enumLiteralTypes3.errors.txt +++ b/tests/baselines/reference/enumLiteralTypes3.errors.txt @@ -1,18 +1,18 @@ -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(10,5): error TS2322: Type 'YesNo' is not assignable to type 'Yes'. - Type 'No' is not assignable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(11,5): error TS2322: Type 'Choice' is not assignable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(12,5): error TS2322: Type 'Choice' is not assignable to type 'Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(10,5): error TS2322: Type 'YesNo' is not assignable to type 'Choice.Yes'. + Type 'Choice.No' is not assignable to type 'Choice.Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(11,5): error TS2322: Type 'Choice' is not assignable to type 'Choice.Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(12,5): error TS2322: Type 'Choice' is not assignable to type 'Choice.Yes'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(18,5): error TS2322: Type 'Choice' is not assignable to type 'YesNo'. tests/cases/conformance/types/literal/enumLiteralTypes3.ts(19,5): error TS2322: Type 'Choice' is not assignable to type 'YesNo'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(37,5): error TS2322: Type 'Unknown' is not assignable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(39,5): error TS2322: Type 'No' is not assignable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(40,5): error TS2322: Type 'Unknown' is not assignable to type 'YesNo'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(52,5): error TS2365: Operator '===' cannot be applied to types 'Yes' and 'Unknown'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(54,5): error TS2365: Operator '===' cannot be applied to types 'Yes' and 'No'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(55,5): error TS2365: Operator '===' cannot be applied to types 'YesNo' and 'Unknown'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(87,14): error TS2678: Type 'Unknown' is not comparable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(89,14): error TS2678: Type 'No' is not comparable to type 'Yes'. -tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: Type 'Unknown' is not comparable to type 'YesNo'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(37,5): error TS2322: Type 'Choice.Unknown' is not assignable to type 'Choice.Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(39,5): error TS2322: Type 'Choice.No' is not assignable to type 'Choice.Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(40,5): error TS2322: Type 'Choice.Unknown' is not assignable to type 'YesNo'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(52,5): error TS2365: Operator '===' cannot be applied to types 'Choice.Yes' and 'Choice.Unknown'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(54,5): error TS2365: Operator '===' cannot be applied to types 'Choice.Yes' and 'Choice.No'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(55,5): error TS2365: Operator '===' cannot be applied to types 'YesNo' and 'Choice.Unknown'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(87,14): error TS2678: Type 'Choice.Unknown' is not comparable to type 'Choice.Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(89,14): error TS2678: Type 'Choice.No' is not comparable to type 'Choice.Yes'. +tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: Type 'Choice.Unknown' is not comparable to type 'YesNo'. ==== tests/cases/conformance/types/literal/enumLiteralTypes3.ts (14 errors) ==== @@ -27,14 +27,14 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: a = a; a = b; ~ -!!! error TS2322: Type 'YesNo' is not assignable to type 'Yes'. -!!! error TS2322: Type 'No' is not assignable to type 'Yes'. +!!! error TS2322: Type 'YesNo' is not assignable to type 'Choice.Yes'. +!!! error TS2322: Type 'Choice.No' is not assignable to type 'Choice.Yes'. a = c; ~ -!!! error TS2322: Type 'Choice' is not assignable to type 'Yes'. +!!! error TS2322: Type 'Choice' is not assignable to type 'Choice.Yes'. a = d; ~ -!!! error TS2322: Type 'Choice' is not assignable to type 'Yes'. +!!! error TS2322: Type 'Choice' is not assignable to type 'Choice.Yes'. } function f2(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { @@ -65,14 +65,14 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: function f5(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { a = Choice.Unknown; ~ -!!! error TS2322: Type 'Unknown' is not assignable to type 'Yes'. +!!! error TS2322: Type 'Choice.Unknown' is not assignable to type 'Choice.Yes'. a = Choice.Yes; a = Choice.No; ~ -!!! error TS2322: Type 'No' is not assignable to type 'Yes'. +!!! error TS2322: Type 'Choice.No' is not assignable to type 'Choice.Yes'. b = Choice.Unknown; ~ -!!! error TS2322: Type 'Unknown' is not assignable to type 'YesNo'. +!!! error TS2322: Type 'Choice.Unknown' is not assignable to type 'YesNo'. b = Choice.Yes; b = Choice.No; c = Choice.Unknown; @@ -86,14 +86,14 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: function f6(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) { a === Choice.Unknown; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'Yes' and 'Unknown'. +!!! error TS2365: Operator '===' cannot be applied to types 'Choice.Yes' and 'Choice.Unknown'. a === Choice.Yes; a === Choice.No; ~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'Yes' and 'No'. +!!! error TS2365: Operator '===' cannot be applied to types 'Choice.Yes' and 'Choice.No'. b === Choice.Unknown; ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'YesNo' and 'Unknown'. +!!! error TS2365: Operator '===' cannot be applied to types 'YesNo' and 'Choice.Unknown'. b === Choice.Yes; b === Choice.No; c === Choice.Unknown; @@ -127,11 +127,11 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: switch (x) { case Choice.Unknown: return x; ~~~~~~~~~~~~~~ -!!! error TS2678: Type 'Unknown' is not comparable to type 'Yes'. +!!! error TS2678: Type 'Choice.Unknown' is not comparable to type 'Choice.Yes'. case Choice.Yes: return x; case Choice.No: return x; ~~~~~~~~~ -!!! error TS2678: Type 'No' is not comparable to type 'Yes'. +!!! error TS2678: Type 'Choice.No' is not comparable to type 'Choice.Yes'. } return x; } @@ -140,7 +140,7 @@ tests/cases/conformance/types/literal/enumLiteralTypes3.ts(96,14): error TS2678: switch (x) { case Choice.Unknown: return x; ~~~~~~~~~~~~~~ -!!! error TS2678: Type 'Unknown' is not comparable to type 'YesNo'. +!!! error TS2678: Type 'Choice.Unknown' is not comparable to type 'YesNo'. case Choice.Yes: return x; case Choice.No: return x; }