Add new tests

This commit is contained in:
Anders Hejlsberg
2017-04-30 16:06:26 -07:00
parent 21d8e9a6fd
commit 6548bcf104
15 changed files with 3289 additions and 0 deletions

View File

@@ -0,0 +1,308 @@
//// [enumClassification.ts]
// An enum type where each member has no initializer or an initializer that specififes
// a numeric literal, a string literal, or a single identifier naming another member in
// the enum type is classified as a literal enum type. An enum type that doesn't adhere
// to this pattern is classified as a numeric enum type.
// Examples of literal enum types
enum E01 {
A
}
enum E02 {
A = 123
}
enum E03 {
A = "hello"
}
enum E04 {
A,
B,
C
}
enum E05 {
A,
B = 10,
C
}
enum E06 {
A = "one",
B = "two",
C = "three"
}
enum E07 {
A,
B,
C = "hi",
D = 10,
E,
F = "bye"
}
enum E08 {
A = 10,
B = "hello",
C = A,
D = B,
E = C,
}
// Examples of numeric enum types with only constant members
enum E10 {}
enum E11 {
A = +0,
B,
C
}
enum E12 {
A = 1 << 0,
B = 1 << 1,
C = 1 << 2
}
// Examples of numeric enum types with constant and computed members
enum E20 {
A = "foo".length,
B = A + 1,
C = +"123",
D = Math.sin(1)
}
//// [enumClassification.js]
// An enum type where each member has no initializer or an initializer that specififes
// a numeric literal, a string literal, or a single identifier naming another member in
// the enum type is classified as a literal enum type. An enum type that doesn't adhere
// to this pattern is classified as a numeric enum type.
// Examples of literal enum types
var E01;
(function (E01) {
E01[E01["A"] = 0] = "A";
})(E01 || (E01 = {}));
var E02;
(function (E02) {
E02[E02["A"] = 123] = "A";
})(E02 || (E02 = {}));
var E03;
(function (E03) {
E03["A"] = "hello";
})(E03 || (E03 = {}));
var E04;
(function (E04) {
E04[E04["A"] = 0] = "A";
E04[E04["B"] = 1] = "B";
E04[E04["C"] = 2] = "C";
})(E04 || (E04 = {}));
var E05;
(function (E05) {
E05[E05["A"] = 0] = "A";
E05[E05["B"] = 10] = "B";
E05[E05["C"] = 11] = "C";
})(E05 || (E05 = {}));
var E06;
(function (E06) {
E06["A"] = "one";
E06["B"] = "two";
E06["C"] = "three";
})(E06 || (E06 = {}));
var E07;
(function (E07) {
E07[E07["A"] = 0] = "A";
E07[E07["B"] = 1] = "B";
E07["C"] = "hi";
E07[E07["D"] = 10] = "D";
E07[E07["E"] = 11] = "E";
E07["F"] = "bye";
})(E07 || (E07 = {}));
var E08;
(function (E08) {
E08[E08["A"] = 10] = "A";
E08["B"] = "hello";
E08[E08["C"] = 10] = "C";
E08["D"] = "hello";
E08[E08["E"] = 10] = "E";
})(E08 || (E08 = {}));
// Examples of numeric enum types with only constant members
var E10;
(function (E10) {
})(E10 || (E10 = {}));
var E11;
(function (E11) {
E11[E11["A"] = 0] = "A";
E11[E11["B"] = 1] = "B";
E11[E11["C"] = 2] = "C";
})(E11 || (E11 = {}));
var E12;
(function (E12) {
E12[E12["A"] = 1] = "A";
E12[E12["B"] = 2] = "B";
E12[E12["C"] = 4] = "C";
})(E12 || (E12 = {}));
// Examples of numeric enum types with constant and computed members
var E20;
(function (E20) {
E20[E20["A"] = "foo".length] = "A";
E20[E20["B"] = E20.A + 1] = "B";
E20[E20["C"] = +"123"] = "C";
E20[E20["D"] = Math.sin(1)] = "D";
})(E20 || (E20 = {}));
//// [enumClassification.d.ts]
declare enum E01 {
A = 0,
}
declare enum E02 {
A = 123,
}
declare enum E03 {
A = hello,
}
declare enum E04 {
A = 0,
B = 1,
C = 2,
}
declare enum E05 {
A = 0,
B = 10,
C = 11,
}
declare enum E06 {
A = one,
B = two,
C = three,
}
declare enum E07 {
A = 0,
B = 1,
C = hi,
D = 10,
E = 11,
F = bye,
}
declare enum E08 {
A = 10,
B = hello,
C = 10,
D = hello,
E = 10,
}
declare enum E10 {
}
declare enum E11 {
A = 0,
B = 1,
C = 2,
}
declare enum E12 {
A = 1,
B = 2,
C = 4,
}
declare enum E20 {
A,
B,
C,
D,
}
//// [DtsFileErrors]
tests/cases/conformance/enums/enumClassification.d.ts(8,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
tests/cases/conformance/enums/enumClassification.d.ts(21,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
tests/cases/conformance/enums/enumClassification.d.ts(22,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
tests/cases/conformance/enums/enumClassification.d.ts(23,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
tests/cases/conformance/enums/enumClassification.d.ts(28,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
tests/cases/conformance/enums/enumClassification.d.ts(31,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
tests/cases/conformance/enums/enumClassification.d.ts(35,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
tests/cases/conformance/enums/enumClassification.d.ts(37,9): error TS1066: In ambient enum declarations member initializer must be constant expression.
==== tests/cases/conformance/enums/enumClassification.d.ts (8 errors) ====
declare enum E01 {
A = 0,
}
declare enum E02 {
A = 123,
}
declare enum E03 {
A = hello,
~~~~~
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
}
declare enum E04 {
A = 0,
B = 1,
C = 2,
}
declare enum E05 {
A = 0,
B = 10,
C = 11,
}
declare enum E06 {
A = one,
~~~
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
B = two,
~~~
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
C = three,
~~~~~
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
}
declare enum E07 {
A = 0,
B = 1,
C = hi,
~~
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
D = 10,
E = 11,
F = bye,
~~~
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
}
declare enum E08 {
A = 10,
B = hello,
~~~~~
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
C = 10,
D = hello,
~~~~~
!!! error TS1066: In ambient enum declarations member initializer must be constant expression.
E = 10,
}
declare enum E10 {
}
declare enum E11 {
A = 0,
B = 1,
C = 2,
}
declare enum E12 {
A = 1,
B = 2,
C = 4,
}
declare enum E20 {
A,
B,
C,
D,
}

View File

@@ -0,0 +1,167 @@
=== tests/cases/conformance/enums/enumClassification.ts ===
// An enum type where each member has no initializer or an initializer that specififes
// a numeric literal, a string literal, or a single identifier naming another member in
// the enum type is classified as a literal enum type. An enum type that doesn't adhere
// to this pattern is classified as a numeric enum type.
// Examples of literal enum types
enum E01 {
>E01 : Symbol(E01, Decl(enumClassification.ts, 0, 0))
A
>A : Symbol(E01.A, Decl(enumClassification.ts, 7, 10))
}
enum E02 {
>E02 : Symbol(E02, Decl(enumClassification.ts, 9, 1))
A = 123
>A : Symbol(E02.A, Decl(enumClassification.ts, 11, 10))
}
enum E03 {
>E03 : Symbol(E03, Decl(enumClassification.ts, 13, 1))
A = "hello"
>A : Symbol(E03.A, Decl(enumClassification.ts, 15, 10))
}
enum E04 {
>E04 : Symbol(E04, Decl(enumClassification.ts, 17, 1))
A,
>A : Symbol(E04.A, Decl(enumClassification.ts, 19, 10))
B,
>B : Symbol(E04.B, Decl(enumClassification.ts, 20, 6))
C
>C : Symbol(E04.C, Decl(enumClassification.ts, 21, 6))
}
enum E05 {
>E05 : Symbol(E05, Decl(enumClassification.ts, 23, 1))
A,
>A : Symbol(E05.A, Decl(enumClassification.ts, 25, 10))
B = 10,
>B : Symbol(E05.B, Decl(enumClassification.ts, 26, 6))
C
>C : Symbol(E05.C, Decl(enumClassification.ts, 27, 11))
}
enum E06 {
>E06 : Symbol(E06, Decl(enumClassification.ts, 29, 1))
A = "one",
>A : Symbol(E06.A, Decl(enumClassification.ts, 31, 10))
B = "two",
>B : Symbol(E06.B, Decl(enumClassification.ts, 32, 14))
C = "three"
>C : Symbol(E06.C, Decl(enumClassification.ts, 33, 14))
}
enum E07 {
>E07 : Symbol(E07, Decl(enumClassification.ts, 35, 1))
A,
>A : Symbol(E07.A, Decl(enumClassification.ts, 37, 10))
B,
>B : Symbol(E07.B, Decl(enumClassification.ts, 38, 6))
C = "hi",
>C : Symbol(E07.C, Decl(enumClassification.ts, 39, 6))
D = 10,
>D : Symbol(E07.D, Decl(enumClassification.ts, 40, 13))
E,
>E : Symbol(E07.E, Decl(enumClassification.ts, 41, 11))
F = "bye"
>F : Symbol(E07.F, Decl(enumClassification.ts, 42, 6))
}
enum E08 {
>E08 : Symbol(E08, Decl(enumClassification.ts, 44, 1))
A = 10,
>A : Symbol(E08.A, Decl(enumClassification.ts, 46, 10))
B = "hello",
>B : Symbol(E08.B, Decl(enumClassification.ts, 47, 11))
C = A,
>C : Symbol(E08.C, Decl(enumClassification.ts, 48, 16))
>A : Symbol(E08.A, Decl(enumClassification.ts, 46, 10))
D = B,
>D : Symbol(E08.D, Decl(enumClassification.ts, 49, 10))
>B : Symbol(E08.B, Decl(enumClassification.ts, 47, 11))
E = C,
>E : Symbol(E08.E, Decl(enumClassification.ts, 50, 10))
>C : Symbol(E08.C, Decl(enumClassification.ts, 48, 16))
}
// Examples of numeric enum types with only constant members
enum E10 {}
>E10 : Symbol(E10, Decl(enumClassification.ts, 52, 1))
enum E11 {
>E11 : Symbol(E11, Decl(enumClassification.ts, 56, 11))
A = +0,
>A : Symbol(E11.A, Decl(enumClassification.ts, 58, 10))
B,
>B : Symbol(E11.B, Decl(enumClassification.ts, 59, 11))
C
>C : Symbol(E11.C, Decl(enumClassification.ts, 60, 6))
}
enum E12 {
>E12 : Symbol(E12, Decl(enumClassification.ts, 62, 1))
A = 1 << 0,
>A : Symbol(E12.A, Decl(enumClassification.ts, 64, 10))
B = 1 << 1,
>B : Symbol(E12.B, Decl(enumClassification.ts, 65, 15))
C = 1 << 2
>C : Symbol(E12.C, Decl(enumClassification.ts, 66, 15))
}
// Examples of numeric enum types with constant and computed members
enum E20 {
>E20 : Symbol(E20, Decl(enumClassification.ts, 68, 1))
A = "foo".length,
>A : Symbol(E20.A, Decl(enumClassification.ts, 72, 10))
>"foo".length : Symbol(String.length, Decl(lib.d.ts, --, --))
>length : Symbol(String.length, Decl(lib.d.ts, --, --))
B = A + 1,
>B : Symbol(E20.B, Decl(enumClassification.ts, 73, 21))
>A : Symbol(E20.A, Decl(enumClassification.ts, 72, 10))
C = +"123",
>C : Symbol(E20.C, Decl(enumClassification.ts, 74, 14))
D = Math.sin(1)
>D : Symbol(E20.D, Decl(enumClassification.ts, 75, 15))
>Math.sin : Symbol(Math.sin, Decl(lib.d.ts, --, --))
>Math : Symbol(Math, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>sin : Symbol(Math.sin, Decl(lib.d.ts, --, --))
}

View File

@@ -0,0 +1,196 @@
=== tests/cases/conformance/enums/enumClassification.ts ===
// An enum type where each member has no initializer or an initializer that specififes
// a numeric literal, a string literal, or a single identifier naming another member in
// the enum type is classified as a literal enum type. An enum type that doesn't adhere
// to this pattern is classified as a numeric enum type.
// Examples of literal enum types
enum E01 {
>E01 : E01
A
>A : E01
}
enum E02 {
>E02 : E02
A = 123
>A : E02
>123 : 123
}
enum E03 {
>E03 : E03
A = "hello"
>A : E03
>"hello" : "hello"
}
enum E04 {
>E04 : E04
A,
>A : E04.A
B,
>B : E04.B
C
>C : E04.C
}
enum E05 {
>E05 : E05
A,
>A : E05.A
B = 10,
>B : E05.B
>10 : 10
C
>C : E05.C
}
enum E06 {
>E06 : E06
A = "one",
>A : E06.A
>"one" : "one"
B = "two",
>B : E06.B
>"two" : "two"
C = "three"
>C : E06.C
>"three" : "three"
}
enum E07 {
>E07 : E07
A,
>A : E07.A
B,
>B : E07.B
C = "hi",
>C : E07.C
>"hi" : "hi"
D = 10,
>D : E07.D
>10 : 10
E,
>E : E07.E
F = "bye"
>F : E07.F
>"bye" : "bye"
}
enum E08 {
>E08 : E08
A = 10,
>A : E08.A
>10 : 10
B = "hello",
>B : E08.B
>"hello" : "hello"
C = A,
>C : E08.A
>A : E08.A
D = B,
>D : E08.B
>B : E08.B
E = C,
>E : E08.A
>C : E08.A
}
// Examples of numeric enum types with only constant members
enum E10 {}
>E10 : E10
enum E11 {
>E11 : E11
A = +0,
>A : E11
>+0 : number
>0 : 0
B,
>B : E11
C
>C : E11
}
enum E12 {
>E12 : E12
A = 1 << 0,
>A : E12
>1 << 0 : number
>1 : 1
>0 : 0
B = 1 << 1,
>B : E12
>1 << 1 : number
>1 : 1
>1 : 1
C = 1 << 2
>C : E12
>1 << 2 : number
>1 : 1
>2 : 2
}
// Examples of numeric enum types with constant and computed members
enum E20 {
>E20 : E20
A = "foo".length,
>A : E20
>"foo".length : number
>"foo" : "foo"
>length : number
B = A + 1,
>B : E20
>A + 1 : number
>A : E20
>1 : 1
C = +"123",
>C : E20
>+"123" : number
>"123" : "123"
D = Math.sin(1)
>D : E20
>Math.sin(1) : number
>Math.sin : (x: number) => number
>Math : Math
>sin : (x: number) => number
>1 : 1
}

View File

@@ -0,0 +1,178 @@
//// [stringEnumLiteralTypes1.ts]
const enum Choice { Unknown = "", Yes = "yes", No = "no" };
type YesNo = Choice.Yes | Choice.No;
type NoYes = Choice.No | Choice.Yes;
type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No;
function f1() {
var a: YesNo;
var a: NoYes;
var a: Choice.Yes | Choice.No;
var a: Choice.No | Choice.Yes;
}
function f2(a: YesNo, b: UnknownYesNo, c: Choice) {
b = a;
c = a;
c = b;
}
function f3(a: Choice.Yes, b: YesNo) {
var x = a + b;
var y = a == b;
var y = a != b;
var y = a === b;
var y = a !== b;
var y = a > b;
var y = a < b;
var y = a >= b;
var y = a <= b;
var y = !b;
}
declare function g(x: Choice.Yes): string;
declare function g(x: Choice.No): boolean;
declare function g(x: Choice): number;
function f5(a: YesNo, b: UnknownYesNo, c: Choice) {
var z1 = g(Choice.Yes);
var z2 = g(Choice.No);
var z3 = g(a);
var z4 = g(b);
var z5 = g(c);
}
function assertNever(x: never): never {
throw new Error("Unexpected value");
}
function f10(x: YesNo) {
switch (x) {
case Choice.Yes: return "true";
case Choice.No: return "false";
}
}
function f11(x: YesNo) {
switch (x) {
case Choice.Yes: return "true";
case Choice.No: return "false";
}
return assertNever(x);
}
function f12(x: UnknownYesNo) {
if (x) {
x;
}
else {
x;
}
}
function f13(x: UnknownYesNo) {
if (x === Choice.Yes) {
x;
}
else {
x;
}
}
type Item =
{ kind: Choice.Yes, a: string } |
{ kind: Choice.No, b: string };
function f20(x: Item) {
switch (x.kind) {
case Choice.Yes: return x.a;
case Choice.No: return x.b;
}
}
function f21(x: Item) {
switch (x.kind) {
case Choice.Yes: return x.a;
case Choice.No: return x.b;
}
return assertNever(x);
}
//// [stringEnumLiteralTypes1.js]
;
function f1() {
var a;
var a;
var a;
var a;
}
function f2(a, b, c) {
b = a;
c = a;
c = b;
}
function f3(a, b) {
var x = a + b;
var y = a == b;
var y = a != b;
var y = a === b;
var y = a !== b;
var y = a > b;
var y = a < b;
var y = a >= b;
var y = a <= b;
var y = !b;
}
function f5(a, b, c) {
var z1 = g("yes" /* Yes */);
var z2 = g("no" /* No */);
var z3 = g(a);
var z4 = g(b);
var z5 = g(c);
}
function assertNever(x) {
throw new Error("Unexpected value");
}
function f10(x) {
switch (x) {
case "yes" /* Yes */: return "true";
case "no" /* No */: return "false";
}
}
function f11(x) {
switch (x) {
case "yes" /* Yes */: return "true";
case "no" /* No */: return "false";
}
return assertNever(x);
}
function f12(x) {
if (x) {
x;
}
else {
x;
}
}
function f13(x) {
if (x === "yes" /* Yes */) {
x;
}
else {
x;
}
}
function f20(x) {
switch (x.kind) {
case "yes" /* Yes */: return x.a;
case "no" /* No */: return x.b;
}
}
function f21(x) {
switch (x.kind) {
case "yes" /* Yes */: return x.a;
case "no" /* No */: return x.b;
}
return assertNever(x);
}

View File

@@ -0,0 +1,353 @@
=== tests/cases/conformance/types/literal/stringEnumLiteralTypes1.ts ===
const enum Choice { Unknown = "", Yes = "yes", No = "no" };
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Unknown : Symbol(Choice.Unknown, Decl(stringEnumLiteralTypes1.ts, 0, 19))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
type YesNo = Choice.Yes | Choice.No;
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes1.ts, 0, 59))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
type NoYes = Choice.No | Choice.Yes;
>NoYes : Symbol(NoYes, Decl(stringEnumLiteralTypes1.ts, 2, 36))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No;
>UnknownYesNo : Symbol(UnknownYesNo, Decl(stringEnumLiteralTypes1.ts, 3, 36))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Unknown : Symbol(Choice.Unknown, Decl(stringEnumLiteralTypes1.ts, 0, 19))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
function f1() {
>f1 : Symbol(f1, Decl(stringEnumLiteralTypes1.ts, 4, 60))
var a: YesNo;
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 7, 7), Decl(stringEnumLiteralTypes1.ts, 8, 7), Decl(stringEnumLiteralTypes1.ts, 9, 7), Decl(stringEnumLiteralTypes1.ts, 10, 7))
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes1.ts, 0, 59))
var a: NoYes;
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 7, 7), Decl(stringEnumLiteralTypes1.ts, 8, 7), Decl(stringEnumLiteralTypes1.ts, 9, 7), Decl(stringEnumLiteralTypes1.ts, 10, 7))
>NoYes : Symbol(NoYes, Decl(stringEnumLiteralTypes1.ts, 2, 36))
var a: Choice.Yes | Choice.No;
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 7, 7), Decl(stringEnumLiteralTypes1.ts, 8, 7), Decl(stringEnumLiteralTypes1.ts, 9, 7), Decl(stringEnumLiteralTypes1.ts, 10, 7))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
var a: Choice.No | Choice.Yes;
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 7, 7), Decl(stringEnumLiteralTypes1.ts, 8, 7), Decl(stringEnumLiteralTypes1.ts, 9, 7), Decl(stringEnumLiteralTypes1.ts, 10, 7))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
}
function f2(a: YesNo, b: UnknownYesNo, c: Choice) {
>f2 : Symbol(f2, Decl(stringEnumLiteralTypes1.ts, 11, 1))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 13, 12))
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes1.ts, 0, 59))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 13, 21))
>UnknownYesNo : Symbol(UnknownYesNo, Decl(stringEnumLiteralTypes1.ts, 3, 36))
>c : Symbol(c, Decl(stringEnumLiteralTypes1.ts, 13, 38))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
b = a;
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 13, 21))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 13, 12))
c = a;
>c : Symbol(c, Decl(stringEnumLiteralTypes1.ts, 13, 38))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 13, 12))
c = b;
>c : Symbol(c, Decl(stringEnumLiteralTypes1.ts, 13, 38))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 13, 21))
}
function f3(a: Choice.Yes, b: YesNo) {
>f3 : Symbol(f3, Decl(stringEnumLiteralTypes1.ts, 17, 1))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 19, 12))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 19, 26))
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes1.ts, 0, 59))
var x = a + b;
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 20, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 19, 26))
var y = a == b;
>y : Symbol(y, Decl(stringEnumLiteralTypes1.ts, 21, 7), Decl(stringEnumLiteralTypes1.ts, 22, 7), Decl(stringEnumLiteralTypes1.ts, 23, 7), Decl(stringEnumLiteralTypes1.ts, 24, 7), Decl(stringEnumLiteralTypes1.ts, 25, 7), Decl(stringEnumLiteralTypes1.ts, 26, 7), Decl(stringEnumLiteralTypes1.ts, 27, 7), Decl(stringEnumLiteralTypes1.ts, 28, 7), Decl(stringEnumLiteralTypes1.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 19, 26))
var y = a != b;
>y : Symbol(y, Decl(stringEnumLiteralTypes1.ts, 21, 7), Decl(stringEnumLiteralTypes1.ts, 22, 7), Decl(stringEnumLiteralTypes1.ts, 23, 7), Decl(stringEnumLiteralTypes1.ts, 24, 7), Decl(stringEnumLiteralTypes1.ts, 25, 7), Decl(stringEnumLiteralTypes1.ts, 26, 7), Decl(stringEnumLiteralTypes1.ts, 27, 7), Decl(stringEnumLiteralTypes1.ts, 28, 7), Decl(stringEnumLiteralTypes1.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 19, 26))
var y = a === b;
>y : Symbol(y, Decl(stringEnumLiteralTypes1.ts, 21, 7), Decl(stringEnumLiteralTypes1.ts, 22, 7), Decl(stringEnumLiteralTypes1.ts, 23, 7), Decl(stringEnumLiteralTypes1.ts, 24, 7), Decl(stringEnumLiteralTypes1.ts, 25, 7), Decl(stringEnumLiteralTypes1.ts, 26, 7), Decl(stringEnumLiteralTypes1.ts, 27, 7), Decl(stringEnumLiteralTypes1.ts, 28, 7), Decl(stringEnumLiteralTypes1.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 19, 26))
var y = a !== b;
>y : Symbol(y, Decl(stringEnumLiteralTypes1.ts, 21, 7), Decl(stringEnumLiteralTypes1.ts, 22, 7), Decl(stringEnumLiteralTypes1.ts, 23, 7), Decl(stringEnumLiteralTypes1.ts, 24, 7), Decl(stringEnumLiteralTypes1.ts, 25, 7), Decl(stringEnumLiteralTypes1.ts, 26, 7), Decl(stringEnumLiteralTypes1.ts, 27, 7), Decl(stringEnumLiteralTypes1.ts, 28, 7), Decl(stringEnumLiteralTypes1.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 19, 26))
var y = a > b;
>y : Symbol(y, Decl(stringEnumLiteralTypes1.ts, 21, 7), Decl(stringEnumLiteralTypes1.ts, 22, 7), Decl(stringEnumLiteralTypes1.ts, 23, 7), Decl(stringEnumLiteralTypes1.ts, 24, 7), Decl(stringEnumLiteralTypes1.ts, 25, 7), Decl(stringEnumLiteralTypes1.ts, 26, 7), Decl(stringEnumLiteralTypes1.ts, 27, 7), Decl(stringEnumLiteralTypes1.ts, 28, 7), Decl(stringEnumLiteralTypes1.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 19, 26))
var y = a < b;
>y : Symbol(y, Decl(stringEnumLiteralTypes1.ts, 21, 7), Decl(stringEnumLiteralTypes1.ts, 22, 7), Decl(stringEnumLiteralTypes1.ts, 23, 7), Decl(stringEnumLiteralTypes1.ts, 24, 7), Decl(stringEnumLiteralTypes1.ts, 25, 7), Decl(stringEnumLiteralTypes1.ts, 26, 7), Decl(stringEnumLiteralTypes1.ts, 27, 7), Decl(stringEnumLiteralTypes1.ts, 28, 7), Decl(stringEnumLiteralTypes1.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 19, 26))
var y = a >= b;
>y : Symbol(y, Decl(stringEnumLiteralTypes1.ts, 21, 7), Decl(stringEnumLiteralTypes1.ts, 22, 7), Decl(stringEnumLiteralTypes1.ts, 23, 7), Decl(stringEnumLiteralTypes1.ts, 24, 7), Decl(stringEnumLiteralTypes1.ts, 25, 7), Decl(stringEnumLiteralTypes1.ts, 26, 7), Decl(stringEnumLiteralTypes1.ts, 27, 7), Decl(stringEnumLiteralTypes1.ts, 28, 7), Decl(stringEnumLiteralTypes1.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 19, 26))
var y = a <= b;
>y : Symbol(y, Decl(stringEnumLiteralTypes1.ts, 21, 7), Decl(stringEnumLiteralTypes1.ts, 22, 7), Decl(stringEnumLiteralTypes1.ts, 23, 7), Decl(stringEnumLiteralTypes1.ts, 24, 7), Decl(stringEnumLiteralTypes1.ts, 25, 7), Decl(stringEnumLiteralTypes1.ts, 26, 7), Decl(stringEnumLiteralTypes1.ts, 27, 7), Decl(stringEnumLiteralTypes1.ts, 28, 7), Decl(stringEnumLiteralTypes1.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 19, 26))
var y = !b;
>y : Symbol(y, Decl(stringEnumLiteralTypes1.ts, 21, 7), Decl(stringEnumLiteralTypes1.ts, 22, 7), Decl(stringEnumLiteralTypes1.ts, 23, 7), Decl(stringEnumLiteralTypes1.ts, 24, 7), Decl(stringEnumLiteralTypes1.ts, 25, 7), Decl(stringEnumLiteralTypes1.ts, 26, 7), Decl(stringEnumLiteralTypes1.ts, 27, 7), Decl(stringEnumLiteralTypes1.ts, 28, 7), Decl(stringEnumLiteralTypes1.ts, 29, 7))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 19, 26))
}
declare function g(x: Choice.Yes): string;
>g : Symbol(g, Decl(stringEnumLiteralTypes1.ts, 30, 1), Decl(stringEnumLiteralTypes1.ts, 32, 42), Decl(stringEnumLiteralTypes1.ts, 33, 42))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 32, 19))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
declare function g(x: Choice.No): boolean;
>g : Symbol(g, Decl(stringEnumLiteralTypes1.ts, 30, 1), Decl(stringEnumLiteralTypes1.ts, 32, 42), Decl(stringEnumLiteralTypes1.ts, 33, 42))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 33, 19))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
declare function g(x: Choice): number;
>g : Symbol(g, Decl(stringEnumLiteralTypes1.ts, 30, 1), Decl(stringEnumLiteralTypes1.ts, 32, 42), Decl(stringEnumLiteralTypes1.ts, 33, 42))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 34, 19))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
function f5(a: YesNo, b: UnknownYesNo, c: Choice) {
>f5 : Symbol(f5, Decl(stringEnumLiteralTypes1.ts, 34, 38))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 36, 12))
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes1.ts, 0, 59))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 36, 21))
>UnknownYesNo : Symbol(UnknownYesNo, Decl(stringEnumLiteralTypes1.ts, 3, 36))
>c : Symbol(c, Decl(stringEnumLiteralTypes1.ts, 36, 38))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
var z1 = g(Choice.Yes);
>z1 : Symbol(z1, Decl(stringEnumLiteralTypes1.ts, 37, 7))
>g : Symbol(g, Decl(stringEnumLiteralTypes1.ts, 30, 1), Decl(stringEnumLiteralTypes1.ts, 32, 42), Decl(stringEnumLiteralTypes1.ts, 33, 42))
>Choice.Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
var z2 = g(Choice.No);
>z2 : Symbol(z2, Decl(stringEnumLiteralTypes1.ts, 38, 7))
>g : Symbol(g, Decl(stringEnumLiteralTypes1.ts, 30, 1), Decl(stringEnumLiteralTypes1.ts, 32, 42), Decl(stringEnumLiteralTypes1.ts, 33, 42))
>Choice.No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
var z3 = g(a);
>z3 : Symbol(z3, Decl(stringEnumLiteralTypes1.ts, 39, 7))
>g : Symbol(g, Decl(stringEnumLiteralTypes1.ts, 30, 1), Decl(stringEnumLiteralTypes1.ts, 32, 42), Decl(stringEnumLiteralTypes1.ts, 33, 42))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 36, 12))
var z4 = g(b);
>z4 : Symbol(z4, Decl(stringEnumLiteralTypes1.ts, 40, 7))
>g : Symbol(g, Decl(stringEnumLiteralTypes1.ts, 30, 1), Decl(stringEnumLiteralTypes1.ts, 32, 42), Decl(stringEnumLiteralTypes1.ts, 33, 42))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 36, 21))
var z5 = g(c);
>z5 : Symbol(z5, Decl(stringEnumLiteralTypes1.ts, 41, 7))
>g : Symbol(g, Decl(stringEnumLiteralTypes1.ts, 30, 1), Decl(stringEnumLiteralTypes1.ts, 32, 42), Decl(stringEnumLiteralTypes1.ts, 33, 42))
>c : Symbol(c, Decl(stringEnumLiteralTypes1.ts, 36, 38))
}
function assertNever(x: never): never {
>assertNever : Symbol(assertNever, Decl(stringEnumLiteralTypes1.ts, 42, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 44, 21))
throw new Error("Unexpected value");
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
}
function f10(x: YesNo) {
>f10 : Symbol(f10, Decl(stringEnumLiteralTypes1.ts, 46, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 48, 13))
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes1.ts, 0, 59))
switch (x) {
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 48, 13))
case Choice.Yes: return "true";
>Choice.Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
case Choice.No: return "false";
>Choice.No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
}
}
function f11(x: YesNo) {
>f11 : Symbol(f11, Decl(stringEnumLiteralTypes1.ts, 53, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 55, 13))
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes1.ts, 0, 59))
switch (x) {
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 55, 13))
case Choice.Yes: return "true";
>Choice.Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
case Choice.No: return "false";
>Choice.No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
}
return assertNever(x);
>assertNever : Symbol(assertNever, Decl(stringEnumLiteralTypes1.ts, 42, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 55, 13))
}
function f12(x: UnknownYesNo) {
>f12 : Symbol(f12, Decl(stringEnumLiteralTypes1.ts, 61, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 63, 13))
>UnknownYesNo : Symbol(UnknownYesNo, Decl(stringEnumLiteralTypes1.ts, 3, 36))
if (x) {
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 63, 13))
x;
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 63, 13))
}
else {
x;
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 63, 13))
}
}
function f13(x: UnknownYesNo) {
>f13 : Symbol(f13, Decl(stringEnumLiteralTypes1.ts, 70, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 72, 13))
>UnknownYesNo : Symbol(UnknownYesNo, Decl(stringEnumLiteralTypes1.ts, 3, 36))
if (x === Choice.Yes) {
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 72, 13))
>Choice.Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
x;
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 72, 13))
}
else {
x;
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 72, 13))
}
}
type Item =
>Item : Symbol(Item, Decl(stringEnumLiteralTypes1.ts, 79, 1))
{ kind: Choice.Yes, a: string } |
>kind : Symbol(kind, Decl(stringEnumLiteralTypes1.ts, 82, 5))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 82, 23))
{ kind: Choice.No, b: string };
>kind : Symbol(kind, Decl(stringEnumLiteralTypes1.ts, 83, 5))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 83, 22))
function f20(x: Item) {
>f20 : Symbol(f20, Decl(stringEnumLiteralTypes1.ts, 83, 35))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 85, 13))
>Item : Symbol(Item, Decl(stringEnumLiteralTypes1.ts, 79, 1))
switch (x.kind) {
>x.kind : Symbol(kind, Decl(stringEnumLiteralTypes1.ts, 82, 5), Decl(stringEnumLiteralTypes1.ts, 83, 5))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 85, 13))
>kind : Symbol(kind, Decl(stringEnumLiteralTypes1.ts, 82, 5), Decl(stringEnumLiteralTypes1.ts, 83, 5))
case Choice.Yes: return x.a;
>Choice.Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>x.a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 82, 23))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 85, 13))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 82, 23))
case Choice.No: return x.b;
>Choice.No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
>x.b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 83, 22))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 85, 13))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 83, 22))
}
}
function f21(x: Item) {
>f21 : Symbol(f21, Decl(stringEnumLiteralTypes1.ts, 90, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 92, 13))
>Item : Symbol(Item, Decl(stringEnumLiteralTypes1.ts, 79, 1))
switch (x.kind) {
>x.kind : Symbol(kind, Decl(stringEnumLiteralTypes1.ts, 82, 5), Decl(stringEnumLiteralTypes1.ts, 83, 5))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 92, 13))
>kind : Symbol(kind, Decl(stringEnumLiteralTypes1.ts, 82, 5), Decl(stringEnumLiteralTypes1.ts, 83, 5))
case Choice.Yes: return x.a;
>Choice.Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes1.ts, 0, 33))
>x.a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 82, 23))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 92, 13))
>a : Symbol(a, Decl(stringEnumLiteralTypes1.ts, 82, 23))
case Choice.No: return x.b;
>Choice.No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes1.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes1.ts, 0, 46))
>x.b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 83, 22))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 92, 13))
>b : Symbol(b, Decl(stringEnumLiteralTypes1.ts, 83, 22))
}
return assertNever(x);
>assertNever : Symbol(assertNever, Decl(stringEnumLiteralTypes1.ts, 42, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes1.ts, 92, 13))
}

