Skip to content

Type a standard import with jsdoc onlyΒ #58675

Open
@HolgerJeromin

Description

@HolgerJeromin

πŸ” Search Terms

ecmascript module import jsdoc

βœ… Viability Checklist

⭐ Suggestion

Right now I can type an require call with

/**
 * @type {typeof import("./accounts").userAccount}
 */
var x = require("./accounts").userAccount;

from https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#import-types

But when I my code uses an import statement
import { shortNameFromImport } from "textmodule";
I did not found a way to type that when the module resolution does found a hit.

@type in the line before can not be used because there is no let or const in this line.

/** @type {import('textmodule')} */
import { shortNameFromImport } from "textmodule";

And the normal way to type a variable with parenthesis can not be used because it is not valid JS code:

import { /** @type {import('textmodule')} */ (shortNameFromImport ) } from "textmodule";

Both variants without parenthesis do not work...

import { /** @type {import('textmodule')} */ shortNameFromImport } from "textmodule";
import { shortNameFromImport /** @type {import('textmodule')} */ } from "textmodule";

πŸ“ƒ Motivating Example

With typescript code I can do some magic with path in the tsconfig.json

"paths": {
  "textmodule": [ "./textmodule.ts" ]
},

But I wanted to have a JSDoc only solution.

πŸ’» Use Cases

See above

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureDomain: JSDocRelates to JSDoc parsing and type generationDomain: JavaScriptThe issue relates to JavaScript specificallySuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions