Skip to content

Commit 5bd73f5

Browse files
committed
Add regrssion test
1 parent d2364f5 commit 5bd73f5

File tree

5 files changed

+149
-1
lines changed

5 files changed

+149
-1
lines changed

tests/baselines/reference/typeAliasesForObjectTypes.errors.txt

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(10,6): error TS2300: Duplicate identifier 'T2'.
22
tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(11,6): error TS2300: Duplicate identifier 'T2'.
3+
tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(26,3): error TS2339: Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
4+
tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(27,3): error TS2339: Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'.
35

46

5-
==== tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts (2 errors) ====
7+
==== tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts (4 errors) ====
68
type T1 = { x: string }
79

810
// An interface can be named in an extends or implements clause, but a type alias for an object type literal cannot.
@@ -21,4 +23,21 @@ tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts(11,6): er
2123

2224
// An interface can have type parameters, but a type alias for an object type literal cannot.
2325
type T3<T> = { x: T }
26+
27+
28+
// Repro from #29991
29+
30+
const a: Required<{ a?: 1; x: 1 }> = { a: 1, x: 1 };
31+
const b: Required<{ b?: 1; x: 1 }> = { b: 1, x: 1 };
32+
export let A = a;
33+
export let B = b;
34+
A = b; // No Error
35+
B = a; // No Error
36+
37+
a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
38+
~
39+
!!! error TS2339: Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
40+
b.a; // Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'.
41+
~
42+
!!! error TS2339: Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'.
2443

tests/baselines/reference/typeAliasesForObjectTypes.js

+24
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,35 @@ type T2 = { y: number }
1313

1414
// An interface can have type parameters, but a type alias for an object type literal cannot.
1515
type T3<T> = { x: T }
16+
17+
18+
// Repro from #29991
19+
20+
const a: Required<{ a?: 1; x: 1 }> = { a: 1, x: 1 };
21+
const b: Required<{ b?: 1; x: 1 }> = { b: 1, x: 1 };
22+
export let A = a;
23+
export let B = b;
24+
A = b; // No Error
25+
B = a; // No Error
26+
27+
a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
28+
b.a; // Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'.
1629

1730

1831
//// [typeAliasesForObjectTypes.js]
32+
"use strict";
33+
exports.__esModule = true;
1934
var C1 = /** @class */ (function () {
2035
function C1() {
2136
}
2237
return C1;
2338
}());
39+
// Repro from #29991
40+
var a = { a: 1, x: 1 };
41+
var b = { b: 1, x: 1 };
42+
exports.A = a;
43+
exports.B = b;
44+
exports.A = b; // No Error
45+
exports.B = a; // No Error
46+
a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
47+
b.a; // Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'.

tests/baselines/reference/typeAliasesForObjectTypes.symbols

+41
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,44 @@ type T3<T> = { x: T }
3333
>x : Symbol(x, Decl(typeAliasesForObjectTypes.ts, 13, 14))
3434
>T : Symbol(T, Decl(typeAliasesForObjectTypes.ts, 13, 8))
3535

