Skip to content

Commit 3b1db10

Browse files
authored
Fixed an issue with write type being left as non-instantiated when coming from a merged instantiation (#56322)
1 parent 424b964 commit 3b1db10

File tree

4 files changed

+182
-0
lines changed

4 files changed

+182
-0
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14629,6 +14629,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1462914629
clone.parent = singleProp.valueDeclaration?.symbol?.parent;
1463014630
clone.links.containingType = containingType;
1463114631
clone.links.mapper = links?.mapper;
14632+
clone.links.writeType = getWriteTypeOfSymbol(singleProp);
1463214633
return clone;
1463314634
}
1463414635
else {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//// [tests/cases/compiler/mergedInstantiationAssignment.ts] ////
2+
3+
=== mergedInstantiationAssignment.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/56320
5+
6+
class GenericObject<T = number> {
7+
>GenericObject : Symbol(GenericObject, Decl(mergedInstantiationAssignment.ts, 0, 0))
8+
>T : Symbol(T, Decl(mergedInstantiationAssignment.ts, 2, 20))
9+
10+
set x(x: T) {}
11+
>x : Symbol(GenericObject.x, Decl(mergedInstantiationAssignment.ts, 2, 33))
12+
>x : Symbol(x, Decl(mergedInstantiationAssignment.ts, 3, 8))
13+
>T : Symbol(T, Decl(mergedInstantiationAssignment.ts, 2, 20))
14+
}
15+
16+
const v1 = new GenericObject() as GenericObject &
17+
>v1 : Symbol(v1, Decl(mergedInstantiationAssignment.ts, 6, 5))
18+
>GenericObject : Symbol(GenericObject, Decl(mergedInstantiationAssignment.ts, 0, 0))
19+
>GenericObject : Symbol(GenericObject, Decl(mergedInstantiationAssignment.ts, 0, 0))
20+
21+
({ a?: string } | { b?: number });
22+
>a : Symbol(a, Decl(mergedInstantiationAssignment.ts, 7, 4))
23+
>b : Symbol(b, Decl(mergedInstantiationAssignment.ts, 7, 21))
24+
25+
v1.x = 432;
26+
>v1.x : Symbol(GenericObject.x, Decl(mergedInstantiationAssignment.ts, 2, 33))
27+
>v1 : Symbol(v1, Decl(mergedInstantiationAssignment.ts, 6, 5))
28+
>x : Symbol(GenericObject.x, Decl(mergedInstantiationAssignment.ts, 2, 33))
29+
30+
class GenericObjectWithoutSetter<T = number> {
31+
>GenericObjectWithoutSetter : Symbol(GenericObjectWithoutSetter, Decl(mergedInstantiationAssignment.ts, 8, 11))
32+
>T : Symbol(T, Decl(mergedInstantiationAssignment.ts, 10, 33))
33+
34+
declare x: T;
35+
>x : Symbol(GenericObjectWithoutSetter.x, Decl(mergedInstantiationAssignment.ts, 10, 46))
36+
>T : Symbol(T, Decl(mergedInstantiationAssignment.ts, 10, 33))
37+
}
38+
39+
const v2 = new GenericObjectWithoutSetter() as GenericObjectWithoutSetter &
40+
>v2 : Symbol(v2, Decl(mergedInstantiationAssignment.ts, 14, 5))
41+
>GenericObjectWithoutSetter : Symbol(GenericObjectWithoutSetter, Decl(mergedInstantiationAssignment.ts, 8, 11))
42+
>GenericObjectWithoutSetter : Symbol(GenericObjectWithoutSetter, Decl(mergedInstantiationAssignment.ts, 8, 11))
43+
44+
({ a?: string } | { b?: number });
45+
>a : Symbol(a, Decl(mergedInstantiationAssignment.ts, 15, 4))
46+
>b : Symbol(b, Decl(mergedInstantiationAssignment.ts, 15, 21))
47+
48+
v2.x = 42;
49+
>v2.x : Symbol(GenericObjectWithoutSetter.x, Decl(mergedInstantiationAssignment.ts, 10, 46))
50+
>v2 : Symbol(v2, Decl(mergedInstantiationAssignment.ts, 14, 5))
51+
>x : Symbol(GenericObjectWithoutSetter.x, Decl(mergedInstantiationAssignment.ts, 10, 46))
52+
53+
class NormalObject {
54+
>NormalObject : Symbol(NormalObject, Decl(mergedInstantiationAssignment.ts, 16, 10))
55+
56+
set x(x: number) {}
57+
>x : Symbol(NormalObject.x, Decl(mergedInstantiationAssignment.ts, 18, 20))
58+
>x : Symbol(x, Decl(mergedInstantiationAssignment.ts, 19, 8))
59+
}
60+
61+
const v3 = new NormalObject() as NormalObject &
62+
>v3 : Symbol(v3, Decl(mergedInstantiationAssignment.ts, 22, 5))
63+
>NormalObject : Symbol(NormalObject, Decl(mergedInstantiationAssignment.ts, 16, 10))
64+
>NormalObject : Symbol(NormalObject, Decl(mergedInstantiationAssignment.ts, 16, 10))
65+
66+
({ a?: string } | { b?: number });
67+
>a : Symbol(a, Decl(mergedInstantiationAssignment.ts, 23, 4))
68+
>b : Symbol(b, Decl(mergedInstantiationAssignment.ts, 23, 21))
69+
70+
v3.x = 42;
71+
>v3.x : Symbol(NormalObject.x, Decl(mergedInstantiationAssignment.ts, 18, 20))
72+
>v3 : Symbol(v3, Decl(mergedInstantiationAssignment.ts, 22, 5))
73+
>x : Symbol(NormalObject.x, Decl(mergedInstantiationAssignment.ts, 18, 20))
74+
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//// [tests/cases/compiler/mergedInstantiationAssignment.ts] ////
2+
3+
=== mergedInstantiationAssignment.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/56320
5+
6+
class GenericObject<T = number> {
7+
>GenericObject : GenericObject<T>
8+
9+
set x(x: T) {}
10+
>x : T
11+
>x : T
12+
}
13+
14+
const v1 = new GenericObject() as GenericObject &
15+
>v1 : GenericObject<number> & ({ a?: string | undefined; } | { b?: number | undefined; })
16+
>new GenericObject() as GenericObject & ({ a?: string } | { b?: number }) : GenericObject<number> & ({ a?: string | undefined; } | { b?: number | undefined; })
17+
>new GenericObject() : GenericObject<number>
18+
>GenericObject : typeof GenericObject
19+
20+
({ a?: string } | { b?: number });
21+
>a : string | undefined
22+
>b : number | undefined
23+
24+
v1.x = 432;
25+
>v1.x = 432 : 432
26+
>v1.x : number
27+
>v1 : GenericObject<number> & ({ a?: string | undefined; } | { b?: number | undefined; })
28+
>x : number
29+
>432 : 432
30+
31+
class GenericObjectWithoutSetter<T = number> {
32+
>GenericObjectWithoutSetter : GenericObjectWithoutSetter<T>
33+
34+
declare x: T;
35+
>x : T
36+
}
37+
38+
const v2 = new GenericObjectWithoutSetter() as GenericObjectWithoutSetter &
39+
>v2 : GenericObjectWithoutSetter<number> & ({ a?: string | undefined; } | { b?: number | undefined; })
40+
>new GenericObjectWithoutSetter() as GenericObjectWithoutSetter & ({ a?: string } | { b?: number }) : GenericObjectWithoutSetter<number> & ({ a?: string | undefined; } | { b?: number | undefined; })
41+
>new GenericObjectWithoutSetter() : GenericObjectWithoutSetter<number>
42+
>GenericObjectWithoutSetter : typeof GenericObjectWithoutSetter
43+
44+
({ a?: string } | { b?: number });
45+
>a : string | undefined
46+
>b : number | undefined
47+
48+
v2.x = 42;
49+
>v2.x = 42 : 42
50+
>v2.x : number
51+
>v2 : GenericObjectWithoutSetter<number> & ({ a?: string | undefined; } | { b?: number | undefined; })
52+
>x : number
53+
>42 : 42
54+
55+
class NormalObject {
56+
>NormalObject : NormalObject
57+
58+
set x(x: number) {}
59+
>x : number
60+
>x : number
61+
}
62+
63+
const v3 = new NormalObject() as NormalObject &
64+
>v3 : NormalObject & ({ a?: string | undefined; } | { b?: number | undefined; })
65+
>new NormalObject() as NormalObject & ({ a?: string } | { b?: number }) : NormalObject & ({ a?: string | undefined; } | { b?: number | undefined; })
66+
>new NormalObject() : NormalObject
67+
>NormalObject : typeof NormalObject
68+
69+
({ a?: string } | { b?: number });
70+
>a : string | undefined
71+
>b : number | undefined
72+
73+
v3.x = 42;
74+
>v3.x = 42 : 42
75+
>v3.x : number
76+
>v3 : NormalObject & ({ a?: string | undefined; } | { b?: number | undefined; })
77+
>x : number
78+
>42 : 42
79+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// https://github.com/microsoft/TypeScript/issues/56320
5+
6+
class GenericObject<T = number> {
7+
set x(x: T) {}
8+
}
9+
10+
const v1 = new GenericObject() as GenericObject &
11+
({ a?: string } | { b?: number });
12+
v1.x = 432;
13+
14+
class GenericObjectWithoutSetter<T = number> {
15+
declare x: T;
16+
}
17+
18+
const v2 = new GenericObjectWithoutSetter() as GenericObjectWithoutSetter &
19+
({ a?: string } | { b?: number });
20+
v2.x = 42;
21+
22+
class NormalObject {
23+
set x(x: number) {}
24+
}
25+
26+
const v3 = new NormalObject() as NormalObject &
27+
({ a?: string } | { b?: number });
28+
v3.x = 42;

0 commit comments

Comments
 (0)