View File

@@ -0,0 +1,383 @@
=== tests/cases/conformance/types/literal/stringEnumLiteralTypes1.ts ===
const enum Choice { Unknown = "", Yes = "yes", No = "no" };
>Choice : Choice
>Unknown : Choice.Unknown
>"" : ""
>Yes : Choice.Yes
>"yes" : "yes"
>No : Choice.No
>"no" : "no"
type YesNo = Choice.Yes | Choice.No;
>YesNo : YesNo
>Choice : any
>Yes : Choice.Yes
>Choice : any
>No : Choice.No
type NoYes = Choice.No | Choice.Yes;
>NoYes : YesNo
>Choice : any
>No : Choice.No
>Choice : any
>Yes : Choice.Yes
type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No;
>UnknownYesNo : Choice
>Choice : any
>Unknown : Choice.Unknown
>Choice : any
>Yes : Choice.Yes
>Choice : any
>No : Choice.No
function f1() {
>f1 : () => void
var a: YesNo;
>a : YesNo
>YesNo : YesNo
var a: NoYes;
>a : YesNo
>NoYes : YesNo
var a: Choice.Yes | Choice.No;
>a : YesNo
>Choice : any
>Yes : Choice.Yes
>Choice : any
>No : Choice.No
var a: Choice.No | Choice.Yes;
>a : YesNo
>Choice : any
>No : Choice.No
>Choice : any
>Yes : Choice.Yes
}
function f2(a: YesNo, b: UnknownYesNo, c: Choice) {
>f2 : (a: YesNo, b: Choice, c: Choice) => void
>a : YesNo
>YesNo : YesNo
>b : Choice
>UnknownYesNo : Choice
>c : Choice
>Choice : Choice
b = a;
>b = a : YesNo
>b : Choice
>a : YesNo
c = a;
>c = a : YesNo
>c : Choice
>a : YesNo
c = b;
>c = b : YesNo
>c : Choice
>b : YesNo
}
function f3(a: Choice.Yes, b: YesNo) {
>f3 : (a: Choice.Yes, b: YesNo) => void
>a : Choice.Yes
>Choice : any
>Yes : Choice.Yes
>b : YesNo
>YesNo : YesNo
var x = a + b;
>x : string
>a + b : string
>a : Choice.Yes
>b : YesNo
var y = a == b;
>y : boolean
>a == b : boolean
>a : Choice.Yes
>b : YesNo
var y = a != b;
>y : boolean
>a != b : boolean
>a : Choice.Yes
>b : YesNo
var y = a === b;
>y : boolean
>a === b : boolean
>a : Choice.Yes
>b : YesNo
var y = a !== b;
>y : boolean
>a !== b : boolean
>a : Choice.Yes
>b : YesNo
var y = a > b;
>y : boolean
>a > b : boolean
>a : Choice.Yes
>b : YesNo
var y = a < b;
>y : boolean
>a < b : boolean
>a : Choice.Yes
>b : YesNo
var y = a >= b;
>y : boolean
>a >= b : boolean
>a : Choice.Yes
>b : YesNo
var y = a <= b;
>y : boolean
>a <= b : boolean
>a : Choice.Yes
>b : YesNo
var y = !b;
>y : boolean
>!b : boolean
>b : YesNo
}
declare function g(x: Choice.Yes): string;
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>x : Choice.Yes
>Choice : any
>Yes : Choice.Yes
declare function g(x: Choice.No): boolean;
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>x : Choice.No
>Choice : any
>No : Choice.No
declare function g(x: Choice): number;
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>x : Choice
>Choice : Choice
function f5(a: YesNo, b: UnknownYesNo, c: Choice) {
>f5 : (a: YesNo, b: Choice, c: Choice) => void
>a : YesNo
>YesNo : YesNo
>b : Choice
>UnknownYesNo : Choice
>c : Choice
>Choice : Choice
var z1 = g(Choice.Yes);
>z1 : string
>g(Choice.Yes) : string
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
var z2 = g(Choice.No);
>z2 : boolean
>g(Choice.No) : boolean
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>Choice.No : Choice.No
>Choice : typeof Choice
>No : Choice.No
var z3 = g(a);
>z3 : number
>g(a) : number
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>a : YesNo
var z4 = g(b);
>z4 : number
>g(b) : number
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>b : Choice
var z5 = g(c);
>z5 : number
>g(c) : number
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>c : Choice
}
function assertNever(x: never): never {
>assertNever : (x: never) => never
>x : never
throw new Error("Unexpected value");
>new Error("Unexpected value") : Error
>Error : ErrorConstructor
>"Unexpected value" : "Unexpected value"
}
function f10(x: YesNo) {
>f10 : (x: YesNo) => "true" | "false"
>x : YesNo
>YesNo : YesNo
switch (x) {
>x : YesNo
case Choice.Yes: return "true";
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
>"true" : "true"
case Choice.No: return "false";
>Choice.No : Choice.No
>Choice : typeof Choice
>No : Choice.No
>"false" : "false"
}
}
function f11(x: YesNo) {
>f11 : (x: YesNo) => "true" | "false"
>x : YesNo
>YesNo : YesNo
switch (x) {
>x : YesNo
case Choice.Yes: return "true";
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
>"true" : "true"
case Choice.No: return "false";
>Choice.No : Choice.No
>Choice : typeof Choice
>No : Choice.No
>"false" : "false"
}
return assertNever(x);
>assertNever(x) : never
>assertNever : (x: never) => never
>x : never
}
function f12(x: UnknownYesNo) {
>f12 : (x: Choice) => void
>x : Choice
>UnknownYesNo : Choice
if (x) {
>x : Choice
x;
>x : YesNo
}
else {
x;
>x : Choice
}
}
function f13(x: UnknownYesNo) {
>f13 : (x: Choice) => void
>x : Choice
>UnknownYesNo : Choice
if (x === Choice.Yes) {
>x === Choice.Yes : boolean
>x : Choice
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
x;
>x : Choice.Yes
}
else {
x;
>x : Choice.Unknown | Choice.No
}
}
type Item =
>Item : Item
{ kind: Choice.Yes, a: string } |
>kind : Choice.Yes
>Choice : any
>Yes : Choice.Yes
>a : string
{ kind: Choice.No, b: string };
>kind : Choice.No
>Choice : any
>No : Choice.No
>b : string
function f20(x: Item) {
>f20 : (x: Item) => string
>x : Item
>Item : Item
switch (x.kind) {
>x.kind : YesNo
>x : Item
>kind : YesNo
case Choice.Yes: return x.a;
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
>x.a : string
>x : { kind: Choice.Yes; a: string; }
>a : string
case Choice.No: return x.b;
>Choice.No : Choice.No
>Choice : typeof Choice
>No : Choice.No
>x.b : string
>x : { kind: Choice.No; b: string; }
>b : string
}
}
function f21(x: Item) {
>f21 : (x: Item) => string
>x : Item
>Item : Item
switch (x.kind) {
>x.kind : YesNo
>x : Item
>kind : YesNo
case Choice.Yes: return x.a;
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
>x.a : string
>x : { kind: Choice.Yes; a: string; }
>a : string
case Choice.No: return x.b;
>Choice.No : Choice.No
>Choice : typeof Choice
>No : Choice.No
>x.b : string
>x : { kind: Choice.No; b: string; }
>b : string
}
return assertNever(x);
>assertNever(x) : never
>assertNever : (x: never) => never
>x : never
}