36+
37+
// Repro from #29991
38+
39+
const a: Required<{ a?: 1; x: 1 }> = { a: 1, x: 1 };
40+
>a : Symbol(a, Decl(typeAliasesForObjectTypes.ts, 18, 5))
41+
>Required : Symbol(Required, Decl(lib.es5.d.ts, --, --))
42+
>a : Symbol(a, Decl(typeAliasesForObjectTypes.ts, 18, 19))
43+
>x : Symbol(x, Decl(typeAliasesForObjectTypes.ts, 18, 26))
44+
>a : Symbol(a, Decl(typeAliasesForObjectTypes.ts, 18, 38))
45+
>x : Symbol(x, Decl(typeAliasesForObjectTypes.ts, 18, 44))
46+
47+
const b: Required<{ b?: 1; x: 1 }> = { b: 1, x: 1 };
48+
>b : Symbol(b, Decl(typeAliasesForObjectTypes.ts, 19, 5))
49+
>Required : Symbol(Required, Decl(lib.es5.d.ts, --, --))
50+
>b : Symbol(b, Decl(typeAliasesForObjectTypes.ts, 19, 19))
51+
>x : Symbol(x, Decl(typeAliasesForObjectTypes.ts, 19, 26))
52+
>b : Symbol(b, Decl(typeAliasesForObjectTypes.ts, 19, 38))
53+
>x : Symbol(x, Decl(typeAliasesForObjectTypes.ts, 19, 44))
54+
55+
export let A = a;
56+
>A : Symbol(A, Decl(typeAliasesForObjectTypes.ts, 20, 10))
57+
>a : Symbol(a, Decl(typeAliasesForObjectTypes.ts, 18, 5))
58+
59+
export let B = b;
60+
>B : Symbol(B, Decl(typeAliasesForObjectTypes.ts, 21, 10))
61+
>b : Symbol(b, Decl(typeAliasesForObjectTypes.ts, 19, 5))
62+
63+
A = b; // No Error
64+
>A : Symbol(A, Decl(typeAliasesForObjectTypes.ts, 20, 10))
65+
>b : Symbol(b, Decl(typeAliasesForObjectTypes.ts, 19, 5))
66+
67+
B = a; // No Error
68+
>B : Symbol(B, Decl(typeAliasesForObjectTypes.ts, 21, 10))
69+
>a : Symbol(a, Decl(typeAliasesForObjectTypes.ts, 18, 5))
70+
71+
a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
72+
>a : Symbol(a, Decl(typeAliasesForObjectTypes.ts, 18, 5))
73+
74+
b.a; // Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'.
75+
>b : Symbol(b, Decl(typeAliasesForObjectTypes.ts, 19, 5))
76+

tests/baselines/reference/typeAliasesForObjectTypes.types

+51
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,54 @@ type T3<T> = { x: T }
2828
>T3 : T3<T>
2929
>x : T
3030

31+
32+
// Repro from #29991
33+
34+
const a: Required<{ a?: 1; x: 1 }> = { a: 1, x: 1 };
35+
>a : Required<{ a?: 1; x: 1; }>
36+
>a : 1
37+
>x : 1
38+
>{ a: 1, x: 1 } : { a: 1; x: 1; }
39+
>a : 1
40+
>1 : 1
41+
>x : 1
42+
>1 : 1
43+
44+
const b: Required<{ b?: 1; x: 1 }> = { b: 1, x: 1 };
45+
>b : Required<{ b?: 1; x: 1; }>
46+
>b : 1
47+
>x : 1
48+
>{ b: 1, x: 1 } : { b: 1; x: 1; }
49+
>b : 1
50+
>1 : 1
51+
>x : 1
52+
>1 : 1
53+
54+
export let A = a;
55+
>A : Required<{ a?: 1; x: 1; }>
56+
>a : Required<{ a?: 1; x: 1; }>
57+
58+
export let B = b;
59+
>B : Required<{ b?: 1; x: 1; }>
60+
>b : Required<{ b?: 1; x: 1; }>
61+
62+
A = b; // No Error
63+
>A = b : Required<{ b?: 1; x: 1; }>
64+
>A : Required<{ a?: 1; x: 1; }>
65+
>b : Required<{ b?: 1; x: 1; }>
66+
67+
B = a; // No Error
68+
>B = a : Required<{ a?: 1; x: 1; }>
69+
>B : Required<{ b?: 1; x: 1; }>
70+
>a : Required<{ a?: 1; x: 1; }>
71+
72+
a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
73+
>a.b : any
74+
>a : Required<{ a?: 1; x: 1; }>
75+
>b : any
76+
77+
b.a; // Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'.
78+
>b.a : any
79+
>b : Required<{ b?: 1; x: 1; }>
80+
>a : any
81+

tests/cases/conformance/types/typeAliases/typeAliasesForObjectTypes.ts

+13
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,16 @@ type T2 = { y: number }
1212

1313
// An interface can have type parameters, but a type alias for an object type literal cannot.
1414
type T3<T> = { x: T }
15+
16+
17+
// Repro from #29991
18+
19+
const a: Required<{ a?: 1; x: 1 }> = { a: 1, x: 1 };
20+
const b: Required<{ b?: 1; x: 1 }> = { b: 1, x: 1 };
21+
export let A = a;
22+
export let B = b;
23+
A = b; // No Error
24+
B = a; // No Error
25+
26+
a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
27+
b.a; // Property 'a' does not exist on type 'Required<{ b?: 1; x: 1; }>'.

0 commit comments

Comments
 (0)