diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 650bc488b0e1d..3d8f9d1fa52cf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8820,11 +8820,13 @@ namespace ts { function getContextualTypeForBinaryOperand(node: Expression): Type { const binaryExpression = node.parent; const operator = binaryExpression.operatorToken.kind; - if (operator >= SyntaxKind.FirstAssignment && operator <= SyntaxKind.LastAssignment) { + + if (SyntaxKind.FirstAssignment <= operator && operator <= SyntaxKind.LastAssignment) { // In an assignment expression, the right operand is contextually typed by the type of the left operand. if (node === binaryExpression.right) { return checkExpression(binaryExpression.left); } + return undefined; } else if (operator === SyntaxKind.BarBarToken) { // When an || expression has a contextual type, the operands are contextually typed by that type. When an || @@ -8991,6 +8993,7 @@ namespace ts { * @returns the contextual type of an expression. */ function getContextualType(node: Expression): Type { + if (isInsideWithStatementBody(node)) { // We cannot answer semantic questions within a with block, do not proceed any further return undefined; @@ -9039,6 +9042,75 @@ namespace ts { return undefined; } + function shouldAcquireLiteralType(literalNode: LiteralExpression) { + if (isEqualityComparisonOperand(literalNode)) { + return true; + } + + const contextualType = getContextualType(literalNode); + return !!contextualType && contextualTypeIsStringLiteralType(contextualType); + } + + /** + * Returns true if an expression might be evaluated as part of an equality comparison. + * This includes inequality (e.g. '!==') and 'switch'/'case' equality. + */ + function isEqualityComparisonOperand(expression: Expression): boolean { + const parent = expression.parent; + + switch (parent.kind) { + // The operand of a 'switch' should get a literal type. + case SyntaxKind.SwitchStatement: + return expression === (parent as SwitchStatement).expression; + + // The tested expression of a 'case' clause should get a literal type. + case SyntaxKind.CaseClause: + return expression === (parent as CaseClause).expression; + + case SyntaxKind.BinaryExpression: + const binaryExpr = parent as BinaryExpression; + switch (binaryExpr.operatorToken.kind) { + // Either operand of an equality/inequality comparison + // should get a literal type. + case SyntaxKind.EqualsEqualsEqualsToken: + case SyntaxKind.ExclamationEqualsEqualsToken: + case SyntaxKind.EqualsEqualsToken: + case SyntaxKind.ExclamationEqualsToken: + return true; + + case SyntaxKind.AmpersandAmpersandToken: + case SyntaxKind.CommaToken: + if (expression === binaryExpr.right) { + return isEqualityComparisonOperand(binaryExpr); + } + return false; + + case SyntaxKind.BarBarToken: + return isEqualityComparisonOperand(binaryExpr); + } + + // No binary operators apply. + return false; + + case SyntaxKind.ConditionalExpression: + const conditional = parent as ConditionalExpression; + if (expression === conditional.whenTrue || expression === conditional.whenFalse) { + return isEqualityComparisonOperand(conditional); + } + return false; + + case SyntaxKind.ParenthesizedExpression: + return isEqualityComparisonOperand(parent as ParenthesizedExpression); + + case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.AsExpression: + return isEqualityComparisonOperand(parent as TypeAssertion); + } + + 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 { @@ -11472,6 +11544,7 @@ namespace ts { const targetType = getTypeFromTypeNode(node.type); if (produceDiagnostics && targetType !== unknownType) { const widenedType = getWidenedType(exprType); + if (!isTypeComparableTo(targetType, widenedType)) { checkTypeComparableTo(exprType, targetType, node, Diagnostics.Type_0_cannot_be_converted_to_type_1); } @@ -12546,8 +12619,7 @@ namespace ts { } function checkStringLiteralExpression(node: StringLiteral): Type { - const contextualType = getContextualType(node); - if (contextualType && contextualTypeIsStringLiteralType(contextualType)) { + if (shouldAcquireLiteralType(node)) { return getStringLiteralTypeForText(node.text); } 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/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/capturedLetConstInLoop5.types b/tests/baselines/reference/capturedLetConstInLoop5.types index b7b4b880dc4c1..ab03cc453bdfa 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5.types +++ b/tests/baselines/reference/capturedLetConstInLoop5.types @@ -74,7 +74,7 @@ function foo00(x) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" return; } @@ -549,7 +549,7 @@ function foo00_c(x) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" return; } diff --git a/tests/baselines/reference/capturedLetConstInLoop5_ES6.types b/tests/baselines/reference/capturedLetConstInLoop5_ES6.types index 855bbfc63086a..d7e8675b312ad 100644 --- a/tests/baselines/reference/capturedLetConstInLoop5_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop5_ES6.types @@ -75,7 +75,7 @@ function foo00(x) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" return; } @@ -550,7 +550,7 @@ function foo00_c(x) { if (x == "1") { >x == "1" : boolean >x : string ->"1" : string +>"1" : "1" return; } diff --git a/tests/baselines/reference/capturedLetConstInLoop6.types b/tests/baselines/reference/capturedLetConstInLoop6.types index f2b1103305fb8..2ce18c5c62ce7 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6.types +++ b/tests/baselines/reference/capturedLetConstInLoop6.types @@ -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; } @@ -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; } diff --git a/tests/baselines/reference/capturedLetConstInLoop6_ES6.types b/tests/baselines/reference/capturedLetConstInLoop6_ES6.types index cfd55a63aaab2..ea6eb5858081a 100644 --- a/tests/baselines/reference/capturedLetConstInLoop6_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop6_ES6.types @@ -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; } @@ -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; } diff --git a/tests/baselines/reference/capturedLetConstInLoop7.types b/tests/baselines/reference/capturedLetConstInLoop7.types index 29ea34e39a16b..456343cd67f39 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7.types +++ b/tests/baselines/reference/capturedLetConstInLoop7.types @@ -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 @@ -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 diff --git a/tests/baselines/reference/capturedLetConstInLoop7_ES6.types b/tests/baselines/reference/capturedLetConstInLoop7_ES6.types index c72afb4194200..288e68948a13c 100644 --- a/tests/baselines/reference/capturedLetConstInLoop7_ES6.types +++ b/tests/baselines/reference/capturedLetConstInLoop7_ES6.types @@ -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 @@ -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 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/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/controlFlowCaching.types b/tests/baselines/reference/controlFlowCaching.types index cd603b274d139..a0cd1b391204e 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 @@ -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..428fb295b02af 100644 --- a/tests/baselines/reference/controlFlowPropertyDeclarations.types +++ b/tests/baselines/reference/controlFlowPropertyDeclarations.types @@ -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/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/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/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/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.errors.txt b/tests/baselines/reference/operatorsAndIntersectionTypes.errors.txt new file mode 100644 index 0000000000000..c0398ca981cf0 --- /dev/null +++ b/tests/baselines/reference/operatorsAndIntersectionTypes.errors.txt @@ -0,0 +1,37 @@ +tests/cases/conformance/types/intersection/operatorsAndIntersectionTypes.ts(27,12): error TS2365: Operator '===' cannot be applied to types 'string & { $Guid: any; }' and '""'. + + +==== tests/cases/conformance/types/intersection/operatorsAndIntersectionTypes.ts (1 errors) ==== + type Guid = string & { $Guid }; // Tagged string type + type SerialNo = number & { $SerialNo }; // Tagged number type + + function createGuid() { + return "21EC2020-3AEA-4069-A2DD-08002B30309D" as Guid; + } + + function createSerialNo() { + return 12345 as SerialNo; + } + + let map1: { [x: string]: number } = {}; + let guid = createGuid(); + map1[guid] = 123; // Can with tagged string + + let map2: { [x: number]: string } = {}; + let serialNo = createSerialNo(); + map2[serialNo] = "hello"; // Can index with tagged number + + const s1 = "{" + guid + "}"; + const s2 = guid.toLowerCase(); + const s3 = guid + guid; + const s4 = guid + serialNo; + const s5 = serialNo.toPrecision(0); + const n1 = serialNo * 3; + const n2 = serialNo + serialNo; + const b1 = guid === ""; + ~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'string & { $Guid: any; }' and '""'. + const b2 = guid === guid; + const b3 = serialNo === 0; + const b4 = serialNo === serialNo; + \ No newline at end of file diff --git a/tests/baselines/reference/operatorsAndIntersectionTypes.symbols b/tests/baselines/reference/operatorsAndIntersectionTypes.symbols deleted file mode 100644 index 7ffc093e4afa2..0000000000000 --- a/tests/baselines/reference/operatorsAndIntersectionTypes.symbols +++ /dev/null @@ -1,100 +0,0 @@ -=== tests/cases/conformance/types/intersection/operatorsAndIntersectionTypes.ts === -type Guid = string & { $Guid }; // Tagged string type ->Guid : Symbol(Guid, Decl(operatorsAndIntersectionTypes.ts, 0, 0)) ->$Guid : Symbol($Guid, Decl(operatorsAndIntersectionTypes.ts, 0, 22)) - -type SerialNo = number & { $SerialNo }; // Tagged number type ->SerialNo : Symbol(SerialNo, Decl(operatorsAndIntersectionTypes.ts, 0, 31)) ->$SerialNo : Symbol($SerialNo, Decl(operatorsAndIntersectionTypes.ts, 1, 26)) - -function createGuid() { ->createGuid : Symbol(createGuid, Decl(operatorsAndIntersectionTypes.ts, 1, 39)) - - return "21EC2020-3AEA-4069-A2DD-08002B30309D" as Guid; ->Guid : Symbol(Guid, Decl(operatorsAndIntersectionTypes.ts, 0, 0)) -} - -function createSerialNo() { ->createSerialNo : Symbol(createSerialNo, Decl(operatorsAndIntersectionTypes.ts, 5, 1)) - - return 12345 as SerialNo; ->SerialNo : Symbol(SerialNo, Decl(operatorsAndIntersectionTypes.ts, 0, 31)) -} - -let map1: { [x: string]: number } = {}; ->map1 : Symbol(map1, Decl(operatorsAndIntersectionTypes.ts, 11, 3)) ->x : Symbol(x, Decl(operatorsAndIntersectionTypes.ts, 11, 13)) - -let guid = createGuid(); ->guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) ->createGuid : Symbol(createGuid, Decl(operatorsAndIntersectionTypes.ts, 1, 39)) - -map1[guid] = 123; // Can with tagged string ->map1 : Symbol(map1, Decl(operatorsAndIntersectionTypes.ts, 11, 3)) ->guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) - -let map2: { [x: number]: string } = {}; ->map2 : Symbol(map2, Decl(operatorsAndIntersectionTypes.ts, 15, 3)) ->x : Symbol(x, Decl(operatorsAndIntersectionTypes.ts, 15, 13)) - -let serialNo = createSerialNo(); ->serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) ->createSerialNo : Symbol(createSerialNo, Decl(operatorsAndIntersectionTypes.ts, 5, 1)) - -map2[serialNo] = "hello"; // Can index with tagged number ->map2 : Symbol(map2, Decl(operatorsAndIntersectionTypes.ts, 15, 3)) ->serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) - -const s1 = "{" + guid + "}"; ->s1 : Symbol(s1, Decl(operatorsAndIntersectionTypes.ts, 19, 5)) ->guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) - -const s2 = guid.toLowerCase(); ->s2 : Symbol(s2, Decl(operatorsAndIntersectionTypes.ts, 20, 5)) ->guid.toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) ->guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) ->toLowerCase : Symbol(String.toLowerCase, Decl(lib.d.ts, --, --)) - -const s3 = guid + guid; ->s3 : Symbol(s3, Decl(operatorsAndIntersectionTypes.ts, 21, 5)) ->guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) ->guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) - -const s4 = guid + serialNo; ->s4 : Symbol(s4, Decl(operatorsAndIntersectionTypes.ts, 22, 5)) ->guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) ->serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) - -const s5 = serialNo.toPrecision(0); ->s5 : Symbol(s5, Decl(operatorsAndIntersectionTypes.ts, 23, 5)) ->serialNo.toPrecision : Symbol(Number.toPrecision, Decl(lib.d.ts, --, --)) ->serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) ->toPrecision : Symbol(Number.toPrecision, Decl(lib.d.ts, --, --)) - -const n1 = serialNo * 3; ->n1 : Symbol(n1, Decl(operatorsAndIntersectionTypes.ts, 24, 5)) ->serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) - -const n2 = serialNo + serialNo; ->n2 : Symbol(n2, Decl(operatorsAndIntersectionTypes.ts, 25, 5)) ->serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) ->serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) - -const b1 = guid === ""; ->b1 : Symbol(b1, Decl(operatorsAndIntersectionTypes.ts, 26, 5)) ->guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) - -const b2 = guid === guid; ->b2 : Symbol(b2, Decl(operatorsAndIntersectionTypes.ts, 27, 5)) ->guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) ->guid : Symbol(guid, Decl(operatorsAndIntersectionTypes.ts, 12, 3)) - -const b3 = serialNo === 0; ->b3 : Symbol(b3, Decl(operatorsAndIntersectionTypes.ts, 28, 5)) ->serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) - -const b4 = serialNo === serialNo; ->b4 : Symbol(b4, Decl(operatorsAndIntersectionTypes.ts, 29, 5)) ->serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) ->serialNo : Symbol(serialNo, Decl(operatorsAndIntersectionTypes.ts, 16, 3)) - diff --git a/tests/baselines/reference/operatorsAndIntersectionTypes.types b/tests/baselines/reference/operatorsAndIntersectionTypes.types deleted file mode 100644 index 6b5987d3a69da..0000000000000 --- a/tests/baselines/reference/operatorsAndIntersectionTypes.types +++ /dev/null @@ -1,132 +0,0 @@ -=== tests/cases/conformance/types/intersection/operatorsAndIntersectionTypes.ts === -type Guid = string & { $Guid }; // Tagged string type ->Guid : string & { $Guid: any; } ->$Guid : any - -type SerialNo = number & { $SerialNo }; // Tagged number type ->SerialNo : number & { $SerialNo: any; } ->$SerialNo : any - -function createGuid() { ->createGuid : () => string & { $Guid: any; } - - return "21EC2020-3AEA-4069-A2DD-08002B30309D" as Guid; ->"21EC2020-3AEA-4069-A2DD-08002B30309D" as Guid : string & { $Guid: any; } ->"21EC2020-3AEA-4069-A2DD-08002B30309D" : string ->Guid : string & { $Guid: any; } -} - -function createSerialNo() { ->createSerialNo : () => number & { $SerialNo: any; } - - return 12345 as SerialNo; ->12345 as SerialNo : number & { $SerialNo: any; } ->12345 : number ->SerialNo : number & { $SerialNo: any; } -} - -let map1: { [x: string]: number } = {}; ->map1 : { [x: string]: number; } ->x : string ->{} : {} - -let guid = createGuid(); ->guid : string & { $Guid: any; } ->createGuid() : string & { $Guid: any; } ->createGuid : () => string & { $Guid: any; } - -map1[guid] = 123; // Can with tagged string ->map1[guid] = 123 : number ->map1[guid] : number ->map1 : { [x: string]: number; } ->guid : string & { $Guid: any; } ->123 : number - -let map2: { [x: number]: string } = {}; ->map2 : { [x: number]: string; } ->x : number ->{} : {} - -let serialNo = createSerialNo(); ->serialNo : number & { $SerialNo: any; } ->createSerialNo() : number & { $SerialNo: any; } ->createSerialNo : () => number & { $SerialNo: any; } - -map2[serialNo] = "hello"; // Can index with tagged number ->map2[serialNo] = "hello" : string ->map2[serialNo] : string ->map2 : { [x: number]: string; } ->serialNo : number & { $SerialNo: any; } ->"hello" : string - -const s1 = "{" + guid + "}"; ->s1 : string ->"{" + guid + "}" : string ->"{" + guid : string ->"{" : string ->guid : string & { $Guid: any; } ->"}" : string - -const s2 = guid.toLowerCase(); ->s2 : string ->guid.toLowerCase() : string ->guid.toLowerCase : () => string ->guid : string & { $Guid: any; } ->toLowerCase : () => string - -const s3 = guid + guid; ->s3 : string ->guid + guid : string ->guid : string & { $Guid: any; } ->guid : string & { $Guid: any; } - -const s4 = guid + serialNo; ->s4 : string ->guid + serialNo : string ->guid : string & { $Guid: any; } ->serialNo : number & { $SerialNo: any; } - -const s5 = serialNo.toPrecision(0); ->s5 : string ->serialNo.toPrecision(0) : string ->serialNo.toPrecision : (precision?: number) => string ->serialNo : number & { $SerialNo: any; } ->toPrecision : (precision?: number) => string ->0 : number - -const n1 = serialNo * 3; ->n1 : number ->serialNo * 3 : number ->serialNo : number & { $SerialNo: any; } ->3 : number - -const n2 = serialNo + serialNo; ->n2 : number ->serialNo + serialNo : number ->serialNo : number & { $SerialNo: any; } ->serialNo : number & { $SerialNo: any; } - -const b1 = guid === ""; ->b1 : boolean ->guid === "" : boolean ->guid : string & { $Guid: any; } ->"" : string - -const b2 = guid === guid; ->b2 : boolean ->guid === guid : boolean ->guid : string & { $Guid: any; } ->guid : string & { $Guid: any; } - -const b3 = serialNo === 0; ->b3 : boolean ->serialNo === 0 : boolean ->serialNo : number & { $SerialNo: any; } ->0 : number - -const b4 = serialNo === serialNo; ->b4 : boolean ->serialNo === serialNo : boolean ->serialNo : number & { $SerialNo: any; } ->serialNo : number & { $SerialNo: any; } - 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/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/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..7e25589b2e89a --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/types/stringLiteral/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..3d443deec503f --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons01.ts === +var a = "foo" === "bar" as string; +>a : boolean +>"foo" === "bar" as string : boolean +>"foo" : "foo" +>"bar" as string : string +>"bar" : "bar" + +var b = "foo" !== ("bar" as string); +>b : boolean +>"foo" !== ("bar" as string) : boolean +>"foo" : "foo" +>("bar" as string) : string +>"bar" as string : string +>"bar" : "bar" + +var c = "foo" == ("bar"); +>c : boolean +>"foo" == ("bar") : boolean +>"foo" : "foo" +>("bar") : any +>"bar" : any +>"bar" : "bar" + diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt new file mode 100644 index 0000000000000..e9ae597603502 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt @@ -0,0 +1,32 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(3,9): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"baz"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(3,19): error TS2352: Type '"bar"' cannot be converted to type '"baz"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(4,20): error TS2352: Type '"bar"' cannot be converted to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(5,9): error TS2365: Operator '==' cannot be applied to types '"foo"' and 'number'. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(5,19): error TS2352: Type '"bar"' cannot be converted to type 'number'. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(6,9): error TS2365: Operator '===' cannot be applied to types '"foo"' and 'string & { enhancements: any; }'. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(6,20): error TS2352: Type '"bar"' cannot be converted to type 'string & { enhancements: any; }'. + Type '"bar"' is not comparable to type '{ enhancements: any; }'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts (7 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 '"foo"' and 'number'. + ~~~~~~~~~~~~~ +!!! error TS2352: Type '"bar"' cannot be converted to type 'number'. + var d = "foo" === ("bar" as EnhancedString); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo"' and 'string & { enhancements: any; }'. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Type '"bar"' cannot be converted to type 'string & { enhancements: any; }'. +!!! error TS2352: Type '"bar"' is not comparable to type '{ enhancements: any; }'. \ 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/stringLiteralsAssertionsInSwitchCase01.js b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.js new file mode 100644 index 0000000000000..9e6ce40829e7c --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.js @@ -0,0 +1,15 @@ +//// [stringLiteralsAssertionsInSwitchCase01.ts] +switch ("foo") { + case "bar" as string: + break; + case (("bar" || "baz") as string): + break; +} + +//// [stringLiteralsAssertionsInSwitchCase01.js] +switch ("foo") { + case "bar": + break; + case ("bar" || "baz"): + break; +} diff --git a/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.symbols b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.symbols new file mode 100644 index 0000000000000..1161b017db01b --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase01.ts === +switch ("foo") { +No type information for this code. case "bar" as string: +No type information for this code. break; +No type information for this code. case (("bar" || "baz") as string): +No type information for this code. break; +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.types b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.types new file mode 100644 index 0000000000000..f4844bc84ba4e --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase01.ts === +switch ("foo") { +>"foo" : "foo" + + case "bar" as string: +>"bar" as string : string +>"bar" : "bar" + + break; + case (("bar" || "baz") as string): +>(("bar" || "baz") as string) : string +>("bar" || "baz") as string : string +>("bar" || "baz") : "bar" | "baz" +>"bar" || "baz" : "bar" | "baz" +>"bar" : "bar" +>"baz" : "baz" + + break; +} diff --git a/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.js b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.js new file mode 100644 index 0000000000000..729b887eb3db5 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.js @@ -0,0 +1,15 @@ +//// [stringLiteralsAssertionsInSwitchCase02.ts] +switch ("foo" as string) { + case "bar": + break; + case (("bar" || "baz")): + break; +} + +//// [stringLiteralsAssertionsInSwitchCase02.js] +switch ("foo") { + case "bar": + break; + case (("bar" || "baz")): + break; +} diff --git a/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.symbols b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.symbols new file mode 100644 index 0000000000000..8c9971ce2d09c --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase02.ts === +switch ("foo" as string) { +No type information for this code. case "bar": +No type information for this code. break; +No type information for this code. case (("bar" || "baz")): +No type information for this code. break; +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.types b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.types new file mode 100644 index 0000000000000..01e14d62481bb --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase02.ts === +switch ("foo" as string) { +>"foo" as string : string +>"foo" : "foo" + + case "bar": +>"bar" : "bar" + + break; + case (("bar" || "baz")): +>(("bar" || "baz")) : "bar" | "baz" +>("bar" || "baz") : "bar" | "baz" +>"bar" || "baz" : "bar" | "baz" +>"bar" : "bar" +>"baz" : "baz" + + break; +} diff --git a/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase03.errors.txt b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase03.errors.txt new file mode 100644 index 0000000000000..acd60adaf99df --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase03.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts(2,10): error TS2352: Type '"bar"' cannot be converted to type '"baz"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts(2,10): error TS2678: Type '"baz"' is not comparable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts(4,11): error TS2352: Type '"bar" | "baz"' cannot be converted to type '"foo"'. + Type '"baz"' is not comparable to type '"foo"'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts (3 errors) ==== + switch ("foo") { + case "bar" as "baz": + ~~~~~~~~~~~~~~ +!!! error TS2352: Type '"bar"' cannot be converted to type '"baz"'. + ~~~~~~~~~~~~~~ +!!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. + break; + case (("bar" || "baz") as "foo"): + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Type '"bar" | "baz"' cannot be converted to type '"foo"'. +!!! error TS2352: Type '"baz"' is not comparable to type '"foo"'. + break; + } \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase03.js b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase03.js new file mode 100644 index 0000000000000..21198a5f48981 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase03.js @@ -0,0 +1,15 @@ +//// [stringLiteralsAssertionsInSwitchCase03.ts] +switch ("foo") { + case "bar" as "baz": + break; + case (("bar" || "baz") as "foo"): + break; +} + +//// [stringLiteralsAssertionsInSwitchCase03.js] +switch ("foo") { + case "bar": + break; + case ("bar" || "baz"): + break; +} diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt new file mode 100644 index 0000000000000..844763519520f --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts(8,5): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts(9,5): error TS2365: Operator '===' cannot be applied to types '"bar"' and '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts(10,5): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts(17,5): error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts(18,5): error TS2365: Operator '!==' cannot be applied to types '"bar"' and '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts(19,5): error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/stringLiteral/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..7d6d01440f67f --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt @@ -0,0 +1,44 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts(8,5): error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts(9,5): error TS2365: Operator '==' cannot be applied to types '"bar"' and '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts(10,5): error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts(17,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts(18,5): error TS2365: Operator '!=' cannot be applied to types '"bar"' and '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts(19,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/stringLiteral/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..f76ea276e0f83 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts(16,5): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts(19,5): error TS2365: Operator '===' cannot be applied to types '"foo" | Refrigerator' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts(20,5): error TS2365: Operator '===' cannot be applied to types '"bar"' and '"foo" | Refrigerator'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts(25,5): error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts(28,5): error TS2365: Operator '!==' cannot be applied to types '"foo" | Refrigerator' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts(29,5): error TS2365: Operator '!==' cannot be applied to types '"bar"' and '"foo" | Refrigerator'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts (6 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"; + ~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo" | Refrigerator' and '"bar"'. + b = "bar" === y; + ~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"bar"' and '"foo" | Refrigerator'. + + 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"; + ~~~~~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types '"foo" | Refrigerator' and '"bar"'. + b = "bar" !== y; + ~~~~~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types '"bar"' and '"foo" | Refrigerator'. + \ 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..6f8c54656d4df --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts(16,5): error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts(19,5): error TS2365: Operator '==' cannot be applied to types '"foo" | Refrigerator' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts(20,5): error TS2365: Operator '==' cannot be applied to types '"bar"' and '"foo" | Refrigerator'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts(25,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts(28,5): error TS2365: Operator '!=' cannot be applied to types '"foo" | Refrigerator' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts(29,5): error TS2365: Operator '!=' cannot be applied to types '"bar"' and '"foo" | Refrigerator'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts (6 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"; + ~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"foo" | Refrigerator' and '"bar"'. + b = "bar" == y; + ~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"bar"' and '"foo" | Refrigerator'. + + 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"; + ~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"foo" | Refrigerator' and '"bar"'. + b = "bar" != y; + ~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"bar"' and '"foo" | Refrigerator'. + \ 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..f4d8a6f4fa045 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements01.ts(7,10): error TS2678: Type '"bar"' is not comparable to type '"foo"'. + + +==== tests/cases/conformance/types/stringLiteral/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..894998559fee9 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements02.ts(8,5): error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements02.ts(13,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/stringLiteral/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..19bdab943ebdc --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements03.ts(7,10): error TS2678: Type '"bar"' is not comparable to type '"foo"'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements03.ts (1 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + + switch ("foo") { + case "foo": + break; + case "bar": + ~~~~~ +!!! error TS2678: Type '"bar"' is not comparable to type '"foo"'. + break; + case x: + x; + break; + case y: + y; + 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..7eeb17bc8514e --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.js @@ -0,0 +1,33 @@ +//// [stringLiteralsWithSwitchStatements03.ts] +let x: "foo"; +let y: "foo" | "bar"; + +switch ("foo") { + case "foo": + break; + case "bar": + break; + case x: + x; + break; + case y: + y; + break; +} + + +//// [stringLiteralsWithSwitchStatements03.js] +var x; +var y; +switch ("foo") { + case "foo": + break; + case "bar": + break; + case x: + x; + break; + case y: + y; + break; +} diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.js b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.js new file mode 100644 index 0000000000000..d5d60a016b3e2 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.js @@ -0,0 +1,35 @@ +//// [stringLiteralsWithSwitchStatements04.ts] +let x: "foo"; +let y: "foo" | "bar"; + +declare function randBool(): boolean; + +switch (randBool() ? "foo" : "bar") { + case "foo": + break; + case "bar": + break; + case x: + x; + break; + case y: + y; + break; +} + + +//// [stringLiteralsWithSwitchStatements04.js] +var x; +var y; +switch (randBool() ? "foo" : "bar") { + case "foo": + break; + case "bar": + break; + case x: + x; + break; + case y: + y; + break; +} diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.symbols b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.symbols new file mode 100644 index 0000000000000..0c86239649576 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/types/stringLiteral/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 (randBool() ? "foo" : "bar") { +>randBool : Symbol(randBool, Decl(stringLiteralsWithSwitchStatements04.ts, 1, 21)) + + case "foo": + break; + case "bar": + break; + case x: +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements04.ts, 0, 3)) + + x; +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements04.ts, 0, 3)) + + break; + case y: +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements04.ts, 1, 3)) + + y; +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements04.ts, 1, 3)) + + break; +} + diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types new file mode 100644 index 0000000000000..257213e41adc0 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements04.ts === +let x: "foo"; +>x : "foo" + +let y: "foo" | "bar"; +>y : "foo" | "bar" + +declare function randBool(): boolean; +>randBool : () => boolean + +switch (randBool() ? "foo" : "bar") { +>randBool() ? "foo" : "bar" : "foo" | "bar" +>randBool() : boolean +>randBool : () => boolean +>"foo" : "foo" +>"bar" : "bar" + + case "foo": +>"foo" : "foo" + + break; + case "bar": +>"bar" : "bar" + + break; + case x: +>x : "foo" + + x; +>x : "foo" + + break; + case y: +>y : "foo" | "bar" + + y; +>y : "foo" | "bar" + + break; +} + diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt new file mode 100644 index 0000000000000..6a67e2df5c044 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt @@ -0,0 +1,56 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.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/stringLiteral/stringLiteralsWithSwitchStatements05.ts(12,10): error TS2678: Type '"bar"' is not comparable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(14,10): error TS2678: Type '"baz"' is not comparable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(20,10): error TS2678: Type '"bar" | "baz"' is not comparable to type '"foo"'. + Type '"baz"' is not comparable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.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/stringLiteral/stringLiteralsWithSwitchStatements05.ts(23,10): error TS2678: Type '"baz" | "bar"' is not comparable to type '"foo"'. + Type '"bar"' is not comparable to type '"foo"'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts (6 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")): + ~~~~~~~~~~~~~~~ +!!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. + x; + y; + break; + case (("foo" || ("bar"))): + break; + case (("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 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: + ~~~~~~~~~~ +!!! error TS2678: Type '"baz" | "bar"' is not comparable to type '"foo"'. +!!! error TS2678: Type '"bar"' is not comparable to type '"foo"'. + z; + break; + } + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.js b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.js new file mode 100644 index 0000000000000..d72c6e88a1ff2 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.js @@ -0,0 +1,53 @@ +//// [stringLiteralsWithSwitchStatements05.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; +} + + +//// [stringLiteralsWithSwitchStatements05.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/stringLiteralsWithSwitchStatements06.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt new file mode 100644 index 0000000000000..8c83e6a110891 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt @@ -0,0 +1,36 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts(11,10): error TS2678: Type '"baz"' is not comparable to type '"foo" | "bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts(17,10): error TS2678: Type '"baz"' is not comparable to type '"foo" | "bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts(17,24): error TS1005: ':' expected. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts (3 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + + declare function randBool(): boolean; + + switch (y) { + case "foo", x: + break; + case x, "foo": + break; + case x, "baz": + ~~~~~~~~ +!!! error TS2678: Type '"baz"' is not comparable to type '"foo" | "bar"'. + break; + case "baz", x: + break; + case "baz" && "bar": + break; + case "bar" && "baz"; + ~~~~~~~~~~~~~~ +!!! error TS2678: Type '"baz"' is not comparable to type '"foo" | "bar"'. + ~ +!!! error TS1005: ':' expected. + break; + case "baz" && ("foo" || "bar"): + break; + case "bar" && ("baz" || "bar"): + break; + } + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements06.js b/tests/baselines/reference/stringLiteralsWithSwitchStatements06.js new file mode 100644 index 0000000000000..1deda91d7f998 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements06.js @@ -0,0 +1,48 @@ +//// [stringLiteralsWithSwitchStatements06.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 "bar" && "baz"; + break; + case "baz" && ("foo" || "bar"): + break; + case "bar" && ("baz" || "bar"): + break; +} + + +//// [stringLiteralsWithSwitchStatements06.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 "bar" && "baz": + ; + break; + case "baz" && ("foo" || "bar"): + break; + case "bar" && ("baz" || "bar"): + break; +} diff --git a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt new file mode 100644 index 0000000000000..96e8f2e90c6cf --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt @@ -0,0 +1,25 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts(3,9): error TS2352: Type '"foo"' cannot be converted to type '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts(4,9): error TS2352: Type '"bar"' cannot be converted to type '"foo"'. +tests/cases/conformance/types/stringLiteral/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/stringLiteral/stringLiteralsWithTypeAssertions01.ts(8,9): error TS2352: Type '"baz"' cannot be converted to type '"foo" | "bar"'. + + +==== tests/cases/conformance/types/stringLiteral/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"; diff --git a/tests/baselines/reference/switchBreakStatements.errors.txt b/tests/baselines/reference/switchBreakStatements.errors.txt new file mode 100644 index 0000000000000..229c42068c308 --- /dev/null +++ b/tests/baselines/reference/switchBreakStatements.errors.txt @@ -0,0 +1,92 @@ +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(3,10): error TS2678: Type '"a"' is not comparable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(9,10): error TS2678: Type '"a"' is not comparable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(16,10): error TS2678: Type '"a"' is not comparable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(22,10): error TS2678: Type '"a"' is not comparable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(25,18): error TS2678: Type '"a"' is not comparable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(31,10): error TS2678: Type '"a"' is not comparable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(34,18): error TS2678: Type '"a"' is not comparable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(41,10): error TS2678: Type '"a"' is not comparable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(43,18): error TS2678: Type '"a"' is not comparable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(45,26): error TS2678: Type '"a"' is not comparable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(49,34): error TS2678: Type '"a"' is not comparable to type '""'. + + +==== tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts (11 errors) ==== + + switch ('') { + case 'a': + ~~~ +!!! error TS2678: Type '"a"' is not comparable to type '""'. + break; + } + + ONE: + switch ('') { + case 'a': + ~~~ +!!! error TS2678: Type '"a"' is not comparable to type '""'. + break ONE; + } + + TWO: + THREE: + switch ('') { + case 'a': + ~~~ +!!! error TS2678: Type '"a"' is not comparable to type '""'. + break THREE; + } + + FOUR: + switch ('') { + case 'a': + ~~~ +!!! error TS2678: Type '"a"' is not comparable to type '""'. + FIVE: + switch ('') { + case 'a': + ~~~ +!!! error TS2678: Type '"a"' is not comparable to type '""'. + break FOUR; + } + } + + switch ('') { + case 'a': + ~~~ +!!! error TS2678: Type '"a"' is not comparable to type '""'. + SIX: + switch ('') { + case 'a': + ~~~ +!!! error TS2678: Type '"a"' is not comparable to type '""'. + break SIX; + } + } + + SEVEN: + switch ('') { + case 'a': + ~~~ +!!! error TS2678: Type '"a"' is not comparable to type '""'. + switch ('') { + case 'a': + ~~~ +!!! error TS2678: Type '"a"' is not comparable to type '""'. + switch ('') { + case 'a': + ~~~ +!!! error TS2678: Type '"a"' is not comparable to type '""'. + break SEVEN; + EIGHT: + switch ('') { + case 'a': + ~~~ +!!! error TS2678: Type '"a"' is not comparable to type '""'. + var fn = function () { } + break EIGHT; + } + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt b/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt index 26d39efef48ec..8866b9c8c3168 100644 --- a/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt +++ b/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt @@ -1,5 +1,5 @@ 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(5,10): error TS2678: Type '"sss"' is not comparable to type 'number'. tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2678: Type 'boolean' is not comparable to type 'number'. @@ -12,7 +12,7 @@ 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 ~~~~ 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/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/trailingSeparatorInFunctionCall.errors.txt b/tests/baselines/reference/trailingSeparatorInFunctionCall.errors.txt new file mode 100644 index 0000000000000..76e09a1a4de3f --- /dev/null +++ b/tests/baselines/reference/trailingSeparatorInFunctionCall.errors.txt @@ -0,0 +1,24 @@ +tests/cases/compiler/trailingSeparatorInFunctionCall.ts(4,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/trailingSeparatorInFunctionCall.ts(4,7): error TS1009: Trailing comma not allowed. +tests/cases/compiler/trailingSeparatorInFunctionCall.ts(9,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/compiler/trailingSeparatorInFunctionCall.ts(9,8): error TS1009: Trailing comma not allowed. + + +==== tests/cases/compiler/trailingSeparatorInFunctionCall.ts (4 errors) ==== + function f(x, y) { + } + + f(1, 2, ); + ~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + ~ +!!! error TS1009: Trailing comma not allowed. + + function f2(x: T, y: T) { + } + + f2(1, 2, ); + ~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + ~ +!!! error TS1009: Trailing comma not allowed. \ No newline at end of file diff --git a/tests/baselines/reference/trailingSeparatorInFunctionCall.js b/tests/baselines/reference/trailingSeparatorInFunctionCall.js new file mode 100644 index 0000000000000..4b531479837b2 --- /dev/null +++ b/tests/baselines/reference/trailingSeparatorInFunctionCall.js @@ -0,0 +1,18 @@ +//// [trailingSeparatorInFunctionCall.ts] +function f(x, y) { +} + +f(1, 2, ); + +function f2(x: T, y: T) { +} + +f2(1, 2, ); + +//// [trailingSeparatorInFunctionCall.js] +function f(x, y) { +} +f(1, 2); +function f2(x, y) { +} +f2(1, 2); 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/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/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..b58a05442d2c6 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 @@ -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 @@ -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,7 +249,7 @@ function foo9(x: number | string) { >length : number >x === "hello" : boolean >x : string ->"hello" : string +>"hello" : "hello" : x === 10; // boolean >x === 10 : boolean @@ -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..65e80ad07ca96 100644 --- a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types +++ b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types @@ -10,7 +10,7 @@ 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 @@ -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 @@ -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..36e4ef855e8e1 100644 --- a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types +++ b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types @@ -11,7 +11,7 @@ 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 @@ -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 @@ -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/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/typeReferenceDirectives11.symbols b/tests/baselines/reference/typeReferenceDirectives11.symbols new file mode 100644 index 0000000000000..875bb2a090062 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectives11.symbols @@ -0,0 +1,23 @@ +=== /mod2.ts === + +import {foo} from "./mod1"; +>foo : Symbol(foo, Decl(mod2.ts, 1, 8)) + +export const bar = foo(); +>bar : Symbol(bar, Decl(mod2.ts, 2, 12)) +>foo : Symbol(foo, Decl(mod2.ts, 1, 8)) + +=== /types/lib/index.d.ts === + + +interface Lib { x } +>Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) +>x : Symbol(Lib.x, Decl(index.d.ts, 2, 15)) + +=== /mod1.ts === + +export function foo(): Lib { return {x: 1} } +>foo : Symbol(foo, Decl(mod1.ts, 0, 0)) +>Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) +>x : Symbol(x, Decl(mod1.ts, 1, 37)) + diff --git a/tests/baselines/reference/typeReferenceDirectives11.types b/tests/baselines/reference/typeReferenceDirectives11.types new file mode 100644 index 0000000000000..93d80b7988af4 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectives11.types @@ -0,0 +1,26 @@ +=== /mod2.ts === + +import {foo} from "./mod1"; +>foo : () => Lib + +export const bar = foo(); +>bar : Lib +>foo() : Lib +>foo : () => Lib + +=== /types/lib/index.d.ts === + + +interface Lib { x } +>Lib : Lib +>x : any + +=== /mod1.ts === + +export function foo(): Lib { return {x: 1} } +>foo : () => Lib +>Lib : Lib +>{x: 1} : { x: number; } +>x : number +>1 : number + diff --git a/tests/baselines/reference/typeReferenceDirectives12.symbols b/tests/baselines/reference/typeReferenceDirectives12.symbols new file mode 100644 index 0000000000000..30b24c3928464 --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectives12.symbols @@ -0,0 +1,68 @@ +=== /mod2.ts === +import { Cls } from "./main"; +>Cls : Symbol(Cls, Decl(mod2.ts, 0, 8)) + +import "./mod1"; + +export const cls = Cls; +>cls : Symbol(cls, Decl(mod2.ts, 3, 12)) +>Cls : Symbol(Cls, Decl(mod2.ts, 0, 8)) + +export const foo = new Cls().foo(); +>foo : Symbol(foo, Decl(mod2.ts, 4, 12)) +>new Cls().foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) +>Cls : Symbol(Cls, Decl(mod2.ts, 0, 8)) +>foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) + +export const bar = Cls.bar(); +>bar : Symbol(bar, Decl(mod2.ts, 5, 12)) +>Cls.bar : Symbol(Cls.bar, Decl(mod1.ts, 9, 19)) +>Cls : Symbol(Cls, Decl(mod2.ts, 0, 8)) +>bar : Symbol(Cls.bar, Decl(mod1.ts, 9, 19)) + +=== /types/lib/index.d.ts === + + +interface Lib { x } +>Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) +>x : Symbol(Lib.x, Decl(index.d.ts, 2, 15)) + +=== /main.ts === +export class Cls { +>Cls : Symbol(Cls, Decl(main.ts, 0, 0), Decl(mod1.ts, 5, 25), Decl(mod1.ts, 8, 5)) + + x +>x : Symbol(Cls.x, Decl(main.ts, 0, 18)) +} + +=== /mod1.ts === +/// + +import {Cls} from "./main"; +>Cls : Symbol(Cls, Decl(mod1.ts, 2, 8)) + +Cls.prototype.foo = function() { return undefined; } +>Cls.prototype.foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) +>Cls.prototype : Symbol(Cls.prototype) +>Cls : Symbol(Cls, Decl(mod1.ts, 2, 8)) +>prototype : Symbol(Cls.prototype) +>foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) +>undefined : Symbol(undefined) + +declare module "./main" { + interface Cls { +>Cls : Symbol(Cls, Decl(main.ts, 0, 0), Decl(mod1.ts, 5, 25), Decl(mod1.ts, 8, 5)) + + foo(): Lib; +>foo : Symbol(Cls.foo, Decl(mod1.ts, 6, 19)) +>Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) + } + namespace Cls { +>Cls : Symbol(Cls, Decl(main.ts, 0, 0), Decl(mod1.ts, 5, 25), Decl(mod1.ts, 8, 5)) + + function bar(): Lib; +>bar : Symbol(bar, Decl(mod1.ts, 9, 19)) +>Lib : Symbol(Lib, Decl(index.d.ts, 0, 0)) + } +} + diff --git a/tests/baselines/reference/typeReferenceDirectives12.types b/tests/baselines/reference/typeReferenceDirectives12.types new file mode 100644 index 0000000000000..bd429b91f1c1f --- /dev/null +++ b/tests/baselines/reference/typeReferenceDirectives12.types @@ -0,0 +1,73 @@ +=== /mod2.ts === +import { Cls } from "./main"; +>Cls : typeof Cls + +import "./mod1"; + +export const cls = Cls; +>cls : typeof Cls +>Cls : typeof Cls + +export const foo = new Cls().foo(); +>foo : Lib +>new Cls().foo() : Lib +>new Cls().foo : () => Lib +>new Cls() : Cls +>Cls : typeof Cls +>foo : () => Lib + +export const bar = Cls.bar(); +>bar : Lib +>Cls.bar() : Lib +>Cls.bar : () => Lib +>Cls : typeof Cls +>bar : () => Lib + +=== /types/lib/index.d.ts === + + +interface Lib { x } +>Lib : Lib +>x : any + +=== /main.ts === +export class Cls { +>Cls : Cls + + x +>x : any +} + +=== /mod1.ts === +/// + +import {Cls} from "./main"; +>Cls : typeof Cls + +Cls.prototype.foo = function() { return undefined; } +>Cls.prototype.foo = function() { return undefined; } : () => any +>Cls.prototype.foo : () => Lib +>Cls.prototype : Cls +>Cls : typeof Cls +>prototype : Cls +>foo : () => Lib +>function() { return undefined; } : () => any +>undefined : undefined + +declare module "./main" { + interface Cls { +>Cls : Cls + + foo(): Lib; +>foo : () => Lib +>Lib : Lib + } + namespace Cls { +>Cls : typeof Cls + + function bar(): Lib; +>bar : () => Lib +>Lib : Lib + } +} + 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/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/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons01.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons01.ts new file mode 100644 index 0000000000000..b161660488ce6 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/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/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts new file mode 100644 index 0000000000000..8ab4469055feb --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/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/stringLiteral/stringLiteralsAssertionsInSwitchCase01.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase01.ts new file mode 100644 index 0000000000000..487a19d342f78 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase01.ts @@ -0,0 +1,6 @@ +switch ("foo") { + case "bar" as string: + break; + case (("bar" || "baz") as string): + break; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase02.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase02.ts new file mode 100644 index 0000000000000..bd92e4b5c2327 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase02.ts @@ -0,0 +1,6 @@ +switch ("foo" as string) { + case "bar": + break; + case (("bar" || "baz")): + break; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts new file mode 100644 index 0000000000000..e4509a37e1e0c --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts @@ -0,0 +1,6 @@ +switch ("foo") { + case "bar" as "baz": + break; + case (("bar" || "baz") as "foo"): + break; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts new file mode 100644 index 0000000000000..3179be186ea48 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/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/stringLiteral/stringLiteralsWithEqualityChecks02.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts new file mode 100644 index 0000000000000..25a687a8941a8 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/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/stringLiteral/stringLiteralsWithEqualityChecks03.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts new file mode 100644 index 0000000000000..b4fb064818728 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/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/stringLiteral/stringLiteralsWithEqualityChecks04.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts new file mode 100644 index 0000000000000..01e1c0896fb2a --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/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/stringLiteral/stringLiteralsWithSwitchStatements01.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements01.ts new file mode 100644 index 0000000000000..b1c1aaa64cae2 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/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/stringLiteral/stringLiteralsWithSwitchStatements02.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements02.ts new file mode 100644 index 0000000000000..d396eb16bed00 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/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/stringLiteral/stringLiteralsWithSwitchStatements03.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements03.ts new file mode 100644 index 0000000000000..e0aced99fa134 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements03.ts @@ -0,0 +1,15 @@ +let x: "foo"; +let y: "foo" | "bar"; + +switch ("foo") { + case "foo": + break; + case "bar": + break; + case x: + x; + break; + case y: + y; + break; +} diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements04.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements04.ts new file mode 100644 index 0000000000000..686e51e10bc5a --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements04.ts @@ -0,0 +1,17 @@ +let x: "foo"; +let y: "foo" | "bar"; + +declare function randBool(): boolean; + +switch (randBool() ? "foo" : "bar") { + case "foo": + break; + case "bar": + break; + case x: + x; + break; + case y: + y; + break; +} diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts new file mode 100644 index 0000000000000..289ffd11060f3 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.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/stringLiteral/stringLiteralsWithSwitchStatements06.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts new file mode 100644 index 0000000000000..7512c63cf5cdf --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts @@ -0,0 +1,23 @@ +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 "bar" && "baz"; + break; + case "baz" && ("foo" || "bar"): + break; + case "bar" && ("baz" || "bar"): + break; +} diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts new file mode 100644 index 0000000000000..2e3542704129d --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/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