Skip to content

@typedef doesn't seem to recognize default exports #35552

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

Closed
matthew-dean opened this issue Dec 6, 2019 · 1 comment
Closed

@typedef doesn't seem to recognize default exports #35552

matthew-dean opened this issue Dec 6, 2019 · 1 comment

Comments

@matthew-dean
Copy link

Search Terms:
JSDoc default named exports @typedef

Code
Given the following files:

/// file1.js
function foo() { return true; }
export { foo };

/// file2.js
/**
 * @typedef { ReturnType<import('./file1').foo> } Foo
 */

TypeScript / VSCode will correctly identify the type.

However, if it's a default export like:

/// file1.js
function foo() { return true; }
export default foo;

... then there seems to be no way for TS to recognize the type via @typedef. Neither of the following will work:

/// file2.js
/**
 * @typedef { ReturnType<import('./file1')> } Foo
 */
/**
 * @typedef { ReturnType<import('./file1').default> } Foo
 */

Related Issues:
Possibly Related? #33136

@matthew-dean
Copy link
Author

Never mind! I made other changes, and the issue was my import path. Using .default worked. However, this would be great to see in the documented examples! -> https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant