diff --git a/tests/baselines/reference/nonPrimitiveAndTypeVariables.errors.txt b/tests/baselines/reference/nonPrimitiveAndTypeVariables.errors.txt new file mode 100644 index 00000000000..27bd17410ac --- /dev/null +++ b/tests/baselines/reference/nonPrimitiveAndTypeVariables.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/types/nonPrimitive/nonPrimitiveAndTypeVariables.ts(10,9): error TS2322: Type 'T' is not assignable to type 'object'. +tests/cases/conformance/types/nonPrimitive/nonPrimitiveAndTypeVariables.ts(11,9): error TS2322: Type 'T' is not assignable to type 'object | U'. + Type 'T' is not assignable to type 'U'. + + +==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveAndTypeVariables.ts (2 errors) ==== + // Repros from #23800 + + type A = { [P in keyof T]: T[P] extends V ? 1 : 0; }; + type B = { [P in keyof T]: T[P] extends V | object ? 1 : 0; }; + + type a = A<{ a: 0 | 1 }, 0>; // { a: 0; } + type b = B<{ a: 0 | 1 }, 0>; // { a: 0; } + + function foo(x: T) { + let a: object = x; // Error + ~ +!!! error TS2322: Type 'T' is not assignable to type 'object'. + let b: U | object = x; // Error + ~ +!!! error TS2322: Type 'T' is not assignable to type 'object | U'. +!!! error TS2322: Type 'T' is not assignable to type 'U'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/nonPrimitiveAndTypeVariables.js b/tests/baselines/reference/nonPrimitiveAndTypeVariables.js new file mode 100644 index 00000000000..6260624706c --- /dev/null +++ b/tests/baselines/reference/nonPrimitiveAndTypeVariables.js @@ -0,0 +1,22 @@ +//// [nonPrimitiveAndTypeVariables.ts] +// Repros from #23800 + +type A = { [P in keyof T]: T[P] extends V ? 1 : 0; }; +type B = { [P in keyof T]: T[P] extends V | object ? 1 : 0; }; + +type a = A<{ a: 0 | 1 }, 0>; // { a: 0; } +type b = B<{ a: 0 | 1 }, 0>; // { a: 0; } + +function foo(x: T) { + let a: object = x; // Error + let b: U | object = x; // Error +} + + +//// [nonPrimitiveAndTypeVariables.js] +"use strict"; +// Repros from #23800 +function foo(x) { + var a = x; // Error + var b = x; // Error +} diff --git a/tests/baselines/reference/nonPrimitiveAndTypeVariables.symbols b/tests/baselines/reference/nonPrimitiveAndTypeVariables.symbols new file mode 100644 index 00000000000..791e47c2663 --- /dev/null +++ b/tests/baselines/reference/nonPrimitiveAndTypeVariables.symbols @@ -0,0 +1,50 @@ +=== tests/cases/conformance/types/nonPrimitive/nonPrimitiveAndTypeVariables.ts === +// Repros from #23800 + +type A = { [P in keyof T]: T[P] extends V ? 1 : 0; }; +>A : Symbol(A, Decl(nonPrimitiveAndTypeVariables.ts, 0, 0)) +>T : Symbol(T, Decl(nonPrimitiveAndTypeVariables.ts, 2, 7)) +>V : Symbol(V, Decl(nonPrimitiveAndTypeVariables.ts, 2, 9)) +>P : Symbol(P, Decl(nonPrimitiveAndTypeVariables.ts, 2, 18)) +>T : Symbol(T, Decl(nonPrimitiveAndTypeVariables.ts, 2, 7)) +>T : Symbol(T, Decl(nonPrimitiveAndTypeVariables.ts, 2, 7)) +>P : Symbol(P, Decl(nonPrimitiveAndTypeVariables.ts, 2, 18)) +>V : Symbol(V, Decl(nonPrimitiveAndTypeVariables.ts, 2, 9)) + +type B = { [P in keyof T]: T[P] extends V | object ? 1 : 0; }; +>B : Symbol(B, Decl(nonPrimitiveAndTypeVariables.ts, 2, 59)) +>T : Symbol(T, Decl(nonPrimitiveAndTypeVariables.ts, 3, 7)) +>V : Symbol(V, Decl(nonPrimitiveAndTypeVariables.ts, 3, 9)) +>P : Symbol(P, Decl(nonPrimitiveAndTypeVariables.ts, 3, 18)) +>T : Symbol(T, Decl(nonPrimitiveAndTypeVariables.ts, 3, 7)) +>T : Symbol(T, Decl(nonPrimitiveAndTypeVariables.ts, 3, 7)) +>P : Symbol(P, Decl(nonPrimitiveAndTypeVariables.ts, 3, 18)) +>V : Symbol(V, Decl(nonPrimitiveAndTypeVariables.ts, 3, 9)) + +type a = A<{ a: 0 | 1 }, 0>; // { a: 0; } +>a : Symbol(a, Decl(nonPrimitiveAndTypeVariables.ts, 3, 68)) +>A : Symbol(A, Decl(nonPrimitiveAndTypeVariables.ts, 0, 0)) +>a : Symbol(a, Decl(nonPrimitiveAndTypeVariables.ts, 5, 12)) + +type b = B<{ a: 0 | 1 }, 0>; // { a: 0; } +>b : Symbol(b, Decl(nonPrimitiveAndTypeVariables.ts, 5, 28)) +>B : Symbol(B, Decl(nonPrimitiveAndTypeVariables.ts, 2, 59)) +>a : Symbol(a, Decl(nonPrimitiveAndTypeVariables.ts, 6, 12)) + +function foo(x: T) { +>foo : Symbol(foo, Decl(nonPrimitiveAndTypeVariables.ts, 6, 28)) +>T : Symbol(T, Decl(nonPrimitiveAndTypeVariables.ts, 8, 13)) +>U : Symbol(U, Decl(nonPrimitiveAndTypeVariables.ts, 8, 15)) +>x : Symbol(x, Decl(nonPrimitiveAndTypeVariables.ts, 8, 19)) +>T : Symbol(T, Decl(nonPrimitiveAndTypeVariables.ts, 8, 13)) + + let a: object = x; // Error +>a : Symbol(a, Decl(nonPrimitiveAndTypeVariables.ts, 9, 7)) +>x : Symbol(x, Decl(nonPrimitiveAndTypeVariables.ts, 8, 19)) + + let b: U | object = x; // Error +>b : Symbol(b, Decl(nonPrimitiveAndTypeVariables.ts, 10, 7)) +>U : Symbol(U, Decl(nonPrimitiveAndTypeVariables.ts, 8, 15)) +>x : Symbol(x, Decl(nonPrimitiveAndTypeVariables.ts, 8, 19)) +} + diff --git a/tests/baselines/reference/nonPrimitiveAndTypeVariables.types b/tests/baselines/reference/nonPrimitiveAndTypeVariables.types new file mode 100644 index 00000000000..76755f5a9a1 --- /dev/null +++ b/tests/baselines/reference/nonPrimitiveAndTypeVariables.types @@ -0,0 +1,50 @@ +=== tests/cases/conformance/types/nonPrimitive/nonPrimitiveAndTypeVariables.ts === +// Repros from #23800 + +type A = { [P in keyof T]: T[P] extends V ? 1 : 0; }; +>A : A +>T : T +>V : V +>P : P +>T : T +>T : T +>P : P +>V : V + +type B = { [P in keyof T]: T[P] extends V | object ? 1 : 0; }; +>B : B +>T : T +>V : V +>P : P +>T : T +>T : T +>P : P +>V : V + +type a = A<{ a: 0 | 1 }, 0>; // { a: 0; } +>a : A<{ a: 0 | 1; }, 0> +>A : A +>a : 0 | 1 + +type b = B<{ a: 0 | 1 }, 0>; // { a: 0; } +>b : B<{ a: 0 | 1; }, 0> +>B : B +>a : 0 | 1 + +function foo(x: T) { +>foo : (x: T) => void +>T : T +>U : U +>x : T +>T : T + + let a: object = x; // Error +>a : object +>x : T + + let b: U | object = x; // Error +>b : object | U +>U : U +>x : T +} +