View File

@@ -0,0 +1,178 @@
//// [stringEnumLiteralTypes2.ts]
const enum Choice { Unknown = "", Yes = "yes", No = "no" };
type YesNo = Choice.Yes | Choice.No;
type NoYes = Choice.No | Choice.Yes;
type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No;
function f1() {
var a: YesNo;
var a: NoYes;
var a: Choice.Yes | Choice.No;
var a: Choice.No | Choice.Yes;
}
function f2(a: YesNo, b: UnknownYesNo, c: Choice) {
b = a;
c = a;
c = b;
}
function f3(a: Choice.Yes, b: YesNo) {
var x = a + b;
var y = a == b;
var y = a != b;
var y = a === b;
var y = a !== b;
var y = a > b;
var y = a < b;
var y = a >= b;
var y = a <= b;
var y = !b;
}
declare function g(x: Choice.Yes): string;
declare function g(x: Choice.No): boolean;
declare function g(x: Choice): number;
function f5(a: YesNo, b: UnknownYesNo, c: Choice) {
var z1 = g(Choice.Yes);
var z2 = g(Choice.No);
var z3 = g(a);
var z4 = g(b);
var z5 = g(c);
}
function assertNever(x: never): never {
throw new Error("Unexpected value");
}
function f10(x: YesNo) {
switch (x) {
case Choice.Yes: return "true";
case Choice.No: return "false";
}
}
function f11(x: YesNo) {
switch (x) {
case Choice.Yes: return "true";
case Choice.No: return "false";
}
return assertNever(x);
}
function f12(x: UnknownYesNo) {
if (x) {
x;
}
else {
x;
}
}
function f13(x: UnknownYesNo) {
if (x === Choice.Yes) {
x;
}
else {
x;
}
}
type Item =
{ kind: Choice.Yes, a: string } |
{ kind: Choice.No, b: string };
function f20(x: Item) {
switch (x.kind) {
case Choice.Yes: return x.a;
case Choice.No: return x.b;
}
}
function f21(x: Item) {
switch (x.kind) {
case Choice.Yes: return x.a;
case Choice.No: return x.b;
}
return assertNever(x);
}
//// [stringEnumLiteralTypes2.js]
;
function f1() {
var a;
var a;
var a;
var a;
}
function f2(a, b, c) {
b = a;
c = a;
c = b;
}
function f3(a, b) {
var x = a + b;
var y = a == b;
var y = a != b;
var y = a === b;
var y = a !== b;
var y = a > b;
var y = a < b;
var y = a >= b;
var y = a <= b;
var y = !b;
}
function f5(a, b, c) {
var z1 = g("yes" /* Yes */);
var z2 = g("no" /* No */);
var z3 = g(a);
var z4 = g(b);
var z5 = g(c);
}
function assertNever(x) {
throw new Error("Unexpected value");
}
function f10(x) {
switch (x) {
case "yes" /* Yes */: return "true";
case "no" /* No */: return "false";
}
}
function f11(x) {
switch (x) {
case "yes" /* Yes */: return "true";
case "no" /* No */: return "false";
}
return assertNever(x);
}
function f12(x) {
if (x) {
x;
}
else {
x;
}
}
function f13(x) {
if (x === "yes" /* Yes */) {
x;
}
else {
x;
}
}
function f20(x) {
switch (x.kind) {
case "yes" /* Yes */: return x.a;
case "no" /* No */: return x.b;
}
}
function f21(x) {
switch (x.kind) {
case "yes" /* Yes */: return x.a;
case "no" /* No */: return x.b;
}
return assertNever(x);
}

