diff --git a/tests/baselines/reference/contextualIntersectionType.js b/tests/baselines/reference/contextualIntersectionType.js new file mode 100644 index 00000000000..d61fc52fce7 --- /dev/null +++ b/tests/baselines/reference/contextualIntersectionType.js @@ -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; } +}; diff --git a/tests/baselines/reference/contextualIntersectionType.symbols b/tests/baselines/reference/contextualIntersectionType.symbols new file mode 100644 index 00000000000..cb7ac9f3d41 --- /dev/null +++ b/tests/baselines/reference/contextualIntersectionType.symbols @@ -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)) + +}; + diff --git a/tests/baselines/reference/contextualIntersectionType.types b/tests/baselines/reference/contextualIntersectionType.types new file mode 100644 index 00000000000..4967979d736 --- /dev/null +++ b/tests/baselines/reference/contextualIntersectionType.types @@ -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 + +}; + diff --git a/tests/baselines/reference/intersectionTypeAssignment.errors.txt b/tests/baselines/reference/intersectionTypeAssignment.errors.txt new file mode 100644 index 00000000000..11ea91d8f0e --- /dev/null +++ b/tests/baselines/reference/intersectionTypeAssignment.errors.txt @@ -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; + \ No newline at end of file diff --git a/tests/baselines/reference/intersectionTypeAssignment.js b/tests/baselines/reference/intersectionTypeAssignment.js new file mode 100644 index 00000000000..f1cddbf3b2a --- /dev/null +++ b/tests/baselines/reference/intersectionTypeAssignment.js @@ -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; diff --git a/tests/cases/conformance/types/intersection/contextualIntersectionType.ts b/tests/cases/conformance/types/intersection/contextualIntersectionType.ts new file mode 100644 index 00000000000..580827992ac --- /dev/null +++ b/tests/cases/conformance/types/intersection/contextualIntersectionType.ts @@ -0,0 +1,5 @@ +var x: { a: (s: string) => string } & { b: (n: number) => number }; +x = { + a: s => s, + b: n => n +}; diff --git a/tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts b/tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts new file mode 100644 index 00000000000..00a299ea244 --- /dev/null +++ b/tests/cases/conformance/types/intersection/intersectionTypeAssignment.ts @@ -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;