Skip to content

Commit 2143a3f

Browse files
authored
Merge pull request #20814 from Microsoft/fixUnionSignatures
Fix union signatures
2 parents a92a594 + 6f42ecd commit 2143a3f

File tree

5 files changed

+105
-1
lines changed

5 files changed

+105
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5936,7 +5936,7 @@ namespace ts {
59365936
if (unionSignatures.length > 1) {
59375937
let thisParameter = signature.thisParameter;
59385938
if (forEach(unionSignatures, sig => sig.thisParameter)) {
5939-
const thisType = getUnionType(map(unionSignatures, sig => getTypeOfSymbol(sig.thisParameter) || anyType), UnionReduction.Subtype);
5939+
const thisType = getUnionType(map(unionSignatures, sig => sig.thisParameter ? getTypeOfSymbol(sig.thisParameter) : anyType), UnionReduction.Subtype);
59405940
thisParameter = createSymbolWithType(signature.thisParameter, thisType);
59415941
}
59425942
s = cloneSignature(signature);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [unionSignaturesWithThisParameter.ts]
2+
// Repro from #20802
3+
4+
function x<T>(ctor: {
5+
(this: {}, v: T): void;
6+
new(v: T): void;
7+
} | {
8+
(v: T): void;
9+
new(v: T): void;
10+
}, t: T) {
11+
new ctor(t);
12+
}
13+
14+
15+
//// [unionSignaturesWithThisParameter.js]
16+
"use strict";
17+
// Repro from #20802
18+
function x(ctor, t) {
19+
new ctor(t);
20+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=== tests/cases/compiler/unionSignaturesWithThisParameter.ts ===
2+
// Repro from #20802
3+
4+
function x<T>(ctor: {
5+
>x : Symbol(x, Decl(unionSignaturesWithThisParameter.ts, 0, 0))
6+
>T : Symbol(T, Decl(unionSignaturesWithThisParameter.ts, 2, 11))
7+
>ctor : Symbol(ctor, Decl(unionSignaturesWithThisParameter.ts, 2, 14))
8+
9+
(this: {}, v: T): void;
10+
>this : Symbol(this, Decl(unionSignaturesWithThisParameter.ts, 3, 5))
11+
>v : Symbol(v, Decl(unionSignaturesWithThisParameter.ts, 3, 14))
12+
>T : Symbol(T, Decl(unionSignaturesWithThisParameter.ts, 2, 11))
13+
14+
new(v: T): void;
15+
>v : Symbol(v, Decl(unionSignaturesWithThisParameter.ts, 4, 8))
16+
>T : Symbol(T, Decl(unionSignaturesWithThisParameter.ts, 2, 11))
17+
18+
} | {
19+
(v: T): void;
20+
>v : Symbol(v, Decl(unionSignaturesWithThisParameter.ts, 6, 5))
21+
>T : Symbol(T, Decl(unionSignaturesWithThisParameter.ts, 2, 11))
22+
23+
new(v: T): void;
24+
>v : Symbol(v, Decl(unionSignaturesWithThisParameter.ts, 7, 8))
25+
>T : Symbol(T, Decl(unionSignaturesWithThisParameter.ts, 2, 11))
26+
27+
}, t: T) {
28+
>t : Symbol(t, Decl(unionSignaturesWithThisParameter.ts, 8, 2))
29+
>T : Symbol(T, Decl(unionSignaturesWithThisParameter.ts, 2, 11))
30+
31+
new ctor(t);
32+
>ctor : Symbol(ctor, Decl(unionSignaturesWithThisParameter.ts, 2, 14))
33+
>t : Symbol(t, Decl(unionSignaturesWithThisParameter.ts, 8, 2))
34+
}
35+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
=== tests/cases/compiler/unionSignaturesWithThisParameter.ts ===
2+
// Repro from #20802
3+
4+
function x<T>(ctor: {
5+
>x : <T>(ctor: { (this: {}, v: T): void; new (v: T): void; } | { (v: T): void; new (v: T): void; }, t: T) => void
6+
>T : T
7+
>ctor : { (this: {}, v: T): void; new (v: T): void; } | { (v: T): void; new (v: T): void; }
8+
9+
(this: {}, v: T): void;
10+
>this : {}
11+
>v : T
12+
>T : T
13+
14+
new(v: T): void;
15+
>v : T
16+
>T : T
17+
18+
} | {
19+
(v: T): void;
20+
>v : T
21+
>T : T
22+
23+
new(v: T): void;
24+
>v : T
25+
>T : T
26+
27+
}, t: T) {
28+
>t : T
29+
>T : T
30+
31+
new ctor(t);
32+
>new ctor(t) : void
33+
>ctor : { (this: {}, v: T): void; new (v: T): void; } | { (v: T): void; new (v: T): void; }
34+
>t : T
35+
}
36+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @strict: true
2+
3+
// Repro from #20802
4+
5+
function x<T>(ctor: {
6+
(this: {}, v: T): void;
7+
new(v: T): void;
8+
} | {
9+
(v: T): void;
10+
new(v: T): void;
11+
}, t: T) {
12+
new ctor(t);
13+
}

0 commit comments

Comments
 (0)