View File

@@ -0,0 +1,353 @@
=== tests/cases/conformance/types/literal/stringEnumLiteralTypes2.ts ===
const enum Choice { Unknown = "", Yes = "yes", No = "no" };
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Unknown : Symbol(Choice.Unknown, Decl(stringEnumLiteralTypes2.ts, 0, 19))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
type YesNo = Choice.Yes | Choice.No;
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes2.ts, 0, 59))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
type NoYes = Choice.No | Choice.Yes;
>NoYes : Symbol(NoYes, Decl(stringEnumLiteralTypes2.ts, 2, 36))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No;
>UnknownYesNo : Symbol(UnknownYesNo, Decl(stringEnumLiteralTypes2.ts, 3, 36))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Unknown : Symbol(Choice.Unknown, Decl(stringEnumLiteralTypes2.ts, 0, 19))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
function f1() {
>f1 : Symbol(f1, Decl(stringEnumLiteralTypes2.ts, 4, 60))
var a: YesNo;
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 7, 7), Decl(stringEnumLiteralTypes2.ts, 8, 7), Decl(stringEnumLiteralTypes2.ts, 9, 7), Decl(stringEnumLiteralTypes2.ts, 10, 7))
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes2.ts, 0, 59))
var a: NoYes;
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 7, 7), Decl(stringEnumLiteralTypes2.ts, 8, 7), Decl(stringEnumLiteralTypes2.ts, 9, 7), Decl(stringEnumLiteralTypes2.ts, 10, 7))
>NoYes : Symbol(NoYes, Decl(stringEnumLiteralTypes2.ts, 2, 36))
var a: Choice.Yes | Choice.No;
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 7, 7), Decl(stringEnumLiteralTypes2.ts, 8, 7), Decl(stringEnumLiteralTypes2.ts, 9, 7), Decl(stringEnumLiteralTypes2.ts, 10, 7))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
var a: Choice.No | Choice.Yes;
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 7, 7), Decl(stringEnumLiteralTypes2.ts, 8, 7), Decl(stringEnumLiteralTypes2.ts, 9, 7), Decl(stringEnumLiteralTypes2.ts, 10, 7))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
}
function f2(a: YesNo, b: UnknownYesNo, c: Choice) {
>f2 : Symbol(f2, Decl(stringEnumLiteralTypes2.ts, 11, 1))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 13, 12))
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes2.ts, 0, 59))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 13, 21))
>UnknownYesNo : Symbol(UnknownYesNo, Decl(stringEnumLiteralTypes2.ts, 3, 36))
>c : Symbol(c, Decl(stringEnumLiteralTypes2.ts, 13, 38))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
b = a;
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 13, 21))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 13, 12))
c = a;
>c : Symbol(c, Decl(stringEnumLiteralTypes2.ts, 13, 38))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 13, 12))
c = b;
>c : Symbol(c, Decl(stringEnumLiteralTypes2.ts, 13, 38))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 13, 21))
}
function f3(a: Choice.Yes, b: YesNo) {
>f3 : Symbol(f3, Decl(stringEnumLiteralTypes2.ts, 17, 1))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 19, 12))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 19, 26))
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes2.ts, 0, 59))
var x = a + b;
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 20, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 19, 26))
var y = a == b;
>y : Symbol(y, Decl(stringEnumLiteralTypes2.ts, 21, 7), Decl(stringEnumLiteralTypes2.ts, 22, 7), Decl(stringEnumLiteralTypes2.ts, 23, 7), Decl(stringEnumLiteralTypes2.ts, 24, 7), Decl(stringEnumLiteralTypes2.ts, 25, 7), Decl(stringEnumLiteralTypes2.ts, 26, 7), Decl(stringEnumLiteralTypes2.ts, 27, 7), Decl(stringEnumLiteralTypes2.ts, 28, 7), Decl(stringEnumLiteralTypes2.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 19, 26))
var y = a != b;
>y : Symbol(y, Decl(stringEnumLiteralTypes2.ts, 21, 7), Decl(stringEnumLiteralTypes2.ts, 22, 7), Decl(stringEnumLiteralTypes2.ts, 23, 7), Decl(stringEnumLiteralTypes2.ts, 24, 7), Decl(stringEnumLiteralTypes2.ts, 25, 7), Decl(stringEnumLiteralTypes2.ts, 26, 7), Decl(stringEnumLiteralTypes2.ts, 27, 7), Decl(stringEnumLiteralTypes2.ts, 28, 7), Decl(stringEnumLiteralTypes2.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 19, 26))
var y = a === b;
>y : Symbol(y, Decl(stringEnumLiteralTypes2.ts, 21, 7), Decl(stringEnumLiteralTypes2.ts, 22, 7), Decl(stringEnumLiteralTypes2.ts, 23, 7), Decl(stringEnumLiteralTypes2.ts, 24, 7), Decl(stringEnumLiteralTypes2.ts, 25, 7), Decl(stringEnumLiteralTypes2.ts, 26, 7), Decl(stringEnumLiteralTypes2.ts, 27, 7), Decl(stringEnumLiteralTypes2.ts, 28, 7), Decl(stringEnumLiteralTypes2.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 19, 26))
var y = a !== b;
>y : Symbol(y, Decl(stringEnumLiteralTypes2.ts, 21, 7), Decl(stringEnumLiteralTypes2.ts, 22, 7), Decl(stringEnumLiteralTypes2.ts, 23, 7), Decl(stringEnumLiteralTypes2.ts, 24, 7), Decl(stringEnumLiteralTypes2.ts, 25, 7), Decl(stringEnumLiteralTypes2.ts, 26, 7), Decl(stringEnumLiteralTypes2.ts, 27, 7), Decl(stringEnumLiteralTypes2.ts, 28, 7), Decl(stringEnumLiteralTypes2.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 19, 26))
var y = a > b;
>y : Symbol(y, Decl(stringEnumLiteralTypes2.ts, 21, 7), Decl(stringEnumLiteralTypes2.ts, 22, 7), Decl(stringEnumLiteralTypes2.ts, 23, 7), Decl(stringEnumLiteralTypes2.ts, 24, 7), Decl(stringEnumLiteralTypes2.ts, 25, 7), Decl(stringEnumLiteralTypes2.ts, 26, 7), Decl(stringEnumLiteralTypes2.ts, 27, 7), Decl(stringEnumLiteralTypes2.ts, 28, 7), Decl(stringEnumLiteralTypes2.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 19, 26))
var y = a < b;
>y : Symbol(y, Decl(stringEnumLiteralTypes2.ts, 21, 7), Decl(stringEnumLiteralTypes2.ts, 22, 7), Decl(stringEnumLiteralTypes2.ts, 23, 7), Decl(stringEnumLiteralTypes2.ts, 24, 7), Decl(stringEnumLiteralTypes2.ts, 25, 7), Decl(stringEnumLiteralTypes2.ts, 26, 7), Decl(stringEnumLiteralTypes2.ts, 27, 7), Decl(stringEnumLiteralTypes2.ts, 28, 7), Decl(stringEnumLiteralTypes2.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 19, 26))
var y = a >= b;
>y : Symbol(y, Decl(stringEnumLiteralTypes2.ts, 21, 7), Decl(stringEnumLiteralTypes2.ts, 22, 7), Decl(stringEnumLiteralTypes2.ts, 23, 7), Decl(stringEnumLiteralTypes2.ts, 24, 7), Decl(stringEnumLiteralTypes2.ts, 25, 7), Decl(stringEnumLiteralTypes2.ts, 26, 7), Decl(stringEnumLiteralTypes2.ts, 27, 7), Decl(stringEnumLiteralTypes2.ts, 28, 7), Decl(stringEnumLiteralTypes2.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 19, 26))
var y = a <= b;
>y : Symbol(y, Decl(stringEnumLiteralTypes2.ts, 21, 7), Decl(stringEnumLiteralTypes2.ts, 22, 7), Decl(stringEnumLiteralTypes2.ts, 23, 7), Decl(stringEnumLiteralTypes2.ts, 24, 7), Decl(stringEnumLiteralTypes2.ts, 25, 7), Decl(stringEnumLiteralTypes2.ts, 26, 7), Decl(stringEnumLiteralTypes2.ts, 27, 7), Decl(stringEnumLiteralTypes2.ts, 28, 7), Decl(stringEnumLiteralTypes2.ts, 29, 7))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 19, 12))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 19, 26))
var y = !b;
>y : Symbol(y, Decl(stringEnumLiteralTypes2.ts, 21, 7), Decl(stringEnumLiteralTypes2.ts, 22, 7), Decl(stringEnumLiteralTypes2.ts, 23, 7), Decl(stringEnumLiteralTypes2.ts, 24, 7), Decl(stringEnumLiteralTypes2.ts, 25, 7), Decl(stringEnumLiteralTypes2.ts, 26, 7), Decl(stringEnumLiteralTypes2.ts, 27, 7), Decl(stringEnumLiteralTypes2.ts, 28, 7), Decl(stringEnumLiteralTypes2.ts, 29, 7))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 19, 26))
}
declare function g(x: Choice.Yes): string;
>g : Symbol(g, Decl(stringEnumLiteralTypes2.ts, 30, 1), Decl(stringEnumLiteralTypes2.ts, 32, 42), Decl(stringEnumLiteralTypes2.ts, 33, 42))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 32, 19))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
declare function g(x: Choice.No): boolean;
>g : Symbol(g, Decl(stringEnumLiteralTypes2.ts, 30, 1), Decl(stringEnumLiteralTypes2.ts, 32, 42), Decl(stringEnumLiteralTypes2.ts, 33, 42))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 33, 19))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
declare function g(x: Choice): number;
>g : Symbol(g, Decl(stringEnumLiteralTypes2.ts, 30, 1), Decl(stringEnumLiteralTypes2.ts, 32, 42), Decl(stringEnumLiteralTypes2.ts, 33, 42))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 34, 19))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
function f5(a: YesNo, b: UnknownYesNo, c: Choice) {
>f5 : Symbol(f5, Decl(stringEnumLiteralTypes2.ts, 34, 38))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 36, 12))
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes2.ts, 0, 59))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 36, 21))
>UnknownYesNo : Symbol(UnknownYesNo, Decl(stringEnumLiteralTypes2.ts, 3, 36))
>c : Symbol(c, Decl(stringEnumLiteralTypes2.ts, 36, 38))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
var z1 = g(Choice.Yes);
>z1 : Symbol(z1, Decl(stringEnumLiteralTypes2.ts, 37, 7))
>g : Symbol(g, Decl(stringEnumLiteralTypes2.ts, 30, 1), Decl(stringEnumLiteralTypes2.ts, 32, 42), Decl(stringEnumLiteralTypes2.ts, 33, 42))
>Choice.Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
var z2 = g(Choice.No);
>z2 : Symbol(z2, Decl(stringEnumLiteralTypes2.ts, 38, 7))
>g : Symbol(g, Decl(stringEnumLiteralTypes2.ts, 30, 1), Decl(stringEnumLiteralTypes2.ts, 32, 42), Decl(stringEnumLiteralTypes2.ts, 33, 42))
>Choice.No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
var z3 = g(a);
>z3 : Symbol(z3, Decl(stringEnumLiteralTypes2.ts, 39, 7))
>g : Symbol(g, Decl(stringEnumLiteralTypes2.ts, 30, 1), Decl(stringEnumLiteralTypes2.ts, 32, 42), Decl(stringEnumLiteralTypes2.ts, 33, 42))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 36, 12))
var z4 = g(b);
>z4 : Symbol(z4, Decl(stringEnumLiteralTypes2.ts, 40, 7))
>g : Symbol(g, Decl(stringEnumLiteralTypes2.ts, 30, 1), Decl(stringEnumLiteralTypes2.ts, 32, 42), Decl(stringEnumLiteralTypes2.ts, 33, 42))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 36, 21))
var z5 = g(c);
>z5 : Symbol(z5, Decl(stringEnumLiteralTypes2.ts, 41, 7))
>g : Symbol(g, Decl(stringEnumLiteralTypes2.ts, 30, 1), Decl(stringEnumLiteralTypes2.ts, 32, 42), Decl(stringEnumLiteralTypes2.ts, 33, 42))
>c : Symbol(c, Decl(stringEnumLiteralTypes2.ts, 36, 38))
}
function assertNever(x: never): never {
>assertNever : Symbol(assertNever, Decl(stringEnumLiteralTypes2.ts, 42, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 44, 21))
throw new Error("Unexpected value");
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
}
function f10(x: YesNo) {
>f10 : Symbol(f10, Decl(stringEnumLiteralTypes2.ts, 46, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 48, 13))
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes2.ts, 0, 59))
switch (x) {
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 48, 13))
case Choice.Yes: return "true";
>Choice.Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
case Choice.No: return "false";
>Choice.No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
}
}
function f11(x: YesNo) {
>f11 : Symbol(f11, Decl(stringEnumLiteralTypes2.ts, 53, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 55, 13))
>YesNo : Symbol(YesNo, Decl(stringEnumLiteralTypes2.ts, 0, 59))
switch (x) {
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 55, 13))
case Choice.Yes: return "true";
>Choice.Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
case Choice.No: return "false";
>Choice.No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
}
return assertNever(x);
>assertNever : Symbol(assertNever, Decl(stringEnumLiteralTypes2.ts, 42, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 55, 13))
}
function f12(x: UnknownYesNo) {
>f12 : Symbol(f12, Decl(stringEnumLiteralTypes2.ts, 61, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 63, 13))
>UnknownYesNo : Symbol(UnknownYesNo, Decl(stringEnumLiteralTypes2.ts, 3, 36))
if (x) {
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 63, 13))
x;
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 63, 13))
}
else {
x;
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 63, 13))
}
}
function f13(x: UnknownYesNo) {
>f13 : Symbol(f13, Decl(stringEnumLiteralTypes2.ts, 70, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 72, 13))
>UnknownYesNo : Symbol(UnknownYesNo, Decl(stringEnumLiteralTypes2.ts, 3, 36))
if (x === Choice.Yes) {
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 72, 13))
>Choice.Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
x;
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 72, 13))
}
else {
x;
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 72, 13))
}
}
type Item =
>Item : Symbol(Item, Decl(stringEnumLiteralTypes2.ts, 79, 1))
{ kind: Choice.Yes, a: string } |
>kind : Symbol(kind, Decl(stringEnumLiteralTypes2.ts, 82, 5))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 82, 23))
{ kind: Choice.No, b: string };
>kind : Symbol(kind, Decl(stringEnumLiteralTypes2.ts, 83, 5))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 83, 22))
function f20(x: Item) {
>f20 : Symbol(f20, Decl(stringEnumLiteralTypes2.ts, 83, 35))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 85, 13))
>Item : Symbol(Item, Decl(stringEnumLiteralTypes2.ts, 79, 1))
switch (x.kind) {
>x.kind : Symbol(kind, Decl(stringEnumLiteralTypes2.ts, 82, 5), Decl(stringEnumLiteralTypes2.ts, 83, 5))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 85, 13))
>kind : Symbol(kind, Decl(stringEnumLiteralTypes2.ts, 82, 5), Decl(stringEnumLiteralTypes2.ts, 83, 5))
case Choice.Yes: return x.a;
>Choice.Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>x.a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 82, 23))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 85, 13))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 82, 23))
case Choice.No: return x.b;
>Choice.No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
>x.b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 83, 22))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 85, 13))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 83, 22))
}
}
function f21(x: Item) {
>f21 : Symbol(f21, Decl(stringEnumLiteralTypes2.ts, 90, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 92, 13))
>Item : Symbol(Item, Decl(stringEnumLiteralTypes2.ts, 79, 1))
switch (x.kind) {
>x.kind : Symbol(kind, Decl(stringEnumLiteralTypes2.ts, 82, 5), Decl(stringEnumLiteralTypes2.ts, 83, 5))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 92, 13))
>kind : Symbol(kind, Decl(stringEnumLiteralTypes2.ts, 82, 5), Decl(stringEnumLiteralTypes2.ts, 83, 5))
case Choice.Yes: return x.a;
>Choice.Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>Yes : Symbol(Choice.Yes, Decl(stringEnumLiteralTypes2.ts, 0, 33))
>x.a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 82, 23))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 92, 13))
>a : Symbol(a, Decl(stringEnumLiteralTypes2.ts, 82, 23))
case Choice.No: return x.b;
>Choice.No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
>Choice : Symbol(Choice, Decl(stringEnumLiteralTypes2.ts, 0, 0))
>No : Symbol(Choice.No, Decl(stringEnumLiteralTypes2.ts, 0, 46))
>x.b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 83, 22))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 92, 13))
>b : Symbol(b, Decl(stringEnumLiteralTypes2.ts, 83, 22))
}
return assertNever(x);
>assertNever : Symbol(assertNever, Decl(stringEnumLiteralTypes2.ts, 42, 1))
>x : Symbol(x, Decl(stringEnumLiteralTypes2.ts, 92, 13))
}

