diff --git a/tests/baselines/reference/intersectionReduction.errors.txt b/tests/baselines/reference/intersectionReduction.errors.txt new file mode 100644 index 0000000000..62631cca76 --- /dev/null +++ b/tests/baselines/reference/intersectionReduction.errors.txt @@ -0,0 +1,66 @@ +tests/cases/conformance/types/intersection/intersectionReduction.ts(40,1): error TS2322: Type 'any' is not assignable to type 'never'. +tests/cases/conformance/types/intersection/intersectionReduction.ts(41,1): error TS2322: Type 'any' is not assignable to type 'never'. + + +==== tests/cases/conformance/types/intersection/intersectionReduction.ts (2 errors) ==== + declare const sym1: unique symbol; + declare const sym2: unique symbol; + + type T1 = string & 'a'; // 'a' + type T2 = 'a' & string & 'b'; // never + type T3 = number & 10; // 10 + type T4 = 10 & number & 20; // never + type T5 = symbol & typeof sym1; // typeof sym1 + type T6 = typeof sym1 & symbol & typeof sym2; // never + type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never + + type T10 = string & ('a' | 'b'); // 'a' | 'b' + type T11 = (string | number) & ('a' | 10); // 'a' | 10 + + type N1 = 'a' & 'b'; + type N2 = { a: string } & null; + type N3 = { a: string } & undefined; + type N4 = string & number; + type N5 = number & object; + type N6 = symbol & string; + type N7 = void & string; + + type X = { x: string }; + + type X1 = X | 'a' & 'b'; + type X2 = X | { a: string } & null; + type X3 = X | { a: string } & undefined; + type X4 = X | string & number; + type X5 = X | number & object; + type X6 = X | symbol & string; + type X7 = X | void & string; + + // Repro from #31663 + + const x1 = { a: 'foo', b: 42 }; + const x2 = { a: 'foo', b: true }; + + declare let k: 'a' | 'b'; + + x1[k] = 'bar' as any; // Error + ~~~~~ +!!! error TS2322: Type 'any' is not assignable to type 'never'. + x2[k] = 'bar' as any; // Error + ~~~~~ +!!! error TS2322: Type 'any' is not assignable to type 'never'. + + const enum Tag1 {} + const enum Tag2 {} + + declare let s1: string & Tag1; + declare let s2: string & Tag2; + + declare let t1: string & Tag1 | undefined; + declare let t2: string & Tag2 | undefined; + + s1 = s2; + s2 = s1; + + t1 = t2; + t2 = t1; + \ No newline at end of file diff --git a/tests/baselines/reference/intersectionReduction.js b/tests/baselines/reference/intersectionReduction.js index ba0c3cea77..f2009cd9cc 100644 --- a/tests/baselines/reference/intersectionReduction.js +++ b/tests/baselines/reference/intersectionReduction.js @@ -1,6 +1,4 @@ //// [intersectionReduction.ts] -// @strict - declare const sym1: unique symbol; declare const sym2: unique symbol; @@ -14,7 +12,58 @@ type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never type T10 = string & ('a' | 'b'); // 'a' | 'b' type T11 = (string | number) & ('a' | 10); // 'a' | 10 + +type N1 = 'a' & 'b'; +type N2 = { a: string } & null; +type N3 = { a: string } & undefined; +type N4 = string & number; +type N5 = number & object; +type N6 = symbol & string; +type N7 = void & string; + +type X = { x: string }; + +type X1 = X | 'a' & 'b'; +type X2 = X | { a: string } & null; +type X3 = X | { a: string } & undefined; +type X4 = X | string & number; +type X5 = X | number & object; +type X6 = X | symbol & string; +type X7 = X | void & string; + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +const x2 = { a: 'foo', b: true }; + +declare let k: 'a' | 'b'; + +x1[k] = 'bar' as any; // Error +x2[k] = 'bar' as any; // Error + +const enum Tag1 {} +const enum Tag2 {} + +declare let s1: string & Tag1; +declare let s2: string & Tag2; + +declare let t1: string & Tag1 | undefined; +declare let t2: string & Tag2 | undefined; + +s1 = s2; +s2 = s1; + +t1 = t2; +t2 = t1; //// [intersectionReduction.js] -// @strict +// Repro from #31663 +var x1 = { a: 'foo', b: 42 }; +var x2 = { a: 'foo', b: true }; +x1[k] = 'bar'; // Error +x2[k] = 'bar'; // Error +s1 = s2; +s2 = s1; +t1 = t2; +t2 = t1; diff --git a/tests/baselines/reference/intersectionReduction.symbols b/tests/baselines/reference/intersectionReduction.symbols index e932e3eb6c..3e22d2e269 100644 --- a/tests/baselines/reference/intersectionReduction.symbols +++ b/tests/baselines/reference/intersectionReduction.symbols @@ -1,40 +1,156 @@ === tests/cases/conformance/types/intersection/intersectionReduction.ts === -// @strict - declare const sym1: unique symbol; ->sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 2, 13)) +>sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 0, 13)) declare const sym2: unique symbol; ->sym2 : Symbol(sym2, Decl(intersectionReduction.ts, 3, 13)) +>sym2 : Symbol(sym2, Decl(intersectionReduction.ts, 1, 13)) type T1 = string & 'a'; // 'a' ->T1 : Symbol(T1, Decl(intersectionReduction.ts, 3, 34)) +>T1 : Symbol(T1, Decl(intersectionReduction.ts, 1, 34)) type T2 = 'a' & string & 'b'; // never ->T2 : Symbol(T2, Decl(intersectionReduction.ts, 5, 23)) +>T2 : Symbol(T2, Decl(intersectionReduction.ts, 3, 23)) type T3 = number & 10; // 10 ->T3 : Symbol(T3, Decl(intersectionReduction.ts, 6, 29)) +>T3 : Symbol(T3, Decl(intersectionReduction.ts, 4, 29)) type T4 = 10 & number & 20; // never ->T4 : Symbol(T4, Decl(intersectionReduction.ts, 7, 22)) +>T4 : Symbol(T4, Decl(intersectionReduction.ts, 5, 22)) type T5 = symbol & typeof sym1; // typeof sym1 ->T5 : Symbol(T5, Decl(intersectionReduction.ts, 8, 27)) ->sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 2, 13)) +>T5 : Symbol(T5, Decl(intersectionReduction.ts, 6, 27)) +>sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 0, 13)) type T6 = typeof sym1 & symbol & typeof sym2; // never ->T6 : Symbol(T6, Decl(intersectionReduction.ts, 9, 31)) ->sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 2, 13)) ->sym2 : Symbol(sym2, Decl(intersectionReduction.ts, 3, 13)) +>T6 : Symbol(T6, Decl(intersectionReduction.ts, 7, 31)) +>sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 0, 13)) +>sym2 : Symbol(sym2, Decl(intersectionReduction.ts, 1, 13)) type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never ->T7 : Symbol(T7, Decl(intersectionReduction.ts, 10, 45)) ->sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 2, 13)) +>T7 : Symbol(T7, Decl(intersectionReduction.ts, 8, 45)) +>sym1 : Symbol(sym1, Decl(intersectionReduction.ts, 0, 13)) type T10 = string & ('a' | 'b'); // 'a' | 'b' ->T10 : Symbol(T10, Decl(intersectionReduction.ts, 11, 60)) +>T10 : Symbol(T10, Decl(intersectionReduction.ts, 9, 60)) type T11 = (string | number) & ('a' | 10); // 'a' | 10 ->T11 : Symbol(T11, Decl(intersectionReduction.ts, 13, 32)) +>T11 : Symbol(T11, Decl(intersectionReduction.ts, 11, 32)) + +type N1 = 'a' & 'b'; +>N1 : Symbol(N1, Decl(intersectionReduction.ts, 12, 42)) + +type N2 = { a: string } & null; +>N2 : Symbol(N2, Decl(intersectionReduction.ts, 14, 20)) +>a : Symbol(a, Decl(intersectionReduction.ts, 15, 11)) + +type N3 = { a: string } & undefined; +>N3 : Symbol(N3, Decl(intersectionReduction.ts, 15, 31)) +>a : Symbol(a, Decl(intersectionReduction.ts, 16, 11)) + +type N4 = string & number; +>N4 : Symbol(N4, Decl(intersectionReduction.ts, 16, 36)) + +type N5 = number & object; +>N5 : Symbol(N5, Decl(intersectionReduction.ts, 17, 26)) + +type N6 = symbol & string; +>N6 : Symbol(N6, Decl(intersectionReduction.ts, 18, 26)) + +type N7 = void & string; +>N7 : Symbol(N7, Decl(intersectionReduction.ts, 19, 26)) + +type X = { x: string }; +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) +>x : Symbol(x, Decl(intersectionReduction.ts, 22, 10)) + +type X1 = X | 'a' & 'b'; +>X1 : Symbol(X1, Decl(intersectionReduction.ts, 22, 23)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) + +type X2 = X | { a: string } & null; +>X2 : Symbol(X2, Decl(intersectionReduction.ts, 24, 24)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) +>a : Symbol(a, Decl(intersectionReduction.ts, 25, 15)) + +type X3 = X | { a: string } & undefined; +>X3 : Symbol(X3, Decl(intersectionReduction.ts, 25, 35)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) +>a : Symbol(a, Decl(intersectionReduction.ts, 26, 15)) + +type X4 = X | string & number; +>X4 : Symbol(X4, Decl(intersectionReduction.ts, 26, 40)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) + +type X5 = X | number & object; +>X5 : Symbol(X5, Decl(intersectionReduction.ts, 27, 30)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) + +type X6 = X | symbol & string; +>X6 : Symbol(X6, Decl(intersectionReduction.ts, 28, 30)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) + +type X7 = X | void & string; +>X7 : Symbol(X7, Decl(intersectionReduction.ts, 29, 30)) +>X : Symbol(X, Decl(intersectionReduction.ts, 20, 24)) + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +>x1 : Symbol(x1, Decl(intersectionReduction.ts, 34, 5)) +>a : Symbol(a, Decl(intersectionReduction.ts, 34, 12)) +>b : Symbol(b, Decl(intersectionReduction.ts, 34, 22)) + +const x2 = { a: 'foo', b: true }; +>x2 : Symbol(x2, Decl(intersectionReduction.ts, 35, 5)) +>a : Symbol(a, Decl(intersectionReduction.ts, 35, 12)) +>b : Symbol(b, Decl(intersectionReduction.ts, 35, 22)) + +declare let k: 'a' | 'b'; +>k : Symbol(k, Decl(intersectionReduction.ts, 37, 11)) + +x1[k] = 'bar' as any; // Error +>x1 : Symbol(x1, Decl(intersectionReduction.ts, 34, 5)) +>k : Symbol(k, Decl(intersectionReduction.ts, 37, 11)) + +x2[k] = 'bar' as any; // Error +>x2 : Symbol(x2, Decl(intersectionReduction.ts, 35, 5)) +>k : Symbol(k, Decl(intersectionReduction.ts, 37, 11)) + +const enum Tag1 {} +>Tag1 : Symbol(Tag1, Decl(intersectionReduction.ts, 40, 21)) + +const enum Tag2 {} +>Tag2 : Symbol(Tag2, Decl(intersectionReduction.ts, 42, 18)) + +declare let s1: string & Tag1; +>s1 : Symbol(s1, Decl(intersectionReduction.ts, 45, 11)) +>Tag1 : Symbol(Tag1, Decl(intersectionReduction.ts, 40, 21)) + +declare let s2: string & Tag2; +>s2 : Symbol(s2, Decl(intersectionReduction.ts, 46, 11)) +>Tag2 : Symbol(Tag2, Decl(intersectionReduction.ts, 42, 18)) + +declare let t1: string & Tag1 | undefined; +>t1 : Symbol(t1, Decl(intersectionReduction.ts, 48, 11)) +>Tag1 : Symbol(Tag1, Decl(intersectionReduction.ts, 40, 21)) + +declare let t2: string & Tag2 | undefined; +>t2 : Symbol(t2, Decl(intersectionReduction.ts, 49, 11)) +>Tag2 : Symbol(Tag2, Decl(intersectionReduction.ts, 42, 18)) + +s1 = s2; +>s1 : Symbol(s1, Decl(intersectionReduction.ts, 45, 11)) +>s2 : Symbol(s2, Decl(intersectionReduction.ts, 46, 11)) + +s2 = s1; +>s2 : Symbol(s2, Decl(intersectionReduction.ts, 46, 11)) +>s1 : Symbol(s1, Decl(intersectionReduction.ts, 45, 11)) + +t1 = t2; +>t1 : Symbol(t1, Decl(intersectionReduction.ts, 48, 11)) +>t2 : Symbol(t2, Decl(intersectionReduction.ts, 49, 11)) + +t2 = t1; +>t2 : Symbol(t2, Decl(intersectionReduction.ts, 49, 11)) +>t1 : Symbol(t1, Decl(intersectionReduction.ts, 48, 11)) diff --git a/tests/baselines/reference/intersectionReduction.types b/tests/baselines/reference/intersectionReduction.types index 725e1b5629..9dfeea5c0e 100644 --- a/tests/baselines/reference/intersectionReduction.types +++ b/tests/baselines/reference/intersectionReduction.types @@ -1,6 +1,4 @@ === tests/cases/conformance/types/intersection/intersectionReduction.ts === -// @strict - declare const sym1: unique symbol; >sym1 : unique symbol @@ -38,3 +36,130 @@ type T10 = string & ('a' | 'b'); // 'a' | 'b' type T11 = (string | number) & ('a' | 10); // 'a' | 10 >T11 : "a" | 10 +type N1 = 'a' & 'b'; +>N1 : never + +type N2 = { a: string } & null; +>N2 : null +>a : string +>null : null + +type N3 = { a: string } & undefined; +>N3 : undefined +>a : string + +type N4 = string & number; +>N4 : never + +type N5 = number & object; +>N5 : never + +type N6 = symbol & string; +>N6 : never + +type N7 = void & string; +>N7 : never + +type X = { x: string }; +>X : X +>x : string + +type X1 = X | 'a' & 'b'; +>X1 : X + +type X2 = X | { a: string } & null; +>X2 : X +>a : string +>null : null + +type X3 = X | { a: string } & undefined; +>X3 : X +>a : string + +type X4 = X | string & number; +>X4 : X + +type X5 = X | number & object; +>X5 : X + +type X6 = X | symbol & string; +>X6 : X + +type X7 = X | void & string; +>X7 : X + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +>x1 : { a: string; b: number; } +>{ a: 'foo', b: 42 } : { a: string; b: number; } +>a : string +>'foo' : "foo" +>b : number +>42 : 42 + +const x2 = { a: 'foo', b: true }; +>x2 : { a: string; b: boolean; } +>{ a: 'foo', b: true } : { a: string; b: boolean; } +>a : string +>'foo' : "foo" +>b : boolean +>true : true + +declare let k: 'a' | 'b'; +>k : "a" | "b" + +x1[k] = 'bar' as any; // Error +>x1[k] = 'bar' as any : any +>x1[k] : never +>x1 : { a: string; b: number; } +>k : "a" | "b" +>'bar' as any : any +>'bar' : "bar" + +x2[k] = 'bar' as any; // Error +>x2[k] = 'bar' as any : any +>x2[k] : never +>x2 : { a: string; b: boolean; } +>k : "a" | "b" +>'bar' as any : any +>'bar' : "bar" + +const enum Tag1 {} +>Tag1 : Tag1 + +const enum Tag2 {} +>Tag2 : Tag2 + +declare let s1: string & Tag1; +>s1 : never + +declare let s2: string & Tag2; +>s2 : never + +declare let t1: string & Tag1 | undefined; +>t1 : undefined + +declare let t2: string & Tag2 | undefined; +>t2 : undefined + +s1 = s2; +>s1 = s2 : never +>s1 : never +>s2 : never + +s2 = s1; +>s2 = s1 : never +>s2 : never +>s1 : never + +t1 = t2; +>t1 = t2 : undefined +>t1 : undefined +>t2 : undefined + +t2 = t1; +>t2 = t1 : undefined +>t2 : undefined +>t1 : undefined + diff --git a/tests/baselines/reference/intersectionReductionStrict.errors.txt b/tests/baselines/reference/intersectionReductionStrict.errors.txt new file mode 100644 index 0000000000..bf174ce04e --- /dev/null +++ b/tests/baselines/reference/intersectionReductionStrict.errors.txt @@ -0,0 +1,66 @@ +tests/cases/conformance/types/intersection/intersectionReductionStrict.ts(40,1): error TS2322: Type 'any' is not assignable to type 'never'. +tests/cases/conformance/types/intersection/intersectionReductionStrict.ts(41,1): error TS2322: Type 'any' is not assignable to type 'never'. + + +==== tests/cases/conformance/types/intersection/intersectionReductionStrict.ts (2 errors) ==== + declare const sym1: unique symbol; + declare const sym2: unique symbol; + + type T1 = string & 'a'; // 'a' + type T2 = 'a' & string & 'b'; // never + type T3 = number & 10; // 10 + type T4 = 10 & number & 20; // never + type T5 = symbol & typeof sym1; // typeof sym1 + type T6 = typeof sym1 & symbol & typeof sym2; // never + type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never + + type T10 = string & ('a' | 'b'); // 'a' | 'b' + type T11 = (string | number) & ('a' | 10); // 'a' | 10 + + type N1 = 'a' & 'b'; + type N2 = { a: string } & null; + type N3 = { a: string } & undefined; + type N4 = string & number; + type N5 = number & object; + type N6 = symbol & string; + type N7 = void & string; + + type X = { x: string }; + + type X1 = X | 'a' & 'b'; + type X2 = X | { a: string } & null; + type X3 = X | { a: string } & undefined; + type X4 = X | string & number; + type X5 = X | number & object; + type X6 = X | symbol & string; + type X7 = X | void & string; + + // Repro from #31663 + + const x1 = { a: 'foo', b: 42 }; + const x2 = { a: 'foo', b: true }; + + declare let k: 'a' | 'b'; + + x1[k] = 'bar' as any; // Error + ~~~~~ +!!! error TS2322: Type 'any' is not assignable to type 'never'. + x2[k] = 'bar' as any; // Error + ~~~~~ +!!! error TS2322: Type 'any' is not assignable to type 'never'. + + const enum Tag1 {} + const enum Tag2 {} + + declare let s1: string & Tag1; + declare let s2: string & Tag2; + + declare let t1: string & Tag1 | undefined; + declare let t2: string & Tag2 | undefined; + + s1 = s2; + s2 = s1; + + t1 = t2; + t2 = t1; + \ No newline at end of file diff --git a/tests/baselines/reference/intersectionReductionStrict.js b/tests/baselines/reference/intersectionReductionStrict.js new file mode 100644 index 0000000000..32845471a0 --- /dev/null +++ b/tests/baselines/reference/intersectionReductionStrict.js @@ -0,0 +1,70 @@ +//// [intersectionReductionStrict.ts] +declare const sym1: unique symbol; +declare const sym2: unique symbol; + +type T1 = string & 'a'; // 'a' +type T2 = 'a' & string & 'b'; // never +type T3 = number & 10; // 10 +type T4 = 10 & number & 20; // never +type T5 = symbol & typeof sym1; // typeof sym1 +type T6 = typeof sym1 & symbol & typeof sym2; // never +type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never + +type T10 = string & ('a' | 'b'); // 'a' | 'b' +type T11 = (string | number) & ('a' | 10); // 'a' | 10 + +type N1 = 'a' & 'b'; +type N2 = { a: string } & null; +type N3 = { a: string } & undefined; +type N4 = string & number; +type N5 = number & object; +type N6 = symbol & string; +type N7 = void & string; + +type X = { x: string }; + +type X1 = X | 'a' & 'b'; +type X2 = X | { a: string } & null; +type X3 = X | { a: string } & undefined; +type X4 = X | string & number; +type X5 = X | number & object; +type X6 = X | symbol & string; +type X7 = X | void & string; + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +const x2 = { a: 'foo', b: true }; + +declare let k: 'a' | 'b'; + +x1[k] = 'bar' as any; // Error +x2[k] = 'bar' as any; // Error + +const enum Tag1 {} +const enum Tag2 {} + +declare let s1: string & Tag1; +declare let s2: string & Tag2; + +declare let t1: string & Tag1 | undefined; +declare let t2: string & Tag2 | undefined; + +s1 = s2; +s2 = s1; + +t1 = t2; +t2 = t1; + + +//// [intersectionReductionStrict.js] +"use strict"; +// Repro from #31663 +var x1 = { a: 'foo', b: 42 }; +var x2 = { a: 'foo', b: true }; +x1[k] = 'bar'; // Error +x2[k] = 'bar'; // Error +s1 = s2; +s2 = s1; +t1 = t2; +t2 = t1; diff --git a/tests/baselines/reference/intersectionReductionStrict.symbols b/tests/baselines/reference/intersectionReductionStrict.symbols new file mode 100644 index 0000000000..6e9d7e03a8 --- /dev/null +++ b/tests/baselines/reference/intersectionReductionStrict.symbols @@ -0,0 +1,156 @@ +=== tests/cases/conformance/types/intersection/intersectionReductionStrict.ts === +declare const sym1: unique symbol; +>sym1 : Symbol(sym1, Decl(intersectionReductionStrict.ts, 0, 13)) + +declare const sym2: unique symbol; +>sym2 : Symbol(sym2, Decl(intersectionReductionStrict.ts, 1, 13)) + +type T1 = string & 'a'; // 'a' +>T1 : Symbol(T1, Decl(intersectionReductionStrict.ts, 1, 34)) + +type T2 = 'a' & string & 'b'; // never +>T2 : Symbol(T2, Decl(intersectionReductionStrict.ts, 3, 23)) + +type T3 = number & 10; // 10 +>T3 : Symbol(T3, Decl(intersectionReductionStrict.ts, 4, 29)) + +type T4 = 10 & number & 20; // never +>T4 : Symbol(T4, Decl(intersectionReductionStrict.ts, 5, 22)) + +type T5 = symbol & typeof sym1; // typeof sym1 +>T5 : Symbol(T5, Decl(intersectionReductionStrict.ts, 6, 27)) +>sym1 : Symbol(sym1, Decl(intersectionReductionStrict.ts, 0, 13)) + +type T6 = typeof sym1 & symbol & typeof sym2; // never +>T6 : Symbol(T6, Decl(intersectionReductionStrict.ts, 7, 31)) +>sym1 : Symbol(sym1, Decl(intersectionReductionStrict.ts, 0, 13)) +>sym2 : Symbol(sym2, Decl(intersectionReductionStrict.ts, 1, 13)) + +type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never +>T7 : Symbol(T7, Decl(intersectionReductionStrict.ts, 8, 45)) +>sym1 : Symbol(sym1, Decl(intersectionReductionStrict.ts, 0, 13)) + +type T10 = string & ('a' | 'b'); // 'a' | 'b' +>T10 : Symbol(T10, Decl(intersectionReductionStrict.ts, 9, 60)) + +type T11 = (string | number) & ('a' | 10); // 'a' | 10 +>T11 : Symbol(T11, Decl(intersectionReductionStrict.ts, 11, 32)) + +type N1 = 'a' & 'b'; +>N1 : Symbol(N1, Decl(intersectionReductionStrict.ts, 12, 42)) + +type N2 = { a: string } & null; +>N2 : Symbol(N2, Decl(intersectionReductionStrict.ts, 14, 20)) +>a : Symbol(a, Decl(intersectionReductionStrict.ts, 15, 11)) + +type N3 = { a: string } & undefined; +>N3 : Symbol(N3, Decl(intersectionReductionStrict.ts, 15, 31)) +>a : Symbol(a, Decl(intersectionReductionStrict.ts, 16, 11)) + +type N4 = string & number; +>N4 : Symbol(N4, Decl(intersectionReductionStrict.ts, 16, 36)) + +type N5 = number & object; +>N5 : Symbol(N5, Decl(intersectionReductionStrict.ts, 17, 26)) + +type N6 = symbol & string; +>N6 : Symbol(N6, Decl(intersectionReductionStrict.ts, 18, 26)) + +type N7 = void & string; +>N7 : Symbol(N7, Decl(intersectionReductionStrict.ts, 19, 26)) + +type X = { x: string }; +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) +>x : Symbol(x, Decl(intersectionReductionStrict.ts, 22, 10)) + +type X1 = X | 'a' & 'b'; +>X1 : Symbol(X1, Decl(intersectionReductionStrict.ts, 22, 23)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) + +type X2 = X | { a: string } & null; +>X2 : Symbol(X2, Decl(intersectionReductionStrict.ts, 24, 24)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) +>a : Symbol(a, Decl(intersectionReductionStrict.ts, 25, 15)) + +type X3 = X | { a: string } & undefined; +>X3 : Symbol(X3, Decl(intersectionReductionStrict.ts, 25, 35)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) +>a : Symbol(a, Decl(intersectionReductionStrict.ts, 26, 15)) + +type X4 = X | string & number; +>X4 : Symbol(X4, Decl(intersectionReductionStrict.ts, 26, 40)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) + +type X5 = X | number & object; +>X5 : Symbol(X5, Decl(intersectionReductionStrict.ts, 27, 30)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) + +type X6 = X | symbol & string; +>X6 : Symbol(X6, Decl(intersectionReductionStrict.ts, 28, 30)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) + +type X7 = X | void & string; +>X7 : Symbol(X7, Decl(intersectionReductionStrict.ts, 29, 30)) +>X : Symbol(X, Decl(intersectionReductionStrict.ts, 20, 24)) + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +>x1 : Symbol(x1, Decl(intersectionReductionStrict.ts, 34, 5)) +>a : Symbol(a, Decl(intersectionReductionStrict.ts, 34, 12)) +>b : Symbol(b, Decl(intersectionReductionStrict.ts, 34, 22)) + +const x2 = { a: 'foo', b: true }; +>x2 : Symbol(x2, Decl(intersectionReductionStrict.ts, 35, 5)) +>a : Symbol(a, Decl(intersectionReductionStrict.ts, 35, 12)) +>b : Symbol(b, Decl(intersectionReductionStrict.ts, 35, 22)) + +declare let k: 'a' | 'b'; +>k : Symbol(k, Decl(intersectionReductionStrict.ts, 37, 11)) + +x1[k] = 'bar' as any; // Error +>x1 : Symbol(x1, Decl(intersectionReductionStrict.ts, 34, 5)) +>k : Symbol(k, Decl(intersectionReductionStrict.ts, 37, 11)) + +x2[k] = 'bar' as any; // Error +>x2 : Symbol(x2, Decl(intersectionReductionStrict.ts, 35, 5)) +>k : Symbol(k, Decl(intersectionReductionStrict.ts, 37, 11)) + +const enum Tag1 {} +>Tag1 : Symbol(Tag1, Decl(intersectionReductionStrict.ts, 40, 21)) + +const enum Tag2 {} +>Tag2 : Symbol(Tag2, Decl(intersectionReductionStrict.ts, 42, 18)) + +declare let s1: string & Tag1; +>s1 : Symbol(s1, Decl(intersectionReductionStrict.ts, 45, 11)) +>Tag1 : Symbol(Tag1, Decl(intersectionReductionStrict.ts, 40, 21)) + +declare let s2: string & Tag2; +>s2 : Symbol(s2, Decl(intersectionReductionStrict.ts, 46, 11)) +>Tag2 : Symbol(Tag2, Decl(intersectionReductionStrict.ts, 42, 18)) + +declare let t1: string & Tag1 | undefined; +>t1 : Symbol(t1, Decl(intersectionReductionStrict.ts, 48, 11)) +>Tag1 : Symbol(Tag1, Decl(intersectionReductionStrict.ts, 40, 21)) + +declare let t2: string & Tag2 | undefined; +>t2 : Symbol(t2, Decl(intersectionReductionStrict.ts, 49, 11)) +>Tag2 : Symbol(Tag2, Decl(intersectionReductionStrict.ts, 42, 18)) + +s1 = s2; +>s1 : Symbol(s1, Decl(intersectionReductionStrict.ts, 45, 11)) +>s2 : Symbol(s2, Decl(intersectionReductionStrict.ts, 46, 11)) + +s2 = s1; +>s2 : Symbol(s2, Decl(intersectionReductionStrict.ts, 46, 11)) +>s1 : Symbol(s1, Decl(intersectionReductionStrict.ts, 45, 11)) + +t1 = t2; +>t1 : Symbol(t1, Decl(intersectionReductionStrict.ts, 48, 11)) +>t2 : Symbol(t2, Decl(intersectionReductionStrict.ts, 49, 11)) + +t2 = t1; +>t2 : Symbol(t2, Decl(intersectionReductionStrict.ts, 49, 11)) +>t1 : Symbol(t1, Decl(intersectionReductionStrict.ts, 48, 11)) + diff --git a/tests/baselines/reference/intersectionReductionStrict.types b/tests/baselines/reference/intersectionReductionStrict.types new file mode 100644 index 0000000000..8227f6b407 --- /dev/null +++ b/tests/baselines/reference/intersectionReductionStrict.types @@ -0,0 +1,165 @@ +=== tests/cases/conformance/types/intersection/intersectionReductionStrict.ts === +declare const sym1: unique symbol; +>sym1 : unique symbol + +declare const sym2: unique symbol; +>sym2 : unique symbol + +type T1 = string & 'a'; // 'a' +>T1 : "a" + +type T2 = 'a' & string & 'b'; // never +>T2 : never + +type T3 = number & 10; // 10 +>T3 : 10 + +type T4 = 10 & number & 20; // never +>T4 : never + +type T5 = symbol & typeof sym1; // typeof sym1 +>T5 : unique symbol +>sym1 : unique symbol + +type T6 = typeof sym1 & symbol & typeof sym2; // never +>T6 : never +>sym1 : unique symbol +>sym2 : unique symbol + +type T7 = string & 'a' & number & 10 & symbol & typeof sym1; // never +>T7 : never +>sym1 : unique symbol + +type T10 = string & ('a' | 'b'); // 'a' | 'b' +>T10 : "a" | "b" + +type T11 = (string | number) & ('a' | 10); // 'a' | 10 +>T11 : "a" | 10 + +type N1 = 'a' & 'b'; +>N1 : never + +type N2 = { a: string } & null; +>N2 : never +>a : string +>null : null + +type N3 = { a: string } & undefined; +>N3 : never +>a : string + +type N4 = string & number; +>N4 : never + +type N5 = number & object; +>N5 : never + +type N6 = symbol & string; +>N6 : never + +type N7 = void & string; +>N7 : never + +type X = { x: string }; +>X : X +>x : string + +type X1 = X | 'a' & 'b'; +>X1 : X + +type X2 = X | { a: string } & null; +>X2 : X +>a : string +>null : null + +type X3 = X | { a: string } & undefined; +>X3 : X +>a : string + +type X4 = X | string & number; +>X4 : X + +type X5 = X | number & object; +>X5 : X + +type X6 = X | symbol & string; +>X6 : X + +type X7 = X | void & string; +>X7 : X + +// Repro from #31663 + +const x1 = { a: 'foo', b: 42 }; +>x1 : { a: string; b: number; } +>{ a: 'foo', b: 42 } : { a: string; b: number; } +>a : string +>'foo' : "foo" +>b : number +>42 : 42 + +const x2 = { a: 'foo', b: true }; +>x2 : { a: string; b: boolean; } +>{ a: 'foo', b: true } : { a: string; b: boolean; } +>a : string +>'foo' : "foo" +>b : boolean +>true : true + +declare let k: 'a' | 'b'; +>k : "a" | "b" + +x1[k] = 'bar' as any; // Error +>x1[k] = 'bar' as any : any +>x1[k] : never +>x1 : { a: string; b: number; } +>k : "a" | "b" +>'bar' as any : any +>'bar' : "bar" + +x2[k] = 'bar' as any; // Error +>x2[k] = 'bar' as any : any +>x2[k] : never +>x2 : { a: string; b: boolean; } +>k : "a" | "b" +>'bar' as any : any +>'bar' : "bar" + +const enum Tag1 {} +>Tag1 : Tag1 + +const enum Tag2 {} +>Tag2 : Tag2 + +declare let s1: string & Tag1; +>s1 : never + +declare let s2: string & Tag2; +>s2 : never + +declare let t1: string & Tag1 | undefined; +>t1 : undefined + +declare let t2: string & Tag2 | undefined; +>t2 : undefined + +s1 = s2; +>s1 = s2 : never +>s1 : never +>s2 : never + +s2 = s1; +>s2 = s1 : never +>s2 : never +>s1 : never + +t1 = t2; +>t1 = t2 : undefined +>t1 : undefined +>t2 : undefined + +t2 = t1; +>t2 = t1 : undefined +>t2 : undefined +>t1 : undefined +