Skip to content

Commit 59844e7

Browse files
authored
Don't consult JSDoc outside of JS in expando function assignment declarations (#52640)
1 parent 6b43f82 commit 59844e7

5 files changed

+47
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10519,7 +10519,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1051910519
// function/class/{} initializers are themselves containers, so they won't merge in the same way as other initializers
1052010520
const container = getAssignedExpandoInitializer(symbol.valueDeclaration);
1052110521
if (container) {
10522-
const tag = getJSDocTypeTag(container);
10522+
const tag = isInJSFile(container) ? getJSDocTypeTag(container) : undefined;
1052310523
if (tag && tag.typeExpression) {
1052410524
return getTypeFromTypeNode(tag.typeExpression);
1052510525
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [expandoFunctionContextualTypesJSDocInTs.ts]
2+
export function Foo() { }
3+
4+
// This comment should have no effect; this is a TS file.
5+
/** @type {never} */
6+
Foo.bar = () => { };
7+
8+
9+
//// [expandoFunctionContextualTypesJSDocInTs.js]
10+
"use strict";
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
exports.Foo = void 0;
13+
function Foo() { }
14+
exports.Foo = Foo;
15+
// This comment should have no effect; this is a TS file.
16+
/** @type {never} */
17+
Foo.bar = function () { };
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/expandoFunctionContextualTypesJSDocInTs.ts ===
2+
export function Foo() { }
3+
>Foo : Symbol(Foo, Decl(expandoFunctionContextualTypesJSDocInTs.ts, 0, 0), Decl(expandoFunctionContextualTypesJSDocInTs.ts, 0, 25))
4+
5+
// This comment should have no effect; this is a TS file.
6+
/** @type {never} */
7+
Foo.bar = () => { };
8+
>Foo.bar : Symbol(Foo.bar, Decl(expandoFunctionContextualTypesJSDocInTs.ts, 0, 25))
9+
>Foo : Symbol(Foo, Decl(expandoFunctionContextualTypesJSDocInTs.ts, 0, 0), Decl(expandoFunctionContextualTypesJSDocInTs.ts, 0, 25))
10+
>bar : Symbol(Foo.bar, Decl(expandoFunctionContextualTypesJSDocInTs.ts, 0, 25))
11+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/expandoFunctionContextualTypesJSDocInTs.ts ===
2+
export function Foo() { }
3+
>Foo : typeof Foo
4+
5+
// This comment should have no effect; this is a TS file.
6+
/** @type {never} */
7+
Foo.bar = () => { };
8+
>Foo.bar = () => { } : () => void
9+
>Foo.bar : () => void
10+
>Foo : typeof Foo
11+
>bar : () => void
12+
>() => { } : () => void
13+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function Foo() { }
2+
3+
// This comment should have no effect; this is a TS file.
4+
/** @type {never} */
5+
Foo.bar = () => { };

0 commit comments

Comments
 (0)