View File

@@ -0,0 +1,383 @@
=== tests/cases/conformance/types/literal/stringEnumLiteralTypes2.ts ===
const enum Choice { Unknown = "", Yes = "yes", No = "no" };
>Choice : Choice
>Unknown : Choice.Unknown
>"" : ""
>Yes : Choice.Yes
>"yes" : "yes"
>No : Choice.No
>"no" : "no"
type YesNo = Choice.Yes | Choice.No;
>YesNo : YesNo
>Choice : any
>Yes : Choice.Yes
>Choice : any
>No : Choice.No
type NoYes = Choice.No | Choice.Yes;
>NoYes : YesNo
>Choice : any
>No : Choice.No
>Choice : any
>Yes : Choice.Yes
type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No;
>UnknownYesNo : Choice
>Choice : any
>Unknown : Choice.Unknown
>Choice : any
>Yes : Choice.Yes
>Choice : any
>No : Choice.No
function f1() {
>f1 : () => void
var a: YesNo;
>a : YesNo
>YesNo : YesNo
var a: NoYes;
>a : YesNo
>NoYes : YesNo
var a: Choice.Yes | Choice.No;
>a : YesNo
>Choice : any
>Yes : Choice.Yes
>Choice : any
>No : Choice.No
var a: Choice.No | Choice.Yes;
>a : YesNo
>Choice : any
>No : Choice.No
>Choice : any
>Yes : Choice.Yes
}
function f2(a: YesNo, b: UnknownYesNo, c: Choice) {
>f2 : (a: YesNo, b: Choice, c: Choice) => void
>a : YesNo
>YesNo : YesNo
>b : Choice
>UnknownYesNo : Choice
>c : Choice
>Choice : Choice
b = a;
>b = a : YesNo
>b : Choice
>a : YesNo
c = a;
>c = a : YesNo
>c : Choice
>a : YesNo
c = b;
>c = b : YesNo
>c : Choice
>b : YesNo
}
function f3(a: Choice.Yes, b: YesNo) {
>f3 : (a: Choice.Yes, b: YesNo) => void
>a : Choice.Yes
>Choice : any
>Yes : Choice.Yes
>b : YesNo
>YesNo : YesNo
var x = a + b;
>x : string
>a + b : string
>a : Choice.Yes
>b : YesNo
var y = a == b;
>y : boolean
>a == b : boolean
>a : Choice.Yes
>b : YesNo
var y = a != b;
>y : boolean
>a != b : boolean
>a : Choice.Yes
>b : YesNo
var y = a === b;
>y : boolean
>a === b : boolean
>a : Choice.Yes
>b : YesNo
var y = a !== b;
>y : boolean
>a !== b : boolean
>a : Choice.Yes
>b : YesNo
var y = a > b;
>y : boolean
>a > b : boolean
>a : Choice.Yes
>b : YesNo
var y = a < b;
>y : boolean
>a < b : boolean
>a : Choice.Yes
>b : YesNo
var y = a >= b;
>y : boolean
>a >= b : boolean
>a : Choice.Yes
>b : YesNo
var y = a <= b;
>y : boolean
>a <= b : boolean
>a : Choice.Yes
>b : YesNo
var y = !b;
>y : boolean
>!b : false
>b : YesNo
}
declare function g(x: Choice.Yes): string;
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>x : Choice.Yes
>Choice : any
>Yes : Choice.Yes
declare function g(x: Choice.No): boolean;
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>x : Choice.No
>Choice : any
>No : Choice.No
declare function g(x: Choice): number;
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>x : Choice
>Choice : Choice
function f5(a: YesNo, b: UnknownYesNo, c: Choice) {
>f5 : (a: YesNo, b: Choice, c: Choice) => void
>a : YesNo
>YesNo : YesNo
>b : Choice
>UnknownYesNo : Choice
>c : Choice
>Choice : Choice
var z1 = g(Choice.Yes);
>z1 : string
>g(Choice.Yes) : string
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
var z2 = g(Choice.No);
>z2 : boolean
>g(Choice.No) : boolean
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>Choice.No : Choice.No
>Choice : typeof Choice
>No : Choice.No
var z3 = g(a);
>z3 : number
>g(a) : number
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>a : YesNo
var z4 = g(b);
>z4 : number
>g(b) : number
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>b : Choice
var z5 = g(c);
>z5 : number
>g(c) : number
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
>c : Choice
}
function assertNever(x: never): never {
>assertNever : (x: never) => never
>x : never
throw new Error("Unexpected value");
>new Error("Unexpected value") : Error
>Error : ErrorConstructor
>"Unexpected value" : "Unexpected value"
}
function f10(x: YesNo) {
>f10 : (x: YesNo) => "true" | "false"
>x : YesNo
>YesNo : YesNo
switch (x) {
>x : YesNo
case Choice.Yes: return "true";
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
>"true" : "true"
case Choice.No: return "false";
>Choice.No : Choice.No
>Choice : typeof Choice
>No : Choice.No
>"false" : "false"
}
}
function f11(x: YesNo) {
>f11 : (x: YesNo) => "true" | "false"
>x : YesNo
>YesNo : YesNo
switch (x) {
>x : YesNo
case Choice.Yes: return "true";
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
>"true" : "true"
case Choice.No: return "false";
>Choice.No : Choice.No
>Choice : typeof Choice
>No : Choice.No
>"false" : "false"
}
return assertNever(x);
>assertNever(x) : never
>assertNever : (x: never) => never
>x : never
}
function f12(x: UnknownYesNo) {
>f12 : (x: Choice) => void
>x : Choice
>UnknownYesNo : Choice
if (x) {
>x : Choice
x;
>x : YesNo
}
else {
x;
>x : Choice.Unknown
}
}
function f13(x: UnknownYesNo) {
>f13 : (x: Choice) => void
>x : Choice
>UnknownYesNo : Choice
if (x === Choice.Yes) {
>x === Choice.Yes : boolean
>x : Choice
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
x;
>x : Choice.Yes
}
else {
x;
>x : Choice.Unknown | Choice.No
}
}
type Item =
>Item : Item
{ kind: Choice.Yes, a: string } |
>kind : Choice.Yes
>Choice : any
>Yes : Choice.Yes
>a : string
{ kind: Choice.No, b: string };
>kind : Choice.No
>Choice : any
>No : Choice.No
>b : string
function f20(x: Item) {
>f20 : (x: Item) => string
>x : Item
>Item : Item
switch (x.kind) {
>x.kind : YesNo
>x : Item
>kind : YesNo
case Choice.Yes: return x.a;
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
>x.a : string
>x : { kind: Choice.Yes; a: string; }
>a : string
case Choice.No: return x.b;
>Choice.No : Choice.No
>Choice : typeof Choice
>No : Choice.No
>x.b : string
>x : { kind: Choice.No; b: string; }
>b : string
}
}
function f21(x: Item) {
>f21 : (x: Item) => string
>x : Item
>Item : Item
switch (x.kind) {
>x.kind : YesNo
>x : Item
>kind : YesNo
case Choice.Yes: return x.a;
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
>x.a : string
>x : { kind: Choice.Yes; a: string; }
>a : string
case Choice.No: return x.b;
>Choice.No : Choice.No
>Choice : typeof Choice
>No : Choice.No
>x.b : string
>x : { kind: Choice.No; b: string; }
>b : string
}
return assertNever(x);
>assertNever(x) : never
>assertNever : (x: never) => never
>x : never
}

