From 0d2fb26366d716d623c2bf86d171546d28cf591f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Dec 2015 15:57:39 -0800 Subject: [PATCH 01/27] Added tests. --- .../stringLiteralsWithEqualityChecks01.ts | 14 ++++++++++++ .../stringLiteralsWithEqualityChecks02.ts | 18 +++++++++++++++ .../stringLiteralsWithEqualityChecks03.ts | 22 +++++++++++++++++++ .../stringLiteralsWithEqualityChecks04.ts | 22 +++++++++++++++++++ .../stringLiteralsWithSwitchStatements01.ts | 12 ++++++++++ .../stringLiteralsWithSwitchStatements02.ts | 14 ++++++++++++ .../stringLiteralsWithSwitchStatements03.ts | 15 +++++++++++++ .../stringLiteralsWithSwitchStatements04.ts | 17 ++++++++++++++ .../stringLiteralsWithSwitchStatements05.ts | 17 ++++++++++++++ .../stringLiteralsWithTypeAssertions01.ts | 8 +++++++ 10 files changed, 159 insertions(+) create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements01.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements02.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements03.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements04.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts new file mode 100644 index 0000000000000..fd9864465778e --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.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/stringLiteralsWithEqualityChecks02.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts new file mode 100644 index 0000000000000..2d532382caea1 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts @@ -0,0 +1,18 @@ +interface Refrigerator { + brrr: boolean; +} + +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/stringLiteralsWithEqualityChecks03.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts new file mode 100644 index 0000000000000..a377698383232 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts @@ -0,0 +1,22 @@ +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 = x !== y; +b = "foo" !== y +b = y !== "foo"; +b = "foo" !== "bar"; + diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts new file mode 100644 index 0000000000000..f4181a3ca6b46 --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts @@ -0,0 +1,22 @@ +interface Runnable { + isRunning: boolean; +} + +interface Refrigerator { + 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 = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; + 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..809380fbb4c2e --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts @@ -0,0 +1,17 @@ +let x: "foo"; +let y: "foo" | "bar"; + +declare function randBool(): boolean; + +switch (x) { + case randBool() ? "foo" : "baz": + break; + case (("bar")): + break; + case (x, y, "baz"): + x; + break; + case (("foo" || "bar")): + y; + 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 From 639d9bfc2c701add7f956e96ca0e3b1586c80119 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Dec 2015 16:00:32 -0800 Subject: [PATCH 02/27] Accepted baselines. --- .../stringLiteralsWithEqualityChecks01.js | 29 +++++++ ...stringLiteralsWithEqualityChecks01.symbols | 43 ++++++++++ .../stringLiteralsWithEqualityChecks01.types | 67 +++++++++++++++ .../stringLiteralsWithEqualityChecks02.js | 33 ++++++++ ...stringLiteralsWithEqualityChecks02.symbols | 50 +++++++++++ .../stringLiteralsWithEqualityChecks02.types | 74 +++++++++++++++++ .../stringLiteralsWithEqualityChecks03.js | 37 +++++++++ ...stringLiteralsWithEqualityChecks03.symbols | 59 +++++++++++++ .../stringLiteralsWithEqualityChecks03.types | 83 +++++++++++++++++++ .../stringLiteralsWithEqualityChecks04.js | 37 +++++++++ ...stringLiteralsWithEqualityChecks04.symbols | 58 +++++++++++++ .../stringLiteralsWithEqualityChecks04.types | 82 ++++++++++++++++++ .../stringLiteralsWithSwitchStatements01.js | 27 ++++++ ...ringLiteralsWithSwitchStatements01.symbols | 23 +++++ ...stringLiteralsWithSwitchStatements01.types | 27 ++++++ .../stringLiteralsWithSwitchStatements02.js | 29 +++++++ ...ringLiteralsWithSwitchStatements02.symbols | 43 ++++++++++ ...stringLiteralsWithSwitchStatements02.types | 67 +++++++++++++++ .../stringLiteralsWithSwitchStatements03.js | 33 ++++++++ ...ringLiteralsWithSwitchStatements03.symbols | 28 +++++++ ...stringLiteralsWithSwitchStatements03.types | 34 ++++++++ .../stringLiteralsWithSwitchStatements04.js | 35 ++++++++ ...ringLiteralsWithSwitchStatements04.symbols | 33 ++++++++ ...stringLiteralsWithSwitchStatements04.types | 41 +++++++++ .../stringLiteralsWithSwitchStatements05.js | 35 ++++++++ ...ringLiteralsWithSwitchStatements05.symbols | 34 ++++++++ ...stringLiteralsWithSwitchStatements05.types | 52 ++++++++++++ .../stringLiteralsWithTypeAssertions01.js | 18 ++++ ...stringLiteralsWithTypeAssertions01.symbols | 26 ++++++ .../stringLiteralsWithTypeAssertions01.types | 35 ++++++++ 30 files changed, 1272 insertions(+) create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks01.js create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks01.symbols create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks01.types create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks02.js create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks02.symbols create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks02.types create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks03.js create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks03.symbols create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks03.types create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks04.js create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks04.symbols create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks04.types create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements01.js create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements01.symbols create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements01.types create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements02.js create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements02.symbols create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements02.types create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements03.js create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements03.symbols create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements03.types create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements04.js create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements04.symbols create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements04.types create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements05.js create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements05.symbols create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements05.types create mode 100644 tests/baselines/reference/stringLiteralsWithTypeAssertions01.js create mode 100644 tests/baselines/reference/stringLiteralsWithTypeAssertions01.symbols create mode 100644 tests/baselines/reference/stringLiteralsWithTypeAssertions01.types diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.js b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.js new file mode 100644 index 0000000000000..7b7741dfc76ed --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.js @@ -0,0 +1,29 @@ +//// [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 = x !== y; +b = "foo" !== y +b = y !== "foo"; +b = "foo" !== "bar"; + + + +//// [stringLiteralsWithEqualityChecks01.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/stringLiteralsWithEqualityChecks01.symbols b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.symbols new file mode 100644 index 0000000000000..e2b1c35795ed1 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.symbols @@ -0,0 +1,43 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts === +let x: "foo"; +>x : Symbol(x, Decl(stringLiteralsWithEqualityChecks01.ts, 0, 3)) + +let y: "foo" | "bar"; +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) + +let b: boolean; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) + +b = x === y; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) +>x : Symbol(x, Decl(stringLiteralsWithEqualityChecks01.ts, 0, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) + +b = "foo" === y +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) + +b = y === "foo"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) + +b = "foo" === "bar"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) + +b = x !== y; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) +>x : Symbol(x, Decl(stringLiteralsWithEqualityChecks01.ts, 0, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) + +b = "foo" !== y +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) + +b = y !== "foo"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) + +b = "foo" !== "bar"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) + + diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.types b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.types new file mode 100644 index 0000000000000..111472beedd73 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.types @@ -0,0 +1,67 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts === +let x: "foo"; +>x : "foo" + +let y: "foo" | "bar"; +>y : "foo" | "bar" + +let b: boolean; +>b : boolean + +b = x === y; +>b = x === y : boolean +>b : boolean +>x === y : boolean +>x : "foo" +>y : "foo" | "bar" + +b = "foo" === y +>b = "foo" === y : boolean +>b : boolean +>"foo" === y : boolean +>"foo" : string +>y : "foo" | "bar" + +b = y === "foo"; +>b = y === "foo" : boolean +>b : boolean +>y === "foo" : boolean +>y : "foo" | "bar" +>"foo" : string + +b = "foo" === "bar"; +>b = "foo" === "bar" : boolean +>b : boolean +>"foo" === "bar" : boolean +>"foo" : string +>"bar" : string + +b = x !== y; +>b = x !== y : boolean +>b : boolean +>x !== y : boolean +>x : "foo" +>y : "foo" | "bar" + +b = "foo" !== y +>b = "foo" !== y : boolean +>b : boolean +>"foo" !== y : boolean +>"foo" : string +>y : "foo" | "bar" + +b = y !== "foo"; +>b = y !== "foo" : boolean +>b : boolean +>y !== "foo" : boolean +>y : "foo" | "bar" +>"foo" : string + +b = "foo" !== "bar"; +>b = "foo" !== "bar" : boolean +>b : boolean +>"foo" !== "bar" : boolean +>"foo" : string +>"bar" : string + + diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.js b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.js new file mode 100644 index 0000000000000..4333e16bf5f82 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.js @@ -0,0 +1,33 @@ +//// [stringLiteralsWithEqualityChecks02.ts] +interface Refrigerator { + brrr: boolean; +} + +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"; + + + +//// [stringLiteralsWithEqualityChecks02.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/stringLiteralsWithEqualityChecks02.symbols b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.symbols new file mode 100644 index 0000000000000..0f92f9a26bdfe --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.symbols @@ -0,0 +1,50 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts === +interface Refrigerator { +>Refrigerator : Symbol(Refrigerator, Decl(stringLiteralsWithEqualityChecks02.ts, 0, 0)) + + brrr: boolean; +>brrr : Symbol(brrr, Decl(stringLiteralsWithEqualityChecks02.ts, 0, 24)) +} + +let x: "foo"; +>x : Symbol(x, Decl(stringLiteralsWithEqualityChecks02.ts, 4, 3)) + +let y: "foo" | "bar"; +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) + +let b: boolean; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) + +b = x === y; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) +>x : Symbol(x, Decl(stringLiteralsWithEqualityChecks02.ts, 4, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) + +b = "foo" === y +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) + +b = y === "foo"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) + +b = "foo" === "bar"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) + +b = x !== y; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) +>x : Symbol(x, Decl(stringLiteralsWithEqualityChecks02.ts, 4, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) + +b = "foo" !== y +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) + +b = y !== "foo"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) + +b = "foo" !== "bar"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) + + diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.types b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.types new file mode 100644 index 0000000000000..902fe5d975717 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.types @@ -0,0 +1,74 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts === +interface Refrigerator { +>Refrigerator : Refrigerator + + brrr: boolean; +>brrr : boolean +} + +let x: "foo"; +>x : "foo" + +let y: "foo" | "bar"; +>y : "foo" | "bar" + +let b: boolean; +>b : boolean + +b = x === y; +>b = x === y : boolean +>b : boolean +>x === y : boolean +>x : "foo" +>y : "foo" | "bar" + +b = "foo" === y +>b = "foo" === y : boolean +>b : boolean +>"foo" === y : boolean +>"foo" : string +>y : "foo" | "bar" + +b = y === "foo"; +>b = y === "foo" : boolean +>b : boolean +>y === "foo" : boolean +>y : "foo" | "bar" +>"foo" : string + +b = "foo" === "bar"; +>b = "foo" === "bar" : boolean +>b : boolean +>"foo" === "bar" : boolean +>"foo" : string +>"bar" : string + +b = x !== y; +>b = x !== y : boolean +>b : boolean +>x !== y : boolean +>x : "foo" +>y : "foo" | "bar" + +b = "foo" !== y +>b = "foo" !== y : boolean +>b : boolean +>"foo" !== y : boolean +>"foo" : string +>y : "foo" | "bar" + +b = y !== "foo"; +>b = y !== "foo" : boolean +>b : boolean +>y !== "foo" : boolean +>y : "foo" | "bar" +>"foo" : string + +b = "foo" !== "bar"; +>b = "foo" !== "bar" : boolean +>b : boolean +>"foo" !== "bar" : boolean +>"foo" : string +>"bar" : string + + diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.js b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.js new file mode 100644 index 0000000000000..0bb42f01c2181 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.js @@ -0,0 +1,37 @@ +//// [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 = x !== y; +b = "foo" !== y +b = y !== "foo"; +b = "foo" !== "bar"; + + + +//// [stringLiteralsWithEqualityChecks03.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/stringLiteralsWithEqualityChecks03.symbols b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.symbols new file mode 100644 index 0000000000000..c430a8d647521 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.symbols @@ -0,0 +1,59 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts === +interface Runnable { +>Runnable : Symbol(Runnable, Decl(stringLiteralsWithEqualityChecks03.ts, 0, 0)) + + isRunning: boolean; +>isRunning : Symbol(isRunning, Decl(stringLiteralsWithEqualityChecks03.ts, 0, 20)) +} + +interface Refrigerator extends Runnable { +>Refrigerator : Symbol(Refrigerator, Decl(stringLiteralsWithEqualityChecks03.ts, 2, 1)) +>Runnable : Symbol(Runnable, Decl(stringLiteralsWithEqualityChecks03.ts, 0, 0)) + + makesFoodGoBrrr: boolean; +>makesFoodGoBrrr : Symbol(makesFoodGoBrrr, Decl(stringLiteralsWithEqualityChecks03.ts, 4, 41)) +} + +let x: string; +>x : Symbol(x, Decl(stringLiteralsWithEqualityChecks03.ts, 8, 3)) + +let y: "foo" | Refrigerator; +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) +>Refrigerator : Symbol(Refrigerator, Decl(stringLiteralsWithEqualityChecks03.ts, 2, 1)) + +let b: boolean; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) + +b = x === y; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) +>x : Symbol(x, Decl(stringLiteralsWithEqualityChecks03.ts, 8, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) + +b = "foo" === y +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) + +b = y === "foo"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) + +b = "foo" === "bar"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) + +b = x !== y; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) +>x : Symbol(x, Decl(stringLiteralsWithEqualityChecks03.ts, 8, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) + +b = "foo" !== y +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) + +b = y !== "foo"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) + +b = "foo" !== "bar"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) + + diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.types b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.types new file mode 100644 index 0000000000000..827e062597691 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts === +interface Runnable { +>Runnable : Runnable + + isRunning: boolean; +>isRunning : boolean +} + +interface Refrigerator extends Runnable { +>Refrigerator : Refrigerator +>Runnable : Runnable + + makesFoodGoBrrr: boolean; +>makesFoodGoBrrr : boolean +} + +let x: string; +>x : string + +let y: "foo" | Refrigerator; +>y : "foo" | Refrigerator +>Refrigerator : Refrigerator + +let b: boolean; +>b : boolean + +b = x === y; +>b = x === y : boolean +>b : boolean +>x === y : boolean +>x : string +>y : "foo" | Refrigerator + +b = "foo" === y +>b = "foo" === y : boolean +>b : boolean +>"foo" === y : boolean +>"foo" : string +>y : "foo" | Refrigerator + +b = y === "foo"; +>b = y === "foo" : boolean +>b : boolean +>y === "foo" : boolean +>y : "foo" | Refrigerator +>"foo" : string + +b = "foo" === "bar"; +>b = "foo" === "bar" : boolean +>b : boolean +>"foo" === "bar" : boolean +>"foo" : string +>"bar" : string + +b = x !== y; +>b = x !== y : boolean +>b : boolean +>x !== y : boolean +>x : string +>y : "foo" | Refrigerator + +b = "foo" !== y +>b = "foo" !== y : boolean +>b : boolean +>"foo" !== y : boolean +>"foo" : string +>y : "foo" | Refrigerator + +b = y !== "foo"; +>b = y !== "foo" : boolean +>b : boolean +>y !== "foo" : boolean +>y : "foo" | Refrigerator +>"foo" : string + +b = "foo" !== "bar"; +>b = "foo" !== "bar" : boolean +>b : boolean +>"foo" !== "bar" : boolean +>"foo" : string +>"bar" : string + + diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.js b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.js new file mode 100644 index 0000000000000..7f78f83b43772 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.js @@ -0,0 +1,37 @@ +//// [stringLiteralsWithEqualityChecks04.ts] +interface Runnable { + isRunning: boolean; +} + +interface Refrigerator { + 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 = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; + + + +//// [stringLiteralsWithEqualityChecks04.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/stringLiteralsWithEqualityChecks04.symbols b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.symbols new file mode 100644 index 0000000000000..f4325d4b184df --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.symbols @@ -0,0 +1,58 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts === +interface Runnable { +>Runnable : Symbol(Runnable, Decl(stringLiteralsWithEqualityChecks04.ts, 0, 0)) + + isRunning: boolean; +>isRunning : Symbol(isRunning, Decl(stringLiteralsWithEqualityChecks04.ts, 0, 20)) +} + +interface Refrigerator { +>Refrigerator : Symbol(Refrigerator, Decl(stringLiteralsWithEqualityChecks04.ts, 2, 1)) + + makesFoodGoBrrr: boolean; +>makesFoodGoBrrr : Symbol(makesFoodGoBrrr, Decl(stringLiteralsWithEqualityChecks04.ts, 4, 24)) +} + +let x: string; +>x : Symbol(x, Decl(stringLiteralsWithEqualityChecks04.ts, 8, 3)) + +let y: "foo" | Refrigerator; +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) +>Refrigerator : Symbol(Refrigerator, Decl(stringLiteralsWithEqualityChecks04.ts, 2, 1)) + +let b: boolean; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) + +b = x == y; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) +>x : Symbol(x, Decl(stringLiteralsWithEqualityChecks04.ts, 8, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) + +b = "foo" == y +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) + +b = y == "foo"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) + +b = "foo" == "bar"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) + +b = x != y; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) +>x : Symbol(x, Decl(stringLiteralsWithEqualityChecks04.ts, 8, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) + +b = "foo" != y +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) + +b = y != "foo"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) +>y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) + +b = "foo" != "bar"; +>b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) + + diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.types b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.types new file mode 100644 index 0000000000000..d3763cbe5e64d --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.types @@ -0,0 +1,82 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts === +interface Runnable { +>Runnable : Runnable + + isRunning: boolean; +>isRunning : boolean +} + +interface Refrigerator { +>Refrigerator : Refrigerator + + makesFoodGoBrrr: boolean; +>makesFoodGoBrrr : boolean +} + +let x: string; +>x : string + +let y: "foo" | Refrigerator; +>y : "foo" | Refrigerator +>Refrigerator : Refrigerator + +let b: boolean; +>b : boolean + +b = x == y; +>b = x == y : boolean +>b : boolean +>x == y : boolean +>x : string +>y : "foo" | Refrigerator + +b = "foo" == y +>b = "foo" == y : boolean +>b : boolean +>"foo" == y : boolean +>"foo" : string +>y : "foo" | Refrigerator + +b = y == "foo"; +>b = y == "foo" : boolean +>b : boolean +>y == "foo" : boolean +>y : "foo" | Refrigerator +>"foo" : string + +b = "foo" == "bar"; +>b = "foo" == "bar" : boolean +>b : boolean +>"foo" == "bar" : boolean +>"foo" : string +>"bar" : string + +b = x != y; +>b = x != y : boolean +>b : boolean +>x != y : boolean +>x : string +>y : "foo" | Refrigerator + +b = "foo" != y +>b = "foo" != y : boolean +>b : boolean +>"foo" != y : boolean +>"foo" : string +>y : "foo" | Refrigerator + +b = y != "foo"; +>b = y != "foo" : boolean +>b : boolean +>y != "foo" : boolean +>y : "foo" | Refrigerator +>"foo" : string + +b = "foo" != "bar"; +>b = "foo" != "bar" : boolean +>b : boolean +>"foo" != "bar" : boolean +>"foo" : string +>"bar" : string + + 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/stringLiteralsWithSwitchStatements01.symbols b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.symbols new file mode 100644 index 0000000000000..441002c0d1e9b --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements01.ts === +let x: "foo"; +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements01.ts, 0, 3)) + +let y: "foo" | "bar"; +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements01.ts, 1, 3)) + +switch (x) { +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements01.ts, 0, 3)) + + case "foo": + break; + case "bar": + break; + case y: +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements01.ts, 1, 3)) + + y; +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements01.ts, 1, 3)) + + break; +} + diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.types new file mode 100644 index 0000000000000..d431b510e176e --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.types @@ -0,0 +1,27 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements01.ts === +let x: "foo"; +>x : "foo" + +let y: "foo" | "bar"; +>y : "foo" | "bar" + +switch (x) { +>x : "foo" + + case "foo": +>"foo" : string + + break; + case "bar": +>"bar" : string + + break; + case y: +>y : "foo" | "bar" + + y; +>y : "foo" | "bar" + + break; +} + 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/stringLiteralsWithSwitchStatements02.symbols b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.symbols new file mode 100644 index 0000000000000..2888d4b62d431 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.symbols @@ -0,0 +1,43 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements02.ts === +let x: "foo"; +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements02.ts, 0, 3)) + +let y: "foo" | "bar"; +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) + +let b: boolean; +>b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) + +b = x == y; +>b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements02.ts, 0, 3)) +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) + +b = "foo" == y +>b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) + +b = y == "foo"; +>b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) + +b = "foo" == "bar"; +>b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) + +b = x != y; +>b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements02.ts, 0, 3)) +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) + +b = "foo" != y +>b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) + +b = y != "foo"; +>b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) + +b = "foo" != "bar"; +>b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) + + diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements02.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.types new file mode 100644 index 0000000000000..f3ca0cb0c57eb --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.types @@ -0,0 +1,67 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements02.ts === +let x: "foo"; +>x : "foo" + +let y: "foo" | "bar"; +>y : "foo" | "bar" + +let b: boolean; +>b : boolean + +b = x == y; +>b = x == y : boolean +>b : boolean +>x == y : boolean +>x : "foo" +>y : "foo" | "bar" + +b = "foo" == y +>b = "foo" == y : boolean +>b : boolean +>"foo" == y : boolean +>"foo" : string +>y : "foo" | "bar" + +b = y == "foo"; +>b = y == "foo" : boolean +>b : boolean +>y == "foo" : boolean +>y : "foo" | "bar" +>"foo" : string + +b = "foo" == "bar"; +>b = "foo" == "bar" : boolean +>b : boolean +>"foo" == "bar" : boolean +>"foo" : string +>"bar" : string + +b = x != y; +>b = x != y : boolean +>b : boolean +>x != y : boolean +>x : "foo" +>y : "foo" | "bar" + +b = "foo" != y +>b = "foo" != y : boolean +>b : boolean +>"foo" != y : boolean +>"foo" : string +>y : "foo" | "bar" + +b = y != "foo"; +>b = y != "foo" : boolean +>b : boolean +>y != "foo" : boolean +>y : "foo" | "bar" +>"foo" : string + +b = "foo" != "bar"; +>b = "foo" != "bar" : boolean +>b : boolean +>"foo" != "bar" : boolean +>"foo" : string +>"bar" : string + + 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/stringLiteralsWithSwitchStatements03.symbols b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.symbols new file mode 100644 index 0000000000000..2fee23e937abf --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements03.ts === +let x: "foo"; +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements03.ts, 0, 3)) + +let y: "foo" | "bar"; +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements03.ts, 1, 3)) + +switch ("foo") { + case "foo": + break; + case "bar": + break; + case x: +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements03.ts, 0, 3)) + + x; +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements03.ts, 0, 3)) + + break; + case y: +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements03.ts, 1, 3)) + + y; +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements03.ts, 1, 3)) + + break; +} + diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.types new file mode 100644 index 0000000000000..e9a1ea5816d4b --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.types @@ -0,0 +1,34 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements03.ts === +let x: "foo"; +>x : "foo" + +let y: "foo" | "bar"; +>y : "foo" | "bar" + +switch ("foo") { +>"foo" : string + + case "foo": +>"foo" : string + + break; + case "bar": +>"bar" : string + + 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/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..b47f9633f5977 --- /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" : string +>randBool() : boolean +>randBool : () => boolean +>"foo" : string +>"bar" : string + + case "foo": +>"foo" : string + + break; + case "bar": +>"bar" : string + + 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.js b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.js new file mode 100644 index 0000000000000..8dd1cc0106e65 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.js @@ -0,0 +1,35 @@ +//// [stringLiteralsWithSwitchStatements05.ts] +let x: "foo"; +let y: "foo" | "bar"; + +declare function randBool(): boolean; + +switch (x) { + case randBool() ? "foo" : "baz": + break; + case (("bar")): + break; + case (x, y, "baz"): + x; + break; + case (("foo" || "bar")): + y; + break; +} + + +//// [stringLiteralsWithSwitchStatements05.js] +var x; +var y; +switch (x) { + case randBool() ? "foo" : "baz": + break; + case (("bar")): + break; + case (x, y, "baz"): + x; + break; + case (("foo" || "bar")): + y; + break; +} diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.symbols b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.symbols new file mode 100644 index 0000000000000..7c264baf64e12 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts === +let x: "foo"; +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements05.ts, 0, 3)) + +let y: "foo" | "bar"; +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements05.ts, 1, 3)) + +declare function randBool(): boolean; +>randBool : Symbol(randBool, Decl(stringLiteralsWithSwitchStatements05.ts, 1, 21)) + +switch (x) { +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements05.ts, 0, 3)) + + case randBool() ? "foo" : "baz": +>randBool : Symbol(randBool, Decl(stringLiteralsWithSwitchStatements05.ts, 1, 21)) + + break; + case (("bar")): + break; + case (x, y, "baz"): +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements05.ts, 0, 3)) +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements05.ts, 1, 3)) + + x; +>x : Symbol(x, Decl(stringLiteralsWithSwitchStatements05.ts, 0, 3)) + + break; + case (("foo" || "bar")): + y; +>y : Symbol(y, Decl(stringLiteralsWithSwitchStatements05.ts, 1, 3)) + + break; +} + diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.types new file mode 100644 index 0000000000000..a4f04ed7dc6b1 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts === +let x: "foo"; +>x : "foo" + +let y: "foo" | "bar"; +>y : "foo" | "bar" + +declare function randBool(): boolean; +>randBool : () => boolean + +switch (x) { +>x : "foo" + + case randBool() ? "foo" : "baz": +>randBool() ? "foo" : "baz" : string +>randBool() : boolean +>randBool : () => boolean +>"foo" : string +>"baz" : string + + break; + case (("bar")): +>(("bar")) : string +>("bar") : string +>"bar" : string + + break; + case (x, y, "baz"): +>(x, y, "baz") : string +>x, y, "baz" : string +>x, y : "foo" | "bar" +>x : "foo" +>y : "foo" | "bar" +>"baz" : string + + x; +>x : "foo" + + break; + case (("foo" || "bar")): +>(("foo" || "bar")) : string +>("foo" || "bar") : string +>"foo" || "bar" : string +>"foo" : string +>"bar" : string + + y; +>y : "foo" | "bar" + + break; +} + 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/stringLiteralsWithTypeAssertions01.symbols b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.symbols new file mode 100644 index 0000000000000..baeda78581516 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts === +let fooOrBar: "foo" | "bar"; +>fooOrBar : Symbol(fooOrBar, Decl(stringLiteralsWithTypeAssertions01.ts, 0, 3)) + +let a = "foo" as "bar"; +>a : Symbol(a, Decl(stringLiteralsWithTypeAssertions01.ts, 2, 3)) + +let b = "bar" as "foo"; +>b : Symbol(b, Decl(stringLiteralsWithTypeAssertions01.ts, 3, 3)) + +let c = fooOrBar as "foo"; +>c : Symbol(c, Decl(stringLiteralsWithTypeAssertions01.ts, 4, 3)) +>fooOrBar : Symbol(fooOrBar, Decl(stringLiteralsWithTypeAssertions01.ts, 0, 3)) + +let d = fooOrBar as "bar"; +>d : Symbol(d, Decl(stringLiteralsWithTypeAssertions01.ts, 5, 3)) +>fooOrBar : Symbol(fooOrBar, Decl(stringLiteralsWithTypeAssertions01.ts, 0, 3)) + +let e = fooOrBar as "baz"; +>e : Symbol(e, Decl(stringLiteralsWithTypeAssertions01.ts, 6, 3)) +>fooOrBar : Symbol(fooOrBar, Decl(stringLiteralsWithTypeAssertions01.ts, 0, 3)) + +let f = "baz" as typeof fooOrBar; +>f : Symbol(f, Decl(stringLiteralsWithTypeAssertions01.ts, 7, 3)) +>fooOrBar : Symbol(fooOrBar, Decl(stringLiteralsWithTypeAssertions01.ts, 0, 3)) + diff --git a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.types b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.types new file mode 100644 index 0000000000000..046afbcf53a5c --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts === +let fooOrBar: "foo" | "bar"; +>fooOrBar : "foo" | "bar" + +let a = "foo" as "bar"; +>a : "bar" +>"foo" as "bar" : "bar" +>"foo" : "foo" + +let b = "bar" as "foo"; +>b : "foo" +>"bar" as "foo" : "foo" +>"bar" : "bar" + +let c = fooOrBar as "foo"; +>c : "foo" +>fooOrBar as "foo" : "foo" +>fooOrBar : "foo" | "bar" + +let d = fooOrBar as "bar"; +>d : "bar" +>fooOrBar as "bar" : "bar" +>fooOrBar : "foo" | "bar" + +let e = fooOrBar as "baz"; +>e : "baz" +>fooOrBar as "baz" : "baz" +>fooOrBar : "foo" | "bar" + +let f = "baz" as typeof fooOrBar; +>f : "foo" | "bar" +>"baz" as typeof fooOrBar : "foo" | "bar" +>"baz" : "baz" +>fooOrBar : "foo" | "bar" + From 13ec5d76d83b4988ee7e067320fbe613405bf9dc Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Dec 2015 16:51:01 -0800 Subject: [PATCH 03/27] Infer string literal types at comparison locations. --- src/compiler/checker.ts | 59 ++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 16 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5d57e9d202874..a29caefec81fe 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7334,24 +7334,37 @@ namespace ts { return undefined; } - function getContextualTypeForBinaryOperand(node: Expression): Type { + function getContextualTypeForBinaryOperand(node: Expression, literalNode: StringLiteral): 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 || - // expression has no contextual type, the right operand is contextually typed by the type of the left operand. - let type = getContextualType(binaryExpression); - if (!type && node === binaryExpression.right) { - type = checkExpression(binaryExpression.left); - } - return type; + + switch (operator) { + case SyntaxKind.BarBarToken: + // When an || expression has a contextual type, the operands are contextually typed by that type. When an || + // expression has no contextual type, the right operand is contextually typed by the type of the left operand. + let type = getContextualTypeWorker(binaryExpression, literalNode); + if (!type && node === binaryExpression.right) { + type = checkExpression(binaryExpression.left); + } + return type; + case SyntaxKind.EqualsEqualsEqualsToken: + case SyntaxKind.ExclamationEqualsEqualsToken: + case SyntaxKind.EqualsEqualsToken: + case SyntaxKind.ExclamationEqualsToken: + if (literalNode) { + return getStringLiteralTypeForText(literalNode.text); + } + break; } + return undefined; } @@ -7459,9 +7472,9 @@ namespace ts { } // In a contextually typed conditional expression, the true/false expressions are contextually typed by the same type. - function getContextualTypeForConditionalOperand(node: Expression): Type { + function getContextualTypeForConditionalOperand(node: Expression, literalNode: StringLiteral): Type { const conditional = node.parent; - return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualType(conditional) : undefined; + return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualTypeWorker(conditional, literalNode) : undefined; } function getContextualTypeForJsxExpression(expr: JsxExpression | JsxSpreadAttribute): Type { @@ -7509,6 +7522,14 @@ namespace ts { * @returns the contextual type of an expression. */ function getContextualType(node: Expression): Type { + return getContextualTypeWorker(node, /*literalNode*/ undefined); + } + + function getLiteralContextualType(literalNode: StringLiteral) { + return getContextualTypeWorker(literalNode, literalNode); + } + + function getContextualTypeWorker(node: Expression, literalNode: StringLiteral): Type { if (isInsideWithStatementBody(node)) { // We cannot answer semantic questions within a with block, do not proceed any further return undefined; @@ -7536,21 +7557,27 @@ namespace ts { case SyntaxKind.AsExpression: return getTypeFromTypeNode((parent).type); case SyntaxKind.BinaryExpression: - return getContextualTypeForBinaryOperand(node); + return getContextualTypeForBinaryOperand(node, literalNode); case SyntaxKind.PropertyAssignment: return getContextualTypeForObjectLiteralElement(parent); case SyntaxKind.ArrayLiteralExpression: return getContextualTypeForElementExpression(node); case SyntaxKind.ConditionalExpression: - return getContextualTypeForConditionalOperand(node); + return getContextualTypeForConditionalOperand(node, literalNode); case SyntaxKind.TemplateSpan: Debug.assert(parent.parent.kind === SyntaxKind.TemplateExpression); return getContextualTypeForSubstitutionExpression(parent.parent, node); case SyntaxKind.ParenthesizedExpression: - return getContextualType(parent); + return getContextualTypeWorker(parent, literalNode); case SyntaxKind.JsxExpression: case SyntaxKind.JsxSpreadAttribute: return getContextualTypeForJsxExpression(parent); + case SyntaxKind.SwitchStatement: + case SyntaxKind.CaseClause: + if (literalNode) { + return getStringLiteralTypeForText(literalNode.text); + } + break; } return undefined; } @@ -10866,7 +10893,7 @@ namespace ts { } function checkStringLiteralExpression(node: StringLiteral): Type { - const contextualType = getContextualType(node); + const contextualType = getLiteralContextualType(node); if (contextualType && contextualTypeIsStringLiteralType(contextualType)) { return getStringLiteralTypeForText(node.text); } From e109b17b2518965e84dabfc646422f0aed7f544a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Dec 2015 16:51:20 -0800 Subject: [PATCH 04/27] Accepted baselines. --- .../reference/TypeGuardWithEnumUnion.types | 8 +-- .../reference/anonymousClassExpression1.types | 2 +- ...eckSwitchStatementIfCaseTypeIsString.types | 2 +- .../classDoesNotDependOnBaseTypes.types | 2 +- ...tionalOperatorConditionIsBooleanType.types | 6 +- .../declFileTypeAnnotationStringLiteral.types | 2 +- ...orInstantiateModulesInFunctionBodies.types | 2 +- .../reference/es3defaultAliasIsQuoted.types | 2 +- .../interfaceDoesNotDependOnBaseTypes.types | 2 +- .../objectLiteralArraySpecialization.types | 2 +- .../overloadResolutionOverNonCTLambdas.types | 2 +- .../reference/overloadReturnTypes.types | 2 +- .../stringLiteralCheckedInIf01.types | 4 +- .../stringLiteralCheckedInIf02.types | 4 +- .../stringLiteralMatchedInSwitch01.types | 4 +- .../stringLiteralTypesAndTuples01.types | 4 +- .../stringLiteralTypesInUnionTypes01.types | 4 +- .../stringLiteralTypesInUnionTypes02.types | 4 +- .../stringLiteralTypesInUnionTypes03.types | 4 +- .../stringLiteralTypesInUnionTypes04.types | 8 +-- .../stringLiteralTypesOverloads01.types | 6 +- .../stringLiteralsWithEqualityChecks01.types | 16 ++--- .../stringLiteralsWithEqualityChecks02.types | 16 ++--- .../stringLiteralsWithEqualityChecks03.types | 16 ++--- .../stringLiteralsWithEqualityChecks04.types | 16 ++--- ...stringLiteralsWithSwitchStatements01.types | 4 +- ...stringLiteralsWithSwitchStatements02.types | 16 ++--- ...stringLiteralsWithSwitchStatements03.types | 6 +- ...stringLiteralsWithSwitchStatements04.types | 10 +-- ...stringLiteralsWithSwitchStatements05.types | 22 +++---- .../reference/switchBreakStatements.types | 44 ++++++------- ...itchCasesExpressionTypeMismatch.errors.txt | 4 +- tests/baselines/reference/symbolType17.types | 2 +- tests/baselines/reference/symbolType18.types | 2 +- tests/baselines/reference/symbolType19.types | 2 +- .../templateStringInEqualityChecks.types | 4 +- .../templateStringInEqualityChecksES6.types | 4 +- .../throwInEnclosingStatements.types | 2 +- .../baselines/reference/typeGuardEnums.types | 4 +- .../reference/typeGuardInClass.types | 2 +- .../reference/typeGuardNesting.types | 24 +++---- .../typeGuardOfFormExpr1AndExpr2.types | 18 +++--- .../typeGuardOfFormExpr1OrExpr2.types | 18 +++--- .../reference/typeGuardOfFormNotExpr.types | 20 +++--- .../typeGuardOfFormTypeOfBoolean.types | 20 +++--- ...ardOfFormTypeOfEqualEqualHasNoEffect.types | 8 +-- ...GuardOfFormTypeOfNotEqualHasNoEffect.types | 8 +-- .../typeGuardOfFormTypeOfNumber.types | 20 +++--- .../typeGuardOfFormTypeOfOther.types | 16 ++--- .../typeGuardOfFormTypeOfString.types | 20 +++--- .../reference/typeGuardRedundancy.types | 16 ++--- .../typeGuardTautologicalConsistiency.types | 8 +-- .../reference/typeGuardTypeOfUndefined.types | 64 +++++++++---------- .../reference/typeGuardsDefeat.types | 6 +- .../typeGuardsInClassAccessors.types | 40 ++++++------ .../reference/typeGuardsInClassMethods.types | 30 ++++----- .../typeGuardsInConditionalExpression.types | 40 ++++++------ .../typeGuardsInExternalModule.types | 4 +- .../reference/typeGuardsInFunction.types | 38 +++++------ .../typeGuardsInFunctionAndModuleBlock.types | 26 ++++---- .../reference/typeGuardsInGlobal.types | 2 +- .../reference/typeGuardsInIfStatement.types | 42 ++++++------ .../reference/typeGuardsInModule.types | 22 +++---- .../reference/typeGuardsInProperties.types | 12 ++-- ...GuardsInRightOperandOfAndAndOperator.types | 26 ++++---- ...peGuardsInRightOperandOfOrOrOperator.types | 26 ++++---- .../reference/typeGuardsObjectMethods.types | 20 +++--- .../reference/uncaughtCompilerError1.types | 10 +-- .../reference/unionTypeInference.types | 4 +- 69 files changed, 438 insertions(+), 438 deletions(-) diff --git a/tests/baselines/reference/TypeGuardWithEnumUnion.types b/tests/baselines/reference/TypeGuardWithEnumUnion.types index 453ec220f021a..972832076405c 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 : Color | string | 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/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/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/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/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/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 f91eea030976d..9c58c0819ab9d 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 c874973e3e590..54348adab4937 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 e5ff509822b99..5787c39f8d466 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes01.types @@ -15,7 +15,7 @@ var y: T = "bar"; 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 b468c620376ba..540007f9927b8 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes02.types @@ -15,7 +15,7 @@ var y: T = "bar"; if (x === "foo") { >x === "foo" : boolean >x : "foo" | "bar" | "baz" | string ->"foo" : string +>"foo" : "foo" let a = x; >a : "foo" | "bar" | "baz" | string @@ -24,7 +24,7 @@ if (x === "foo") { else if (x !== "bar") { >x !== "bar" : boolean >x : "foo" | "bar" | "baz" | 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 5fca6e69be996..6529c555a9e3c 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes03.types @@ -14,7 +14,7 @@ var y: T = "bar"; 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 ad92dc360d0a9..e1180603ccff0 100644 --- a/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types +++ b/tests/baselines/reference/stringLiteralTypesInUnionTypes04.types @@ -16,7 +16,7 @@ let y: T = "foo"; 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/stringLiteralsWithEqualityChecks01.types b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.types index 111472beedd73..1a419083ae124 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.types +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.types @@ -19,7 +19,7 @@ b = "foo" === y >b = "foo" === y : boolean >b : boolean >"foo" === y : boolean ->"foo" : string +>"foo" : "foo" >y : "foo" | "bar" b = y === "foo"; @@ -27,14 +27,14 @@ b = y === "foo"; >b : boolean >y === "foo" : boolean >y : "foo" | "bar" ->"foo" : string +>"foo" : "foo" b = "foo" === "bar"; >b = "foo" === "bar" : boolean >b : boolean >"foo" === "bar" : boolean ->"foo" : string ->"bar" : string +>"foo" : "foo" +>"bar" : "bar" b = x !== y; >b = x !== y : boolean @@ -47,7 +47,7 @@ b = "foo" !== y >b = "foo" !== y : boolean >b : boolean >"foo" !== y : boolean ->"foo" : string +>"foo" : "foo" >y : "foo" | "bar" b = y !== "foo"; @@ -55,13 +55,13 @@ b = y !== "foo"; >b : boolean >y !== "foo" : boolean >y : "foo" | "bar" ->"foo" : string +>"foo" : "foo" b = "foo" !== "bar"; >b = "foo" !== "bar" : boolean >b : boolean >"foo" !== "bar" : boolean ->"foo" : string ->"bar" : string +>"foo" : "foo" +>"bar" : "bar" diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.types b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.types index 902fe5d975717..39da95ce827ed 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.types +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.types @@ -26,7 +26,7 @@ b = "foo" === y >b = "foo" === y : boolean >b : boolean >"foo" === y : boolean ->"foo" : string +>"foo" : "foo" >y : "foo" | "bar" b = y === "foo"; @@ -34,14 +34,14 @@ b = y === "foo"; >b : boolean >y === "foo" : boolean >y : "foo" | "bar" ->"foo" : string +>"foo" : "foo" b = "foo" === "bar"; >b = "foo" === "bar" : boolean >b : boolean >"foo" === "bar" : boolean ->"foo" : string ->"bar" : string +>"foo" : "foo" +>"bar" : "bar" b = x !== y; >b = x !== y : boolean @@ -54,7 +54,7 @@ b = "foo" !== y >b = "foo" !== y : boolean >b : boolean >"foo" !== y : boolean ->"foo" : string +>"foo" : "foo" >y : "foo" | "bar" b = y !== "foo"; @@ -62,13 +62,13 @@ b = y !== "foo"; >b : boolean >y !== "foo" : boolean >y : "foo" | "bar" ->"foo" : string +>"foo" : "foo" b = "foo" !== "bar"; >b = "foo" !== "bar" : boolean >b : boolean >"foo" !== "bar" : boolean ->"foo" : string ->"bar" : string +>"foo" : "foo" +>"bar" : "bar" diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.types b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.types index 827e062597691..dede9108f6563 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.types +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.types @@ -35,7 +35,7 @@ b = "foo" === y >b = "foo" === y : boolean >b : boolean >"foo" === y : boolean ->"foo" : string +>"foo" : "foo" >y : "foo" | Refrigerator b = y === "foo"; @@ -43,14 +43,14 @@ b = y === "foo"; >b : boolean >y === "foo" : boolean >y : "foo" | Refrigerator ->"foo" : string +>"foo" : "foo" b = "foo" === "bar"; >b = "foo" === "bar" : boolean >b : boolean >"foo" === "bar" : boolean ->"foo" : string ->"bar" : string +>"foo" : "foo" +>"bar" : "bar" b = x !== y; >b = x !== y : boolean @@ -63,7 +63,7 @@ b = "foo" !== y >b = "foo" !== y : boolean >b : boolean >"foo" !== y : boolean ->"foo" : string +>"foo" : "foo" >y : "foo" | Refrigerator b = y !== "foo"; @@ -71,13 +71,13 @@ b = y !== "foo"; >b : boolean >y !== "foo" : boolean >y : "foo" | Refrigerator ->"foo" : string +>"foo" : "foo" b = "foo" !== "bar"; >b = "foo" !== "bar" : boolean >b : boolean >"foo" !== "bar" : boolean ->"foo" : string ->"bar" : string +>"foo" : "foo" +>"bar" : "bar" diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.types b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.types index d3763cbe5e64d..e18f9255af742 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.types +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.types @@ -34,7 +34,7 @@ b = "foo" == y >b = "foo" == y : boolean >b : boolean >"foo" == y : boolean ->"foo" : string +>"foo" : "foo" >y : "foo" | Refrigerator b = y == "foo"; @@ -42,14 +42,14 @@ b = y == "foo"; >b : boolean >y == "foo" : boolean >y : "foo" | Refrigerator ->"foo" : string +>"foo" : "foo" b = "foo" == "bar"; >b = "foo" == "bar" : boolean >b : boolean >"foo" == "bar" : boolean ->"foo" : string ->"bar" : string +>"foo" : "foo" +>"bar" : "bar" b = x != y; >b = x != y : boolean @@ -62,7 +62,7 @@ b = "foo" != y >b = "foo" != y : boolean >b : boolean >"foo" != y : boolean ->"foo" : string +>"foo" : "foo" >y : "foo" | Refrigerator b = y != "foo"; @@ -70,13 +70,13 @@ b = y != "foo"; >b : boolean >y != "foo" : boolean >y : "foo" | Refrigerator ->"foo" : string +>"foo" : "foo" b = "foo" != "bar"; >b = "foo" != "bar" : boolean >b : boolean >"foo" != "bar" : boolean ->"foo" : string ->"bar" : string +>"foo" : "foo" +>"bar" : "bar" diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.types index d431b510e176e..2ef4cb32e0d28 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.types +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.types @@ -9,11 +9,11 @@ switch (x) { >x : "foo" case "foo": ->"foo" : string +>"foo" : "foo" break; case "bar": ->"bar" : string +>"bar" : "bar" break; case y: diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements02.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.types index f3ca0cb0c57eb..bff18c95c8b5e 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements02.types +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.types @@ -19,7 +19,7 @@ b = "foo" == y >b = "foo" == y : boolean >b : boolean >"foo" == y : boolean ->"foo" : string +>"foo" : "foo" >y : "foo" | "bar" b = y == "foo"; @@ -27,14 +27,14 @@ b = y == "foo"; >b : boolean >y == "foo" : boolean >y : "foo" | "bar" ->"foo" : string +>"foo" : "foo" b = "foo" == "bar"; >b = "foo" == "bar" : boolean >b : boolean >"foo" == "bar" : boolean ->"foo" : string ->"bar" : string +>"foo" : "foo" +>"bar" : "bar" b = x != y; >b = x != y : boolean @@ -47,7 +47,7 @@ b = "foo" != y >b = "foo" != y : boolean >b : boolean >"foo" != y : boolean ->"foo" : string +>"foo" : "foo" >y : "foo" | "bar" b = y != "foo"; @@ -55,13 +55,13 @@ b = y != "foo"; >b : boolean >y != "foo" : boolean >y : "foo" | "bar" ->"foo" : string +>"foo" : "foo" b = "foo" != "bar"; >b = "foo" != "bar" : boolean >b : boolean >"foo" != "bar" : boolean ->"foo" : string ->"bar" : string +>"foo" : "foo" +>"bar" : "bar" diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.types index e9a1ea5816d4b..65da543566d26 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.types +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.types @@ -6,14 +6,14 @@ let y: "foo" | "bar"; >y : "foo" | "bar" switch ("foo") { ->"foo" : string +>"foo" : "foo" case "foo": ->"foo" : string +>"foo" : "foo" break; case "bar": ->"bar" : string +>"bar" : "bar" break; case x: diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types index b47f9633f5977..257213e41adc0 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements04.types @@ -9,18 +9,18 @@ declare function randBool(): boolean; >randBool : () => boolean switch (randBool() ? "foo" : "bar") { ->randBool() ? "foo" : "bar" : string +>randBool() ? "foo" : "bar" : "foo" | "bar" >randBool() : boolean >randBool : () => boolean ->"foo" : string ->"bar" : string +>"foo" : "foo" +>"bar" : "bar" case "foo": ->"foo" : string +>"foo" : "foo" break; case "bar": ->"bar" : string +>"bar" : "bar" break; case x: diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.types index a4f04ed7dc6b1..f62c06e5a0419 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.types +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.types @@ -12,17 +12,17 @@ switch (x) { >x : "foo" case randBool() ? "foo" : "baz": ->randBool() ? "foo" : "baz" : string +>randBool() ? "foo" : "baz" : "foo" | "baz" >randBool() : boolean >randBool : () => boolean ->"foo" : string ->"baz" : string +>"foo" : "foo" +>"baz" : "baz" break; case (("bar")): ->(("bar")) : string ->("bar") : string ->"bar" : string +>(("bar")) : "bar" +>("bar") : "bar" +>"bar" : "bar" break; case (x, y, "baz"): @@ -38,11 +38,11 @@ switch (x) { break; case (("foo" || "bar")): ->(("foo" || "bar")) : string ->("foo" || "bar") : string ->"foo" || "bar" : string ->"foo" : string ->"bar" : string +>(("foo" || "bar")) : "foo" | "bar" +>("foo" || "bar") : "foo" | "bar" +>"foo" || "bar" : "foo" | "bar" +>"foo" : "foo" +>"bar" : "bar" y; >y : "foo" | "bar" diff --git a/tests/baselines/reference/switchBreakStatements.types b/tests/baselines/reference/switchBreakStatements.types index 0364d878d5ab4..bc8391a325559 100644 --- a/tests/baselines/reference/switchBreakStatements.types +++ b/tests/baselines/reference/switchBreakStatements.types @@ -1,10 +1,10 @@ === tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts === switch ('') { ->'' : string +>'' : "" case 'a': ->'a' : string +>'a' : "a" break; } @@ -13,10 +13,10 @@ ONE: >ONE : any switch ('') { ->'' : string +>'' : "" case 'a': ->'a' : string +>'a' : "a" break ONE; >ONE : any @@ -29,10 +29,10 @@ THREE: >THREE : any switch ('') { ->'' : string +>'' : "" case 'a': ->'a' : string +>'a' : "a" break THREE; >THREE : any @@ -42,19 +42,19 @@ FOUR: >FOUR : any switch ('') { ->'' : string +>'' : "" case 'a': ->'a' : string +>'a' : "a" FIVE: >FIVE : any switch ('') { ->'' : string +>'' : "" case 'a': ->'a' : string +>'a' : "a" break FOUR; >FOUR : any @@ -62,19 +62,19 @@ switch ('') { } switch ('') { ->'' : string +>'' : "" case 'a': ->'a' : string +>'a' : "a" SIX: >SIX : any switch ('') { ->'' : string +>'' : "" case 'a': ->'a' : string +>'a' : "a" break SIX; >SIX : any @@ -85,22 +85,22 @@ SEVEN: >SEVEN : any switch ('') { ->'' : string +>'' : "" case 'a': ->'a' : string +>'a' : "a" switch ('') { ->'' : string +>'' : "" case 'a': ->'a' : string +>'a' : "a" switch ('') { ->'' : string +>'' : "" case 'a': ->'a' : string +>'a' : "a" break SEVEN; >SEVEN : any @@ -109,10 +109,10 @@ switch ('') { >EIGHT : any switch ('') { ->'' : string +>'' : "" case 'a': ->'a' : string +>'a' : "a" var fn = function () { } >fn : () => void diff --git a/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt b/tests/baselines/reference/switchCasesExpressionTypeMismatch.errors.txt index de739af007d9b..149d609dcff95 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 TS2322: Type 'typeof Foo' is not assignable to type 'number'. -tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2322: Type 'string' is not assignable to type 'number'. +tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(5,10): error TS2322: Type '"sss"' is not assignable to type 'number'. tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2322: Type 'boolean' is not assignable to type 'number'. @@ -12,7 +12,7 @@ tests/cases/compiler/switchCasesExpressionTypeMismatch.ts(7,10): error TS2322: T !!! error TS2322: Type 'typeof Foo' is not assignable to type 'number'. case "sss": break; // Error ~~~~~ -!!! error TS2322: Type 'string' is not assignable to type 'number'. +!!! error TS2322: Type '"sss"' is not assignable 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 568fd800e353f..efdf899f3634c 100644 --- a/tests/baselines/reference/throwInEnclosingStatements.types +++ b/tests/baselines/reference/throwInEnclosingStatements.types @@ -22,7 +22,7 @@ switch (y) { >y : string case 'a': ->'a' : string +>'a' : "a" throw y; >y : string diff --git a/tests/baselines/reference/typeGuardEnums.types b/tests/baselines/reference/typeGuardEnums.types index 1d39a81d78acd..196322b13f00a 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 | E | V ->"number" : string +>"number" : "number" x; // string >x : string diff --git a/tests/baselines/reference/typeGuardInClass.types b/tests/baselines/reference/typeGuardInClass.types index 93fe9f28c5e9e..6a32583dafb4b 100644 --- a/tests/baselines/reference/typeGuardInClass.types +++ b/tests/baselines/reference/typeGuardInClass.types @@ -6,7 +6,7 @@ if (typeof x === "string") { >typeof x === "string" : boolean >typeof x : string >x : string | number ->"string" : string +>"string" : "string" let n = class { >n : typeof (Anonymous class) diff --git a/tests/baselines/reference/typeGuardNesting.types b/tests/baselines/reference/typeGuardNesting.types index 255e96da89eb8..4183d75f0700e 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 : boolean | string ->'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 : boolean | string ->'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 : string | boolean ->'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 : boolean | string ->'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 : boolean | string ->'string' : string +>'string' : "string" >strOrBool : boolean >false : boolean } diff --git a/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types b/tests/baselines/reference/typeGuardOfFormExpr1AndExpr2.types index 10f50bed52e94..ddfa4f826d0aa 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 : 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" cOrBool = strOrNumOrBoolOrC; // C | boolean >cOrBool = strOrNumOrBoolOrC : 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/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 a99db08efab5b..e4490d42dae3c 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 : 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" 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 : string | number | boolean ->"string" : string +>"string" : "string" >numOrBool !== strOrNumOrBool : boolean >numOrBool : number | boolean >strOrNumOrBool : number | boolean diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types b/tests/baselines/reference/typeGuardOfFormTypeOfBoolean.types index 9d9f28548be75..68df1ac3d93fb 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 @@ -118,7 +118,7 @@ if (typeof strOrNum === "boolean") { >typeof strOrNum === "boolean" : boolean >typeof strOrNum : string >strOrNum : string | number ->"boolean" : string +>"boolean" : "boolean" var z1: string | number = strOrNum; // string | number >z1 : string | number @@ -138,7 +138,7 @@ if (typeof strOrBool !== "boolean") { >typeof strOrBool !== "boolean" : boolean >typeof strOrBool : string >strOrBool : string | boolean ->"boolean" : string +>"boolean" : "boolean" str = strOrBool; // string >str = strOrBool : string @@ -155,7 +155,7 @@ if (typeof numOrBool !== "boolean") { >typeof numOrBool !== "boolean" : boolean >typeof numOrBool : string >numOrBool : number | boolean ->"boolean" : string +>"boolean" : "boolean" num = numOrBool; // number >num = numOrBool : number @@ -172,7 +172,7 @@ if (typeof strOrNumOrBool !== "boolean") { >typeof strOrNumOrBool !== "boolean" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"boolean" : string +>"boolean" : "boolean" strOrNum = strOrNumOrBool; // string | number >strOrNum = strOrNumOrBool : string | number @@ -189,7 +189,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 @@ -208,7 +208,7 @@ if (typeof strOrNum !== "boolean") { >typeof strOrNum !== "boolean" : boolean >typeof strOrNum : string >strOrNum : string | number ->"boolean" : string +>"boolean" : "boolean" var z1: string | number = strOrNum; // string | number >z1 : string | number diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.types b/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.types index 4bfc8fe6bf1c4..0c9b2a140bc09 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.types @@ -21,7 +21,7 @@ if (typeof strOrNum == "string") { >typeof strOrNum == "string" : boolean >typeof strOrNum : string >strOrNum : string | number ->"string" : string +>"string" : "string" var r1 = strOrNum; // string | number >r1 : string | number @@ -37,7 +37,7 @@ if (typeof strOrBool == "boolean") { >typeof strOrBool == "boolean" : boolean >typeof strOrBool : string >strOrBool : string | boolean ->"boolean" : string +>"boolean" : "boolean" var r2 = strOrBool; // string | boolean >r2 : string | boolean @@ -53,7 +53,7 @@ if (typeof numOrBool == "number") { >typeof numOrBool == "number" : boolean >typeof numOrBool : string >numOrBool : number | boolean ->"number" : string +>"number" : "number" var r3 = numOrBool; // number | boolean >r3 : number | boolean @@ -69,7 +69,7 @@ if (typeof strOrC == "Object") { >typeof strOrC == "Object" : boolean >typeof strOrC : string >strOrC : string | C ->"Object" : string +>"Object" : "Object" var r4 = strOrC; // string | C >r4 : string | C diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.types b/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.types index 6eabeb25ede19..c8b7766fc5d49 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.types @@ -21,7 +21,7 @@ if (typeof strOrNum != "string") { >typeof strOrNum != "string" : boolean >typeof strOrNum : string >strOrNum : string | number ->"string" : string +>"string" : "string" var r1 = strOrNum; // string | number >r1 : string | number @@ -37,7 +37,7 @@ if (typeof strOrBool != "boolean") { >typeof strOrBool != "boolean" : boolean >typeof strOrBool : string >strOrBool : string | boolean ->"boolean" : string +>"boolean" : "boolean" var r2 = strOrBool; // string | boolean >r2 : string | boolean @@ -53,7 +53,7 @@ if (typeof numOrBool != "number") { >typeof numOrBool != "number" : boolean >typeof numOrBool : string >numOrBool : number | boolean ->"number" : string +>"number" : "number" var r3 = numOrBool; // number | boolean >r3 : number | boolean @@ -69,7 +69,7 @@ if (typeof strOrC != "Object") { >typeof strOrC != "Object" : boolean >typeof strOrC : string >strOrC : string | C ->"Object" : string +>"Object" : "Object" var r4 = strOrC; // string | C >r4 : string | C diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types b/tests/baselines/reference/typeGuardOfFormTypeOfNumber.types index d3caef24efded..52efab2848554 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 @@ -117,7 +117,7 @@ if (typeof strOrBool === "number") { >typeof strOrBool === "number" : boolean >typeof strOrBool : string >strOrBool : string | boolean ->"number" : string +>"number" : "number" var y1: string | boolean = strOrBool; // string | boolean >y1 : string | boolean @@ -136,7 +136,7 @@ if (typeof strOrNum !== "number") { >typeof strOrNum !== "number" : boolean >typeof strOrNum : string >strOrNum : string | number ->"number" : string +>"number" : "number" str === strOrNum; // string >str === strOrNum : boolean @@ -153,7 +153,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 @@ -169,7 +169,7 @@ if (typeof strOrNumOrBool !== "number") { >typeof strOrNumOrBool !== "number" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"number" : string +>"number" : "number" strOrBool = strOrNumOrBool; // string | boolean >strOrBool = strOrNumOrBool : string | boolean @@ -186,7 +186,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 @@ -205,7 +205,7 @@ if (typeof strOrBool !== "number") { >typeof strOrBool !== "number" : boolean >typeof strOrBool : string >strOrBool : string | boolean ->"number" : string +>"number" : "number" var y1: string | boolean = strOrBool; // string | boolean >y1 : string | boolean diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfOther.types b/tests/baselines/reference/typeGuardOfFormTypeOfOther.types index 5cec356719493..e68281e979213 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 @@ -102,7 +102,7 @@ if (typeof strOrNumOrBool === "Object") { >typeof strOrNumOrBool === "Object" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"Object" : string +>"Object" : "Object" var q1: string | number | boolean = strOrNumOrBool; // string | number | boolean >q1 : string | number | boolean @@ -121,7 +121,7 @@ if (typeof strOrC !== "Object") { >typeof strOrC !== "Object" : boolean >typeof strOrC : string >strOrC : string | C ->"Object" : string +>"Object" : "Object" var r2: string = strOrC; // string >r2 : string @@ -137,7 +137,7 @@ if (typeof numOrC !== "Object") { >typeof numOrC !== "Object" : boolean >typeof numOrC : string >numOrC : number | C ->"Object" : string +>"Object" : "Object" var r3: number = numOrC; // number >r3 : number @@ -153,7 +153,7 @@ if (typeof boolOrC !== "Object") { >typeof boolOrC !== "Object" : boolean >typeof boolOrC : string >boolOrC : boolean | C ->"Object" : string +>"Object" : "Object" var r4: boolean = boolOrC; // boolean >r4 : boolean @@ -171,7 +171,7 @@ if (typeof strOrNumOrBool !== "Object") { >typeof strOrNumOrBool !== "Object" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean ->"Object" : string +>"Object" : "Object" var q1: string | number | boolean = strOrNumOrBool; // string | number | boolean >q1 : string | number | boolean diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfString.types b/tests/baselines/reference/typeGuardOfFormTypeOfString.types index d6a382261ac55..89160112b346f 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 @@ -118,7 +118,7 @@ if (typeof numOrBool === "string") { >typeof numOrBool === "string" : boolean >typeof numOrBool : string >numOrBool : number | boolean ->"string" : string +>"string" : "string" var x1: number | boolean = numOrBool; // number | boolean >x1 : number | boolean @@ -137,7 +137,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 @@ -154,7 +154,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 @@ -171,7 +171,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 @@ -188,7 +188,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 @@ -207,7 +207,7 @@ if (typeof numOrBool !== "string") { >typeof numOrBool !== "string" : boolean >typeof numOrBool : string >numOrBool : number | boolean ->"string" : string +>"string" : "string" var x1: number | boolean = numOrBool; // number | boolean >x1 : number | boolean diff --git a/tests/baselines/reference/typeGuardRedundancy.types b/tests/baselines/reference/typeGuardRedundancy.types index 1507ceb850ef3..a3ea012a9b4fa 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 : string | number ->"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 d758dcde22bc8..9d112e294dba6 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 | number @@ -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 | number diff --git a/tests/baselines/reference/typeGuardTypeOfUndefined.types b/tests/baselines/reference/typeGuardTypeOfUndefined.types index 6cf57e1a1ddce..636740127d17b 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 : any ->"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 : any @@ -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 | void ->"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 | void ->"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 | void ->"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 | void ->"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 | void ->"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 | void ->"boolean" : string +>"boolean" : "boolean" a; >a : boolean diff --git a/tests/baselines/reference/typeGuardsDefeat.types b/tests/baselines/reference/typeGuardsDefeat.types index cc655d3ce0f36..a78efdd0a9503 100644 --- a/tests/baselines/reference/typeGuardsDefeat.types +++ b/tests/baselines/reference/typeGuardsDefeat.types @@ -17,7 +17,7 @@ function foo(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" f(); >f() : void @@ -42,7 +42,7 @@ function foo2(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" return x.length; // string >x.length : number @@ -78,7 +78,7 @@ function foo3(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" return x.length; // string >x.length : 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 493a8c0a31afd..319e6411ad6cc 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 @@ -36,7 +36,7 @@ function foo2(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" ? (x = 10 && x)// string | number >(x = 10 && x) : number | string @@ -60,7 +60,7 @@ function foo3(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" ? (x = "Hello" && x) // string | number >(x = "Hello" && x) : number | string @@ -84,7 +84,7 @@ function foo4(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" ? x // string | number >x : number | string @@ -107,7 +107,7 @@ function foo5(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" ? x // string | number >x : number | string @@ -130,7 +130,7 @@ function foo6(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" ? (x = 10 && x) // string | number >(x = 10 && x) : number | string @@ -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" // string >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") // string >((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; // number >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 @@ -309,7 +309,7 @@ function foo11(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" ? x // number | boolean | string - changed in the false branch >x : number | string | boolean @@ -328,7 +328,7 @@ function foo11(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | string | boolean ->"number" : string +>"number" : "number" && (x = 10) // assignment to x >(x = 10) : number @@ -353,7 +353,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 | boolean | string - changed here >(x = 10 && x.toString().length) : number @@ -381,7 +381,7 @@ function foo12(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | string | boolean ->"number" : string +>"number" : "number" && x); // x is number >x : number diff --git a/tests/baselines/reference/typeGuardsInExternalModule.types b/tests/baselines/reference/typeGuardsInExternalModule.types index e20063719f5b6..cf1b6e7c42f32 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/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 f7d56ed17d1a6..2d95d92a9be50 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/typeGuardsInIfStatement.types b/tests/baselines/reference/typeGuardsInIfStatement.types index 0095a7cc768ea..dc3c0979978a1 100644 --- a/tests/baselines/reference/typeGuardsInIfStatement.types +++ b/tests/baselines/reference/typeGuardsInIfStatement.types @@ -13,7 +13,7 @@ function foo(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" return 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 = 10; >x = 10 : number @@ -59,7 +59,7 @@ function foo3(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" x = "Hello"; // even though assigned using same type as narrowed expression >x = "Hello" : string @@ -83,7 +83,7 @@ function foo4(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" return x; // string | number >x : number | string @@ -107,7 +107,7 @@ function foo5(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" return x; // string | number >x : number | string @@ -131,7 +131,7 @@ function foo6(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" x = 10; >x = 10 : number @@ -159,18 +159,18 @@ function foo7(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" return x === "hello"; // string >x === "hello" : boolean >x : string ->"hello" : string +>"hello" : "hello" } else if (typeof x === "boolean") { >typeof x === "boolean" : boolean >typeof x : string >x : number | boolean ->"boolean" : string +>"boolean" : "boolean" return x; // boolean >x : boolean @@ -190,12 +190,12 @@ function foo8(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" return x === "hello"; // string >x === "hello" : boolean >x : string ->"hello" : string +>"hello" : "hello" } else { var b: number | boolean = x; // number | boolean @@ -206,7 +206,7 @@ function foo8(x: number | string | boolean) { >typeof x === "boolean" : boolean >typeof x : string >x : number | boolean ->"boolean" : string +>"boolean" : "boolean" return x; // boolean >x : boolean @@ -231,7 +231,7 @@ function foo9(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" // usage of x or assignment to separate variable shouldn't cause narrowing of type to stop y = x.length; @@ -244,7 +244,7 @@ function foo9(x: number | string) { return x === "hello"; // string >x === "hello" : boolean >x : string ->"hello" : string +>"hello" : "hello" } else { return x == 10; // number @@ -262,12 +262,12 @@ function foo10(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" return x === "hello"; // string >x === "hello" : boolean >x : string ->"hello" : string +>"hello" : "hello" } else { var y: boolean | string; @@ -282,7 +282,7 @@ function foo10(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | boolean ->"number" : string +>"number" : "number" ? x === 10 // number >x === 10 : boolean @@ -303,7 +303,7 @@ function foo11(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" return x; // string | number | boolean - x changed in else branch >x : number | string | boolean @@ -321,7 +321,7 @@ function foo11(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | string | boolean ->"number" : string +>"number" : "number" ? ( >( // change value of x x = 10 && x.toString() // number | boolean | string ) : string @@ -365,7 +365,7 @@ function foo12(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" return x.toString(); // string | number | boolean - x changed in else branch >x.toString() : string @@ -388,7 +388,7 @@ function foo12(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | string | boolean ->"number" : string +>"number" : "number" ? x.toString() // number >x.toString() : string diff --git a/tests/baselines/reference/typeGuardsInModule.types b/tests/baselines/reference/typeGuardsInModule.types index 6b6c552f0cced..a15055ebee11e 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 | number @@ -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 | number // 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 | number @@ -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 | number diff --git a/tests/baselines/reference/typeGuardsInProperties.types b/tests/baselines/reference/typeGuardsInProperties.types index ca4d8b9452786..618ee41fb7998 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 | number >this : this >pp1 : string | number @@ -51,7 +51,7 @@ class C1 { >this.pp2 : string | number >this : this >pp2 : string | number ->"string" : string +>"string" : "string" >this.pp2 : string | number >this : this >pp2 : string | number @@ -65,7 +65,7 @@ class C1 { >this.pp3 : string | number >this : this >pp3 : string | number ->"string" : string +>"string" : "string" >this.pp3 : string | number >this : this >pp3 : string | number @@ -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 | number >c1 : C1 >pp2 : string | number @@ -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 | number >c1 : C1 >pp3 : string | number @@ -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 | number >obj1 : { x: string | number; } >x : string | number diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types index 22d390618c165..56e5bf8550e87 100644 --- a/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.types +++ b/tests/baselines/reference/typeGuardsInRightOperandOfAndAndOperator.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 | string >(x = 10) && x : number | string >(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) : number | string >(x = "hello") && x : number | 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)) : 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 @@ -154,7 +154,7 @@ function foo7(x: number | string | boolean) { >typeof x !== "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" && ((z = x) // string | number | boolean - x changed deeper in conditional expression >((z = x) // string | number | boolean - x changed deeper in conditional expression && (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()))) : string @@ -170,7 +170,7 @@ function foo7(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | string | boolean ->"number" : string +>"number" : "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string @@ -208,7 +208,7 @@ function foo8(x: number | string) { >typeof x !== "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" && (x = 10) // change x - number| string >(x = 10) : number @@ -222,7 +222,7 @@ function foo8(x: number | string) { >typeof x === "number" : boolean >typeof x : string >x : number | string ->"number" : string +>"number" : "number" ? x // number >x : number diff --git a/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types b/tests/baselines/reference/typeGuardsInRightOperandOfOrOrOperator.types index 38d9a723d3a86..a7bde542fb21f 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 | string >(x = 10) || x : number | string >(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 | number >(x = "hello") || x : string | number >(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 @@ -154,7 +154,7 @@ function foo7(x: number | string | boolean) { >typeof x === "string" : boolean >typeof x : string >x : number | string | boolean ->"string" : string +>"string" : "string" || ((z = x) // string | number | boolean - x changed deeper in conditional expression >((z = x) // string | number | boolean - x changed deeper in conditional expression || (typeof x === "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string // do not change value : (y = x && x.toString()))) : number | string | boolean @@ -170,7 +170,7 @@ function foo7(x: number | string | boolean) { >typeof x === "number" : boolean >typeof x : string >x : number | string | boolean ->"number" : string +>"number" : "number" // change value of x ? (x = 10 && x.toString()) // number | boolean | string @@ -208,7 +208,7 @@ function foo8(x: number | string) { >typeof x === "string" : boolean >typeof x : string >x : number | string ->"string" : string +>"string" : "string" || (x = 10) // change x - number| string >(x = 10) : number @@ -222,7 +222,7 @@ function foo8(x: number | string) { >typeof x === "number" : boolean >typeof x : string >x : number | string ->"number" : string +>"number" : "number" ? x // number >x : number diff --git a/tests/baselines/reference/typeGuardsObjectMethods.types b/tests/baselines/reference/typeGuardsObjectMethods.types index 4ca691bc02061..725a3eb574aa2 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 | number >obj1 : { method(param: string | number): string | number; prop: string | number; } >prop : string | number 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 } From de9789a4bab2c9fc228bb96ed3142b88fd5096e6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Dec 2015 17:13:16 -0800 Subject: [PATCH 05/27] Removed ad-hoc string-like checking for type assertions, switch/cases, and equality comparisons. --- src/compiler/checker.ts | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a29caefec81fe..3cb8b994b5d39 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9896,11 +9896,7 @@ namespace ts { if (produceDiagnostics && targetType !== unknownType) { const widenedType = getWidenedType(exprType); - // Permit 'number[] | "foo"' to be asserted to 'string'. - const bothAreStringLike = - someConstituentTypeHasKind(targetType, TypeFlags.StringLike) && - someConstituentTypeHasKind(widenedType, TypeFlags.StringLike); - if (!bothAreStringLike && !(isTypeAssignableTo(targetType, widenedType))) { + if (!isTypeAssignableTo(targetType, widenedType)) { checkTypeAssignableTo(exprType, targetType, node, Diagnostics.Neither_type_0_nor_type_1_is_assignable_to_the_other); } } @@ -10750,10 +10746,6 @@ namespace ts { case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: case SyntaxKind.ExclamationEqualsEqualsToken: - // Permit 'number[] | "foo"' to be asserted to 'string'. - if (someConstituentTypeHasKind(leftType, TypeFlags.StringLike) && someConstituentTypeHasKind(rightType, TypeFlags.StringLike)) { - return booleanType; - } if (!isTypeAssignableTo(leftType, rightType) && !isTypeAssignableTo(rightType, leftType)) { reportOperatorError(); } @@ -13276,7 +13268,6 @@ namespace ts { let hasDuplicateDefaultClause = false; const expressionType = checkExpression(node.expression); - const expressionTypeIsStringLike = someConstituentTypeHasKind(expressionType, TypeFlags.StringLike); forEach(node.caseBlock.clauses, clause => { // Grammar check for duplicate default clauses, skip if we already report duplicate default clause if (clause.kind === SyntaxKind.DefaultClause && !hasDuplicateDefaultClause) { @@ -13298,12 +13289,7 @@ namespace ts { // In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from the type of the 'switch' expression. const caseType = checkExpression(caseClause.expression); - const expressionTypeIsAssignableToCaseType = - // Permit 'number[] | "foo"' to be asserted to 'string'. - (expressionTypeIsStringLike && someConstituentTypeHasKind(caseType, TypeFlags.StringLike)) || - isTypeAssignableTo(expressionType, caseType); - - if (!expressionTypeIsAssignableToCaseType) { + if (!isTypeAssignableTo(expressionType, caseType)) { // 'expressionType is not assignable to caseType', try the reversed check and report errors if it fails checkTypeAssignableTo(caseType, expressionType, caseClause.expression, /*headMessage*/ undefined); } From d0a857320f9f509a23c1e3c2f4dc6b75dbe4b4ac Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Dec 2015 17:14:00 -0800 Subject: [PATCH 06/27] Accepted baselines. --- .../stringLiteralTypeAssertion01.errors.txt | 55 ++++++++ .../stringLiteralTypeAssertion01.symbols | 83 ------------ .../stringLiteralTypeAssertion01.types | 107 --------------- ...eralTypesWithVariousOperators02.errors.txt | 13 +- ...ingLiteralsWithEqualityChecks01.errors.txt | 24 ++++ ...stringLiteralsWithEqualityChecks01.symbols | 43 ------ .../stringLiteralsWithEqualityChecks01.types | 67 --------- ...ingLiteralsWithEqualityChecks02.errors.txt | 28 ++++ ...stringLiteralsWithEqualityChecks02.symbols | 50 ------- .../stringLiteralsWithEqualityChecks02.types | 74 ---------- ...ingLiteralsWithEqualityChecks03.errors.txt | 38 ++++++ ...stringLiteralsWithEqualityChecks03.symbols | 59 -------- .../stringLiteralsWithEqualityChecks03.types | 83 ------------ ...ingLiteralsWithEqualityChecks04.errors.txt | 38 ++++++ ...stringLiteralsWithEqualityChecks04.symbols | 58 -------- .../stringLiteralsWithEqualityChecks04.types | 82 ----------- ...gLiteralsWithSwitchStatements01.errors.txt | 19 +++ ...ringLiteralsWithSwitchStatements01.symbols | 23 ---- ...stringLiteralsWithSwitchStatements01.types | 27 ---- ...gLiteralsWithSwitchStatements02.errors.txt | 24 ++++ ...ringLiteralsWithSwitchStatements02.symbols | 43 ------ ...stringLiteralsWithSwitchStatements02.types | 67 --------- ...gLiteralsWithSwitchStatements03.errors.txt | 22 +++ ...ringLiteralsWithSwitchStatements03.symbols | 28 ---- ...stringLiteralsWithSwitchStatements03.types | 34 ----- ...gLiteralsWithSwitchStatements05.errors.txt | 24 ++++ ...ringLiteralsWithSwitchStatements05.symbols | 34 ----- ...stringLiteralsWithSwitchStatements05.types | 52 ------- ...ingLiteralsWithTypeAssertions01.errors.txt | 27 ++++ ...stringLiteralsWithTypeAssertions01.symbols | 26 ---- .../stringLiteralsWithTypeAssertions01.types | 35 ----- .../switchBreakStatements.errors.txt | 92 +++++++++++++ .../reference/switchBreakStatements.symbols | 59 -------- .../reference/switchBreakStatements.types | 127 ------------------ 34 files changed, 402 insertions(+), 1263 deletions(-) create mode 100644 tests/baselines/reference/stringLiteralTypeAssertion01.errors.txt delete mode 100644 tests/baselines/reference/stringLiteralTypeAssertion01.symbols delete mode 100644 tests/baselines/reference/stringLiteralTypeAssertion01.types create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt delete mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks01.symbols delete mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks01.types create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt delete mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks02.symbols delete mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks02.types create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt delete mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks03.symbols delete mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks03.types create mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt delete mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks04.symbols delete mode 100644 tests/baselines/reference/stringLiteralsWithEqualityChecks04.types create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt delete mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements01.symbols delete mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements01.types create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements02.errors.txt delete mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements02.symbols delete mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements02.types create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt delete mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements03.symbols delete mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements03.types create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt delete mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements05.symbols delete mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements05.types create mode 100644 tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt delete mode 100644 tests/baselines/reference/stringLiteralsWithTypeAssertions01.symbols delete mode 100644 tests/baselines/reference/stringLiteralsWithTypeAssertions01.types create mode 100644 tests/baselines/reference/switchBreakStatements.errors.txt delete mode 100644 tests/baselines/reference/switchBreakStatements.symbols delete mode 100644 tests/baselines/reference/switchBreakStatements.types diff --git a/tests/baselines/reference/stringLiteralTypeAssertion01.errors.txt b/tests/baselines/reference/stringLiteralTypeAssertion01.errors.txt new file mode 100644 index 0000000000000..867ad80ee7fbf --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypeAssertion01.errors.txt @@ -0,0 +1,55 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(22,5): error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other. + Type 'string' is not assignable to type '"b"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(23,5): error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other. + Type 'string' is not assignable to type '"b"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(30,7): error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other. + Type '("a" | "b")[]' is not assignable to type 'string'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(31,7): error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other. + Type '("a" | "b")[]' is not assignable to type 'string'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts (4 errors) ==== + + type S = "a" | "b"; + type T = S[] | S; + + var s: S; + var t: T; + var str: string; + + //////////////// + + s = t; + s = t as S; + + s = str; + s = str as S; + + //////////////// + + t = s; + t = s as T; + + t = str; + ~~~~~~ +!!! error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other. +!!! error TS2352: Type 'string' is not assignable to type '"b"'. + t = str as T; + ~~~~~~~~ +!!! error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other. +!!! error TS2352: Type 'string' is not assignable to type '"b"'. + + //////////////// + + str = s; + str = s as string; + + str = t; + ~~~~~~~~~ +!!! error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other. +!!! error TS2352: Type '("a" | "b")[]' is not assignable to type 'string'. + str = t as string; + ~~~~~~~~~~~ +!!! error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other. +!!! error TS2352: Type '("a" | "b")[]' is not assignable to type 'string'. + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypeAssertion01.symbols b/tests/baselines/reference/stringLiteralTypeAssertion01.symbols deleted file mode 100644 index 1491a32b6f8bf..0000000000000 --- a/tests/baselines/reference/stringLiteralTypeAssertion01.symbols +++ /dev/null @@ -1,83 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts === - -type S = "a" | "b"; ->S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) - -type T = S[] | S; ->T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) ->S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) ->S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) - -var s: S; ->s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) ->S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) - -var t: T; ->t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) ->T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) - -var str: string; ->str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) - -//////////////// - -s = t; ->s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) ->S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) ->t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) - -s = t as S; ->s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) ->t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) ->S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) - -s = str; ->s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) ->S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) ->str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) - -s = str as S; ->s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) ->str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) ->S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) - -//////////////// - -t = s; ->t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) ->T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) ->s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) - -t = s as T; ->t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) ->s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) ->T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) - -t = str; ->t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) ->T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) ->str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) - -t = str as T; ->t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) ->str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) ->T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) - -//////////////// - -str = s; ->str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) ->s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) - -str = s as string; ->str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) ->s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) - -str = t; ->str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) ->t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) - -str = t as string; ->str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) ->t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) - diff --git a/tests/baselines/reference/stringLiteralTypeAssertion01.types b/tests/baselines/reference/stringLiteralTypeAssertion01.types deleted file mode 100644 index f70313f834700..0000000000000 --- a/tests/baselines/reference/stringLiteralTypeAssertion01.types +++ /dev/null @@ -1,107 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts === - -type S = "a" | "b"; ->S : "a" | "b" - -type T = S[] | S; ->T : ("a" | "b")[] | "a" | "b" ->S : "a" | "b" ->S : "a" | "b" - -var s: S; ->s : "a" | "b" ->S : "a" | "b" - -var t: T; ->t : ("a" | "b")[] | "a" | "b" ->T : ("a" | "b")[] | "a" | "b" - -var str: string; ->str : string - -//////////////// - -s = t; ->s = t : "a" | "b" ->s : "a" | "b" ->t : "a" | "b" ->S : "a" | "b" ->t : ("a" | "b")[] | "a" | "b" - -s = t as S; ->s = t as S : "a" | "b" ->s : "a" | "b" ->t as S : "a" | "b" ->t : ("a" | "b")[] | "a" | "b" ->S : "a" | "b" - -s = str; ->s = str : "a" | "b" ->s : "a" | "b" ->str : "a" | "b" ->S : "a" | "b" ->str : string - -s = str as S; ->s = str as S : "a" | "b" ->s : "a" | "b" ->str as S : "a" | "b" ->str : string ->S : "a" | "b" - -//////////////// - -t = s; ->t = s : ("a" | "b")[] | "a" | "b" ->t : ("a" | "b")[] | "a" | "b" ->s : ("a" | "b")[] | "a" | "b" ->T : ("a" | "b")[] | "a" | "b" ->s : "a" | "b" - -t = s as T; ->t = s as T : ("a" | "b")[] | "a" | "b" ->t : ("a" | "b")[] | "a" | "b" ->s as T : ("a" | "b")[] | "a" | "b" ->s : "a" | "b" ->T : ("a" | "b")[] | "a" | "b" - -t = str; ->t = str : ("a" | "b")[] | "a" | "b" ->t : ("a" | "b")[] | "a" | "b" ->str : ("a" | "b")[] | "a" | "b" ->T : ("a" | "b")[] | "a" | "b" ->str : string - -t = str as T; ->t = str as T : ("a" | "b")[] | "a" | "b" ->t : ("a" | "b")[] | "a" | "b" ->str as T : ("a" | "b")[] | "a" | "b" ->str : string ->T : ("a" | "b")[] | "a" | "b" - -//////////////// - -str = s; ->str = s : string ->str : string ->s : string ->s : "a" | "b" - -str = s as string; ->str = s as string : string ->str : string ->s as string : string ->s : "a" | "b" - -str = t; ->str = t : string ->str : string ->t : string ->t : ("a" | "b")[] | "a" | "b" - -str = t as string; ->str = t as string : string ->str : string ->t as string : string ->t : ("a" | "b")[] | "a" | "b" - diff --git a/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt b/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt index 69dd6c2f6a955..92afe67df0c62 100644 --- a/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt +++ b/tests/baselines/reference/stringLiteralTypesWithVariousOperators02.errors.txt @@ -7,9 +7,12 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperato tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(13,11): error TS2356: An arithmetic operand must be of type 'any', 'number' or an enum type. tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(14,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(15,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(16,9): error TS2365: Operator '<' cannot be applied to types '"ABC"' and '"XYZ"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(17,9): error TS2365: Operator '===' cannot be applied to types '"ABC"' and '"XYZ"'. +tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts(18,9): error TS2365: Operator '!=' cannot be applied to types '"ABC"' and '"XYZ"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts (9 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperators02.ts (12 errors) ==== let abc: "ABC" = "ABC"; let xyz: "XYZ" = "XYZ"; @@ -44,5 +47,11 @@ tests/cases/conformance/types/stringLiteral/stringLiteralTypesWithVariousOperato ~~~~~~~~~~~~~~~~ !!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. let j = abc < xyz; + ~~~~~~~~~ +!!! error TS2365: Operator '<' cannot be applied to types '"ABC"' and '"XYZ"'. let k = abc === xyz; - let l = abc != xyz; \ No newline at end of file + ~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"ABC"' and '"XYZ"'. + let l = abc != xyz; + ~~~~~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types '"ABC"' and '"XYZ"'. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt new file mode 100644 index 0000000000000..7bb5c04b5249d --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt @@ -0,0 +1,24 @@ +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(13,5): error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.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/stringLiteralsWithEqualityChecks01.symbols b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.symbols deleted file mode 100644 index e2b1c35795ed1..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.symbols +++ /dev/null @@ -1,43 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts === -let x: "foo"; ->x : Symbol(x, Decl(stringLiteralsWithEqualityChecks01.ts, 0, 3)) - -let y: "foo" | "bar"; ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) - -let b: boolean; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) - -b = x === y; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) ->x : Symbol(x, Decl(stringLiteralsWithEqualityChecks01.ts, 0, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) - -b = "foo" === y ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) - -b = y === "foo"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) - -b = "foo" === "bar"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) - -b = x !== y; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) ->x : Symbol(x, Decl(stringLiteralsWithEqualityChecks01.ts, 0, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) - -b = "foo" !== y ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) - -b = y !== "foo"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks01.ts, 1, 3)) - -b = "foo" !== "bar"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks01.ts, 3, 3)) - - diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.types b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.types deleted file mode 100644 index 1a419083ae124..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.types +++ /dev/null @@ -1,67 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts === -let x: "foo"; ->x : "foo" - -let y: "foo" | "bar"; ->y : "foo" | "bar" - -let b: boolean; ->b : boolean - -b = x === y; ->b = x === y : boolean ->b : boolean ->x === y : boolean ->x : "foo" ->y : "foo" | "bar" - -b = "foo" === y ->b = "foo" === y : boolean ->b : boolean ->"foo" === y : boolean ->"foo" : "foo" ->y : "foo" | "bar" - -b = y === "foo"; ->b = y === "foo" : boolean ->b : boolean ->y === "foo" : boolean ->y : "foo" | "bar" ->"foo" : "foo" - -b = "foo" === "bar"; ->b = "foo" === "bar" : boolean ->b : boolean ->"foo" === "bar" : boolean ->"foo" : "foo" ->"bar" : "bar" - -b = x !== y; ->b = x !== y : boolean ->b : boolean ->x !== y : boolean ->x : "foo" ->y : "foo" | "bar" - -b = "foo" !== y ->b = "foo" !== y : boolean ->b : boolean ->"foo" !== y : boolean ->"foo" : "foo" ->y : "foo" | "bar" - -b = y !== "foo"; ->b = y !== "foo" : boolean ->b : boolean ->y !== "foo" : boolean ->y : "foo" | "bar" ->"foo" : "foo" - -b = "foo" !== "bar"; ->b = "foo" !== "bar" : boolean ->b : boolean ->"foo" !== "bar" : boolean ->"foo" : "foo" ->"bar" : "bar" - - diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt new file mode 100644 index 0000000000000..25b0ee2368a62 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt @@ -0,0 +1,28 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts(12,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 (2 errors) ==== + interface Refrigerator { + brrr: boolean; + } + + 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/stringLiteralsWithEqualityChecks02.symbols b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.symbols deleted file mode 100644 index 0f92f9a26bdfe..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.symbols +++ /dev/null @@ -1,50 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts === -interface Refrigerator { ->Refrigerator : Symbol(Refrigerator, Decl(stringLiteralsWithEqualityChecks02.ts, 0, 0)) - - brrr: boolean; ->brrr : Symbol(brrr, Decl(stringLiteralsWithEqualityChecks02.ts, 0, 24)) -} - -let x: "foo"; ->x : Symbol(x, Decl(stringLiteralsWithEqualityChecks02.ts, 4, 3)) - -let y: "foo" | "bar"; ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) - -let b: boolean; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) - -b = x === y; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) ->x : Symbol(x, Decl(stringLiteralsWithEqualityChecks02.ts, 4, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) - -b = "foo" === y ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) - -b = y === "foo"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) - -b = "foo" === "bar"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) - -b = x !== y; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) ->x : Symbol(x, Decl(stringLiteralsWithEqualityChecks02.ts, 4, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) - -b = "foo" !== y ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) - -b = y !== "foo"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks02.ts, 5, 3)) - -b = "foo" !== "bar"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks02.ts, 7, 3)) - - diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.types b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.types deleted file mode 100644 index 39da95ce827ed..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.types +++ /dev/null @@ -1,74 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts === -interface Refrigerator { ->Refrigerator : Refrigerator - - brrr: boolean; ->brrr : boolean -} - -let x: "foo"; ->x : "foo" - -let y: "foo" | "bar"; ->y : "foo" | "bar" - -let b: boolean; ->b : boolean - -b = x === y; ->b = x === y : boolean ->b : boolean ->x === y : boolean ->x : "foo" ->y : "foo" | "bar" - -b = "foo" === y ->b = "foo" === y : boolean ->b : boolean ->"foo" === y : boolean ->"foo" : "foo" ->y : "foo" | "bar" - -b = y === "foo"; ->b = y === "foo" : boolean ->b : boolean ->y === "foo" : boolean ->y : "foo" | "bar" ->"foo" : "foo" - -b = "foo" === "bar"; ->b = "foo" === "bar" : boolean ->b : boolean ->"foo" === "bar" : boolean ->"foo" : "foo" ->"bar" : "bar" - -b = x !== y; ->b = x !== y : boolean ->b : boolean ->x !== y : boolean ->x : "foo" ->y : "foo" | "bar" - -b = "foo" !== y ->b = "foo" !== y : boolean ->b : boolean ->"foo" !== y : boolean ->"foo" : "foo" ->y : "foo" | "bar" - -b = y !== "foo"; ->b = y !== "foo" : boolean ->b : boolean ->y !== "foo" : boolean ->y : "foo" | "bar" ->"foo" : "foo" - -b = "foo" !== "bar"; ->b = "foo" !== "bar" : boolean ->b : boolean ->"foo" !== "bar" : boolean ->"foo" : "foo" ->"bar" : "bar" - - diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt new file mode 100644 index 0000000000000..07bb00ecc3af6 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts(13,5): error TS2365: Operator '===' cannot be applied to types 'string' and '"foo" | Refrigerator'. +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(18,5): error TS2365: Operator '!==' cannot be applied to types 'string' and '"foo" | Refrigerator'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts(21,5): error TS2365: Operator '!==' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts (4 errors) ==== + interface Runnable { + isRunning: boolean; + } + + interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; + } + + let x: string; + let y: "foo" | Refrigerator; + + let b: boolean; + b = x === y; + ~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types 'string' and '"foo" | Refrigerator'. + b = "foo" === y + b = y === "foo"; + b = "foo" === "bar"; + ~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo"' and '"bar"'. + + b = x !== y; + ~~~~~~~ +!!! error TS2365: Operator '!==' cannot be applied to types 'string' and '"foo" | Refrigerator'. + 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/stringLiteralsWithEqualityChecks03.symbols b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.symbols deleted file mode 100644 index c430a8d647521..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.symbols +++ /dev/null @@ -1,59 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts === -interface Runnable { ->Runnable : Symbol(Runnable, Decl(stringLiteralsWithEqualityChecks03.ts, 0, 0)) - - isRunning: boolean; ->isRunning : Symbol(isRunning, Decl(stringLiteralsWithEqualityChecks03.ts, 0, 20)) -} - -interface Refrigerator extends Runnable { ->Refrigerator : Symbol(Refrigerator, Decl(stringLiteralsWithEqualityChecks03.ts, 2, 1)) ->Runnable : Symbol(Runnable, Decl(stringLiteralsWithEqualityChecks03.ts, 0, 0)) - - makesFoodGoBrrr: boolean; ->makesFoodGoBrrr : Symbol(makesFoodGoBrrr, Decl(stringLiteralsWithEqualityChecks03.ts, 4, 41)) -} - -let x: string; ->x : Symbol(x, Decl(stringLiteralsWithEqualityChecks03.ts, 8, 3)) - -let y: "foo" | Refrigerator; ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) ->Refrigerator : Symbol(Refrigerator, Decl(stringLiteralsWithEqualityChecks03.ts, 2, 1)) - -let b: boolean; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) - -b = x === y; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) ->x : Symbol(x, Decl(stringLiteralsWithEqualityChecks03.ts, 8, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) - -b = "foo" === y ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) - -b = y === "foo"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) - -b = "foo" === "bar"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) - -b = x !== y; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) ->x : Symbol(x, Decl(stringLiteralsWithEqualityChecks03.ts, 8, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) - -b = "foo" !== y ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) - -b = y !== "foo"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks03.ts, 9, 3)) - -b = "foo" !== "bar"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks03.ts, 11, 3)) - - diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.types b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.types deleted file mode 100644 index dede9108f6563..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.types +++ /dev/null @@ -1,83 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts === -interface Runnable { ->Runnable : Runnable - - isRunning: boolean; ->isRunning : boolean -} - -interface Refrigerator extends Runnable { ->Refrigerator : Refrigerator ->Runnable : Runnable - - makesFoodGoBrrr: boolean; ->makesFoodGoBrrr : boolean -} - -let x: string; ->x : string - -let y: "foo" | Refrigerator; ->y : "foo" | Refrigerator ->Refrigerator : Refrigerator - -let b: boolean; ->b : boolean - -b = x === y; ->b = x === y : boolean ->b : boolean ->x === y : boolean ->x : string ->y : "foo" | Refrigerator - -b = "foo" === y ->b = "foo" === y : boolean ->b : boolean ->"foo" === y : boolean ->"foo" : "foo" ->y : "foo" | Refrigerator - -b = y === "foo"; ->b = y === "foo" : boolean ->b : boolean ->y === "foo" : boolean ->y : "foo" | Refrigerator ->"foo" : "foo" - -b = "foo" === "bar"; ->b = "foo" === "bar" : boolean ->b : boolean ->"foo" === "bar" : boolean ->"foo" : "foo" ->"bar" : "bar" - -b = x !== y; ->b = x !== y : boolean ->b : boolean ->x !== y : boolean ->x : string ->y : "foo" | Refrigerator - -b = "foo" !== y ->b = "foo" !== y : boolean ->b : boolean ->"foo" !== y : boolean ->"foo" : "foo" ->y : "foo" | Refrigerator - -b = y !== "foo"; ->b = y !== "foo" : boolean ->b : boolean ->y !== "foo" : boolean ->y : "foo" | Refrigerator ->"foo" : "foo" - -b = "foo" !== "bar"; ->b = "foo" !== "bar" : boolean ->b : boolean ->"foo" !== "bar" : boolean ->"foo" : "foo" ->"bar" : "bar" - - diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt new file mode 100644 index 0000000000000..407e9dfa2b1b1 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts(13,5): error TS2365: Operator '==' cannot be applied to types 'string' and '"foo" | Refrigerator'. +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(18,5): error TS2365: Operator '!=' cannot be applied to types 'string' and '"foo" | Refrigerator'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts(21,5): error TS2365: Operator '!=' cannot be applied to types '"foo"' and '"bar"'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts (4 errors) ==== + interface Runnable { + isRunning: boolean; + } + + interface Refrigerator { + makesFoodGoBrrr: boolean; + } + + let x: string; + let y: "foo" | Refrigerator; + + let b: boolean; + b = x == y; + ~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types 'string' and '"foo" | Refrigerator'. + b = "foo" == y + b = y == "foo"; + b = "foo" == "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"foo"' and '"bar"'. + + b = x != y; + ~~~~~~ +!!! error TS2365: Operator '!=' cannot be applied to types 'string' and '"foo" | Refrigerator'. + 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/stringLiteralsWithEqualityChecks04.symbols b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.symbols deleted file mode 100644 index f4325d4b184df..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.symbols +++ /dev/null @@ -1,58 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts === -interface Runnable { ->Runnable : Symbol(Runnable, Decl(stringLiteralsWithEqualityChecks04.ts, 0, 0)) - - isRunning: boolean; ->isRunning : Symbol(isRunning, Decl(stringLiteralsWithEqualityChecks04.ts, 0, 20)) -} - -interface Refrigerator { ->Refrigerator : Symbol(Refrigerator, Decl(stringLiteralsWithEqualityChecks04.ts, 2, 1)) - - makesFoodGoBrrr: boolean; ->makesFoodGoBrrr : Symbol(makesFoodGoBrrr, Decl(stringLiteralsWithEqualityChecks04.ts, 4, 24)) -} - -let x: string; ->x : Symbol(x, Decl(stringLiteralsWithEqualityChecks04.ts, 8, 3)) - -let y: "foo" | Refrigerator; ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) ->Refrigerator : Symbol(Refrigerator, Decl(stringLiteralsWithEqualityChecks04.ts, 2, 1)) - -let b: boolean; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) - -b = x == y; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) ->x : Symbol(x, Decl(stringLiteralsWithEqualityChecks04.ts, 8, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) - -b = "foo" == y ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) - -b = y == "foo"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) - -b = "foo" == "bar"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) - -b = x != y; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) ->x : Symbol(x, Decl(stringLiteralsWithEqualityChecks04.ts, 8, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) - -b = "foo" != y ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) - -b = y != "foo"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) ->y : Symbol(y, Decl(stringLiteralsWithEqualityChecks04.ts, 9, 3)) - -b = "foo" != "bar"; ->b : Symbol(b, Decl(stringLiteralsWithEqualityChecks04.ts, 11, 3)) - - diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.types b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.types deleted file mode 100644 index e18f9255af742..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.types +++ /dev/null @@ -1,82 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts === -interface Runnable { ->Runnable : Runnable - - isRunning: boolean; ->isRunning : boolean -} - -interface Refrigerator { ->Refrigerator : Refrigerator - - makesFoodGoBrrr: boolean; ->makesFoodGoBrrr : boolean -} - -let x: string; ->x : string - -let y: "foo" | Refrigerator; ->y : "foo" | Refrigerator ->Refrigerator : Refrigerator - -let b: boolean; ->b : boolean - -b = x == y; ->b = x == y : boolean ->b : boolean ->x == y : boolean ->x : string ->y : "foo" | Refrigerator - -b = "foo" == y ->b = "foo" == y : boolean ->b : boolean ->"foo" == y : boolean ->"foo" : "foo" ->y : "foo" | Refrigerator - -b = y == "foo"; ->b = y == "foo" : boolean ->b : boolean ->y == "foo" : boolean ->y : "foo" | Refrigerator ->"foo" : "foo" - -b = "foo" == "bar"; ->b = "foo" == "bar" : boolean ->b : boolean ->"foo" == "bar" : boolean ->"foo" : "foo" ->"bar" : "bar" - -b = x != y; ->b = x != y : boolean ->b : boolean ->x != y : boolean ->x : string ->y : "foo" | Refrigerator - -b = "foo" != y ->b = "foo" != y : boolean ->b : boolean ->"foo" != y : boolean ->"foo" : "foo" ->y : "foo" | Refrigerator - -b = y != "foo"; ->b = y != "foo" : boolean ->b : boolean ->y != "foo" : boolean ->y : "foo" | Refrigerator ->"foo" : "foo" - -b = "foo" != "bar"; ->b = "foo" != "bar" : boolean ->b : boolean ->"foo" != "bar" : boolean ->"foo" : "foo" ->"bar" : "bar" - - diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt new file mode 100644 index 0000000000000..9e210c6692158 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements01.ts(7,10): error TS2322: Type '"bar"' is not assignable 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 TS2322: Type '"bar"' is not assignable to type '"foo"'. + break; + case y: + y; + break; + } + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.symbols b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.symbols deleted file mode 100644 index 441002c0d1e9b..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.symbols +++ /dev/null @@ -1,23 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements01.ts === -let x: "foo"; ->x : Symbol(x, Decl(stringLiteralsWithSwitchStatements01.ts, 0, 3)) - -let y: "foo" | "bar"; ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements01.ts, 1, 3)) - -switch (x) { ->x : Symbol(x, Decl(stringLiteralsWithSwitchStatements01.ts, 0, 3)) - - case "foo": - break; - case "bar": - break; - case y: ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements01.ts, 1, 3)) - - y; ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements01.ts, 1, 3)) - - break; -} - diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.types deleted file mode 100644 index 2ef4cb32e0d28..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.types +++ /dev/null @@ -1,27 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements01.ts === -let x: "foo"; ->x : "foo" - -let y: "foo" | "bar"; ->y : "foo" | "bar" - -switch (x) { ->x : "foo" - - case "foo": ->"foo" : "foo" - - break; - case "bar": ->"bar" : "bar" - - break; - case y: ->y : "foo" | "bar" - - y; ->y : "foo" | "bar" - - 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.symbols b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.symbols deleted file mode 100644 index 2888d4b62d431..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements02.symbols +++ /dev/null @@ -1,43 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements02.ts === -let x: "foo"; ->x : Symbol(x, Decl(stringLiteralsWithSwitchStatements02.ts, 0, 3)) - -let y: "foo" | "bar"; ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) - -let b: boolean; ->b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) - -b = x == y; ->b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) ->x : Symbol(x, Decl(stringLiteralsWithSwitchStatements02.ts, 0, 3)) ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) - -b = "foo" == y ->b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) - -b = y == "foo"; ->b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) - -b = "foo" == "bar"; ->b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) - -b = x != y; ->b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) ->x : Symbol(x, Decl(stringLiteralsWithSwitchStatements02.ts, 0, 3)) ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) - -b = "foo" != y ->b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) - -b = y != "foo"; ->b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements02.ts, 1, 3)) - -b = "foo" != "bar"; ->b : Symbol(b, Decl(stringLiteralsWithSwitchStatements02.ts, 3, 3)) - - diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements02.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements02.types deleted file mode 100644 index bff18c95c8b5e..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements02.types +++ /dev/null @@ -1,67 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements02.ts === -let x: "foo"; ->x : "foo" - -let y: "foo" | "bar"; ->y : "foo" | "bar" - -let b: boolean; ->b : boolean - -b = x == y; ->b = x == y : boolean ->b : boolean ->x == y : boolean ->x : "foo" ->y : "foo" | "bar" - -b = "foo" == y ->b = "foo" == y : boolean ->b : boolean ->"foo" == y : boolean ->"foo" : "foo" ->y : "foo" | "bar" - -b = y == "foo"; ->b = y == "foo" : boolean ->b : boolean ->y == "foo" : boolean ->y : "foo" | "bar" ->"foo" : "foo" - -b = "foo" == "bar"; ->b = "foo" == "bar" : boolean ->b : boolean ->"foo" == "bar" : boolean ->"foo" : "foo" ->"bar" : "bar" - -b = x != y; ->b = x != y : boolean ->b : boolean ->x != y : boolean ->x : "foo" ->y : "foo" | "bar" - -b = "foo" != y ->b = "foo" != y : boolean ->b : boolean ->"foo" != y : boolean ->"foo" : "foo" ->y : "foo" | "bar" - -b = y != "foo"; ->b = y != "foo" : boolean ->b : boolean ->y != "foo" : boolean ->y : "foo" | "bar" ->"foo" : "foo" - -b = "foo" != "bar"; ->b = "foo" != "bar" : boolean ->b : boolean ->"foo" != "bar" : boolean ->"foo" : "foo" ->"bar" : "bar" - - diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt new file mode 100644 index 0000000000000..503cb97350d49 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements03.ts(7,10): error TS2322: Type '"bar"' is not assignable 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 TS2322: Type '"bar"' is not assignable 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.symbols b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.symbols deleted file mode 100644 index 2fee23e937abf..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.symbols +++ /dev/null @@ -1,28 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements03.ts === -let x: "foo"; ->x : Symbol(x, Decl(stringLiteralsWithSwitchStatements03.ts, 0, 3)) - -let y: "foo" | "bar"; ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements03.ts, 1, 3)) - -switch ("foo") { - case "foo": - break; - case "bar": - break; - case x: ->x : Symbol(x, Decl(stringLiteralsWithSwitchStatements03.ts, 0, 3)) - - x; ->x : Symbol(x, Decl(stringLiteralsWithSwitchStatements03.ts, 0, 3)) - - break; - case y: ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements03.ts, 1, 3)) - - y; ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements03.ts, 1, 3)) - - break; -} - diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.types deleted file mode 100644 index 65da543566d26..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.types +++ /dev/null @@ -1,34 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements03.ts === -let x: "foo"; ->x : "foo" - -let y: "foo" | "bar"; ->y : "foo" | "bar" - -switch ("foo") { ->"foo" : "foo" - - 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..2ef632ab34382 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(9,10): error TS2322: Type '"bar"' is not assignable to type '"foo"'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts (1 errors) ==== + let x: "foo"; + let y: "foo" | "bar"; + + declare function randBool(): boolean; + + switch (x) { + case randBool() ? "foo" : "baz": + break; + case (("bar")): + ~~~~~~~~~ +!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. + break; + case (x, y, "baz"): + x; + break; + case (("foo" || "bar")): + y; + break; + } + \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.symbols b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.symbols deleted file mode 100644 index 7c264baf64e12..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.symbols +++ /dev/null @@ -1,34 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts === -let x: "foo"; ->x : Symbol(x, Decl(stringLiteralsWithSwitchStatements05.ts, 0, 3)) - -let y: "foo" | "bar"; ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements05.ts, 1, 3)) - -declare function randBool(): boolean; ->randBool : Symbol(randBool, Decl(stringLiteralsWithSwitchStatements05.ts, 1, 21)) - -switch (x) { ->x : Symbol(x, Decl(stringLiteralsWithSwitchStatements05.ts, 0, 3)) - - case randBool() ? "foo" : "baz": ->randBool : Symbol(randBool, Decl(stringLiteralsWithSwitchStatements05.ts, 1, 21)) - - break; - case (("bar")): - break; - case (x, y, "baz"): ->x : Symbol(x, Decl(stringLiteralsWithSwitchStatements05.ts, 0, 3)) ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements05.ts, 1, 3)) - - x; ->x : Symbol(x, Decl(stringLiteralsWithSwitchStatements05.ts, 0, 3)) - - break; - case (("foo" || "bar")): - y; ->y : Symbol(y, Decl(stringLiteralsWithSwitchStatements05.ts, 1, 3)) - - break; -} - diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.types b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.types deleted file mode 100644 index f62c06e5a0419..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.types +++ /dev/null @@ -1,52 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts === -let x: "foo"; ->x : "foo" - -let y: "foo" | "bar"; ->y : "foo" | "bar" - -declare function randBool(): boolean; ->randBool : () => boolean - -switch (x) { ->x : "foo" - - case randBool() ? "foo" : "baz": ->randBool() ? "foo" : "baz" : "foo" | "baz" ->randBool() : boolean ->randBool : () => boolean ->"foo" : "foo" ->"baz" : "baz" - - break; - case (("bar")): ->(("bar")) : "bar" ->("bar") : "bar" ->"bar" : "bar" - - break; - case (x, y, "baz"): ->(x, y, "baz") : string ->x, y, "baz" : string ->x, y : "foo" | "bar" ->x : "foo" ->y : "foo" | "bar" ->"baz" : string - - x; ->x : "foo" - - break; - case (("foo" || "bar")): ->(("foo" || "bar")) : "foo" | "bar" ->("foo" || "bar") : "foo" | "bar" ->"foo" || "bar" : "foo" | "bar" ->"foo" : "foo" ->"bar" : "bar" - - y; ->y : "foo" | "bar" - - break; -} - diff --git a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt new file mode 100644 index 0000000000000..c6ab0729d86ea --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts(3,9): error TS2352: Neither type '"foo"' nor type '"bar"' is assignable to the other. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts(4,9): error TS2352: Neither type '"bar"' nor type '"foo"' is assignable to the other. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts(7,9): error TS2352: Neither type '"foo" | "bar"' nor type '"baz"' is assignable to the other. + Type '"foo"' is not assignable to type '"baz"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts(8,9): error TS2352: Neither type '"baz"' nor type '"foo" | "bar"' is assignable to the other. + Type '"baz"' is not assignable to type '"bar"'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts (4 errors) ==== + let fooOrBar: "foo" | "bar"; + + let a = "foo" as "bar"; + ~~~~~~~~~~~~~~ +!!! error TS2352: Neither type '"foo"' nor type '"bar"' is assignable to the other. + let b = "bar" as "foo"; + ~~~~~~~~~~~~~~ +!!! error TS2352: Neither type '"bar"' nor type '"foo"' is assignable to the other. + let c = fooOrBar as "foo"; + let d = fooOrBar as "bar"; + let e = fooOrBar as "baz"; + ~~~~~~~~~~~~~~~~~ +!!! error TS2352: Neither type '"foo" | "bar"' nor type '"baz"' is assignable to the other. +!!! error TS2352: Type '"foo"' is not assignable to type '"baz"'. + let f = "baz" as typeof fooOrBar; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Neither type '"baz"' nor type '"foo" | "bar"' is assignable to the other. +!!! error TS2352: Type '"baz"' is not assignable to type '"bar"'. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.symbols b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.symbols deleted file mode 100644 index baeda78581516..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.symbols +++ /dev/null @@ -1,26 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts === -let fooOrBar: "foo" | "bar"; ->fooOrBar : Symbol(fooOrBar, Decl(stringLiteralsWithTypeAssertions01.ts, 0, 3)) - -let a = "foo" as "bar"; ->a : Symbol(a, Decl(stringLiteralsWithTypeAssertions01.ts, 2, 3)) - -let b = "bar" as "foo"; ->b : Symbol(b, Decl(stringLiteralsWithTypeAssertions01.ts, 3, 3)) - -let c = fooOrBar as "foo"; ->c : Symbol(c, Decl(stringLiteralsWithTypeAssertions01.ts, 4, 3)) ->fooOrBar : Symbol(fooOrBar, Decl(stringLiteralsWithTypeAssertions01.ts, 0, 3)) - -let d = fooOrBar as "bar"; ->d : Symbol(d, Decl(stringLiteralsWithTypeAssertions01.ts, 5, 3)) ->fooOrBar : Symbol(fooOrBar, Decl(stringLiteralsWithTypeAssertions01.ts, 0, 3)) - -let e = fooOrBar as "baz"; ->e : Symbol(e, Decl(stringLiteralsWithTypeAssertions01.ts, 6, 3)) ->fooOrBar : Symbol(fooOrBar, Decl(stringLiteralsWithTypeAssertions01.ts, 0, 3)) - -let f = "baz" as typeof fooOrBar; ->f : Symbol(f, Decl(stringLiteralsWithTypeAssertions01.ts, 7, 3)) ->fooOrBar : Symbol(fooOrBar, Decl(stringLiteralsWithTypeAssertions01.ts, 0, 3)) - diff --git a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.types b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.types deleted file mode 100644 index 046afbcf53a5c..0000000000000 --- a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.types +++ /dev/null @@ -1,35 +0,0 @@ -=== tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts === -let fooOrBar: "foo" | "bar"; ->fooOrBar : "foo" | "bar" - -let a = "foo" as "bar"; ->a : "bar" ->"foo" as "bar" : "bar" ->"foo" : "foo" - -let b = "bar" as "foo"; ->b : "foo" ->"bar" as "foo" : "foo" ->"bar" : "bar" - -let c = fooOrBar as "foo"; ->c : "foo" ->fooOrBar as "foo" : "foo" ->fooOrBar : "foo" | "bar" - -let d = fooOrBar as "bar"; ->d : "bar" ->fooOrBar as "bar" : "bar" ->fooOrBar : "foo" | "bar" - -let e = fooOrBar as "baz"; ->e : "baz" ->fooOrBar as "baz" : "baz" ->fooOrBar : "foo" | "bar" - -let f = "baz" as typeof fooOrBar; ->f : "foo" | "bar" ->"baz" as typeof fooOrBar : "foo" | "bar" ->"baz" : "baz" ->fooOrBar : "foo" | "bar" - diff --git a/tests/baselines/reference/switchBreakStatements.errors.txt b/tests/baselines/reference/switchBreakStatements.errors.txt new file mode 100644 index 0000000000000..794549413ce66 --- /dev/null +++ b/tests/baselines/reference/switchBreakStatements.errors.txt @@ -0,0 +1,92 @@ +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(3,10): error TS2322: Type '"a"' is not assignable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(9,10): error TS2322: Type '"a"' is not assignable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(16,10): error TS2322: Type '"a"' is not assignable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(22,10): error TS2322: Type '"a"' is not assignable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(25,18): error TS2322: Type '"a"' is not assignable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(31,10): error TS2322: Type '"a"' is not assignable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(34,18): error TS2322: Type '"a"' is not assignable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(41,10): error TS2322: Type '"a"' is not assignable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(43,18): error TS2322: Type '"a"' is not assignable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(45,26): error TS2322: Type '"a"' is not assignable to type '""'. +tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(49,34): error TS2322: Type '"a"' is not assignable to type '""'. + + +==== tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts (11 errors) ==== + + switch ('') { + case 'a': + ~~~ +!!! error TS2322: Type '"a"' is not assignable to type '""'. + break; + } + + ONE: + switch ('') { + case 'a': + ~~~ +!!! error TS2322: Type '"a"' is not assignable to type '""'. + break ONE; + } + + TWO: + THREE: + switch ('') { + case 'a': + ~~~ +!!! error TS2322: Type '"a"' is not assignable to type '""'. + break THREE; + } + + FOUR: + switch ('') { + case 'a': + ~~~ +!!! error TS2322: Type '"a"' is not assignable to type '""'. + FIVE: + switch ('') { + case 'a': + ~~~ +!!! error TS2322: Type '"a"' is not assignable to type '""'. + break FOUR; + } + } + + switch ('') { + case 'a': + ~~~ +!!! error TS2322: Type '"a"' is not assignable to type '""'. + SIX: + switch ('') { + case 'a': + ~~~ +!!! error TS2322: Type '"a"' is not assignable to type '""'. + break SIX; + } + } + + SEVEN: + switch ('') { + case 'a': + ~~~ +!!! error TS2322: Type '"a"' is not assignable to type '""'. + switch ('') { + case 'a': + ~~~ +!!! error TS2322: Type '"a"' is not assignable to type '""'. + switch ('') { + case 'a': + ~~~ +!!! error TS2322: Type '"a"' is not assignable to type '""'. + break SEVEN; + EIGHT: + switch ('') { + case 'a': + ~~~ +!!! error TS2322: Type '"a"' is not assignable to type '""'. + var fn = function () { } + break EIGHT; + } + } + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/switchBreakStatements.symbols b/tests/baselines/reference/switchBreakStatements.symbols deleted file mode 100644 index dde7ca028ccd3..0000000000000 --- a/tests/baselines/reference/switchBreakStatements.symbols +++ /dev/null @@ -1,59 +0,0 @@ -=== tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts === - -switch ('') { - case 'a': - break; -} - -ONE: -switch ('') { - case 'a': - break ONE; -} - -TWO: -THREE: -switch ('') { - case 'a': - break THREE; -} - -FOUR: -switch ('') { - case 'a': - FIVE: - switch ('') { - case 'a': - break FOUR; - } -} - -switch ('') { - case 'a': - SIX: - switch ('') { - case 'a': - break SIX; - } -} - -SEVEN: -switch ('') { - case 'a': - switch ('') { - case 'a': - switch ('') { - case 'a': - break SEVEN; - EIGHT: - switch ('') { - case 'a': - var fn = function () { } ->fn : Symbol(fn, Decl(switchBreakStatements.ts, 49, 35)) - - break EIGHT; - } - } - } -} - diff --git a/tests/baselines/reference/switchBreakStatements.types b/tests/baselines/reference/switchBreakStatements.types deleted file mode 100644 index bc8391a325559..0000000000000 --- a/tests/baselines/reference/switchBreakStatements.types +++ /dev/null @@ -1,127 +0,0 @@ -=== tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts === - -switch ('') { ->'' : "" - - case 'a': ->'a' : "a" - - break; -} - -ONE: ->ONE : any - -switch ('') { ->'' : "" - - case 'a': ->'a' : "a" - - break ONE; ->ONE : any -} - -TWO: ->TWO : any - -THREE: ->THREE : any - -switch ('') { ->'' : "" - - case 'a': ->'a' : "a" - - break THREE; ->THREE : any -} - -FOUR: ->FOUR : any - -switch ('') { ->'' : "" - - case 'a': ->'a' : "a" - - FIVE: ->FIVE : any - - switch ('') { ->'' : "" - - case 'a': ->'a' : "a" - - break FOUR; ->FOUR : any - } -} - -switch ('') { ->'' : "" - - case 'a': ->'a' : "a" - - SIX: ->SIX : any - - switch ('') { ->'' : "" - - case 'a': ->'a' : "a" - - break SIX; ->SIX : any - } -} - -SEVEN: ->SEVEN : any - -switch ('') { ->'' : "" - - case 'a': ->'a' : "a" - - switch ('') { ->'' : "" - - case 'a': ->'a' : "a" - - switch ('') { ->'' : "" - - case 'a': ->'a' : "a" - - break SEVEN; ->SEVEN : any - - EIGHT: ->EIGHT : any - - switch ('') { ->'' : "" - - case 'a': ->'a' : "a" - - var fn = function () { } ->fn : () => void ->function () { } : () => void - - break EIGHT; ->EIGHT : any - } - } - } -} - From e452955f053a88de23b76823dd6be829008ce8c9 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Dec 2015 17:17:29 -0800 Subject: [PATCH 07/27] Amended tests. --- .../stringLiteralsWithEqualityChecks01.ts | 8 +++++ .../stringLiteralsWithEqualityChecks02.ts | 30 +++++++++++-------- .../stringLiteralsWithEqualityChecks03.ts | 9 +++++- .../stringLiteralsWithEqualityChecks04.ts | 11 +++++-- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts index fd9864465778e..3179be186ea48 100644 --- a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts @@ -6,9 +6,17 @@ 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 index 2d532382caea1..25a687a8941a8 100644 --- a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts @@ -1,18 +1,22 @@ -interface Refrigerator { - brrr: boolean; -} - -let x: "foo"; +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"; +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 = 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 index a377698383232..b4fb064818728 100644 --- a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts @@ -14,9 +14,16 @@ 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 index f4181a3ca6b46..01e1c0896fb2a 100644 --- a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts @@ -2,7 +2,7 @@ isRunning: boolean; } -interface Refrigerator { +interface Refrigerator extends Runnable { makesFoodGoBrrr: boolean; } @@ -14,9 +14,16 @@ 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; From ced65acb40a2ad859e56f26d29966ebdf2d7a582 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Dec 2015 17:21:38 -0800 Subject: [PATCH 08/27] Accepted baselines. --- ...ingLiteralsWithEqualityChecks01.errors.txt | 24 ++++++++- .../stringLiteralsWithEqualityChecks01.js | 16 ++++++ ...ingLiteralsWithEqualityChecks02.errors.txt | 54 ++++++++++++------- .../stringLiteralsWithEqualityChecks02.js | 52 +++++++++++------- ...ingLiteralsWithEqualityChecks03.errors.txt | 27 ++++++++-- .../stringLiteralsWithEqualityChecks03.js | 17 +++++- ...ingLiteralsWithEqualityChecks04.errors.txt | 29 ++++++++-- .../stringLiteralsWithEqualityChecks04.js | 19 ++++++- 8 files changed, 185 insertions(+), 53 deletions(-) diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt index 7bb5c04b5249d..844763519520f 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.errors.txt @@ -1,8 +1,12 @@ 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(13,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 (2 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.ts (6 errors) ==== let x: "foo"; let y: "foo" | "bar"; @@ -13,6 +17,14 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.t 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 @@ -20,5 +32,13 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks01.t 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 index 7b7741dfc76ed..fc08a354338d2 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks01.js +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks01.js @@ -7,11 +7,19 @@ 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; @@ -23,7 +31,15 @@ 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 index 25b0ee2368a62..7d6d01440f67f 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.errors.txt @@ -1,28 +1,44 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks02.ts(12,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(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 (2 errors) ==== - interface Refrigerator { - brrr: boolean; - } - +==== 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 = 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 = 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 index 4333e16bf5f82..b31246251a393 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks02.js +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks02.js @@ -1,21 +1,25 @@ //// [stringLiteralsWithEqualityChecks02.ts] -interface Refrigerator { - brrr: boolean; -} - 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"; +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 = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; @@ -23,11 +27,19 @@ b = "foo" !== "bar"; 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"; +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 index 07bb00ecc3af6..2ec298a91f1c4 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt @@ -1,10 +1,14 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts(13,5): error TS2365: Operator '===' cannot be applied to types 'string' and '"foo" | Refrigerator'. 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(18,5): error TS2365: Operator '!==' cannot be applied to types 'string' and '"foo" | Refrigerator'. -tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts(21,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(22,5): error TS2365: Operator '!==' cannot be applied to types 'string' 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 (4 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts (8 errors) ==== interface Runnable { isRunning: boolean; } @@ -25,6 +29,14 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.t 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; ~~~~~~~ @@ -34,5 +46,12 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.t 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 index 0bb42f01c2181..e418c73ff691b 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.js +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.js @@ -15,12 +15,19 @@ 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] @@ -31,7 +38,15 @@ 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 index 407e9dfa2b1b1..9b714c803851e 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt @@ -1,15 +1,19 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts(13,5): error TS2365: Operator '==' cannot be applied to types 'string' and '"foo" | Refrigerator'. 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(18,5): error TS2365: Operator '!=' cannot be applied to types 'string' and '"foo" | Refrigerator'. -tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts(21,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(22,5): error TS2365: Operator '!=' cannot be applied to types 'string' 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 (4 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts (8 errors) ==== interface Runnable { isRunning: boolean; } - interface Refrigerator { + interface Refrigerator extends Runnable { makesFoodGoBrrr: boolean; } @@ -25,6 +29,14 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.t 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; ~~~~~~ @@ -34,5 +46,12 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.t 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 index 7f78f83b43772..52f43cdfa5eef 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.js +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.js @@ -3,7 +3,7 @@ interface Runnable { isRunning: boolean; } -interface Refrigerator { +interface Refrigerator extends Runnable { makesFoodGoBrrr: boolean; } @@ -15,12 +15,19 @@ 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] @@ -31,7 +38,15 @@ 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; From 881b52dfe37005e7705009799a1d364961eb457a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 21 Dec 2015 22:28:17 -0800 Subject: [PATCH 09/27] Separated logic out to 'shouldAcquireLiteralType'. --- src/compiler/checker.ts | 108 +++++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 39 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3cb8b994b5d39..415db99c4eb4c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7334,7 +7334,7 @@ namespace ts { return undefined; } - function getContextualTypeForBinaryOperand(node: Expression, literalNode: StringLiteral): Type { + function getContextualTypeForBinaryOperand(node: Expression): Type { const binaryExpression = node.parent; const operator = binaryExpression.operatorToken.kind; @@ -7345,24 +7345,14 @@ namespace ts { } return undefined; } - - switch (operator) { - case SyntaxKind.BarBarToken: - // When an || expression has a contextual type, the operands are contextually typed by that type. When an || - // expression has no contextual type, the right operand is contextually typed by the type of the left operand. - let type = getContextualTypeWorker(binaryExpression, literalNode); - if (!type && node === binaryExpression.right) { - type = checkExpression(binaryExpression.left); - } - return type; - case SyntaxKind.EqualsEqualsEqualsToken: - case SyntaxKind.ExclamationEqualsEqualsToken: - case SyntaxKind.EqualsEqualsToken: - case SyntaxKind.ExclamationEqualsToken: - if (literalNode) { - return getStringLiteralTypeForText(literalNode.text); - } - break; + else if (operator === SyntaxKind.BarBarToken) { + // When an || expression has a contextual type, the operands are contextually typed by that type. When an || + // expression has no contextual type, the right operand is contextually typed by the type of the left operand. + let type = getContextualType(binaryExpression); + if (!type && node === binaryExpression.right) { + type = checkExpression(binaryExpression.left); + } + return type; } return undefined; @@ -7472,9 +7462,9 @@ namespace ts { } // In a contextually typed conditional expression, the true/false expressions are contextually typed by the same type. - function getContextualTypeForConditionalOperand(node: Expression, literalNode: StringLiteral): Type { + function getContextualTypeForConditionalOperand(node: Expression): Type { const conditional = node.parent; - return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualTypeWorker(conditional, literalNode) : undefined; + return node === conditional.whenTrue || node === conditional.whenFalse ? getContextualType(conditional) : undefined; } function getContextualTypeForJsxExpression(expr: JsxExpression | JsxSpreadAttribute): Type { @@ -7522,14 +7512,7 @@ namespace ts { * @returns the contextual type of an expression. */ function getContextualType(node: Expression): Type { - return getContextualTypeWorker(node, /*literalNode*/ undefined); - } - - function getLiteralContextualType(literalNode: StringLiteral) { - return getContextualTypeWorker(literalNode, literalNode); - } - function getContextualTypeWorker(node: Expression, literalNode: StringLiteral): Type { if (isInsideWithStatementBody(node)) { // We cannot answer semantic questions within a with block, do not proceed any further return undefined; @@ -7557,31 +7540,79 @@ namespace ts { case SyntaxKind.AsExpression: return getTypeFromTypeNode((parent).type); case SyntaxKind.BinaryExpression: - return getContextualTypeForBinaryOperand(node, literalNode); + return getContextualTypeForBinaryOperand(node); case SyntaxKind.PropertyAssignment: return getContextualTypeForObjectLiteralElement(parent); case SyntaxKind.ArrayLiteralExpression: return getContextualTypeForElementExpression(node); case SyntaxKind.ConditionalExpression: - return getContextualTypeForConditionalOperand(node, literalNode); + return getContextualTypeForConditionalOperand(node); case SyntaxKind.TemplateSpan: Debug.assert(parent.parent.kind === SyntaxKind.TemplateExpression); return getContextualTypeForSubstitutionExpression(parent.parent, node); case SyntaxKind.ParenthesizedExpression: - return getContextualTypeWorker(parent, literalNode); + return getContextualType(parent); case SyntaxKind.JsxExpression: case SyntaxKind.JsxSpreadAttribute: return getContextualTypeForJsxExpression(parent); - case SyntaxKind.SwitchStatement: - case SyntaxKind.CaseClause: - if (literalNode) { - return getStringLiteralTypeForText(literalNode.text); - } - break; } return undefined; } + function shouldAcquireLiteralType(literalNode: StringLiteral) { + + let current: Node = literalNode; + while (true) { + const { parent } = current; + switch (parent.kind) { + // The operand of a 'switch' should get a literal type. + case SyntaxKind.SwitchStatement: + return current === (parent as SwitchStatement).expression; + + // The tested expression of a 'case' clause should get a literal type. + case SyntaxKind.CaseClause: + return current === (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 current === binaryExpr.left || current === binaryExpr.right; + + case SyntaxKind.BarBarToken: + current = parent; + continue; + + } + break; + + case SyntaxKind.ConditionalExpression: + case SyntaxKind.ParenthesizedExpression: + current = parent; + continue; + } + + // This is not a node we can account for. + // Let contextual typing take over. + break; + } + + // We could perform our walk, check if 'current' is an expression + // when we get to an unsupported node, and then get the contextual type on that. + // That would save a few steps through "pass-though" nodes, + // but the checks in 'isExpression' seem so involved that it would probably + // be better to simply grab the contextual type first and then see if we + // need to do any work. + const contextualType = getContextualType(literalNode); + return !!contextualType && contextualTypeIsStringLiteralType(contextualType); + } + + // 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 { @@ -10885,8 +10916,7 @@ namespace ts { } function checkStringLiteralExpression(node: StringLiteral): Type { - const contextualType = getLiteralContextualType(node); - if (contextualType && contextualTypeIsStringLiteralType(contextualType)) { + if (shouldAcquireLiteralType(node)) { return getStringLiteralTypeForText(node.text); } From 8365410dc9312cecbb293aa6e0c1ab69570329f6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 22 Dec 2015 00:10:59 -0800 Subject: [PATCH 10/27] Amended comment. --- src/compiler/checker.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 415db99c4eb4c..346907248f878 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7602,12 +7602,14 @@ namespace ts { break; } - // We could perform our walk, check if 'current' is an expression - // when we get to an unsupported node, and then get the contextual type on that. - // That would save a few steps through "pass-though" nodes, - // but the checks in 'isExpression' seem so involved that it would probably - // be better to simply grab the contextual type first and then see if we - // need to do any work. + // We haven't found a "literal match location" (i.e. a location that signals + // a literal should get a literal type). Check whether the contextual type + // has a literal type in it. + // + // We could perform our walk, check if 'current' is an expression when we get to a + // a node that isn't a match location, and then get the contextual type of that. + // That would save a few steps but the checks in 'isExpression' seem so involved + // that it would probably be better to simply grab the contextual type if we didn't. const contextualType = getContextualType(literalNode); return !!contextualType && contextualTypeIsStringLiteralType(contextualType); } From 58580edf7cce5910734291f74c4840400e95771e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 22 Dec 2015 14:45:28 -0800 Subject: [PATCH 11/27] Rewrote loop, amended comment. --- src/compiler/checker.ts | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 346907248f878..f988879c88356 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7560,10 +7560,10 @@ namespace ts { } function shouldAcquireLiteralType(literalNode: StringLiteral) { + loop: for (let current: Node = literalNode, parent = current.parent; + parent; + current = parent, parent = current.parent) { - let current: Node = literalNode; - while (true) { - const { parent } = current; switch (parent.kind) { // The operand of a 'switch' should get a literal type. case SyntaxKind.SwitchStatement: @@ -7585,31 +7585,34 @@ namespace ts { return current === binaryExpr.left || current === binaryExpr.right; case SyntaxKind.BarBarToken: - current = parent; - continue; - + continue loop; } - break; + break loop; case SyntaxKind.ConditionalExpression: + const conditional = parent as ConditionalExpression; + if (current === conditional.whenTrue || current === conditional.whenFalse) { + continue loop; + } + break loop; + case SyntaxKind.ParenthesizedExpression: - current = parent; - continue; - } + continue loop; - // This is not a node we can account for. - // Let contextual typing take over. - break; + default: + break loop; + } } // We haven't found a "literal match location" (i.e. a location that signals // a literal should get a literal type). Check whether the contextual type - // has a literal type in it. + // of the literal has a literal type in it. // - // We could perform our walk, check if 'current' is an expression when we get to a - // a node that isn't a match location, and then get the contextual type of that. - // That would save a few steps but the checks in 'isExpression' seem so involved - // that it would probably be better to simply grab the contextual type if we didn't. + // You might ask why we're not passing 'current' or 'parent' into 'getContextualType' + // since we've already walked up several nodes anyway. This is not correct + // because several nodes *do not* strictly acquire a contextual type from their parents. + // An example of this is '||' expressions, whose right operand is contextually typed by + // its left operand if it could not acquire a contextual type from its parent. const contextualType = getContextualType(literalNode); return !!contextualType && contextualTypeIsStringLiteralType(contextualType); } From 069ff33c77f602c9fc5a55d2771a1010469f5dac Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 22 Dec 2015 16:17:01 -0800 Subject: [PATCH 12/27] Add conditional expressions, be more conservative in checks for '||'. --- src/compiler/checker.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f988879c88356..a55b2e908ae8f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7585,8 +7585,13 @@ namespace ts { return current === binaryExpr.left || current === binaryExpr.right; case SyntaxKind.BarBarToken: - continue loop; + if (current === binaryExpr.left || current === binaryExpr.right) { + continue loop; + } + break loop; } + + // No binary operators apply. Try to get the contextual type below. break loop; case SyntaxKind.ConditionalExpression: @@ -7600,6 +7605,7 @@ namespace ts { continue loop; default: + // Nothing applies. Try to get the contextual type below. break loop; } } From 2874156da3d912b2d5a92b71538456bdc83e13e1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 22 Dec 2015 17:02:23 -0800 Subject: [PATCH 13/27] Added more to test. --- .../stringLiteralsWithSwitchStatements05.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts index 809380fbb4c2e..289ffd11060f3 100644 --- a/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts @@ -1,17 +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"): + case (x, y, ("baz")): x; - break; - case (("foo" || "bar")): y; break; + case (("foo" || ("bar"))): + break; + case (("bar" || ("baz"))): + break; + case z || "baz": + case "baz" || z: + z; + break; } From e2ddb29fdc2ae93708f12d68988ed8b4f37db54d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 22 Dec 2015 17:02:42 -0800 Subject: [PATCH 14/27] Accepted baselines. --- ...gLiteralsWithSwitchStatements05.errors.txt | 39 ++++++++++++++++--- .../stringLiteralsWithSwitchStatements05.js | 30 +++++++++++--- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt index 2ef632ab34382..f7ba9a7d9bbb7 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt @@ -1,24 +1,53 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(9,10): error TS2322: Type '"bar"' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(10,10): error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. + Type '"bar"' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(12,10): error TS2322: Type '"bar"' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(20,10): error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. + Type '"bar"' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(22,10): error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. + Type '"bar"' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(23,10): error TS2322: Type '"baz" | "bar"' is not assignable to type '"foo"'. + Type '"baz"' is not assignable to type '"foo"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts (1 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts (5 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 TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. +!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. + break; case (("bar")): ~~~~~~~~~ !!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. break; - case (x, y, "baz"): + case (x, y, ("baz")): x; - break; - case (("foo" || "bar")): y; break; + case (("foo" || ("bar"))): + break; + case (("bar" || ("baz"))): + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. +!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. + break; + case z || "baz": + ~~~~~~~~~~ +!!! error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. +!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. + case "baz" || z: + ~~~~~~~~~~ +!!! error TS2322: Type '"baz" | "bar"' is not assignable to type '"foo"'. +!!! error TS2322: Type '"baz"' is not assignable 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 index 8dd1cc0106e65..d72c6e88a1ff2 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.js +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.js @@ -1,35 +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"): + case (x, y, ("baz")): x; - break; - case (("foo" || "bar")): 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"): + case (x, y, ("baz")): x; - break; - case (("foo" || "bar")): y; break; + case (("foo" || ("bar"))): + break; + case (("bar" || ("baz"))): + break; + case z || "baz": + case "baz" || z: + z; + break; } From e6bd7ad9e286e3c957cb620bf11dc71eb596bd81 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 5 Jan 2016 00:33:22 -0500 Subject: [PATCH 15/27] Added test. --- .../stringLiteralsWithSwitchStatements06.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts 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; +} From 16fe01ba0afa0a949e9d2bb65382d3741a636031 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 5 Jan 2016 00:37:04 -0500 Subject: [PATCH 16/27] Accepted baselines. --- ...gLiteralsWithSwitchStatements06.errors.txt | 30 ++++++++++++ .../stringLiteralsWithSwitchStatements06.js | 48 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt create mode 100644 tests/baselines/reference/stringLiteralsWithSwitchStatements06.js diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt new file mode 100644 index 0000000000000..b15533d2db654 --- /dev/null +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt @@ -0,0 +1,30 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts(17,24): error TS1005: ':' expected. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts (1 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": + break; + case "baz", x: + break; + case "baz" && "bar": + break; + case "bar" && "baz"; + ~ +!!! 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; +} From bc34ebb719cfdbbf2b13c9c7f668c075abda2f25 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 5 Jan 2016 00:37:46 -0500 Subject: [PATCH 17/27] Added RHS operands of '&&' and ',' as match locations. --- src/compiler/checker.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7f25ed2cdfc58..2fcfe21bad9f0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7599,6 +7599,13 @@ namespace ts { case SyntaxKind.ExclamationEqualsToken: return current === binaryExpr.left || current === binaryExpr.right; + case SyntaxKind.AmpersandAmpersandToken: + case SyntaxKind.CommaToken: + if (current === binaryExpr.right) { + continue loop; + } + break loop; + case SyntaxKind.BarBarToken: if (current === binaryExpr.left || current === binaryExpr.right) { continue loop; From 4eced90e124b042afdc57f16c8b52be6684c6dc1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 5 Jan 2016 00:39:23 -0500 Subject: [PATCH 18/27] Accepted baselines. --- ...gLiteralsWithSwitchStatements05.errors.txt | 5 ++++- ...gLiteralsWithSwitchStatements06.errors.txt | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt index f7ba9a7d9bbb7..5d3fedaa9a58c 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt @@ -1,6 +1,7 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(10,10): error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. Type '"bar"' is not assignable to type '"foo"'. tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(12,10): error TS2322: Type '"bar"' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(14,10): error TS2322: Type '"baz"' is not assignable to type '"foo"'. tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(20,10): error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. Type '"bar"' is not assignable to type '"foo"'. tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(22,10): error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. @@ -9,7 +10,7 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05 Type '"baz"' is not assignable to type '"foo"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts (5 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts (6 errors) ==== let x: "foo"; let y: "foo" | "bar"; let z: "bar"; @@ -29,6 +30,8 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05 !!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. break; case (x, y, ("baz")): + ~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"baz"' is not assignable to type '"foo"'. x; y; break; diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt index b15533d2db654..fca96d9d69fe8 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt @@ -1,7 +1,14 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts(11,10): error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'. + Type '"baz"' is not assignable to type '"bar"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts(17,10): error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'. + Type '"baz"' is not assignable to type '"bar"'. tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts(17,24): error TS1005: ':' expected. +tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts(21,10): error TS2322: Type '"baz" | "bar"' is not assignable to type '"foo" | "bar"'. + Type '"baz"' is not assignable to type '"foo" | "bar"'. + Type '"baz"' is not assignable to type '"bar"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts (1 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts (4 errors) ==== let x: "foo"; let y: "foo" | "bar"; @@ -13,18 +20,28 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06 case x, "foo": break; case x, "baz": + ~~~~~~~~ +!!! error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'. +!!! error TS2322: Type '"baz"' is not assignable to type '"bar"'. break; case "baz", x: break; case "baz" && "bar": break; case "bar" && "baz"; + ~~~~~~~~~~~~~~ +!!! error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'. +!!! error TS2322: Type '"baz"' is not assignable to type '"bar"'. ~ !!! error TS1005: ':' expected. break; case "baz" && ("foo" || "bar"): break; case "bar" && ("baz" || "bar"): + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '"baz" | "bar"' is not assignable to type '"foo" | "bar"'. +!!! error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'. +!!! error TS2322: Type '"baz"' is not assignable to type '"bar"'. break; } \ No newline at end of file From 01cc2f1140f8e8a4905f9273a038f8028c8c305c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 8 Jan 2016 00:23:56 -0500 Subject: [PATCH 19/27] Added tests for type assertions in match locations. --- .../stringLiteralsAssertionsInEqualityComparisons01.ts | 3 +++ .../stringLiteralsAssertionsInEqualityComparisons02.ts | 3 +++ .../stringLiteral/stringLiteralsAssertionsInSwitchCase01.ts | 6 ++++++ .../stringLiteral/stringLiteralsAssertionsInSwitchCase02.ts | 6 ++++++ .../stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts | 6 ++++++ 5 files changed, 24 insertions(+) create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons01.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase01.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase02.ts create mode 100644 tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts 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..2208ff206a84b --- /dev/null +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts @@ -0,0 +1,3 @@ +var a = "foo" === "bar" as "baz"; +var b = "foo" !== ("bar" as "foo"); +var c = "foo" == ("bar"); \ 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 From 259a3cf6f8b6b5cdb4e66db04b3416150a5a68c5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 8 Jan 2016 00:28:29 -0500 Subject: [PATCH 20/27] Accepted baselines. --- ...teralsAssertionsInEqualityComparisons01.js | 9 +++++++ ...sAssertionsInEqualityComparisons01.symbols | 10 ++++++++ ...alsAssertionsInEqualityComparisons01.types | 24 +++++++++++++++++++ ...sertionsInEqualityComparisons02.errors.txt | 21 ++++++++++++++++ ...teralsAssertionsInEqualityComparisons02.js | 9 +++++++ .../stringLiteralsAssertionsInSwitchCase01.js | 15 ++++++++++++ ...ngLiteralsAssertionsInSwitchCase01.symbols | 8 +++++++ ...ringLiteralsAssertionsInSwitchCase01.types | 19 +++++++++++++++ .../stringLiteralsAssertionsInSwitchCase02.js | 15 ++++++++++++ ...ngLiteralsAssertionsInSwitchCase02.symbols | 8 +++++++ ...ringLiteralsAssertionsInSwitchCase02.types | 18 ++++++++++++++ ...iteralsAssertionsInSwitchCase03.errors.txt | 20 ++++++++++++++++ .../stringLiteralsAssertionsInSwitchCase03.js | 15 ++++++++++++ 13 files changed, 191 insertions(+) create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.js create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.symbols create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.js create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.symbols create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.types create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.js create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.symbols create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.types create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInSwitchCase03.errors.txt create mode 100644 tests/baselines/reference/stringLiteralsAssertionsInSwitchCase03.js 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..86f02773fb3bc --- /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" : string + +var b = "foo" !== ("bar" as string); +>b : boolean +>"foo" !== ("bar" as string) : boolean +>"foo" : "foo" +>("bar" as string) : string +>"bar" as string : string +>"bar" : string + +var c = "foo" == ("bar"); +>c : boolean +>"foo" == ("bar") : boolean +>"foo" : "foo" +>("bar") : any +>"bar" : any +>"bar" : string + diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt new file mode 100644 index 0000000000000..1115b8b73290f --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(1,9): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"baz"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(1,19): error TS2352: Neither type '"bar"' nor type '"baz"' is assignable to the other. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(2,20): error TS2352: Neither type '"bar"' nor type '"foo"' is assignable to the other. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(3,9): error TS2365: Operator '==' cannot be applied to types '"foo"' and 'number'. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(3,19): error TS2352: Neither type 'string' nor type 'number' is assignable to the other. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts (5 errors) ==== + var a = "foo" === "bar" as "baz"; + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo"' and '"baz"'. + ~~~~~~~~~~~~~~ +!!! error TS2352: Neither type '"bar"' nor type '"baz"' is assignable to the other. + var b = "foo" !== ("bar" as "foo"); + ~~~~~~~~~~~~~~ +!!! error TS2352: Neither type '"bar"' nor type '"foo"' is assignable to the other. + var c = "foo" == ("bar"); + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '==' cannot be applied to types '"foo"' and 'number'. + ~~~~~~~~~~~~~ +!!! error TS2352: Neither type 'string' nor type 'number' is assignable to the other. \ 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..e52fc87e90b2e --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js @@ -0,0 +1,9 @@ +//// [stringLiteralsAssertionsInEqualityComparisons02.ts] +var a = "foo" === "bar" as "baz"; +var b = "foo" !== ("bar" as "foo"); +var c = "foo" == ("bar"); + +//// [stringLiteralsAssertionsInEqualityComparisons02.js] +var a = "foo" === "bar"; +var b = "foo" !== "bar"; +var c = "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..c97519a22dc66 --- /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" : string + + break; + case (("bar" || "baz") as string): +>(("bar" || "baz") as string) : string +>("bar" || "baz") as string : string +>("bar" || "baz") : string +>"bar" || "baz" : string +>"bar" : string +>"baz" : string + + 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..d980120bbf542 --- /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" : string + + 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..484eb6940818c --- /dev/null +++ b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase03.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts(2,10): error TS2322: Type '"baz"' is not assignable to type '"foo"'. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts(2,10): error TS2352: Neither type '"bar"' nor type '"baz"' is assignable to the other. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts(4,11): error TS2352: Neither type '"bar" | "baz"' nor type '"foo"' is assignable to the other. + Type '"bar"' is not assignable to type '"foo"'. + + +==== tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts (3 errors) ==== + switch ("foo") { + case "bar" as "baz": + ~~~~~~~~~~~~~~ +!!! error TS2322: Type '"baz"' is not assignable to type '"foo"'. + ~~~~~~~~~~~~~~ +!!! error TS2352: Neither type '"bar"' nor type '"baz"' is assignable to the other. + break; + case (("bar" || "baz") as "foo"): + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Neither type '"bar" | "baz"' nor type '"foo"' is assignable to the other. +!!! error TS2352: Type '"bar"' is not assignable 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; +} From cc2ab55d0d783f10e273ae0f5314aeaa684ac17b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 8 Jan 2016 00:40:12 -0500 Subject: [PATCH 21/27] Factored out operand detection logic and made it recursive. --- src/compiler/checker.ts | 112 +++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 59 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2fcfe21bad9f0..3fefee8038a66 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7574,75 +7574,69 @@ namespace ts { return undefined; } - function shouldAcquireLiteralType(literalNode: StringLiteral) { - loop: for (let current: Node = literalNode, parent = current.parent; - parent; - current = parent, parent = current.parent) { + function shouldAcquireLiteralType(literalNode: LiteralExpression) { + if (isEqualityComparisonOperand(literalNode)) { + return true; + } - switch (parent.kind) { - // The operand of a 'switch' should get a literal type. - case SyntaxKind.SwitchStatement: - return current === (parent as SwitchStatement).expression; + const contextualType = getContextualType(literalNode); + return !!contextualType && contextualTypeIsStringLiteralType(contextualType); + } - // The tested expression of a 'case' clause should get a literal type. - case SyntaxKind.CaseClause: - return current === (parent as CaseClause).expression; + /** + * 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; + const parentKind = parent.kind; - 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 current === binaryExpr.left || current === binaryExpr.right; - - case SyntaxKind.AmpersandAmpersandToken: - case SyntaxKind.CommaToken: - if (current === binaryExpr.right) { - continue loop; - } - break loop; + switch (parent.kind) { + // The operand of a 'switch' should get a literal type. + case SyntaxKind.SwitchStatement: + return expression === (parent as SwitchStatement).expression; - case SyntaxKind.BarBarToken: - if (current === binaryExpr.left || current === binaryExpr.right) { - continue loop; - } - break loop; - } + // 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; - // No binary operators apply. Try to get the contextual type below. - break loop; + case SyntaxKind.AmpersandAmpersandToken: + case SyntaxKind.CommaToken: + if (expression === binaryExpr.right) { + return isEqualityComparisonOperand(binaryExpr) + } + return false; - case SyntaxKind.ConditionalExpression: - const conditional = parent as ConditionalExpression; - if (current === conditional.whenTrue || current === conditional.whenFalse) { - continue loop; - } - break loop; + case SyntaxKind.BarBarToken: + return isEqualityComparisonOperand(binaryExpr); + } - case SyntaxKind.ParenthesizedExpression: - continue loop; + // No binary operators apply. + return false; - default: - // Nothing applies. Try to get the contextual type below. - break loop; - } + 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); } - // We haven't found a "literal match location" (i.e. a location that signals - // a literal should get a literal type). Check whether the contextual type - // of the literal has a literal type in it. - // - // You might ask why we're not passing 'current' or 'parent' into 'getContextualType' - // since we've already walked up several nodes anyway. This is not correct - // because several nodes *do not* strictly acquire a contextual type from their parents. - // An example of this is '||' expressions, whose right operand is contextually typed by - // its left operand if it could not acquire a contextual type from its parent. - const contextualType = getContextualType(literalNode); - return !!contextualType && contextualTypeIsStringLiteralType(contextualType); + return false; } From 5b9e5d14ce40eb69c2443bc5ffbe4f235eca3724 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 8 Jan 2016 00:40:56 -0500 Subject: [PATCH 22/27] Included type assertions in operand detection logic. --- src/compiler/checker.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3fefee8038a66..d8b253fd677a6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7634,6 +7634,10 @@ namespace ts { case SyntaxKind.ParenthesizedExpression: return isEqualityComparisonOperand(parent as ParenthesizedExpression); + + case SyntaxKind.TypeAssertionExpression: + case SyntaxKind.AsExpression: + return isEqualityComparisonOperand(parent as TypeAssertion); } return false; From fdd7fdeed5b8bb15d786b5a42fcb69d3791a99bd Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 8 Jan 2016 00:41:10 -0500 Subject: [PATCH 23/27] Accepted baselines. --- ...ringLiteralsAssertionsInEqualityComparisons01.types | 6 +++--- ...iteralsAssertionsInEqualityComparisons02.errors.txt | 4 ++-- .../stringLiteralsAssertionsInSwitchCase01.types | 10 +++++----- .../stringLiteralsAssertionsInSwitchCase02.types | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types index 86f02773fb3bc..3d443deec503f 100644 --- a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons01.types @@ -4,7 +4,7 @@ var a = "foo" === "bar" as string; >"foo" === "bar" as string : boolean >"foo" : "foo" >"bar" as string : string ->"bar" : string +>"bar" : "bar" var b = "foo" !== ("bar" as string); >b : boolean @@ -12,7 +12,7 @@ var b = "foo" !== ("bar" as string); >"foo" : "foo" >("bar" as string) : string >"bar" as string : string ->"bar" : string +>"bar" : "bar" var c = "foo" == ("bar"); >c : boolean @@ -20,5 +20,5 @@ var c = "foo" == ("bar"); >"foo" : "foo" >("bar") : any >"bar" : any ->"bar" : string +>"bar" : "bar" diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt index 1115b8b73290f..fee31353b978b 100644 --- a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityCo tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(1,19): error TS2352: Neither type '"bar"' nor type '"baz"' is assignable to the other. tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(2,20): error TS2352: Neither type '"bar"' nor type '"foo"' is assignable to the other. tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(3,9): error TS2365: Operator '==' cannot be applied to types '"foo"' and 'number'. -tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(3,19): error TS2352: Neither type 'string' nor type 'number' is assignable to the other. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(3,19): error TS2352: Neither type '"bar"' nor type 'number' is assignable to the other. ==== tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts (5 errors) ==== @@ -18,4 +18,4 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityCo ~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '==' cannot be applied to types '"foo"' and 'number'. ~~~~~~~~~~~~~ -!!! error TS2352: Neither type 'string' nor type 'number' is assignable to the other. \ No newline at end of file +!!! error TS2352: Neither type '"bar"' nor type 'number' is assignable to the other. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.types b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.types index c97519a22dc66..f4844bc84ba4e 100644 --- a/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.types +++ b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase01.types @@ -4,16 +4,16 @@ switch ("foo") { case "bar" as string: >"bar" as string : string ->"bar" : string +>"bar" : "bar" break; case (("bar" || "baz") as string): >(("bar" || "baz") as string) : string >("bar" || "baz") as string : string ->("bar" || "baz") : string ->"bar" || "baz" : string ->"bar" : string ->"baz" : string +>("bar" || "baz") : "bar" | "baz" +>"bar" || "baz" : "bar" | "baz" +>"bar" : "bar" +>"baz" : "baz" break; } diff --git a/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.types b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.types index d980120bbf542..01e14d62481bb 100644 --- a/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.types +++ b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase02.types @@ -1,7 +1,7 @@ === tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase02.ts === switch ("foo" as string) { >"foo" as string : string ->"foo" : string +>"foo" : "foo" case "bar": >"bar" : "bar" From 09d1762e42a1f4e372d0dd7d6b00abaa5be0d54b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 8 Jan 2016 00:50:21 -0500 Subject: [PATCH 24/27] Fix lint issues. --- src/compiler/checker.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d8b253fd677a6..d8c686c2ddfc0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7589,7 +7589,6 @@ namespace ts { */ function isEqualityComparisonOperand(expression: Expression): boolean { const parent = expression.parent; - const parentKind = parent.kind; switch (parent.kind) { // The operand of a 'switch' should get a literal type. @@ -7614,7 +7613,7 @@ namespace ts { case SyntaxKind.AmpersandAmpersandToken: case SyntaxKind.CommaToken: if (expression === binaryExpr.right) { - return isEqualityComparisonOperand(binaryExpr) + return isEqualityComparisonOperand(binaryExpr); } return false; From dec70f18c2a64eef6858ec035695c7dcf9094be1 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 8 Jan 2016 00:54:20 -0500 Subject: [PATCH 25/27] Added scenario to tests. --- .../stringLiteralsAssertionsInEqualityComparisons02.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts b/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts index 2208ff206a84b..8ab4469055feb 100644 --- a/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts +++ b/tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts @@ -1,3 +1,6 @@ -var a = "foo" === "bar" as "baz"; +type EnhancedString = string & { enhancements: any }; + +var a = "foo" === "bar" as "baz"; var b = "foo" !== ("bar" as "foo"); -var c = "foo" == ("bar"); \ No newline at end of file +var c = "foo" == ("bar"); +var d = "foo" === ("bar" as EnhancedString); \ No newline at end of file From 1dd43fa7620362b606cbf4c46419dda11b30bc09 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 8 Jan 2016 00:58:47 -0500 Subject: [PATCH 26/27] Accepted baselines. --- ...sertionsInEqualityComparisons02.errors.txt | 27 ++++++++++++++----- ...teralsAssertionsInEqualityComparisons02.js | 6 ++++- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt index fee31353b978b..6d3bf171a9d94 100644 --- a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt @@ -1,11 +1,17 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(1,9): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"baz"'. -tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(1,19): error TS2352: Neither type '"bar"' nor type '"baz"' is assignable to the other. -tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(2,20): error TS2352: Neither type '"bar"' nor type '"foo"' is assignable to the other. -tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(3,9): error TS2365: Operator '==' cannot be applied to types '"foo"' and 'number'. -tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(3,19): error TS2352: Neither type '"bar"' nor type 'number' is assignable to the other. +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: Neither type '"bar"' nor type '"baz"' is assignable to the other. +tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(4,20): error TS2352: Neither type '"bar"' nor type '"foo"' is assignable to the other. +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: Neither type '"bar"' nor type 'number' is assignable to the other. +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: Neither type '"bar"' nor type 'string & { enhancements: any; }' is assignable to the other. + Type '"bar"' is not assignable to type '{ enhancements: any; }'. + Property 'enhancements' is missing in type 'String'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts (5 errors) ==== +==== 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"'. @@ -18,4 +24,11 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityCo ~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '==' cannot be applied to types '"foo"' and 'number'. ~~~~~~~~~~~~~ -!!! error TS2352: Neither type '"bar"' nor type 'number' is assignable to the other. \ No newline at end of file +!!! error TS2352: Neither type '"bar"' nor type 'number' is assignable to the other. + var d = "foo" === ("bar" as EnhancedString); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2365: Operator '===' cannot be applied to types '"foo"' and 'string & { enhancements: any; }'. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Neither type '"bar"' nor type 'string & { enhancements: any; }' is assignable to the other. +!!! error TS2352: Type '"bar"' is not assignable to type '{ enhancements: any; }'. +!!! error TS2352: Property 'enhancements' is missing in type 'String'. \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js index e52fc87e90b2e..32beac89bf734 100644 --- a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.js @@ -1,9 +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 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"; From 6b8bac3ae8e2f8d5e8b9c187c65076492e363395 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 5 Apr 2016 11:40:27 -0700 Subject: [PATCH 27/27] Accepted other baselines. --- .../reference/capturedLetConstInLoop5.types | 4 +- .../capturedLetConstInLoop5_ES6.types | 4 +- .../reference/capturedLetConstInLoop6.types | 8 +- .../capturedLetConstInLoop6_ES6.types | 8 +- .../reference/capturedLetConstInLoop7.types | 16 +-- .../capturedLetConstInLoop7_ES6.types | 16 +-- ...eclarationEmitIdentifierPredicates01.types | 2 +- .../operatorsAndIntersectionTypes.errors.txt | 37 +++++ .../operatorsAndIntersectionTypes.symbols | 100 ------------- .../operatorsAndIntersectionTypes.types | 132 ------------------ .../stringLiteralTypeAssertion01.errors.txt | 55 -------- .../stringLiteralTypeAssertion01.symbols | 83 +++++++++++ .../stringLiteralTypeAssertion01.types | 107 ++++++++++++++ ...sertionsInEqualityComparisons02.errors.txt | 22 ++- ...iteralsAssertionsInSwitchCase03.errors.txt | 16 +-- ...ingLiteralsWithEqualityChecks03.errors.txt | 8 +- ...ingLiteralsWithEqualityChecks04.errors.txt | 8 +- ...gLiteralsWithSwitchStatements01.errors.txt | 4 +- ...gLiteralsWithSwitchStatements03.errors.txt | 4 +- ...gLiteralsWithSwitchStatements05.errors.txt | 40 +++--- ...gLiteralsWithSwitchStatements06.errors.txt | 21 +-- ...ingLiteralsWithTypeAssertions01.errors.txt | 22 ++- .../switchBreakStatements.errors.txt | 44 +++--- ...ypeGuardOfFormTypeOfPrimitiveSubtype.types | 12 +- .../reference/typeGuardsOnClassProperty.types | 8 +- 25 files changed, 347 insertions(+), 434 deletions(-) create mode 100644 tests/baselines/reference/operatorsAndIntersectionTypes.errors.txt delete mode 100644 tests/baselines/reference/operatorsAndIntersectionTypes.symbols delete mode 100644 tests/baselines/reference/operatorsAndIntersectionTypes.types delete mode 100644 tests/baselines/reference/stringLiteralTypeAssertion01.errors.txt create mode 100644 tests/baselines/reference/stringLiteralTypeAssertion01.symbols create mode 100644 tests/baselines/reference/stringLiteralTypeAssertion01.types 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/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/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/stringLiteralTypeAssertion01.errors.txt b/tests/baselines/reference/stringLiteralTypeAssertion01.errors.txt deleted file mode 100644 index 867ad80ee7fbf..0000000000000 --- a/tests/baselines/reference/stringLiteralTypeAssertion01.errors.txt +++ /dev/null @@ -1,55 +0,0 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(22,5): error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other. - Type 'string' is not assignable to type '"b"'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(23,5): error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other. - Type 'string' is not assignable to type '"b"'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(30,7): error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other. - Type '("a" | "b")[]' is not assignable to type 'string'. -tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(31,7): error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other. - Type '("a" | "b")[]' is not assignable to type 'string'. - - -==== tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts (4 errors) ==== - - type S = "a" | "b"; - type T = S[] | S; - - var s: S; - var t: T; - var str: string; - - //////////////// - - s = t; - s = t as S; - - s = str; - s = str as S; - - //////////////// - - t = s; - t = s as T; - - t = str; - ~~~~~~ -!!! error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other. -!!! error TS2352: Type 'string' is not assignable to type '"b"'. - t = str as T; - ~~~~~~~~ -!!! error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other. -!!! error TS2352: Type 'string' is not assignable to type '"b"'. - - //////////////// - - str = s; - str = s as string; - - str = t; - ~~~~~~~~~ -!!! error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other. -!!! error TS2352: Type '("a" | "b")[]' is not assignable to type 'string'. - str = t as string; - ~~~~~~~~~~~ -!!! error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other. -!!! error TS2352: Type '("a" | "b")[]' is not assignable to type 'string'. - \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralTypeAssertion01.symbols b/tests/baselines/reference/stringLiteralTypeAssertion01.symbols new file mode 100644 index 0000000000000..1491a32b6f8bf --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypeAssertion01.symbols @@ -0,0 +1,83 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts === + +type S = "a" | "b"; +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) + +type T = S[] | S; +>T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) + +var s: S; +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) + +var t: T; +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) +>T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) + +var str: string; +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) + +//////////////// + +s = t; +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) + +s = t as S; +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) + +s = str; +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) + +s = str as S; +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) +>S : Symbol(S, Decl(stringLiteralTypeAssertion01.ts, 0, 0)) + +//////////////// + +t = s; +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) +>T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) + +t = s as T; +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) +>T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) + +t = str; +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) +>T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) + +t = str as T; +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) +>T : Symbol(T, Decl(stringLiteralTypeAssertion01.ts, 1, 19)) + +//////////////// + +str = s; +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) + +str = s as string; +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) +>s : Symbol(s, Decl(stringLiteralTypeAssertion01.ts, 4, 3)) + +str = t; +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) + +str = t as string; +>str : Symbol(str, Decl(stringLiteralTypeAssertion01.ts, 6, 3)) +>t : Symbol(t, Decl(stringLiteralTypeAssertion01.ts, 5, 3)) + diff --git a/tests/baselines/reference/stringLiteralTypeAssertion01.types b/tests/baselines/reference/stringLiteralTypeAssertion01.types new file mode 100644 index 0000000000000..f70313f834700 --- /dev/null +++ b/tests/baselines/reference/stringLiteralTypeAssertion01.types @@ -0,0 +1,107 @@ +=== tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts === + +type S = "a" | "b"; +>S : "a" | "b" + +type T = S[] | S; +>T : ("a" | "b")[] | "a" | "b" +>S : "a" | "b" +>S : "a" | "b" + +var s: S; +>s : "a" | "b" +>S : "a" | "b" + +var t: T; +>t : ("a" | "b")[] | "a" | "b" +>T : ("a" | "b")[] | "a" | "b" + +var str: string; +>str : string + +//////////////// + +s = t; +>s = t : "a" | "b" +>s : "a" | "b" +>t : "a" | "b" +>S : "a" | "b" +>t : ("a" | "b")[] | "a" | "b" + +s = t as S; +>s = t as S : "a" | "b" +>s : "a" | "b" +>t as S : "a" | "b" +>t : ("a" | "b")[] | "a" | "b" +>S : "a" | "b" + +s = str; +>s = str : "a" | "b" +>s : "a" | "b" +>str : "a" | "b" +>S : "a" | "b" +>str : string + +s = str as S; +>s = str as S : "a" | "b" +>s : "a" | "b" +>str as S : "a" | "b" +>str : string +>S : "a" | "b" + +//////////////// + +t = s; +>t = s : ("a" | "b")[] | "a" | "b" +>t : ("a" | "b")[] | "a" | "b" +>s : ("a" | "b")[] | "a" | "b" +>T : ("a" | "b")[] | "a" | "b" +>s : "a" | "b" + +t = s as T; +>t = s as T : ("a" | "b")[] | "a" | "b" +>t : ("a" | "b")[] | "a" | "b" +>s as T : ("a" | "b")[] | "a" | "b" +>s : "a" | "b" +>T : ("a" | "b")[] | "a" | "b" + +t = str; +>t = str : ("a" | "b")[] | "a" | "b" +>t : ("a" | "b")[] | "a" | "b" +>str : ("a" | "b")[] | "a" | "b" +>T : ("a" | "b")[] | "a" | "b" +>str : string + +t = str as T; +>t = str as T : ("a" | "b")[] | "a" | "b" +>t : ("a" | "b")[] | "a" | "b" +>str as T : ("a" | "b")[] | "a" | "b" +>str : string +>T : ("a" | "b")[] | "a" | "b" + +//////////////// + +str = s; +>str = s : string +>str : string +>s : string +>s : "a" | "b" + +str = s as string; +>str = s as string : string +>str : string +>s as string : string +>s : "a" | "b" + +str = t; +>str = t : string +>str : string +>t : string +>t : ("a" | "b")[] | "a" | "b" + +str = t as string; +>str = t as string : string +>str : string +>t as string : string +>t : ("a" | "b")[] | "a" | "b" + diff --git a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt index 6d3bf171a9d94..e9ae597603502 100644 --- a/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt +++ b/tests/baselines/reference/stringLiteralsAssertionsInEqualityComparisons02.errors.txt @@ -1,12 +1,11 @@ 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: Neither type '"bar"' nor type '"baz"' is assignable to the other. -tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityComparisons02.ts(4,20): error TS2352: Neither type '"bar"' nor type '"foo"' is assignable to the other. +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: Neither type '"bar"' nor type 'number' is assignable to the other. +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: Neither type '"bar"' nor type 'string & { enhancements: any; }' is assignable to the other. - Type '"bar"' is not assignable to type '{ enhancements: any; }'. - Property 'enhancements' is missing in type 'String'. +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) ==== @@ -16,19 +15,18 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInEqualityCo ~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2365: Operator '===' cannot be applied to types '"foo"' and '"baz"'. ~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '"bar"' nor type '"baz"' is assignable to the other. +!!! error TS2352: Type '"bar"' cannot be converted to type '"baz"'. var b = "foo" !== ("bar" as "foo"); ~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '"bar"' nor type '"foo"' is assignable to the other. +!!! 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: Neither type '"bar"' nor type 'number' is assignable to the other. +!!! 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: Neither type '"bar"' nor type 'string & { enhancements: any; }' is assignable to the other. -!!! error TS2352: Type '"bar"' is not assignable to type '{ enhancements: any; }'. -!!! error TS2352: Property 'enhancements' is missing in type 'String'. \ No newline at end of file +!!! 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/stringLiteralsAssertionsInSwitchCase03.errors.txt b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase03.errors.txt index 484eb6940818c..acd60adaf99df 100644 --- a/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase03.errors.txt +++ b/tests/baselines/reference/stringLiteralsAssertionsInSwitchCase03.errors.txt @@ -1,20 +1,20 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts(2,10): error TS2322: Type '"baz"' is not assignable to type '"foo"'. -tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts(2,10): error TS2352: Neither type '"bar"' nor type '"baz"' is assignable to the other. -tests/cases/conformance/types/stringLiteral/stringLiteralsAssertionsInSwitchCase03.ts(4,11): error TS2352: Neither type '"bar" | "baz"' nor type '"foo"' is assignable to the other. - Type '"bar"' is not assignable to type '"foo"'. +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 TS2322: Type '"baz"' is not assignable to type '"foo"'. +!!! error TS2352: Type '"bar"' cannot be converted to type '"baz"'. ~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '"bar"' nor type '"baz"' is assignable to the other. +!!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. break; case (("bar" || "baz") as "foo"): ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '"bar" | "baz"' nor type '"foo"' is assignable to the other. -!!! error TS2352: Type '"bar"' is not assignable to type '"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/stringLiteralsWithEqualityChecks03.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt index 2ec298a91f1c4..f76ea276e0f83 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks03.errors.txt @@ -1,14 +1,12 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts(13,5): error TS2365: Operator '===' cannot be applied to types 'string' and '"foo" | Refrigerator'. 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(22,5): error TS2365: Operator '!==' cannot be applied to types 'string' 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 (8 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.ts (6 errors) ==== interface Runnable { isRunning: boolean; } @@ -22,8 +20,6 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.t let b: boolean; b = x === y; - ~~~~~~~ -!!! error TS2365: Operator '===' cannot be applied to types 'string' and '"foo" | Refrigerator'. b = "foo" === y b = y === "foo"; b = "foo" === "bar"; @@ -39,8 +35,6 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks03.t !!! error TS2365: Operator '===' cannot be applied to types '"bar"' and '"foo" | Refrigerator'. b = x !== y; - ~~~~~~~ -!!! error TS2365: Operator '!==' cannot be applied to types 'string' and '"foo" | Refrigerator'. b = "foo" !== y b = y !== "foo"; b = "foo" !== "bar"; diff --git a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt index 9b714c803851e..6f8c54656d4df 100644 --- a/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithEqualityChecks04.errors.txt @@ -1,14 +1,12 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts(13,5): error TS2365: Operator '==' cannot be applied to types 'string' and '"foo" | Refrigerator'. 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(22,5): error TS2365: Operator '!=' cannot be applied to types 'string' 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 (8 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.ts (6 errors) ==== interface Runnable { isRunning: boolean; } @@ -22,8 +20,6 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.t let b: boolean; b = x == y; - ~~~~~~ -!!! error TS2365: Operator '==' cannot be applied to types 'string' and '"foo" | Refrigerator'. b = "foo" == y b = y == "foo"; b = "foo" == "bar"; @@ -39,8 +35,6 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithEqualityChecks04.t !!! error TS2365: Operator '==' cannot be applied to types '"bar"' and '"foo" | Refrigerator'. b = x != y; - ~~~~~~ -!!! error TS2365: Operator '!=' cannot be applied to types 'string' and '"foo" | Refrigerator'. b = "foo" != y b = y != "foo"; b = "foo" != "bar"; diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt index 9e210c6692158..f4d8a6f4fa045 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements01.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements01.ts(7,10): error TS2322: Type '"bar"' is not assignable to type '"foo"'. +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) ==== @@ -10,7 +10,7 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements01 break; case "bar": ~~~~~ -!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. +!!! error TS2678: Type '"bar"' is not comparable to type '"foo"'. break; case y: y; diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt index 503cb97350d49..19bdab943ebdc 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements03.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements03.ts(7,10): error TS2322: Type '"bar"' is not assignable to type '"foo"'. +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) ==== @@ -10,7 +10,7 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements03 break; case "bar": ~~~~~ -!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. +!!! error TS2678: Type '"bar"' is not comparable to type '"foo"'. break; case x: x; diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt index 5d3fedaa9a58c..6a67e2df5c044 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements05.errors.txt @@ -1,13 +1,13 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(10,10): error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. - Type '"bar"' is not assignable to type '"foo"'. -tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(12,10): error TS2322: Type '"bar"' is not assignable to type '"foo"'. -tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(14,10): error TS2322: Type '"baz"' is not assignable to type '"foo"'. -tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(20,10): error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. - Type '"bar"' is not assignable to type '"foo"'. -tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(22,10): error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. - Type '"bar"' is not assignable to type '"foo"'. -tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05.ts(23,10): error TS2322: Type '"baz" | "bar"' is not assignable to type '"foo"'. - Type '"baz"' is not assignable to type '"foo"'. +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) ==== @@ -22,16 +22,16 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05 break; case (randBool() ? ("bar") : "baz" ? "bar" : "baz"): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. -!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. +!!! 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 TS2322: Type '"bar"' is not assignable to type '"foo"'. +!!! error TS2678: Type '"bar"' is not comparable to type '"foo"'. break; case (x, y, ("baz")): ~~~~~~~~~~~~~~~ -!!! error TS2322: Type '"baz"' is not assignable to type '"foo"'. +!!! error TS2678: Type '"baz"' is not comparable to type '"foo"'. x; y; break; @@ -39,17 +39,17 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements05 break; case (("bar" || ("baz"))): ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. -!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. +!!! 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 TS2322: Type '"bar" | "baz"' is not assignable to type '"foo"'. -!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. +!!! 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 TS2322: Type '"baz" | "bar"' is not assignable to type '"foo"'. -!!! error TS2322: Type '"baz"' is not assignable to type '"foo"'. +!!! error TS2678: Type '"baz" | "bar"' is not comparable to type '"foo"'. +!!! error TS2678: Type '"bar"' is not comparable to type '"foo"'. z; break; } diff --git a/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt b/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt index fca96d9d69fe8..8c83e6a110891 100644 --- a/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithSwitchStatements06.errors.txt @@ -1,14 +1,9 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts(11,10): error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'. - Type '"baz"' is not assignable to type '"bar"'. -tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts(17,10): error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'. - Type '"baz"' is not assignable to type '"bar"'. +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(21,10): error TS2322: Type '"baz" | "bar"' is not assignable to type '"foo" | "bar"'. - Type '"baz"' is not assignable to type '"foo" | "bar"'. - Type '"baz"' is not assignable to type '"bar"'. -==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts (4 errors) ==== +==== tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06.ts (3 errors) ==== let x: "foo"; let y: "foo" | "bar"; @@ -21,8 +16,7 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06 break; case x, "baz": ~~~~~~~~ -!!! error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'. -!!! error TS2322: Type '"baz"' is not assignable to type '"bar"'. +!!! error TS2678: Type '"baz"' is not comparable to type '"foo" | "bar"'. break; case "baz", x: break; @@ -30,18 +24,13 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithSwitchStatements06 break; case "bar" && "baz"; ~~~~~~~~~~~~~~ -!!! error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'. -!!! error TS2322: Type '"baz"' is not assignable to type '"bar"'. +!!! error TS2678: Type '"baz"' is not comparable to type '"foo" | "bar"'. ~ !!! error TS1005: ':' expected. break; case "baz" && ("foo" || "bar"): break; case "bar" && ("baz" || "bar"): - ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '"baz" | "bar"' is not assignable to type '"foo" | "bar"'. -!!! error TS2322: Type '"baz"' is not assignable to type '"foo" | "bar"'. -!!! error TS2322: Type '"baz"' is not assignable to type '"bar"'. break; } \ No newline at end of file diff --git a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt index c6ab0729d86ea..96e8f2e90c6cf 100644 --- a/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt +++ b/tests/baselines/reference/stringLiteralsWithTypeAssertions01.errors.txt @@ -1,9 +1,8 @@ -tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts(3,9): error TS2352: Neither type '"foo"' nor type '"bar"' is assignable to the other. -tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts(4,9): error TS2352: Neither type '"bar"' nor type '"foo"' is assignable to the other. -tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts(7,9): error TS2352: Neither type '"foo" | "bar"' nor type '"baz"' is assignable to the other. - Type '"foo"' is not assignable to type '"baz"'. -tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.ts(8,9): error TS2352: Neither type '"baz"' nor type '"foo" | "bar"' is assignable to the other. - Type '"baz"' is not assignable to type '"bar"'. +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) ==== @@ -11,17 +10,16 @@ tests/cases/conformance/types/stringLiteral/stringLiteralsWithTypeAssertions01.t let a = "foo" as "bar"; ~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '"foo"' nor type '"bar"' is assignable to the other. +!!! error TS2352: Type '"foo"' cannot be converted to type '"bar"'. let b = "bar" as "foo"; ~~~~~~~~~~~~~~ -!!! error TS2352: Neither type '"bar"' nor type '"foo"' is assignable to the other. +!!! 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: Neither type '"foo" | "bar"' nor type '"baz"' is assignable to the other. -!!! error TS2352: Type '"foo"' is not assignable to type '"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: Neither type '"baz"' nor type '"foo" | "bar"' is assignable to the other. -!!! error TS2352: Type '"baz"' is not assignable to type '"bar"'. \ No newline at end of file +!!! error TS2352: Type '"baz"' cannot be converted to type '"foo" | "bar"'. \ No newline at end of file diff --git a/tests/baselines/reference/switchBreakStatements.errors.txt b/tests/baselines/reference/switchBreakStatements.errors.txt index 794549413ce66..229c42068c308 100644 --- a/tests/baselines/reference/switchBreakStatements.errors.txt +++ b/tests/baselines/reference/switchBreakStatements.errors.txt @@ -1,14 +1,14 @@ -tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(3,10): error TS2322: Type '"a"' is not assignable to type '""'. -tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(9,10): error TS2322: Type '"a"' is not assignable to type '""'. -tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(16,10): error TS2322: Type '"a"' is not assignable to type '""'. -tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(22,10): error TS2322: Type '"a"' is not assignable to type '""'. -tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(25,18): error TS2322: Type '"a"' is not assignable to type '""'. -tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(31,10): error TS2322: Type '"a"' is not assignable to type '""'. -tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(34,18): error TS2322: Type '"a"' is not assignable to type '""'. -tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(41,10): error TS2322: Type '"a"' is not assignable to type '""'. -tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(43,18): error TS2322: Type '"a"' is not assignable to type '""'. -tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(45,26): error TS2322: Type '"a"' is not assignable to type '""'. -tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(49,34): error TS2322: Type '"a"' is not assignable to type '""'. +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) ==== @@ -16,7 +16,7 @@ tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(49,3 switch ('') { case 'a': ~~~ -!!! error TS2322: Type '"a"' is not assignable to type '""'. +!!! error TS2678: Type '"a"' is not comparable to type '""'. break; } @@ -24,7 +24,7 @@ tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(49,3 switch ('') { case 'a': ~~~ -!!! error TS2322: Type '"a"' is not assignable to type '""'. +!!! error TS2678: Type '"a"' is not comparable to type '""'. break ONE; } @@ -33,7 +33,7 @@ tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(49,3 switch ('') { case 'a': ~~~ -!!! error TS2322: Type '"a"' is not assignable to type '""'. +!!! error TS2678: Type '"a"' is not comparable to type '""'. break THREE; } @@ -41,12 +41,12 @@ tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(49,3 switch ('') { case 'a': ~~~ -!!! error TS2322: Type '"a"' is not assignable to type '""'. +!!! error TS2678: Type '"a"' is not comparable to type '""'. FIVE: switch ('') { case 'a': ~~~ -!!! error TS2322: Type '"a"' is not assignable to type '""'. +!!! error TS2678: Type '"a"' is not comparable to type '""'. break FOUR; } } @@ -54,12 +54,12 @@ tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(49,3 switch ('') { case 'a': ~~~ -!!! error TS2322: Type '"a"' is not assignable to type '""'. +!!! error TS2678: Type '"a"' is not comparable to type '""'. SIX: switch ('') { case 'a': ~~~ -!!! error TS2322: Type '"a"' is not assignable to type '""'. +!!! error TS2678: Type '"a"' is not comparable to type '""'. break SIX; } } @@ -68,21 +68,21 @@ tests/cases/conformance/statements/breakStatements/switchBreakStatements.ts(49,3 switch ('') { case 'a': ~~~ -!!! error TS2322: Type '"a"' is not assignable to type '""'. +!!! error TS2678: Type '"a"' is not comparable to type '""'. switch ('') { case 'a': ~~~ -!!! error TS2322: Type '"a"' is not assignable to type '""'. +!!! error TS2678: Type '"a"' is not comparable to type '""'. switch ('') { case 'a': ~~~ -!!! error TS2322: Type '"a"' is not assignable to type '""'. +!!! error TS2678: Type '"a"' is not comparable to type '""'. break SEVEN; EIGHT: switch ('') { case 'a': ~~~ -!!! error TS2322: Type '"a"' is not assignable to type '""'. +!!! error TS2678: Type '"a"' is not comparable to type '""'. var fn = function () { } break EIGHT; } 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/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