diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 62aab9ca5c062..44904e0aae7ee 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10519,7 +10519,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // function/class/{} initializers are themselves containers, so they won't merge in the same way as other initializers const container = getAssignedExpandoInitializer(symbol.valueDeclaration); if (container) { - const tag = getJSDocTypeTag(container); + const tag = isInJSFile(container) ? getJSDocTypeTag(container) : undefined; if (tag && tag.typeExpression) { return getTypeFromTypeNode(tag.typeExpression); } diff --git a/tests/baselines/reference/expandoFunctionContextualTypesJSDocInTs.js b/tests/baselines/reference/expandoFunctionContextualTypesJSDocInTs.js new file mode 100644 index 0000000000000..a9693850eec11 --- /dev/null +++ b/tests/baselines/reference/expandoFunctionContextualTypesJSDocInTs.js @@ -0,0 +1,17 @@ +//// [expandoFunctionContextualTypesJSDocInTs.ts] +export function Foo() { } + +// This comment should have no effect; this is a TS file. +/** @type {never} */ +Foo.bar = () => { }; + + +//// [expandoFunctionContextualTypesJSDocInTs.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Foo = void 0; +function Foo() { } +exports.Foo = Foo; +// This comment should have no effect; this is a TS file. +/** @type {never} */ +Foo.bar = function () { }; diff --git a/tests/baselines/reference/expandoFunctionContextualTypesJSDocInTs.symbols b/tests/baselines/reference/expandoFunctionContextualTypesJSDocInTs.symbols new file mode 100644 index 0000000000000..667bc1dd8c341 --- /dev/null +++ b/tests/baselines/reference/expandoFunctionContextualTypesJSDocInTs.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/expandoFunctionContextualTypesJSDocInTs.ts === +export function Foo() { } +>Foo : Symbol(Foo, Decl(expandoFunctionContextualTypesJSDocInTs.ts, 0, 0), Decl(expandoFunctionContextualTypesJSDocInTs.ts, 0, 25)) + +// This comment should have no effect; this is a TS file. +/** @type {never} */ +Foo.bar = () => { }; +>Foo.bar : Symbol(Foo.bar, Decl(expandoFunctionContextualTypesJSDocInTs.ts, 0, 25)) +>Foo : Symbol(Foo, Decl(expandoFunctionContextualTypesJSDocInTs.ts, 0, 0), Decl(expandoFunctionContextualTypesJSDocInTs.ts, 0, 25)) +>bar : Symbol(Foo.bar, Decl(expandoFunctionContextualTypesJSDocInTs.ts, 0, 25)) + diff --git a/tests/baselines/reference/expandoFunctionContextualTypesJSDocInTs.types b/tests/baselines/reference/expandoFunctionContextualTypesJSDocInTs.types new file mode 100644 index 0000000000000..7e818015f1a79 --- /dev/null +++ b/tests/baselines/reference/expandoFunctionContextualTypesJSDocInTs.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/expandoFunctionContextualTypesJSDocInTs.ts === +export function Foo() { } +>Foo : typeof Foo + +// This comment should have no effect; this is a TS file. +/** @type {never} */ +Foo.bar = () => { }; +>Foo.bar = () => { } : () => void +>Foo.bar : () => void +>Foo : typeof Foo +>bar : () => void +>() => { } : () => void + diff --git a/tests/cases/compiler/expandoFunctionContextualTypesJSDocInTs.ts b/tests/cases/compiler/expandoFunctionContextualTypesJSDocInTs.ts new file mode 100644 index 0000000000000..c26397a764a80 --- /dev/null +++ b/tests/cases/compiler/expandoFunctionContextualTypesJSDocInTs.ts @@ -0,0 +1,5 @@ +export function Foo() { } + +// This comment should have no effect; this is a TS file. +/** @type {never} */ +Foo.bar = () => { };