Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intersection types #3622

Merged
merged 14 commits into from
Jul 6, 2015
Merged
Prev Previous commit
Next Next commit
Adding a few more tests
  • Loading branch information
ahejlsberg committed Jun 26, 2015
commit c623e6cc642d37c355423ad3365bb67494bedb42
14 changes: 14 additions & 0 deletions tests/baselines/reference/contextualIntersectionType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//// [contextualIntersectionType.ts]
var x: { a: (s: string) => string } & { b: (n: number) => number };
x = {
a: s => s,
b: n => n
};


//// [contextualIntersectionType.js]
var x;
x = {
a: function (s) { return s; },
b: function (n) { return n; }
};
23 changes: 23 additions & 0 deletions tests/baselines/reference/contextualIntersectionType.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
=== tests/cases/conformance/types/intersection/contextualIntersectionType.ts ===
var x: { a: (s: string) => string } & { b: (n: number) => number };
>x : Symbol(x, Decl(contextualIntersectionType.ts, 0, 3))
>a : Symbol(a, Decl(contextualIntersectionType.ts, 0, 8))
>s : Symbol(s, Decl(contextualIntersectionType.ts, 0, 13))
>b : Symbol(b, Decl(contextualIntersectionType.ts, 0, 39))
>n : Symbol(n, Decl(contextualIntersectionType.ts, 0, 44))

x = {
>x : Symbol(x, Decl(contextualIntersectionType.ts, 0, 3))

a: s => s,
>a : Symbol(a, Decl(contextualIntersectionType.ts, 1, 5))
>s : Symbol(s, Decl(contextualIntersectionType.ts, 2, 6))
>s : Symbol(s, Decl(contextualIntersectionType.ts, 2, 6))

b: n => n
>b : Symbol(b, Decl(contextualIntersectionType.ts, 2, 14))
>n : Symbol(n, Decl(contextualIntersectionType.ts, 3, 6))
>n : Symbol(n, Decl(contextualIntersectionType.ts, 3, 6))

};

27 changes: 27 additions & 0 deletions tests/baselines/reference/contextualIntersectionType.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
=== tests/cases/conformance/types/intersection/contextualIntersectionType.ts ===
var x: { a: (s: string) => string } & { b: (n: number) => number };
>x : { a: (s: string) => string; } & { b: (n: number) => number; }
>a : (s: string) => string
>s : string
>b : (n: number) => number
>n : number

x = {
>x = { a: s => s, b: n => n} : { a: (s: string) => string; b: (n: number) => number; }
>x : { a: (s: string) => string; } & { b: (n: number) => number; }
>{ a: s => s, b: n => n} : { a: (s: string) => string; b: (n: number) => number; }

a: s => s,
>a : (s: string) => string
>s => s : (s: string) => string
>s : string
>s : string

b: n => n
>b : (n: number) => number
>n => n : (n: number) => number
>n : number
>n : number

};

45 changes: 45 additions & 0 deletions tests/baselines/reference/intersectionTypeAssignment.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts(8,1): error TS2322: Type '{ a: string; }' is not assignable to type '{ a: string; b: string; }'.
Property 'b' is missing in type '{ a: string; }'.
tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts(9,1): error TS2322: Type '{ a: string; }' is not assignable to type '{ a: string; } & { b: string; }'.
Type '{ a: string; }' is not assignable to type '{ b: string; }'.
Property 'b' is missing in type '{ a: string; }'.
tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts(13,1): error TS2322: Type '{ b: string; }' is not assignable to type '{ a: string; b: string; }'.
Property 'a' is missing in type '{ b: string; }'.
tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts(14,1): error TS2322: Type '{ b: string; }' is not assignable to type '{ a: string; } & { b: string; }'.
Type '{ b: string; }' is not assignable to type '{ a: string; }'.
Property 'a' is missing in type '{ b: string; }'.


==== tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts (4 errors) ====
var a: { a: string };
var b: { b: string };
var x: { a: string, b: string };
var y: { a: string } & { b: string };

a = x;
a = y;
x = a; // Error
~
!!! error TS2322: Type '{ a: string; }' is not assignable to type '{ a: string; b: string; }'.
!!! error TS2322: Property 'b' is missing in type '{ a: string; }'.
y = a; // Error
~
!!! error TS2322: Type '{ a: string; }' is not assignable to type '{ a: string; } & { b: string; }'.
!!! error TS2322: Type '{ a: string; }' is not assignable to type '{ b: string; }'.
!!! error TS2322: Property 'b' is missing in type '{ a: string; }'.

b = x;
b = y;
x = b; // Error
~
!!! error TS2322: Type '{ b: string; }' is not assignable to type '{ a: string; b: string; }'.
!!! error TS2322: Property 'a' is missing in type '{ b: string; }'.
y = b; // Error
~
!!! error TS2322: Type '{ b: string; }' is not assignable to type '{ a: string; } & { b: string; }'.
!!! error TS2322: Type '{ b: string; }' is not assignable to type '{ a: string; }'.
!!! error TS2322: Property 'a' is missing in type '{ b: string; }'.

x = y;
y = x;

35 changes: 35 additions & 0 deletions tests/baselines/reference/intersectionTypeAssignment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//// [intersectionTypeAssignment.ts]
var a: { a: string };
var b: { b: string };
var x: { a: string, b: string };
var y: { a: string } & { b: string };

a = x;
a = y;
x = a; // Error
y = a; // Error

b = x;
b = y;
x = b; // Error
y = b; // Error

x = y;
y = x;


//// [intersectionTypeAssignment.js]
var a;
var b;
var x;
var y;
a = x;
a = y;
x = a; // Error
y = a; // Error
b = x;
b = y;
x = b; // Error
y = b; // Error
x = y;
y = x;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var x: { a: (s: string) => string } & { b: (n: number) => number };
x = {
a: s => s,
b: n => n
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var a: { a: string };
var b: { b: string };
var x: { a: string, b: string };
var y: { a: string } & { b: string };

a = x;
a = y;
x = a; // Error
y = a; // Error

b = x;
b = y;
x = b; // Error
y = b; // Error

x = y;
y = x;