Skip to content

Don't consult JSDoc outside of JS in expando function assignment declarations #52640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 () { };
Original file line number Diff line number Diff line change
@@ -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))

Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function Foo() { }

// This comment should have no effect; this is a TS file.
/** @type {never} */
Foo.bar = () => { };