TypeScript/tests/baselines/reference/enumLiteralTypes1.types
2016-07-22 16:56:33 -07:00

450 lines
7.7 KiB
Plaintext

=== tests/cases/conformance/types/literal/enumLiteralTypes1.ts ===
const enum Choice { Unknown, Yes, No };
>Choice : Choice
>Unknown : Choice
>Yes : Choice
>No : Choice
type YesNo = Choice.Yes | Choice.No;
>YesNo : 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 : number
>a + b : number
>a : Choice.Yes
>b : YesNo
var x = a - b;
>x : number
>a - b : number
>a : Choice.Yes
>b : YesNo
var x = a * b;
>x : number
>a * b : number
>a : Choice.Yes
>b : YesNo
var x = a / b;
>x : number
>a / b : number
>a : Choice.Yes
>b : YesNo
var x = a % b;
>x : number
>a % b : number
>a : Choice.Yes
>b : YesNo
var x = a | b;
>x : number
>a | b : number
>a : Choice.Yes
>b : YesNo
var x = a & b;
>x : number
>a & b : number
>a : Choice.Yes
>b : YesNo
var x = a ^ b;
>x : number
>a ^ b : number
>a : Choice.Yes
>b : YesNo
var x = -b;
>x : number
>-b : number
>b : YesNo
var x = ~b;
>x : number
>~b : number
>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
}
function f4(a: Choice.Yes, b: YesNo) {
>f4 : (a: Choice.Yes, b: YesNo) => void
>a : Choice.Yes
>Choice : any
>Yes : Choice.Yes
>b : YesNo
>YesNo : YesNo
a++;
>a++ : number
>a : Choice.Yes
b++;
>b++ : number
>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" : string
}
function f10(x: YesNo) {
>f10 : (x: YesNo) => string
>x : YesNo
>YesNo : YesNo
switch (x) {
>x : YesNo
case Choice.Yes: return "true";
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
>"true" : string
case Choice.No: return "false";
>Choice.No : Choice.No
>Choice : typeof Choice
>No : Choice.No
>"false" : string
}
}
function f11(x: YesNo) {
>f11 : (x: YesNo) => string
>x : YesNo
>YesNo : YesNo
switch (x) {
>x : YesNo
case Choice.Yes: return "true";
>Choice.Yes : Choice.Yes
>Choice : typeof Choice
>Yes : Choice.Yes
>"true" : string
case Choice.No: return "false";
>Choice.No : Choice.No
>Choice : typeof Choice
>No : Choice.No
>"false" : string
}
return assertNever(x);
>assertNever(x) : never
>assertNever : (x: never) => never
>x : never
}
function f12(x: UnknownYesNo) {
>f12 : (x: Choice) => 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
}