View File

@@ -0,0 +1,166 @@
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(10,5): error TS2322: Type 'YesNo' is not assignable to type 'Choice.Yes'.
Type 'Choice.No' is not assignable to type 'Choice.Yes'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(11,5): error TS2322: Type 'Choice' is not assignable to type 'Choice.Yes'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(12,5): error TS2322: Type 'Choice' is not assignable to type 'Choice.Yes'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(18,5): error TS2322: Type 'Choice' is not assignable to type 'YesNo'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(19,5): error TS2322: Type 'Choice' is not assignable to type 'YesNo'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(37,5): error TS2322: Type 'Choice.Unknown' is not assignable to type 'Choice.Yes'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(39,5): error TS2322: Type 'Choice.No' is not assignable to type 'Choice.Yes'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(40,5): error TS2322: Type 'Choice.Unknown' is not assignable to type 'YesNo'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(52,5): error TS2365: Operator '===' cannot be applied to types 'Choice.Yes' and 'Choice.Unknown'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(54,5): error TS2365: Operator '===' cannot be applied to types 'Choice.Yes' and 'Choice.No'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(55,5): error TS2365: Operator '===' cannot be applied to types 'YesNo' and 'Choice.Unknown'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(87,14): error TS2678: Type 'Choice.Unknown' is not comparable to type 'Choice.Yes'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(89,14): error TS2678: Type 'Choice.No' is not comparable to type 'Choice.Yes'.
tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts(96,14): error TS2678: Type 'Choice.Unknown' is not comparable to type 'YesNo'.
==== tests/cases/conformance/types/literal/stringEnumLiteralTypes3.ts (14 errors) ====
const enum Choice { Unknown = "", Yes = "yes", No = "no" };
type Yes = Choice.Yes;
type YesNo = Choice.Yes | Choice.No;
type NoYes = Choice.No | Choice.Yes;
type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No;
function f1(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
a = a;
a = b;
~
!!! error TS2322: Type 'YesNo' is not assignable to type 'Choice.Yes'.
!!! error TS2322: Type 'Choice.No' is not assignable to type 'Choice.Yes'.
a = c;
~
!!! error TS2322: Type 'Choice' is not assignable to type 'Choice.Yes'.
a = d;
~
!!! error TS2322: Type 'Choice' is not assignable to type 'Choice.Yes'.
}
function f2(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
b = a;
b = b;
b = c;
~
!!! error TS2322: Type 'Choice' is not assignable to type 'YesNo'.
b = d;
~
!!! error TS2322: Type 'Choice' is not assignable to type 'YesNo'.
}
function f3(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
c = a;
c = b;
c = c;
c = d;
}
function f4(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
d = a;
d = b;
d = c;
d = d;
}
function f5(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
a = Choice.Unknown;
~
!!! error TS2322: Type 'Choice.Unknown' is not assignable to type 'Choice.Yes'.
a = Choice.Yes;
a = Choice.No;
~
!!! error TS2322: Type 'Choice.No' is not assignable to type 'Choice.Yes'.
b = Choice.Unknown;
~
!!! error TS2322: Type 'Choice.Unknown' is not assignable to type 'YesNo'.
b = Choice.Yes;
b = Choice.No;
c = Choice.Unknown;
c = Choice.Yes;
c = Choice.No;
d = Choice.Unknown;
d = Choice.Yes;
d = Choice.No;
}
function f6(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
a === Choice.Unknown;
~~~~~~~~~~~~~~~~~~~~
!!! error TS2365: Operator '===' cannot be applied to types 'Choice.Yes' and 'Choice.Unknown'.
a === Choice.Yes;
a === Choice.No;
~~~~~~~~~~~~~~~
!!! error TS2365: Operator '===' cannot be applied to types 'Choice.Yes' and 'Choice.No'.
b === Choice.Unknown;
~~~~~~~~~~~~~~~~~~~~
!!! error TS2365: Operator '===' cannot be applied to types 'YesNo' and 'Choice.Unknown'.
b === Choice.Yes;
b === Choice.No;
c === Choice.Unknown;
c === Choice.Yes;
c === Choice.No;
d === Choice.Unknown;
d === Choice.Yes;
d === Choice.No;
}
function f7(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
a === a;
a === b;
a === c;
a === d;
b === a;
b === b;
b === c;
b === d;
c === a;
c === b;
c === c;
c === d;
d === a;
d === b;
d === c;
d === d;
}
function f10(x: Yes): Yes {
switch (x) {
case Choice.Unknown: return x;
~~~~~~~~~~~~~~
!!! error TS2678: Type 'Choice.Unknown' is not comparable to type 'Choice.Yes'.
case Choice.Yes: return x;
case Choice.No: return x;
~~~~~~~~~
!!! error TS2678: Type 'Choice.No' is not comparable to type 'Choice.Yes'.
}
return x;
}
function f11(x: YesNo): YesNo {
switch (x) {
case Choice.Unknown: return x;
~~~~~~~~~~~~~~
!!! error TS2678: Type 'Choice.Unknown' is not comparable to type 'YesNo'.
case Choice.Yes: return x;
case Choice.No: return x;
}
return x;
}
function f12(x: UnknownYesNo): UnknownYesNo {
switch (x) {
case Choice.Unknown: return x;
case Choice.Yes: return x;
case Choice.No: return x;
}
return x;
}
function f13(x: Choice): Choice {
switch (x) {
case Choice.Unknown: return x;
case Choice.Yes: return x;
case Choice.No: return x;
}
return x;
}

