How to get VS Code to understand JSDOC’s @typedef across multiple files

I’ve had some success with using jsconfig.json and its include property in a plain JavaScript project in Visual Studio Code 1.33.1

{
  "include": [
    "src/**/*.js"
  ]
}

Given the following JavaScript project:

src/
├── types/
|   ├── person.js
|   ├── question.js
|
├── answer.js
├── jsconfig.json

Where both question.js and person.js are type definitions:

person.js

/**
 * @typedef {object} Person
 * @property {string} firstName
 * @property {string} lastName
 */

question.js

/**
 * @typedef {object} Question
 * @property {Person} askedBy
 * @property {string} text
 */

And answer.js is a function that accepts a question and return an answer:

/**
 * Takes a question and return an answer
 * @param {Question} question 
 */
function answer(question) {
  return 42;
}

As you can see in the first screencast I do get IntelliSense support when hovering over the Question type notation:

enter image description here

On top of that IntelliSense is also now able to offer code completion based on my types definitions:

enter image description here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)