* Create separate types for equivalent aliased unions * Accept new baselines * Preserve original types for union types * Accept new baselines * Preserve intersection origin for union types * Accept new baselines * Accept new baselines * Preserve aliases during relationship checks * Accept new baselines * Preserve aliases for intersection and indexed access types * Accept new baselines * Compute intersection-of-unions cross product without recursion * Accept new baselines * Use denormalized type objects for origin / support 'keyof' origins * Accept new baselines * Fix fourslash test * Recursively extract named union types * Accept new baselines * Map on union origin in mapType to better preserve aliases and origins * Remove redundant call * Accept new baselines * Revert back to declared type when branches produce equivalent union * Accept new baselines * Don't include denormal origin types in regular type statistics * Fix issue with unions not being marked primitive-only * Allow new alias to be associated with type alias instantiation * Accept new baselines * Revert "Accept new baselines" This reverts commit4507270cc1
. * Revert "Allow new alias to be associated with type alias instantiation" This reverts commit2c2d06dfe1
.
416 lines
7.5 KiB
Plaintext
416 lines
7.5 KiB
Plaintext
=== tests/cases/conformance/types/literal/enumLiteralTypes2.ts ===
|
|
const enum Choice { Unknown, Yes, No };
|
|
>Choice : Choice
|
|
>Unknown : Choice.Unknown
|
|
>Yes : Choice.Yes
|
|
>No : Choice.No
|
|
|
|
type YesNo = Choice.Yes | Choice.No;
|
|
>YesNo : YesNo
|
|
>Choice : any
|
|
>Choice : any
|
|
|
|
type NoYes = Choice.No | Choice.Yes;
|
|
>NoYes : NoYes
|
|
>Choice : any
|
|
>Choice : any
|
|
|
|
type UnknownYesNo = Choice.Unknown | Choice.Yes | Choice.No;
|
|
>UnknownYesNo : UnknownYesNo
|
|
>Choice : any
|
|
>Choice : any
|
|
>Choice : any
|
|
|
|
function f1() {
|
|
>f1 : () => void
|
|
|
|
var a: YesNo;
|
|
>a : YesNo
|
|
|
|
var a: NoYes;
|
|
>a : YesNo
|
|
|
|
var a: Choice.Yes | Choice.No;
|
|
>a : YesNo
|
|
>Choice : any
|
|
>Choice : any
|
|
|
|
var a: Choice.No | Choice.Yes;
|
|
>a : YesNo
|
|
>Choice : any
|
|
>Choice : any
|
|
}
|
|
|
|
function f2(a: YesNo, b: UnknownYesNo, c: Choice) {
|
|
>f2 : (a: YesNo, b: UnknownYesNo, c: Choice) => void
|
|
>a : YesNo
|
|
>b : UnknownYesNo
|
|
>c : Choice
|
|
|
|
b = a;
|
|
>b = a : YesNo
|
|
>b : UnknownYesNo
|
|
>a : YesNo
|
|
|
|
c = a;
|
|
>c = a : YesNo
|
|
>c : Choice
|
|
>a : YesNo
|
|
|
|
c = b;
|
|
>c = b : Choice.Yes | Choice.No
|
|
>c : Choice
|
|
>b : Choice.Yes | Choice.No
|
|
}
|
|
|
|
function f3(a: Choice.Yes, b: UnknownYesNo) {
|
|
>f3 : (a: Choice.Yes, b: UnknownYesNo) => void
|
|
>a : Choice.Yes
|
|
>Choice : any
|
|
>b : UnknownYesNo
|
|
|
|
var x = a + b;
|
|
>x : number
|
|
>a + b : number
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var x = a - b;
|
|
>x : number
|
|
>a - b : number
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var x = a * b;
|
|
>x : number
|
|
>a * b : number
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var x = a / b;
|
|
>x : number
|
|
>a / b : number
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var x = a % b;
|
|
>x : number
|
|
>a % b : number
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var x = a | b;
|
|
>x : number
|
|
>a | b : number
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var x = a & b;
|
|
>x : number
|
|
>a & b : number
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var x = a ^ b;
|
|
>x : number
|
|
>a ^ b : number
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var x = -b;
|
|
>x : number
|
|
>-b : number
|
|
>b : UnknownYesNo
|
|
|
|
var x = ~b;
|
|
>x : number
|
|
>~b : number
|
|
>b : UnknownYesNo
|
|
|
|
var y = a == b;
|
|
>y : boolean
|
|
>a == b : boolean
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var y = a != b;
|
|
>y : boolean
|
|
>a != b : boolean
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var y = a === b;
|
|
>y : boolean
|
|
>a === b : boolean
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var y = a !== b;
|
|
>y : boolean
|
|
>a !== b : boolean
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var y = a > b;
|
|
>y : boolean
|
|
>a > b : boolean
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var y = a < b;
|
|
>y : boolean
|
|
>a < b : boolean
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var y = a >= b;
|
|
>y : boolean
|
|
>a >= b : boolean
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var y = a <= b;
|
|
>y : boolean
|
|
>a <= b : boolean
|
|
>a : Choice.Yes
|
|
>b : UnknownYesNo
|
|
|
|
var y = !b;
|
|
>y : boolean
|
|
>!b : boolean
|
|
>b : UnknownYesNo
|
|
}
|
|
|
|
function f4(a: Choice.Yes, b: UnknownYesNo) {
|
|
>f4 : (a: Choice.Yes, b: UnknownYesNo) => void
|
|
>a : Choice.Yes
|
|
>Choice : any
|
|
>b : UnknownYesNo
|
|
|
|
a++;
|
|
>a++ : number
|
|
>a : Choice
|
|
|
|
b++;
|
|
>b++ : number
|
|
>b : Choice
|
|
}
|
|
|
|
declare function g(x: Choice.Yes): string;
|
|
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
|
|
>x : Choice.Yes
|
|
>Choice : any
|
|
|
|
declare function g(x: Choice.No): boolean;
|
|
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
|
|
>x : Choice.No
|
|
>Choice : any
|
|
|
|
declare function g(x: Choice): number;
|
|
>g : { (x: Choice.Yes): string; (x: Choice.No): boolean; (x: Choice): number; }
|
|
>x : Choice
|
|
|
|
function f5(a: YesNo, b: UnknownYesNo, c: Choice) {
|
|
>f5 : (a: YesNo, b: UnknownYesNo, c: Choice) => void
|
|
>a : YesNo
|
|
>b : UnknownYesNo
|
|
>c : 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 : UnknownYesNo
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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: UnknownYesNo) => void
|
|
>x : UnknownYesNo
|
|
|
|
if (x) {
|
|
>x : UnknownYesNo
|
|
|
|
x;
|
|
>x : Choice.Yes | Choice.No
|
|
}
|
|
else {
|
|
x;
|
|
>x : Choice.Unknown
|
|
}
|
|
}
|
|
|
|
function f13(x: UnknownYesNo) {
|
|
>f13 : (x: UnknownYesNo) => void
|
|
>x : UnknownYesNo
|
|
|
|
if (x === Choice.Yes) {
|
|
>x === Choice.Yes : boolean
|
|
>x : UnknownYesNo
|
|
>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
|
|
>a : string
|
|
|
|
{ kind: Choice.No, b: string };
|
|
>kind : Choice.No
|
|
>Choice : any
|
|
>b : string
|
|
|
|
function f20(x: Item) {
|
|
>f20 : (x: Item) => string
|
|
>x : Item
|
|
|
|
switch (x.kind) {
|
|
>x.kind : Choice.Yes | Choice.No
|
|
>x : Item
|
|
>kind : Choice.Yes | Choice.No
|
|
|
|
case Choice.Yes: return x.a;
|
|
>Choice.Yes : Choice.Yes
|
|
>Choice : typeof Choice
|
|
>Yes : Choice.Yes
|
|
>x.a : string
|
|
>x : { kind: Choice.Yes; a: string; }
|
|
>a : string
|
|
|
|
case Choice.No: return x.b;
|
|
>Choice.No : Choice.No
|
|
>Choice : typeof Choice
|
|
>No : Choice.No
|
|
>x.b : string
|
|
>x : { kind: Choice.No; b: string; }
|
|
>b : string
|
|
}
|
|
}
|
|
|
|
function f21(x: Item) {
|
|
>f21 : (x: Item) => string
|
|
>x : Item
|
|
|
|
switch (x.kind) {
|
|
>x.kind : Choice.Yes | Choice.No
|
|
>x : Item
|
|
>kind : Choice.Yes | Choice.No
|
|
|
|
case Choice.Yes: return x.a;
|
|
>Choice.Yes : Choice.Yes
|
|
>Choice : typeof Choice
|
|
>Yes : Choice.Yes
|
|
>x.a : string
|
|
>x : { kind: Choice.Yes; a: string; }
|
|
>a : string
|
|
|
|
case Choice.No: return x.b;
|
|
>Choice.No : Choice.No
|
|
>Choice : typeof Choice
|
|
>No : Choice.No
|
|
>x.b : string
|
|
>x : { kind: Choice.No; b: string; }
|
|
>b : string
|
|
}
|
|
return assertNever(x);
|
|
>assertNever(x) : never
|
|
>assertNever : (x: never) => never
|
|
>x : never
|
|
}
|