Enable Intellisense for my custom ES6 JavaScript modules in VS Code

Using VS Code Intellisense can greatly enhance productivity when working with internal project files, providing helpful autocompletion features and utilizing written JSDoc comments.

However, my current projects involve custom JavaScript libraries stored in Bitbucket Cloud repositories as ES6 modules, which are accessed via NPM or Yarn dependencies.

Despite knowing that JSDoc is available in these libraries, I have been unable to make use of Intellisense for them.

I attempted to explicitly include the library files in the jsconfig.json file, but to no avail:

{
  "compilerOptions": {
    "target": "es2017",
    "moduleResolution": "node",
    "checkJs": true,
    "allowSyntheticDefaultImports": true,
    "noEmit": true,
    "noImplicitAny": false,
    "strictNullChecks": false,
    "alwaysStrict": true,
    "sourceMap": false
  },
  "include": ["src/**/*", "node_modules/my-lib/**/*"]
}

Is there a straightforward method to instruct VS Code to recognize my library files? While one solution could involve creating and publishing TypeScript definition files for each library, I believe there must be a simpler way for VS Code to handle my library JavaScript files just like it handles internal project files.

Answer №1

This particular question may be considered outdated, but I recently encountered a similar issue and devised a solution.

One approach is to generate a types declaration file, which can be conveniently done using the tsd-jsdoc package in conjunction with your jsdoc comments.

To create the types file, I included the following script in my package.json file...

jsdoc -r src -t node_modules/tsd-jsdoc/dist -d lib

Executing this script will produce a lib/types.d.ts file.

Next, add a types entry in your package.json that points to this generated file.

Ensure that this script is integrated into your prepublishOnly script to guarantee the file is current before running npm publish.

Typically, my src/index.js file comprises multiple

export { default as thing } from './thing';
lines. To create a declaration file readable by vscode, I formatted the file as follows...

/** @module my-module */

export { default as thing1 } from './thing1';
export { default as thing2 } from './thing2';

For the thing1 and thing2 jsdoc comments within the export, remember to include @memberof module:my-module, like so...

/**
 * Thing 1
 * @param {string} thing
 * @memberof module:my-module
*/
function thing1(thing) {
}

export default thing1;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Obtaining the chosen options from a dropdown menu

I am facing an issue with retrieving values from dropdown menus on a webpage that are used to filter a list. Despite trying various methods, I am not getting any values returned in my function. Here is what I have attempted: - var browserVal= document.ge ...

What are the effects of calling callback(false) and callback(true)?

I'm currently diving into a nodejs chat project, and I’m a bit confused about the outcome when callback(false) and callback(true) are triggered in this context... io.sockets.on('connection', function(socket){ socket.on('new user& ...

Filtering out undefined elements from an array created by mapping over a nested array using map() and filter()

I'm currently in the process of creating multiple variables to be utilized later on, each one representing a specific array within a set of nested arrays (essentially a data array that will be used for various projects). As I attempt to select the pr ...

Tips for creating various instances of a single type within mock data

In my Schema.js, I have a simple schema and server setup: const typeDefs = gql` type Query { people: [Person!]! } type Person { name: String! age: Int! job: String } `; And here is my server configuration: const mocks = { Person ...

Sending information to a subpage through props using a query in the URL triggers a 431 Request Header Fields Too Large error

I have a page called campaigns, and I am facing an issue on the index page where I want to pass data to my dynamic page [campaignId].tsx. Although I can see the data on my dynamic page, the URL links are becoming too long, leading to an HTTP Status code 4 ...

When making jQuery Ajax calls, the $_POST variable may be empty and a warning about headers already being sent may also

I've been working on a PHP project and encountered an issue with sending data from an HTML page using jQuery Ajax to another PHP page. After numerous attempts to debug the problem, I still can't figure out why $_POST is empty when I try to echo. ...

Send information to modal using Javascript

I am facing an issue when trying to transfer data from JavaScript to a Bootstrap modal. Here is how my code looks: Modal: <div id="myModal" class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> ...

Using the useRef validation can lead to errors when trying to reference the current value against an input

Currently, the code is functioning well but an error alert from Typescript needs to be addressed. A warning pops up regarding the use of ref.current.value. ERROR 1. TS18048: 'ref.current' is possibly 'undefined'. To tackle this issue, ...

Adding design to distinct element after clicking a button

Struggling with a JS/Jquery issue on my portfolio website, I admit that I am still just an average programmer. My portfolio website has five buttons, each representing a different project. For each project, there is a corresponding text description and an ...

Transforming date and timezone offset into an isoDate format using moment.js

When retrieving data from the API, I encounter Date, Time, and Offset values in separate columns. My goal is to obtain an ISO date while maintaining the original date and time values. const date = "2019-04-15" const time = "13:45" const ...

Guide on converting JSON encoded data into a JavaScript array

I have a few web pages that display results in the following format: [{"id":"1","company":"Gaurishankar","bus_no":"JHA 12 KH 1230"}, {"id":"2","company":"Gaurishankar","bus_no":"BA 2 KH 2270"}] Now, I want to take this JSON encoded data and use it in a J ...

Utilizing dynamic class and color binding features in VueJs?

I need help with implementing a Custom Sort method on my divs to arrange them in ascending or descending order. My query is how can I pre-set the icon color to grey by default, and only change it to black when clicked, while keeping the others greyed out a ...

Dynamically size and position elements to fit perfectly within the container

I am currently facing a challenge with my absolutely positioned elements that have different position.top and height values generated from the database. The main goal is to resolve collisions between these elements by shifting them to the right while adju ...

What are the built-in modules in node.js that handle System calls?

Can you list the built-in modules in Node.js that handle system calls, such as child_process? I'm interested in learning about all the methods within these modules. Thank you! ...

VueJs Ellipsis Filter: Enhance Your Texts with

Using Vue.JS, I am dynamically injecting text content into a DOM element. <article>{{ movie.summary }}</article> My goal is to implement an auto-ellipsis filter. Essentially, the code would look like this: <article>{{ movie.summary | e ...

A dynamic JavaScript object that functions similarly to a multidimensional associative array in PHP

How can you efficiently update or add properties to an object in JavaScript? Unlike PHP's associative array, achieving this dynamically in JavaScript can be a bit tricky. For example: $test = []; foreach ($data as $key => $value) { ... $te ...

Tips for creating a personalized callback within a user function using JavaScript

Utilizing callbacks is a common practice when working with third-party libraries like jQuery. However, I have encountered a situation where I need to implement my own callback function. Consider the following snippet from my current code: // Get All Rates ...

Why does my dialog box only open the first time and not the second time?

I have created my own custom dialog box using jQuery and it seems to be working fine initially. However, after closing it once, when I try to open it again nothing appears. Can anyone help me identify what's causing this issue? Below is the source co ...

Need at least one of two methods, or both, in an abstract class

Consider the following scenario: export abstract class AbstractButton { // Must always provide this method abstract someRequiredMethod(): void; // The successor must implement one of these (or both) abstract setInnerText?(): void; abst ...

Problems encountered with React Image Magnifiers while attempting to zoom in with Next.js

When I try to use the react-image-magnifiers plugin to make an image zoom in on hover, it works fine without next.js. However, when I integrate it with next.js, the zoom functionality does not work. Could there be an issue in my next.config.js file? This ...