How to make jsDoc "import" work with vscode?

Viewed 4348

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

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
 */
Related