Adding a few more tests

This commit is contained in:
Anders Hejlsberg 2015-06-25 18:45:03 -07:00
parent 529fcfd4c9
commit c623e6cc64
7 changed files with 166 additions and 0 deletions

View File

@ -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; }
};

View File

@ -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))
};

View File

@ -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
};

View File

@ -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;

View File

@ -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;

View File

@ -0,0 +1,5 @@
var x: { a: (s: string) => string } & { b: (n: number) => number };
x = {
a: s => s,
b: n => n
};

View File

@ -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;