Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make jsDoc "import" work with vscode?

Tags:

I want to import a node module with @import, but it seems visual studio code is not getting it. Or am I doing it wrong?

Missing type in visual studio code

like image 266
stoefln Avatar asked Mar 04 '20 10:03

stoefln


People also ask

How do I run a JavaScript file in VS Code?

1) Take VSCode 2) Right click on the file in left pane 3) Click "Reveal in explorer" from context menu 4) Right click on the file -> Select "Open with" -> Select "Choose another program" 5) Check box "Always use this app to open . js file" 6) Click "More apps" -> "Look for another app in PC" 7) Navigate to node.

How do I run node js file in Visual Studio Code terminal?

You'll need to open a new terminal (command prompt) for the node and npm command-line tools to be on your PATH. To test that you have Node. js installed correctly on your computer, open a new terminal and type node --version and you should see the current Node. js version installed.


1 Answers

Personally I would suggest TypeScript over JSDoc.

Nevertheless, try something like this? (there is no @import tag in JSDoc).

// path/to/UiStore.js

/**
 * @typedef UiStore
 * @type {object}
 * @property {string} foo - description for foo
 * @property {string} bar - description for bar
 */

// path/to/another.js

/** @typedef {import("path/to/UiStore").UiStore} UiStore */

/** @type {UiStore} */
const uiStore = {
  foo: 'hello',
  bar: 'world',
};

With mobx-state-tree it works like this:

In file UiStore.js:

export const UiStoreType = UiStore.Type

and then in path/to/another.js

/**
 * @typedef Props
 * @prop { import("../stores/UiStore").UiStoreType } uiStore
 * @prop { import("../stores/DbStore").DbStoreType } dbStore
 */
like image 189
87hz Avatar answered Sep 23 '22 04:09

87hz