Skip to content

Commit ab9bc3a

Browse files
committed
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 f12eee2 commit ab9bc3a

File tree

4 files changed

+62
-2
lines changed

4 files changed

+62
-2
lines changed

src/compiler/checker.ts

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

1397313973
// The following block preserves behavior forbidding boolean returning functions from being assignable to type guard returning functions
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+
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+
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)