View File

@@ -0,0 +1,225 @@
//// [stringEnumLiteralTypes3.ts]
const enum Choice { Unknown = "", Yes = "yes", No = "no" };
type Yes = Choice.Yes;
type YesNo = Choice.Yes | Choice.No;
type NoYes = Choice.No | Choice.Yes;
type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No;
function f1(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
a = a;
a = b;
a = c;
a = d;
}
function f2(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
b = a;
b = b;
b = c;
b = d;
}
function f3(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
c = a;
c = b;
c = c;
c = d;
}
function f4(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
d = a;
d = b;
d = c;
d = d;
}
function f5(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
a = Choice.Unknown;
a = Choice.Yes;
a = Choice.No;
b = Choice.Unknown;
b = Choice.Yes;
b = Choice.No;
c = Choice.Unknown;
c = Choice.Yes;
c = Choice.No;
d = Choice.Unknown;
d = Choice.Yes;
d = Choice.No;
}
function f6(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
a === Choice.Unknown;
a === Choice.Yes;
a === Choice.No;
b === Choice.Unknown;
b === Choice.Yes;
b === Choice.No;
c === Choice.Unknown;
c === Choice.Yes;
c === Choice.No;
d === Choice.Unknown;
d === Choice.Yes;
d === Choice.No;
}
function f7(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
a === a;
a === b;
a === c;
a === d;
b === a;
b === b;
b === c;
b === d;
c === a;
c === b;
c === c;
c === d;
d === a;
d === b;
d === c;
d === d;
}
function f10(x: Yes): Yes {
switch (x) {
case Choice.Unknown: return x;
case Choice.Yes: return x;
case Choice.No: return x;
}
return x;
}
function f11(x: YesNo): YesNo {
switch (x) {
case Choice.Unknown: return x;
case Choice.Yes: return x;
case Choice.No: return x;
}
return x;
}
function f12(x: UnknownYesNo): UnknownYesNo {
switch (x) {
case Choice.Unknown: return x;
case Choice.Yes: return x;
case Choice.No: return x;
}
return x;
}
function f13(x: Choice): Choice {
switch (x) {
case Choice.Unknown: return x;
case Choice.Yes: return x;
case Choice.No: return x;
}
return x;
}
//// [stringEnumLiteralTypes3.js]
;
function f1(a, b, c, d) {
a = a;
a = b;
a = c;
a = d;
}
function f2(a, b, c, d) {
b = a;
b = b;
b = c;
b = d;
}
function f3(a, b, c, d) {
c = a;
c = b;
c = c;
c = d;
}
function f4(a, b, c, d) {
d = a;
d = b;
d = c;
d = d;
}
function f5(a, b, c, d) {
a = "" /* Unknown */;
a = "yes" /* Yes */;
a = "no" /* No */;
b = "" /* Unknown */;
b = "yes" /* Yes */;
b = "no" /* No */;
c = "" /* Unknown */;
c = "yes" /* Yes */;
c = "no" /* No */;
d = "" /* Unknown */;
d = "yes" /* Yes */;
d = "no" /* No */;
}
function f6(a, b, c, d) {
a === "" /* Unknown */;
a === "yes" /* Yes */;
a === "no" /* No */;
b === "" /* Unknown */;
b === "yes" /* Yes */;
b === "no" /* No */;
c === "" /* Unknown */;
c === "yes" /* Yes */;
c === "no" /* No */;
d === "" /* Unknown */;
d === "yes" /* Yes */;
d === "no" /* No */;
}
function f7(a, b, c, d) {
a === a;
a === b;
a === c;
a === d;
b === a;
b === b;
b === c;
b === d;
c === a;
c === b;
c === c;
c === d;
d === a;
d === b;
d === c;
d === d;
}
function f10(x) {
switch (x) {
case "" /* Unknown */: return x;
case "yes" /* Yes */: return x;
case "no" /* No */: return x;
}
return x;
}
function f11(x) {
switch (x) {
case "" /* Unknown */: return x;
case "yes" /* Yes */: return x;
case "no" /* No */: return x;
}
return x;
}
function f12(x) {
switch (x) {
case "" /* Unknown */: return x;
case "yes" /* Yes */: return x;
case "no" /* No */: return x;
}
return x;
}
function f13(x) {
switch (x) {
case "" /* Unknown */: return x;
case "yes" /* Yes */: return x;
case "no" /* No */: return x;
}
return x;
}

