TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

JSDoc `@import` no longer works correctly with default exports

Open wagenet opened this issue 1 year ago • 4 comments

🔎 Search Terms

jsdoc import @import

🕗 Version & Regression Information

This changed between versions 5.5.4 and 5.6.3.

⏯ Playground Link

No response

💻 Code

/** @import Foo from "my-app/foo" */

/** @return {Foo} */
function getFoo() {
  return myFoo;
}

tsconfig.json excerpt:

{
 "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "my-app/*": ["src/*"]
    }
  }
}

🙁 Actual behavior

In TypeScript 5.5 the above worked correctly with getFoo returning Foo. As of TypeScript 5.6 this now returns an any. This workaround resolves the problem but feels like it is not what is intended.

/** @import { default as Foo } from "my-app/foo" */

/** @return {Foo} */
function getFoo() {
  return myFoo;
}

🙂 Expected behavior

I expected default exports to work with @import in JSDoc.

Additional information about the issue

No response

wagenet avatar Oct 22 '24 15:10 wagenet

@wagenet Does the following test apply to your case?

// @Filename: /tsconfig.json
{
    "compilerOptions": {
        "allowJs": true,
        "checkJs": true,
        "baseUrl": ".",
        "paths": {
            "ns/*": ["src/*"]
        }
    }
}

// @Filename: /src/foo.ts
export default interface Foo {
    a: number;
}

// @Filename: /src/bar.js
/** @import Foo from "ns/foo" */

/** @return {Foo} */
function f() {
    return { a: "" };
}

a-tarasyuk avatar Oct 22 '24 19:10 a-tarasyuk

@a-tarasyuk I have allowJs: true but no setting for checkJs.

wagenet avatar Oct 22 '24 20:10 wagenet

@wagenet I modified @a-tarasyuk 's example slightly. But it works as expected -- Foo gets imported and shows the correct error. Can you give more detail about your repro, like what the filenames are and what all your tsconfig settings are?

I would recommend setting checkJs: true first thing because that will show errors in JS files, and there's probably an error on your @import that you're not seeing.

// @Filename: /tsconfig.json
{
    "compilerOptions": {
        "noEmit": true,
        "allowJs": true,
        "checkJs": true,
        "baseUrl": ".",
        "paths": {
            "ns/*": ["src/*"]
        }
    },
    "files": ["src/bar.js"]
}

// @Filename: /src/foo.ts
export default interface Foo {
    a: number;
}

// @Filename: /src/bar.js
/** @import Foo from "ns/foo" */

/** @return {Foo} */
function f() {
    return { a: "" };
}

sandersn avatar Nov 22 '24 22:11 sandersn

I have encountered the same problem with Typescript version 5.8.3 (in VS Code version 1.101.0)

ZpeedTube avatar Jun 18 '25 11:06 ZpeedTube