mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 01:43:59 -05:00
Adding tests
This commit is contained in:
162
tests/baselines/reference/intersectionAndUnionTypes.errors.txt
Normal file
162
tests/baselines/reference/intersectionAndUnionTypes.errors.txt
Normal file
@@ -0,0 +1,162 @@
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(19,1): error TS2322: Type 'A' is not assignable to type 'A & B'.
|
||||
Type 'A' is not assignable to type 'B'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(20,1): error TS2322: Type 'B' is not assignable to type 'A & B'.
|
||||
Type 'B' is not assignable to type 'A'.
|
||||
Property 'a' is missing in type 'B'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(23,1): error TS2322: Type 'A | B' is not assignable to type '(A & B) | (C & D)'.
|
||||
Type 'A' is not assignable to type '(A & B) | (C & D)'.
|
||||
Type 'A' is not assignable to type 'C & D'.
|
||||
Type 'A' is not assignable to type 'C'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(25,1): error TS2322: Type 'C | D' is not assignable to type '(A & B) | (C & D)'.
|
||||
Type 'C' is not assignable to type '(A & B) | (C & D)'.
|
||||
Type 'C' is not assignable to type 'C & D'.
|
||||
Type 'C' is not assignable to type 'D'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(26,1): error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'A & B'.
|
||||
Type 'C & D' is not assignable to type 'A & B'.
|
||||
Type 'C & D' is not assignable to type 'A'.
|
||||
Type 'D' is not assignable to type 'A'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(27,1): error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'A | B'.
|
||||
Type 'C & D' is not assignable to type 'A | B'.
|
||||
Type 'C & D' is not assignable to type 'B'.
|
||||
Type 'D' is not assignable to type 'B'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(28,1): error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'C & D'.
|
||||
Type 'A & B' is not assignable to type 'C & D'.
|
||||
Type 'A & B' is not assignable to type 'C'.
|
||||
Type 'B' is not assignable to type 'C'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(29,1): error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'C | D'.
|
||||
Type 'A & B' is not assignable to type 'C | D'.
|
||||
Type 'A & B' is not assignable to type 'D'.
|
||||
Type 'B' is not assignable to type 'D'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(31,1): error TS2322: Type 'A & B' is not assignable to type '(A | B) & (C | D)'.
|
||||
Type 'A & B' is not assignable to type 'C | D'.
|
||||
Type 'A & B' is not assignable to type 'D'.
|
||||
Type 'B' is not assignable to type 'D'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(32,1): error TS2322: Type 'A | B' is not assignable to type '(A | B) & (C | D)'.
|
||||
Type 'A' is not assignable to type '(A | B) & (C | D)'.
|
||||
Type 'A' is not assignable to type 'C | D'.
|
||||
Type 'A' is not assignable to type 'D'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(33,1): error TS2322: Type 'C & D' is not assignable to type '(A | B) & (C | D)'.
|
||||
Type 'C & D' is not assignable to type 'A | B'.
|
||||
Type 'C & D' is not assignable to type 'B'.
|
||||
Type 'D' is not assignable to type 'B'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(34,1): error TS2322: Type 'C | D' is not assignable to type '(A | B) & (C | D)'.
|
||||
Type 'C' is not assignable to type '(A | B) & (C | D)'.
|
||||
Type 'C' is not assignable to type 'A | B'.
|
||||
Type 'C' is not assignable to type 'B'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(35,1): error TS2322: Type '(A | B) & (C | D)' is not assignable to type 'A & B'.
|
||||
Type '(A | B) & (C | D)' is not assignable to type 'A'.
|
||||
Type 'C | D' is not assignable to type 'A'.
|
||||
Type 'C' is not assignable to type 'A'.
|
||||
tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts(37,1): error TS2322: Type '(A | B) & (C | D)' is not assignable to type 'C & D'.
|
||||
Type '(A | B) & (C | D)' is not assignable to type 'C'.
|
||||
Type 'C | D' is not assignable to type 'C'.
|
||||
Type 'D' is not assignable to type 'C'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/intersection/intersectionAndUnionTypes.ts (14 errors) ====
|
||||
interface A { a: string }
|
||||
interface B { b: string }
|
||||
interface C { c: string }
|
||||
interface D { d: string }
|
||||
|
||||
var a: A;
|
||||
var b: B;
|
||||
var c: C;
|
||||
var d: D;
|
||||
var anb: A & B;
|
||||
var aob: A | B;
|
||||
var cnd: C & D;
|
||||
var cod: C | D;
|
||||
var x: A & B | C & D;
|
||||
var y: (A | B) & (C | D);
|
||||
|
||||
a = anb; // Ok
|
||||
b = anb; // Ok
|
||||
anb = a;
|
||||
~~~
|
||||
!!! error TS2322: Type 'A' is not assignable to type 'A & B'.
|
||||
!!! error TS2322: Type 'A' is not assignable to type 'B'.
|
||||
anb = b;
|
||||
~~~
|
||||
!!! error TS2322: Type 'B' is not assignable to type 'A & B'.
|
||||
!!! error TS2322: Type 'B' is not assignable to type 'A'.
|
||||
!!! error TS2322: Property 'a' is missing in type 'B'.
|
||||
|
||||
x = anb; // Ok
|
||||
x = aob;
|
||||
~
|
||||
!!! error TS2322: Type 'A | B' is not assignable to type '(A & B) | (C & D)'.
|
||||
!!! error TS2322: Type 'A' is not assignable to type '(A & B) | (C & D)'.
|
||||
!!! error TS2322: Type 'A' is not assignable to type 'C & D'.
|
||||
!!! error TS2322: Type 'A' is not assignable to type 'C'.
|
||||
x = cnd; // Ok
|
||||
x = cod;
|
||||
~
|
||||
!!! error TS2322: Type 'C | D' is not assignable to type '(A & B) | (C & D)'.
|
||||
!!! error TS2322: Type 'C' is not assignable to type '(A & B) | (C & D)'.
|
||||
!!! error TS2322: Type 'C' is not assignable to type 'C & D'.
|
||||
!!! error TS2322: Type 'C' is not assignable to type 'D'.
|
||||
anb = x;
|
||||
~~~
|
||||
!!! error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'A & B'.
|
||||
!!! error TS2322: Type 'C & D' is not assignable to type 'A & B'.
|
||||
!!! error TS2322: Type 'C & D' is not assignable to type 'A'.
|
||||
!!! error TS2322: Type 'D' is not assignable to type 'A'.
|
||||
aob = x;
|
||||
~~~
|
||||
!!! error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'A | B'.
|
||||
!!! error TS2322: Type 'C & D' is not assignable to type 'A | B'.
|
||||
!!! error TS2322: Type 'C & D' is not assignable to type 'B'.
|
||||
!!! error TS2322: Type 'D' is not assignable to type 'B'.
|
||||
cnd = x;
|
||||
~~~
|
||||
!!! error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'C & D'.
|
||||
!!! error TS2322: Type 'A & B' is not assignable to type 'C & D'.
|
||||
!!! error TS2322: Type 'A & B' is not assignable to type 'C'.
|
||||
!!! error TS2322: Type 'B' is not assignable to type 'C'.
|
||||
cod = x;
|
||||
~~~
|
||||
!!! error TS2322: Type '(A & B) | (C & D)' is not assignable to type 'C | D'.
|
||||
!!! error TS2322: Type 'A & B' is not assignable to type 'C | D'.
|
||||
!!! error TS2322: Type 'A & B' is not assignable to type 'D'.
|
||||
!!! error TS2322: Type 'B' is not assignable to type 'D'.
|
||||
|
||||
y = anb;
|
||||
~
|
||||
!!! error TS2322: Type 'A & B' is not assignable to type '(A | B) & (C | D)'.
|
||||
!!! error TS2322: Type 'A & B' is not assignable to type 'C | D'.
|
||||
!!! error TS2322: Type 'A & B' is not assignable to type 'D'.
|
||||
!!! error TS2322: Type 'B' is not assignable to type 'D'.
|
||||
y = aob;
|
||||
~
|
||||
!!! error TS2322: Type 'A | B' is not assignable to type '(A | B) & (C | D)'.
|
||||
!!! error TS2322: Type 'A' is not assignable to type '(A | B) & (C | D)'.
|
||||
!!! error TS2322: Type 'A' is not assignable to type 'C | D'.
|
||||
!!! error TS2322: Type 'A' is not assignable to type 'D'.
|
||||
y = cnd;
|
||||
~
|
||||
!!! error TS2322: Type 'C & D' is not assignable to type '(A | B) & (C | D)'.
|
||||
!!! error TS2322: Type 'C & D' is not assignable to type 'A | B'.
|
||||
!!! error TS2322: Type 'C & D' is not assignable to type 'B'.
|
||||
!!! error TS2322: Type 'D' is not assignable to type 'B'.
|
||||
y = cod;
|
||||
~
|
||||
!!! error TS2322: Type 'C | D' is not assignable to type '(A | B) & (C | D)'.
|
||||
!!! error TS2322: Type 'C' is not assignable to type '(A | B) & (C | D)'.
|
||||
!!! error TS2322: Type 'C' is not assignable to type 'A | B'.
|
||||
!!! error TS2322: Type 'C' is not assignable to type 'B'.
|
||||
anb = y;
|
||||
~~~
|
||||
!!! error TS2322: Type '(A | B) & (C | D)' is not assignable to type 'A & B'.
|
||||
!!! error TS2322: Type '(A | B) & (C | D)' is not assignable to type 'A'.
|
||||
!!! error TS2322: Type 'C | D' is not assignable to type 'A'.
|
||||
!!! error TS2322: Type 'C' is not assignable to type 'A'.
|
||||
aob = y; // Ok
|
||||
cnd = y;
|
||||
~~~
|
||||
!!! error TS2322: Type '(A | B) & (C | D)' is not assignable to type 'C & D'.
|
||||
!!! error TS2322: Type '(A | B) & (C | D)' is not assignable to type 'C'.
|
||||
!!! error TS2322: Type 'C | D' is not assignable to type 'C'.
|
||||
!!! error TS2322: Type 'D' is not assignable to type 'C'.
|
||||
cod = y; // Ok
|
||||
|
||||
72
tests/baselines/reference/intersectionAndUnionTypes.js
Normal file
72
tests/baselines/reference/intersectionAndUnionTypes.js
Normal file
@@ -0,0 +1,72 @@
|
||||
//// [intersectionAndUnionTypes.ts]
|
||||
interface A { a: string }
|
||||
interface B { b: string }
|
||||
interface C { c: string }
|
||||
interface D { d: string }
|
||||
|
||||
var a: A;
|
||||
var b: B;
|
||||
var c: C;
|
||||
var d: D;
|
||||
var anb: A & B;
|
||||
var aob: A | B;
|
||||
var cnd: C & D;
|
||||
var cod: C | D;
|
||||
var x: A & B | C & D;
|
||||
var y: (A | B) & (C | D);
|
||||
|
||||
a = anb; // Ok
|
||||
b = anb; // Ok
|
||||
anb = a;
|
||||
anb = b;
|
||||
|
||||
x = anb; // Ok
|
||||
x = aob;
|
||||
x = cnd; // Ok
|
||||
x = cod;
|
||||
anb = x;
|
||||
aob = x;
|
||||
cnd = x;
|
||||
cod = x;
|
||||
|
||||
y = anb;
|
||||
y = aob;
|
||||
y = cnd;
|
||||
y = cod;
|
||||
anb = y;
|
||||
aob = y; // Ok
|
||||
cnd = y;
|
||||
cod = y; // Ok
|
||||
|
||||
|
||||
//// [intersectionAndUnionTypes.js]
|
||||
var a;
|
||||
var b;
|
||||
var c;
|
||||
var d;
|
||||
var anb;
|
||||
var aob;
|
||||
var cnd;
|
||||
var cod;
|
||||
var x;
|
||||
var y;
|
||||
a = anb; // Ok
|
||||
b = anb; // Ok
|
||||
anb = a;
|
||||
anb = b;
|
||||
x = anb; // Ok
|
||||
x = aob;
|
||||
x = cnd; // Ok
|
||||
x = cod;
|
||||
anb = x;
|
||||
aob = x;
|
||||
cnd = x;
|
||||
cod = x;
|
||||
y = anb;
|
||||
y = aob;
|
||||
y = cnd;
|
||||
y = cod;
|
||||
anb = y;
|
||||
aob = y; // Ok
|
||||
cnd = y;
|
||||
cod = y; // Ok
|
||||
31
tests/baselines/reference/intersectionTypeEquivalence.js
Normal file
31
tests/baselines/reference/intersectionTypeEquivalence.js
Normal file
@@ -0,0 +1,31 @@
|
||||
//// [intersectionTypeEquivalence.ts]
|
||||
interface A { a: string }
|
||||
interface B { b: string }
|
||||
interface C { c: string }
|
||||
|
||||
// A & B is equivalent to B & A.
|
||||
var y: A & B;
|
||||
var y : B & A;
|
||||
|
||||
// AB & C is equivalent to A & BC, where AB is A & B and BC is B & C.
|
||||
var z : A & B & C;
|
||||
var z : (A & B) & C;
|
||||
var z : A & (B & C);
|
||||
var ab : A & B;
|
||||
var bc : B & C;
|
||||
var z1: typeof ab & C;
|
||||
var z1: A & typeof bc;
|
||||
|
||||
|
||||
//// [intersectionTypeEquivalence.js]
|
||||
// A & B is equivalent to B & A.
|
||||
var y;
|
||||
var y;
|
||||
// AB & C is equivalent to A & BC, where AB is A & B and BC is B & C.
|
||||
var z;
|
||||
var z;
|
||||
var z;
|
||||
var ab;
|
||||
var bc;
|
||||
var z1;
|
||||
var z1;
|
||||
@@ -0,0 +1,63 @@
|
||||
=== tests/cases/conformance/types/intersection/intersectionTypeEquivalence.ts ===
|
||||
interface A { a: string }
|
||||
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(intersectionTypeEquivalence.ts, 0, 13))
|
||||
|
||||
interface B { b: string }
|
||||
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
|
||||
>b : Symbol(b, Decl(intersectionTypeEquivalence.ts, 1, 13))
|
||||
|
||||
interface C { c: string }
|
||||
>C : Symbol(C, Decl(intersectionTypeEquivalence.ts, 1, 25))
|
||||
>c : Symbol(c, Decl(intersectionTypeEquivalence.ts, 2, 13))
|
||||
|
||||
// A & B is equivalent to B & A.
|
||||
var y: A & B;
|
||||
>y : Symbol(y, Decl(intersectionTypeEquivalence.ts, 5, 3), Decl(intersectionTypeEquivalence.ts, 6, 3))
|
||||
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
|
||||
|
||||
var y : B & A;
|
||||
>y : Symbol(y, Decl(intersectionTypeEquivalence.ts, 5, 3), Decl(intersectionTypeEquivalence.ts, 6, 3))
|
||||
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
|
||||
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
|
||||
|
||||
// AB & C is equivalent to A & BC, where AB is A & B and BC is B & C.
|
||||
var z : A & B & C;
|
||||
>z : Symbol(z, Decl(intersectionTypeEquivalence.ts, 9, 3), Decl(intersectionTypeEquivalence.ts, 10, 3), Decl(intersectionTypeEquivalence.ts, 11, 3))
|
||||
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
|
||||
>C : Symbol(C, Decl(intersectionTypeEquivalence.ts, 1, 25))
|
||||
|
||||
var z : (A & B) & C;
|
||||
>z : Symbol(z, Decl(intersectionTypeEquivalence.ts, 9, 3), Decl(intersectionTypeEquivalence.ts, 10, 3), Decl(intersectionTypeEquivalence.ts, 11, 3))
|
||||
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
|
||||
>C : Symbol(C, Decl(intersectionTypeEquivalence.ts, 1, 25))
|
||||
|
||||
var z : A & (B & C);
|
||||
>z : Symbol(z, Decl(intersectionTypeEquivalence.ts, 9, 3), Decl(intersectionTypeEquivalence.ts, 10, 3), Decl(intersectionTypeEquivalence.ts, 11, 3))
|
||||
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
|
||||
>C : Symbol(C, Decl(intersectionTypeEquivalence.ts, 1, 25))
|
||||
|
||||
var ab : A & B;
|
||||
>ab : Symbol(ab, Decl(intersectionTypeEquivalence.ts, 12, 3))
|
||||
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
|
||||
|
||||
var bc : B & C;
|
||||
>bc : Symbol(bc, Decl(intersectionTypeEquivalence.ts, 13, 3))
|
||||
>B : Symbol(B, Decl(intersectionTypeEquivalence.ts, 0, 25))
|
||||
>C : Symbol(C, Decl(intersectionTypeEquivalence.ts, 1, 25))
|
||||
|
||||
var z1: typeof ab & C;
|
||||
>z1 : Symbol(z1, Decl(intersectionTypeEquivalence.ts, 14, 3), Decl(intersectionTypeEquivalence.ts, 15, 3))
|
||||
>ab : Symbol(ab, Decl(intersectionTypeEquivalence.ts, 12, 3))
|
||||
>C : Symbol(C, Decl(intersectionTypeEquivalence.ts, 1, 25))
|
||||
|
||||
var z1: A & typeof bc;
|
||||
>z1 : Symbol(z1, Decl(intersectionTypeEquivalence.ts, 14, 3), Decl(intersectionTypeEquivalence.ts, 15, 3))
|
||||
>A : Symbol(A, Decl(intersectionTypeEquivalence.ts, 0, 0))
|
||||
>bc : Symbol(bc, Decl(intersectionTypeEquivalence.ts, 13, 3))
|
||||
|
||||
63
tests/baselines/reference/intersectionTypeEquivalence.types
Normal file
63
tests/baselines/reference/intersectionTypeEquivalence.types
Normal file
@@ -0,0 +1,63 @@
|
||||
=== tests/cases/conformance/types/intersection/intersectionTypeEquivalence.ts ===
|
||||
interface A { a: string }
|
||||
>A : A
|
||||
>a : string
|
||||
|
||||
interface B { b: string }
|
||||
>B : B
|
||||
>b : string
|
||||
|
||||
interface C { c: string }
|
||||
>C : C
|
||||
>c : string
|
||||
|
||||
// A & B is equivalent to B & A.
|
||||
var y: A & B;
|
||||
>y : A & B
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
var y : B & A;
|
||||
>y : A & B
|
||||
>B : B
|
||||
>A : A
|
||||
|
||||
// AB & C is equivalent to A & BC, where AB is A & B and BC is B & C.
|
||||
var z : A & B & C;
|
||||
>z : A & B & C
|
||||
>A : A
|
||||
>B : B
|
||||
>C : C
|
||||
|
||||
var z : (A & B) & C;
|
||||
>z : A & B & C
|
||||
>A : A
|
||||
>B : B
|
||||
>C : C
|
||||
|
||||
var z : A & (B & C);
|
||||
>z : A & B & C
|
||||
>A : A
|
||||
>B : B
|
||||
>C : C
|
||||
|
||||
var ab : A & B;
|
||||
>ab : A & B
|
||||
>A : A
|
||||
>B : B
|
||||
|
||||
var bc : B & C;
|
||||
>bc : B & C
|
||||
>B : B
|
||||
>C : C
|
||||
|
||||
var z1: typeof ab & C;
|
||||
>z1 : A & B & C
|
||||
>ab : A & B
|
||||
>C : C
|
||||
|
||||
var z1: A & typeof bc;
|
||||
>z1 : A & B & C
|
||||
>A : A
|
||||
>bc : B & C
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
tests/cases/conformance/types/intersection/intersectionTypeInference.ts(6,5): error TS2322: Type 'T' is not assignable to type 'T & U'.
|
||||
Type 'T' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/intersection/intersectionTypeInference.ts(7,5): error TS2322: Type 'U' is not assignable to type 'T & U'.
|
||||
Type 'U' is not assignable to type 'T'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/intersection/intersectionTypeInference.ts (2 errors) ====
|
||||
|
||||
function extend<T, U>(obj1: T, obj2: U): T & U {
|
||||
var result: T & U;
|
||||
obj1 = result;
|
||||
obj2 = result;
|
||||
result = obj1; // Error
|
||||
~~~~~~
|
||||
!!! error TS2322: Type 'T' is not assignable to type 'T & U'.
|
||||
!!! error TS2322: Type 'T' is not assignable to type 'U'.
|
||||
result = obj2; // Error
|
||||
~~~~~~
|
||||
!!! error TS2322: Type 'U' is not assignable to type 'T & U'.
|
||||
!!! error TS2322: Type 'U' is not assignable to type 'T'.
|
||||
return result;
|
||||
}
|
||||
|
||||
var x = extend({ a: "hello" }, { b: 42 });
|
||||
var s = x.a;
|
||||
var n = x.b;
|
||||
|
||||
28
tests/baselines/reference/intersectionTypeInference.js
Normal file
28
tests/baselines/reference/intersectionTypeInference.js
Normal file
@@ -0,0 +1,28 @@
|
||||
//// [intersectionTypeInference.ts]
|
||||
|
||||
function extend<T, U>(obj1: T, obj2: U): T & U {
|
||||
var result: T & U;
|
||||
obj1 = result;
|
||||
obj2 = result;
|
||||
result = obj1; // Error
|
||||
result = obj2; // Error
|
||||
return result;
|
||||
}
|
||||
|
||||
var x = extend({ a: "hello" }, { b: 42 });
|
||||
var s = x.a;
|
||||
var n = x.b;
|
||||
|
||||
|
||||
//// [intersectionTypeInference.js]
|
||||
function extend(obj1, obj2) {
|
||||
var result;
|
||||
obj1 = result;
|
||||
obj2 = result;
|
||||
result = obj1; // Error
|
||||
result = obj2; // Error
|
||||
return result;
|
||||
}
|
||||
var x = extend({ a: "hello" }, { b: 42 });
|
||||
var s = x.a;
|
||||
var n = x.b;
|
||||
44
tests/baselines/reference/intersectionTypeMembers.js
Normal file
44
tests/baselines/reference/intersectionTypeMembers.js
Normal file
@@ -0,0 +1,44 @@
|
||||
//// [intersectionTypeMembers.ts]
|
||||
// An intersection type has those members that are present in any of its constituent types,
|
||||
// with types that are intersections of the respective members in the constituent types
|
||||
|
||||
interface A { a: string }
|
||||
interface B { b: string }
|
||||
interface C { c: string }
|
||||
|
||||
var abc: A & B & C;
|
||||
abc.a = "hello";
|
||||
abc.b = "hello";
|
||||
abc.c = "hello";
|
||||
|
||||
interface X { x: A }
|
||||
interface Y { x: B }
|
||||
interface Z { x: C }
|
||||
|
||||
var xyz: X & Y & Z;
|
||||
xyz.x.a = "hello";
|
||||
xyz.x.b = "hello";
|
||||
xyz.x.c = "hello";
|
||||
|
||||
type F1 = (x: string) => string;
|
||||
type F2 = (x: number) => number;
|
||||
|
||||
var f: F1 & F2;
|
||||
var s = f("hello");
|
||||
var n = f(42);
|
||||
|
||||
|
||||
//// [intersectionTypeMembers.js]
|
||||
// An intersection type has those members that are present in any of its constituent types,
|
||||
// with types that are intersections of the respective members in the constituent types
|
||||
var abc;
|
||||
abc.a = "hello";
|
||||
abc.b = "hello";
|
||||
abc.c = "hello";
|
||||
var xyz;
|
||||
xyz.x.a = "hello";
|
||||
xyz.x.b = "hello";
|
||||
xyz.x.c = "hello";
|
||||
var f;
|
||||
var s = f("hello");
|
||||
var n = f(42);
|
||||
100
tests/baselines/reference/intersectionTypeMembers.symbols
Normal file
100
tests/baselines/reference/intersectionTypeMembers.symbols
Normal file
@@ -0,0 +1,100 @@
|
||||
=== tests/cases/conformance/types/intersection/intersectionTypeMembers.ts ===
|
||||
// An intersection type has those members that are present in any of its constituent types,
|
||||
// with types that are intersections of the respective members in the constituent types
|
||||
|
||||
interface A { a: string }
|
||||
>A : Symbol(A, Decl(intersectionTypeMembers.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(intersectionTypeMembers.ts, 3, 13))
|
||||
|
||||
interface B { b: string }
|
||||
>B : Symbol(B, Decl(intersectionTypeMembers.ts, 3, 25))
|
||||
>b : Symbol(b, Decl(intersectionTypeMembers.ts, 4, 13))
|
||||
|
||||
interface C { c: string }
|
||||
>C : Symbol(C, Decl(intersectionTypeMembers.ts, 4, 25))
|
||||
>c : Symbol(c, Decl(intersectionTypeMembers.ts, 5, 13))
|
||||
|
||||
var abc: A & B & C;
|
||||
>abc : Symbol(abc, Decl(intersectionTypeMembers.ts, 7, 3))
|
||||
>A : Symbol(A, Decl(intersectionTypeMembers.ts, 0, 0))
|
||||
>B : Symbol(B, Decl(intersectionTypeMembers.ts, 3, 25))
|
||||
>C : Symbol(C, Decl(intersectionTypeMembers.ts, 4, 25))
|
||||
|
||||
abc.a = "hello";
|
||||
>abc.a : Symbol(A.a, Decl(intersectionTypeMembers.ts, 3, 13))
|
||||
>abc : Symbol(abc, Decl(intersectionTypeMembers.ts, 7, 3))
|
||||
>a : Symbol(A.a, Decl(intersectionTypeMembers.ts, 3, 13))
|
||||
|
||||
abc.b = "hello";
|
||||
>abc.b : Symbol(B.b, Decl(intersectionTypeMembers.ts, 4, 13))
|
||||
>abc : Symbol(abc, Decl(intersectionTypeMembers.ts, 7, 3))
|
||||
>b : Symbol(B.b, Decl(intersectionTypeMembers.ts, 4, 13))
|
||||
|
||||
abc.c = "hello";
|
||||
>abc.c : Symbol(C.c, Decl(intersectionTypeMembers.ts, 5, 13))
|
||||
>abc : Symbol(abc, Decl(intersectionTypeMembers.ts, 7, 3))
|
||||
>c : Symbol(C.c, Decl(intersectionTypeMembers.ts, 5, 13))
|
||||
|
||||
interface X { x: A }
|
||||
>X : Symbol(X, Decl(intersectionTypeMembers.ts, 10, 16))
|
||||
>x : Symbol(x, Decl(intersectionTypeMembers.ts, 12, 13))
|
||||
>A : Symbol(A, Decl(intersectionTypeMembers.ts, 0, 0))
|
||||
|
||||
interface Y { x: B }
|
||||
>Y : Symbol(Y, Decl(intersectionTypeMembers.ts, 12, 20))
|
||||
>x : Symbol(x, Decl(intersectionTypeMembers.ts, 13, 13))
|
||||
>B : Symbol(B, Decl(intersectionTypeMembers.ts, 3, 25))
|
||||
|
||||
interface Z { x: C }
|
||||
>Z : Symbol(Z, Decl(intersectionTypeMembers.ts, 13, 20))
|
||||
>x : Symbol(x, Decl(intersectionTypeMembers.ts, 14, 13))
|
||||
>C : Symbol(C, Decl(intersectionTypeMembers.ts, 4, 25))
|
||||
|
||||
var xyz: X & Y & Z;
|
||||
>xyz : Symbol(xyz, Decl(intersectionTypeMembers.ts, 16, 3))
|
||||
>X : Symbol(X, Decl(intersectionTypeMembers.ts, 10, 16))
|
||||
>Y : Symbol(Y, Decl(intersectionTypeMembers.ts, 12, 20))
|
||||
>Z : Symbol(Z, Decl(intersectionTypeMembers.ts, 13, 20))
|
||||
|
||||
xyz.x.a = "hello";
|
||||
>xyz.x.a : Symbol(A.a, Decl(intersectionTypeMembers.ts, 3, 13))
|
||||
>xyz.x : Symbol(x, Decl(intersectionTypeMembers.ts, 12, 13), Decl(intersectionTypeMembers.ts, 13, 13), Decl(intersectionTypeMembers.ts, 14, 13))
|
||||
>xyz : Symbol(xyz, Decl(intersectionTypeMembers.ts, 16, 3))
|
||||
>x : Symbol(x, Decl(intersectionTypeMembers.ts, 12, 13), Decl(intersectionTypeMembers.ts, 13, 13), Decl(intersectionTypeMembers.ts, 14, 13))
|
||||
>a : Symbol(A.a, Decl(intersectionTypeMembers.ts, 3, 13))
|
||||
|
||||
xyz.x.b = "hello";
|
||||
>xyz.x.b : Symbol(B.b, Decl(intersectionTypeMembers.ts, 4, 13))
|
||||
>xyz.x : Symbol(x, Decl(intersectionTypeMembers.ts, 12, 13), Decl(intersectionTypeMembers.ts, 13, 13), Decl(intersectionTypeMembers.ts, 14, 13))
|
||||
>xyz : Symbol(xyz, Decl(intersectionTypeMembers.ts, 16, 3))
|
||||
>x : Symbol(x, Decl(intersectionTypeMembers.ts, 12, 13), Decl(intersectionTypeMembers.ts, 13, 13), Decl(intersectionTypeMembers.ts, 14, 13))
|
||||
>b : Symbol(B.b, Decl(intersectionTypeMembers.ts, 4, 13))
|
||||
|
||||
xyz.x.c = "hello";
|
||||
>xyz.x.c : Symbol(C.c, Decl(intersectionTypeMembers.ts, 5, 13))
|
||||
>xyz.x : Symbol(x, Decl(intersectionTypeMembers.ts, 12, 13), Decl(intersectionTypeMembers.ts, 13, 13), Decl(intersectionTypeMembers.ts, 14, 13))
|
||||
>xyz : Symbol(xyz, Decl(intersectionTypeMembers.ts, 16, 3))
|
||||
>x : Symbol(x, Decl(intersectionTypeMembers.ts, 12, 13), Decl(intersectionTypeMembers.ts, 13, 13), Decl(intersectionTypeMembers.ts, 14, 13))
|
||||
>c : Symbol(C.c, Decl(intersectionTypeMembers.ts, 5, 13))
|
||||
|
||||
type F1 = (x: string) => string;
|
||||
>F1 : Symbol(F1, Decl(intersectionTypeMembers.ts, 19, 18))
|
||||
>x : Symbol(x, Decl(intersectionTypeMembers.ts, 21, 11))
|
||||
|
||||
type F2 = (x: number) => number;
|
||||
>F2 : Symbol(F2, Decl(intersectionTypeMembers.ts, 21, 32))
|
||||
>x : Symbol(x, Decl(intersectionTypeMembers.ts, 22, 11))
|
||||
|
||||
var f: F1 & F2;
|
||||
>f : Symbol(f, Decl(intersectionTypeMembers.ts, 24, 3))
|
||||
>F1 : Symbol(F1, Decl(intersectionTypeMembers.ts, 19, 18))
|
||||
>F2 : Symbol(F2, Decl(intersectionTypeMembers.ts, 21, 32))
|
||||
|
||||
var s = f("hello");
|
||||
>s : Symbol(s, Decl(intersectionTypeMembers.ts, 25, 3))
|
||||
>f : Symbol(f, Decl(intersectionTypeMembers.ts, 24, 3))
|
||||
|
||||
var n = f(42);
|
||||
>n : Symbol(n, Decl(intersectionTypeMembers.ts, 26, 3))
|
||||
>f : Symbol(f, Decl(intersectionTypeMembers.ts, 24, 3))
|
||||
|
||||
116
tests/baselines/reference/intersectionTypeMembers.types
Normal file
116
tests/baselines/reference/intersectionTypeMembers.types
Normal file
@@ -0,0 +1,116 @@
|
||||
=== tests/cases/conformance/types/intersection/intersectionTypeMembers.ts ===
|
||||
// An intersection type has those members that are present in any of its constituent types,
|
||||
// with types that are intersections of the respective members in the constituent types
|
||||
|
||||
interface A { a: string }
|
||||
>A : A
|
||||
>a : string
|
||||
|
||||
interface B { b: string }
|
||||
>B : B
|
||||
>b : string
|
||||
|
||||
interface C { c: string }
|
||||
>C : C
|
||||
>c : string
|
||||
|
||||
var abc: A & B & C;
|
||||
>abc : A & B & C
|
||||
>A : A
|
||||
>B : B
|
||||
>C : C
|
||||
|
||||
abc.a = "hello";
|
||||
>abc.a = "hello" : string
|
||||
>abc.a : string
|
||||
>abc : A & B & C
|
||||
>a : string
|
||||
>"hello" : string
|
||||
|
||||
abc.b = "hello";
|
||||
>abc.b = "hello" : string
|
||||
>abc.b : string
|
||||
>abc : A & B & C
|
||||
>b : string
|
||||
>"hello" : string
|
||||
|
||||
abc.c = "hello";
|
||||
>abc.c = "hello" : string
|
||||
>abc.c : string
|
||||
>abc : A & B & C
|
||||
>c : string
|
||||
>"hello" : string
|
||||
|
||||
interface X { x: A }
|
||||
>X : X
|
||||
>x : A
|
||||
>A : A
|
||||
|
||||
interface Y { x: B }
|
||||
>Y : Y
|
||||
>x : B
|
||||
>B : B
|
||||
|
||||
interface Z { x: C }
|
||||
>Z : Z
|
||||
>x : C
|
||||
>C : C
|
||||
|
||||
var xyz: X & Y & Z;
|
||||
>xyz : X & Y & Z
|
||||
>X : X
|
||||
>Y : Y
|
||||
>Z : Z
|
||||
|
||||
xyz.x.a = "hello";
|
||||
>xyz.x.a = "hello" : string
|
||||
>xyz.x.a : string
|
||||
>xyz.x : A & B & C
|
||||
>xyz : X & Y & Z
|
||||
>x : A & B & C
|
||||
>a : string
|
||||
>"hello" : string
|
||||
|
||||
xyz.x.b = "hello";
|
||||
>xyz.x.b = "hello" : string
|
||||
>xyz.x.b : string
|
||||
>xyz.x : A & B & C
|
||||
>xyz : X & Y & Z
|
||||
>x : A & B & C
|
||||
>b : string
|
||||
>"hello" : string
|
||||
|
||||
xyz.x.c = "hello";
|
||||
>xyz.x.c = "hello" : string
|
||||
>xyz.x.c : string
|
||||
>xyz.x : A & B & C
|
||||
>xyz : X & Y & Z
|
||||
>x : A & B & C
|
||||
>c : string
|
||||
>"hello" : string
|
||||
|
||||
type F1 = (x: string) => string;
|
||||
>F1 : (x: string) => string
|
||||
>x : string
|
||||
|
||||
type F2 = (x: number) => number;
|
||||
>F2 : (x: number) => number
|
||||
>x : number
|
||||
|
||||
var f: F1 & F2;
|
||||
>f : ((x: string) => string) & ((x: number) => number)
|
||||
>F1 : (x: string) => string
|
||||
>F2 : (x: number) => number
|
||||
|
||||
var s = f("hello");
|
||||
>s : string
|
||||
>f("hello") : string
|
||||
>f : ((x: string) => string) & ((x: number) => number)
|
||||
>"hello" : string
|
||||
|
||||
var n = f(42);
|
||||
>n : number
|
||||
>f(42) : number
|
||||
>f : ((x: string) => string) & ((x: number) => number)
|
||||
>42 : number
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
tests/cases/conformance/types/intersection/recursiveIntersectionTypes.ts(19,1): error TS2322: Type 'Entity & { next: Entity & any; }' is not assignable to type 'Product & { next: Product & any; }'.
|
||||
Type 'Entity & { next: Entity & any; }' is not assignable to type 'Product'.
|
||||
Type '{ next: Entity & any; }' is not assignable to type 'Product'.
|
||||
Property 'price' is missing in type '{ next: Entity & any; }'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/intersection/recursiveIntersectionTypes.ts (1 errors) ====
|
||||
type LinkedList<T> = T & { next: LinkedList<T> };
|
||||
|
||||
interface Entity {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Product extends Entity {
|
||||
price: number;
|
||||
}
|
||||
|
||||
var entityList: LinkedList<Entity>;
|
||||
var s = entityList.name;
|
||||
var s = entityList.next.name;
|
||||
var s = entityList.next.next.name;
|
||||
var s = entityList.next.next.next.name;
|
||||
|
||||
var productList: LinkedList<Product>;
|
||||
entityList = productList;
|
||||
productList = entityList; // Error
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2322: Type 'Entity & { next: Entity & any; }' is not assignable to type 'Product & { next: Product & any; }'.
|
||||
!!! error TS2322: Type 'Entity & { next: Entity & any; }' is not assignable to type 'Product'.
|
||||
!!! error TS2322: Type '{ next: Entity & any; }' is not assignable to type 'Product'.
|
||||
!!! error TS2322: Property 'price' is missing in type '{ next: Entity & any; }'.
|
||||
|
||||
31
tests/baselines/reference/recursiveIntersectionTypes.js
Normal file
31
tests/baselines/reference/recursiveIntersectionTypes.js
Normal file
@@ -0,0 +1,31 @@
|
||||
//// [recursiveIntersectionTypes.ts]
|
||||
type LinkedList<T> = T & { next: LinkedList<T> };
|
||||
|
||||
interface Entity {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Product extends Entity {
|
||||
price: number;
|
||||
}
|
||||
|
||||
var entityList: LinkedList<Entity>;
|
||||
var s = entityList.name;
|
||||
var s = entityList.next.name;
|
||||
var s = entityList.next.next.name;
|
||||
var s = entityList.next.next.next.name;
|
||||
|
||||
var productList: LinkedList<Product>;
|
||||
entityList = productList;
|
||||
productList = entityList; // Error
|
||||
|
||||
|
||||
//// [recursiveIntersectionTypes.js]
|
||||
var entityList;
|
||||
var s = entityList.name;
|
||||
var s = entityList.next.name;
|
||||
var s = entityList.next.next.name;
|
||||
var s = entityList.next.next.next.name;
|
||||
var productList;
|
||||
entityList = productList;
|
||||
productList = entityList; // Error
|
||||
@@ -0,0 +1,38 @@
|
||||
interface A { a: string }
|
||||
interface B { b: string }
|
||||
interface C { c: string }
|
||||
interface D { d: string }
|
||||
|
||||
var a: A;
|
||||
var b: B;
|
||||
var c: C;
|
||||
var d: D;
|
||||
var anb: A & B;
|
||||
var aob: A | B;
|
||||
var cnd: C & D;
|
||||
var cod: C | D;
|
||||
var x: A & B | C & D;
|
||||
var y: (A | B) & (C | D);
|
||||
|
||||
a = anb; // Ok
|
||||
b = anb; // Ok
|
||||
anb = a;
|
||||
anb = b;
|
||||
|
||||
x = anb; // Ok
|
||||
x = aob;
|
||||
x = cnd; // Ok
|
||||
x = cod;
|
||||
anb = x;
|
||||
aob = x;
|
||||
cnd = x;
|
||||
cod = x;
|
||||
|
||||
y = anb;
|
||||
y = aob;
|
||||
y = cnd;
|
||||
y = cod;
|
||||
anb = y;
|
||||
aob = y; // Ok
|
||||
cnd = y;
|
||||
cod = y; // Ok
|
||||
@@ -0,0 +1,16 @@
|
||||
interface A { a: string }
|
||||
interface B { b: string }
|
||||
interface C { c: string }
|
||||
|
||||
// A & B is equivalent to B & A.
|
||||
var y: A & B;
|
||||
var y : B & A;
|
||||
|
||||
// AB & C is equivalent to A & BC, where AB is A & B and BC is B & C.
|
||||
var z : A & B & C;
|
||||
var z : (A & B) & C;
|
||||
var z : A & (B & C);
|
||||
var ab : A & B;
|
||||
var bc : B & C;
|
||||
var z1: typeof ab & C;
|
||||
var z1: A & typeof bc;
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
function extend<T, U>(obj1: T, obj2: U): T & U {
|
||||
var result: T & U;
|
||||
obj1 = result;
|
||||
obj2 = result;
|
||||
result = obj1; // Error
|
||||
result = obj2; // Error
|
||||
return result;
|
||||
}
|
||||
|
||||
var x = extend({ a: "hello" }, { b: 42 });
|
||||
var s = x.a;
|
||||
var n = x.b;
|
||||
@@ -0,0 +1,27 @@
|
||||
// An intersection type has those members that are present in any of its constituent types,
|
||||
// with types that are intersections of the respective members in the constituent types
|
||||
|
||||
interface A { a: string }
|
||||
interface B { b: string }
|
||||
interface C { c: string }
|
||||
|
||||
var abc: A & B & C;
|
||||
abc.a = "hello";
|
||||
abc.b = "hello";
|
||||
abc.c = "hello";
|
||||
|
||||
interface X { x: A }
|
||||
interface Y { x: B }
|
||||
interface Z { x: C }
|
||||
|
||||
var xyz: X & Y & Z;
|
||||
xyz.x.a = "hello";
|
||||
xyz.x.b = "hello";
|
||||
xyz.x.c = "hello";
|
||||
|
||||
type F1 = (x: string) => string;
|
||||
type F2 = (x: number) => number;
|
||||
|
||||
var f: F1 & F2;
|
||||
var s = f("hello");
|
||||
var n = f(42);
|
||||
@@ -0,0 +1,19 @@
|
||||
type LinkedList<T> = T & { next: LinkedList<T> };
|
||||
|
||||
interface Entity {
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface Product extends Entity {
|
||||
price: number;
|
||||
}
|
||||
|
||||
var entityList: LinkedList<Entity>;
|
||||
var s = entityList.name;
|
||||
var s = entityList.next.name;
|
||||
var s = entityList.next.next.name;
|
||||
var s = entityList.next.next.next.name;
|
||||
|
||||
var productList: LinkedList<Product>;
|
||||
entityList = productList;
|
||||
productList = entityList; // Error
|
||||
Reference in New Issue
Block a user