Skip to content

Commit b8b8aaa

Browse files
sandersntypescript-bot
authored andcommitted
Cherry-pick PR microsoft#34764 into release-3.7
Component commits: ab9bc3a Fix type reference to merged prototype property assignment The constructor function code path in the return type checking of signatures needs to pass the *merged* symbol of the declaration to getDeclaredTypeOfClassOrInterface. Other callers of getDeclaredTypeOfClassOrInterface do this, or used an already-merged symbol. Fixes microsoft#33993
1 parent 330c8ac commit b8b8aaa

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13960,13 +13960,13 @@ namespace ts {
1396013960
// If a signature resolution is already in-flight, skip issuing a circularity error
1396113961
// here and just use the `any` type directly
1396213962
const targetReturnType = isResolvingReturnTypeOfSignature(target) ? anyType
13963-
: target.declaration && isJSConstructor(target.declaration) ? getDeclaredTypeOfClassOrInterface(target.declaration.symbol)
13963+
: target.declaration && isJSConstructor(target.declaration) ? getDeclaredTypeOfClassOrInterface(getMergedSymbol(target.declaration.symbol))
1396413964
: getReturnTypeOfSignature(target);
1396513965
if (targetReturnType === voidType) {
1396613966
return result;
1396713967
}
1396813968
const sourceReturnType = isResolvingReturnTypeOfSignature(source) ? anyType
13969-
: source.declaration && isJSConstructor(source.declaration) ? getDeclaredTypeOfClassOrInterface(source.declaration.symbol)
13969+
: source.declaration && isJSConstructor(source.declaration) ? getDeclaredTypeOfClassOrInterface(getMergedSymbol(source.declaration.symbol))
1397013970
: getReturnTypeOfSignature(source);
1397113971

1397213972
// The following block preserves behavior forbidding boolean returning functions from being assignable to type guard returning functions
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/conformance/salsa/prototypePropertyAssignmentMergedTypeReference.js ===
2+
// https://github.com/microsoft/TypeScript/issues/33993
3+
var f = function() {
4+
>f : Symbol(f, Decl(prototypePropertyAssignmentMergedTypeReference.js, 1, 3))
5+
6+
return 12;
7+
};
8+
9+
f.prototype.a = "a";
10+
>f.prototype : Symbol(f.a, Decl(prototypePropertyAssignmentMergedTypeReference.js, 3, 2))
11+
>f : Symbol(f, Decl(prototypePropertyAssignmentMergedTypeReference.js, 1, 3))
12+
>prototype : Symbol(Function.prototype, Decl(lib.es5.d.ts, --, --))
13+
>a : Symbol(f.a, Decl(prototypePropertyAssignmentMergedTypeReference.js, 3, 2))
14+
15+
/** @type {new () => f} */
16+
var x = f;
17+
>x : Symbol(x, Decl(prototypePropertyAssignmentMergedTypeReference.js, 8, 3))
18+
>f : Symbol(f, Decl(prototypePropertyAssignmentMergedTypeReference.js, 1, 3))
19+
20+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/conformance/salsa/prototypePropertyAssignmentMergedTypeReference.js ===
2+
// https://github.com/microsoft/TypeScript/issues/33993
3+
var f = function() {
4+
>f : typeof f
5+
>function() { return 12;} : typeof f
6+
7+
return 12;
8+
>12 : 12
9+
10+
};
11+
12+
f.prototype.a = "a";
13+
>f.prototype.a = "a" : "a"
14+
>f.prototype.a : any
15+
>f.prototype : any
16+
>f : typeof f
17+
>prototype : any
18+
>a : any
19+
>"a" : "a"
20+
21+
/** @type {new () => f} */
22+
var x = f;
23+
>x : new () => f
24+
>f : typeof f
25+
26+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// https://github.com/microsoft/TypeScript/issues/33993
2+
// @noEmit: true
3+
// @allowJs: true
4+
// @checkJS: true
5+
// @filename: prototypePropertyAssignmentMergedTypeReference.js
6+
var f = function() {
7+
return 12;
8+
};
9+
10+
f.prototype.a = "a";
11+
12+
/** @type {new () => f} */
13+
var x = f;
14+

0 commit comments

Comments
 (0)