Skip to content

Commit

Permalink
Merge pull request #20814 from Microsoft/fixUnionSignatures
Browse files Browse the repository at this point in the history
Fix union signatures
  • Loading branch information
ahejlsberg authored Dec 20, 2017
2 parents a92a594 + 6f42ecd commit 2143a3f
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5936,7 +5936,7 @@ namespace ts {
if (unionSignatures.length > 1) {
let thisParameter = signature.thisParameter;
if (forEach(unionSignatures, sig => sig.thisParameter)) {
const thisType = getUnionType(map(unionSignatures, sig => getTypeOfSymbol(sig.thisParameter) || anyType), UnionReduction.Subtype);
const thisType = getUnionType(map(unionSignatures, sig => sig.thisParameter ? getTypeOfSymbol(sig.thisParameter) : anyType), UnionReduction.Subtype);
thisParameter = createSymbolWithType(signature.thisParameter, thisType);
}
s = cloneSignature(signature);
Expand Down
20 changes: 20 additions & 0 deletions tests/baselines/reference/unionSignaturesWithThisParameter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//// [unionSignaturesWithThisParameter.ts]
// Repro from #20802

function x<T>(ctor: {
(this: {}, v: T): void;
new(v: T): void;
} | {
(v: T): void;
new(v: T): void;
}, t: T) {
new ctor(t);
}


//// [unionSignaturesWithThisParameter.js]
"use strict";
// Repro from #20802
function x(ctor, t) {
new ctor(t);
}
35 changes: 35 additions & 0 deletions tests/baselines/reference/unionSignaturesWithThisParameter.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
=== tests/cases/compiler/unionSignaturesWithThisParameter.ts ===
// Repro from #20802

function x<T>(ctor: {
>x : Symbol(x, Decl(unionSignaturesWithThisParameter.ts, 0, 0))
>T : Symbol(T, Decl(unionSignaturesWithThisParameter.ts, 2, 11))
>ctor : Symbol(ctor, Decl(unionSignaturesWithThisParameter.ts, 2, 14))

(this: {}, v: T): void;
>this : Symbol(this, Decl(unionSignaturesWithThisParameter.ts, 3, 5))
>v : Symbol(v, Decl(unionSignaturesWithThisParameter.ts, 3, 14))
>T : Symbol(T, Decl(unionSignaturesWithThisParameter.ts, 2, 11))

new(v: T): void;
>v : Symbol(v, Decl(unionSignaturesWithThisParameter.ts, 4, 8))
>T : Symbol(T, Decl(unionSignaturesWithThisParameter.ts, 2, 11))

} | {
(v: T): void;
>v : Symbol(v, Decl(unionSignaturesWithThisParameter.ts, 6, 5))
>T : Symbol(T, Decl(unionSignaturesWithThisParameter.ts, 2, 11))

new(v: T): void;
>v : Symbol(v, Decl(unionSignaturesWithThisParameter.ts, 7, 8))
>T : Symbol(T, Decl(unionSignaturesWithThisParameter.ts, 2, 11))

}, t: T) {
>t : Symbol(t, Decl(unionSignaturesWithThisParameter.ts, 8, 2))
>T : Symbol(T, Decl(unionSignaturesWithThisParameter.ts, 2, 11))

new ctor(t);
>ctor : Symbol(ctor, Decl(unionSignaturesWithThisParameter.ts, 2, 14))
>t : Symbol(t, Decl(unionSignaturesWithThisParameter.ts, 8, 2))
}

36 changes: 36 additions & 0 deletions tests/baselines/reference/unionSignaturesWithThisParameter.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
=== tests/cases/compiler/unionSignaturesWithThisParameter.ts ===
// Repro from #20802

function x<T>(ctor: {
>x : <T>(ctor: { (this: {}, v: T): void; new (v: T): void; } | { (v: T): void; new (v: T): void; }, t: T) => void
>T : T
>ctor : { (this: {}, v: T): void; new (v: T): void; } | { (v: T): void; new (v: T): void; }

(this: {}, v: T): void;
>this : {}
>v : T
>T : T

new(v: T): void;
>v : T
>T : T

} | {
(v: T): void;
>v : T
>T : T

new(v: T): void;
>v : T
>T : T

}, t: T) {
>t : T
>T : T

new ctor(t);
>new ctor(t) : void
>ctor : { (this: {}, v: T): void; new (v: T): void; } | { (v: T): void; new (v: T): void; }
>t : T
}

13 changes: 13 additions & 0 deletions tests/cases/compiler/unionSignaturesWithThisParameter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// @strict: true

// Repro from #20802

function x<T>(ctor: {
(this: {}, v: T): void;
new(v: T): void;
} | {
(v: T): void;
new(v: T): void;
}, t: T) {
new ctor(t);
}

0 comments on commit 2143a3f

Please sign in to comment.