View File

@@ -0,0 +1,80 @@
// @declaration: true
// An enum type where each member has no initializer or an initializer that specififes
// a numeric literal, a string literal, or a single identifier naming another member in
// the enum type is classified as a literal enum type. An enum type that doesn't adhere
// to this pattern is classified as a numeric enum type.
// Examples of literal enum types
enum E01 {
A
}
enum E02 {
A = 123
}
enum E03 {
A = "hello"
}
enum E04 {
A,
B,
C
}
enum E05 {
A,
B = 10,
C
}
enum E06 {
A = "one",
B = "two",
C = "three"
}
enum E07 {
A,
B,
C = "hi",
D = 10,
E,
F = "bye"
}
enum E08 {
A = 10,
B = "hello",
C = A,
D = B,
E = C,
}
// Examples of numeric enum types with only constant members
enum E10 {}
enum E11 {
A = +0,
B,
C
}
enum E12 {
A = 1 << 0,
B = 1 << 1,
C = 1 << 2
}
// Examples of numeric enum types with constant and computed members
enum E20 {
A = "foo".length,
B = A + 1,
C = +"123",
D = Math.sin(1)
}

View File

@@ -0,0 +1,99 @@
const enum Choice { Unknown = "", Yes = "yes", No = "no" };
type YesNo = Choice.Yes | Choice.No;
type NoYes = Choice.No | Choice.Yes;
type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No;
function f1() {
var a: YesNo;
var a: NoYes;
var a: Choice.Yes | Choice.No;
var a: Choice.No | Choice.Yes;
}
function f2(a: YesNo, b: UnknownYesNo, c: Choice) {
b = a;
c = a;
c = b;
}
function f3(a: Choice.Yes, b: YesNo) {
var x = a + b;
var y = a == b;
var y = a != b;
var y = a === b;
var y = a !== b;
var y = a > b;
var y = a < b;
var y = a >= b;
var y = a <= b;
var y = !b;
}
declare function g(x: Choice.Yes): string;
declare function g(x: Choice.No): boolean;
declare function g(x: Choice): number;
function f5(a: YesNo, b: UnknownYesNo, c: Choice) {
var z1 = g(Choice.Yes);
var z2 = g(Choice.No);
var z3 = g(a);
var z4 = g(b);
var z5 = g(c);
}
function assertNever(x: never): never {
throw new Error("Unexpected value");
}
function f10(x: YesNo) {
switch (x) {
case Choice.Yes: return "true";
case Choice.No: return "false";
}
}
function f11(x: YesNo) {
switch (x) {
case Choice.Yes: return "true";
case Choice.No: return "false";
}
return assertNever(x);
}
function f12(x: UnknownYesNo) {
if (x) {
x;
}
else {
x;
}
}
function f13(x: UnknownYesNo) {
if (x === Choice.Yes) {
x;
}
else {
x;
}
}
type Item =
{ kind: Choice.Yes, a: string } |
{ kind: Choice.No, b: string };
function f20(x: Item) {
switch (x.kind) {
case Choice.Yes: return x.a;
case Choice.No: return x.b;
}
}
function f21(x: Item) {
switch (x.kind) {
case Choice.Yes: return x.a;
case Choice.No: return x.b;
}
return assertNever(x);
}

View File

@@ -0,0 +1,101 @@
// @strictNullChecks: true
const enum Choice { Unknown = "", Yes = "yes", No = "no" };
type YesNo = Choice.Yes | Choice.No;
type NoYes = Choice.No | Choice.Yes;
type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No;
function f1() {
var a: YesNo;
var a: NoYes;
var a: Choice.Yes | Choice.No;
var a: Choice.No | Choice.Yes;
}
function f2(a: YesNo, b: UnknownYesNo, c: Choice) {
b = a;
c = a;
c = b;
}
function f3(a: Choice.Yes, b: YesNo) {
var x = a + b;
var y = a == b;
var y = a != b;
var y = a === b;
var y = a !== b;
var y = a > b;
var y = a < b;
var y = a >= b;
var y = a <= b;
var y = !b;
}
declare function g(x: Choice.Yes): string;
declare function g(x: Choice.No): boolean;
declare function g(x: Choice): number;
function f5(a: YesNo, b: UnknownYesNo, c: Choice) {
var z1 = g(Choice.Yes);
var z2 = g(Choice.No);
var z3 = g(a);
var z4 = g(b);
var z5 = g(c);
}
function assertNever(x: never): never {
throw new Error("Unexpected value");
}
function f10(x: YesNo) {
switch (x) {
case Choice.Yes: return "true";
case Choice.No: return "false";
}
}
function f11(x: YesNo) {
switch (x) {
case Choice.Yes: return "true";
case Choice.No: return "false";
}
return assertNever(x);
}
function f12(x: UnknownYesNo) {
if (x) {
x;
}
else {
x;
}
}
function f13(x: UnknownYesNo) {
if (x === Choice.Yes) {
x;
}
else {
x;
}
}
type Item =
{ kind: Choice.Yes, a: string } |
{ kind: Choice.No, b: string };
function f20(x: Item) {
switch (x.kind) {
case Choice.Yes: return x.a;
case Choice.No: return x.b;
}
}
function f21(x: Item) {
switch (x.kind) {
case Choice.Yes: return x.a;
case Choice.No: return x.b;
}
return assertNever(x);
}

View File

@@ -0,0 +1,119 @@
const enum Choice { Unknown = "", Yes = "yes", No = "no" };
type Yes = Choice.Yes;
type YesNo = Choice.Yes | Choice.No;
type NoYes = Choice.No | Choice.Yes;
type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No;
function f1(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
a = a;
a = b;
a = c;
a = d;
}
function f2(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
b = a;
b = b;
b = c;
b = d;
}
function f3(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
c = a;
c = b;
c = c;
c = d;
}
function f4(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
d = a;
d = b;
d = c;
d = d;
}
function f5(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
a = Choice.Unknown;
a = Choice.Yes;
a = Choice.No;
b = Choice.Unknown;
b = Choice.Yes;
b = Choice.No;
c = Choice.Unknown;
c = Choice.Yes;
c = Choice.No;
d = Choice.Unknown;
d = Choice.Yes;
d = Choice.No;
}
function f6(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
a === Choice.Unknown;
a === Choice.Yes;
a === Choice.No;
b === Choice.Unknown;
b === Choice.Yes;
b === Choice.No;
c === Choice.Unknown;
c === Choice.Yes;
c === Choice.No;
d === Choice.Unknown;
d === Choice.Yes;
d === Choice.No;
}
function f7(a: Yes, b: YesNo, c: UnknownYesNo, d: Choice) {
a === a;
a === b;
a === c;
a === d;
b === a;
b === b;
b === c;
b === d;
c === a;
c === b;
c === c;
c === d;
d === a;
d === b;
d === c;
d === d;
}
function f10(x: Yes): Yes {
switch (x) {
case Choice.Unknown: return x;
case Choice.Yes: return x;
case Choice.No: return x;
}
return x;
}
function f11(x: YesNo): YesNo {
switch (x) {
case Choice.Unknown: return x;
case Choice.Yes: return x;
case Choice.No: return x;
}
return x;
}
function f12(x: UnknownYesNo): UnknownYesNo {
switch (x) {
case Choice.Unknown: return x;
case Choice.Yes: return x;
case Choice.No: return x;
}
return x;
}
function f13(x: Choice): Choice {
switch (x) {
case Choice.Unknown: return x;
case Choice.Yes: return x;
case Choice.No: return x;
}
return x;
}