DEV Community

Discussion on: Using Custom Types in JavaScript Docs

4lch4 profile image
Devin W. Leaman Author

Would you happen to have an example of what you mean? Or some resources to learn more about this?

thecyberronin profile image
Ronin • Edited on

Unfortunately, you'll still have to get comfortable with TypeScript in order to use typings at its fullest. I think it may actually be a nice segway into learning TypeScript in my opinion. Starting out initially doing typings files would be a very good way to learn and get better with TypeScript. Since you'd be learning, starting out with a basic typings file would be a really good start.

I can give you the example that I shared with my initial comment. I created a lib that dynamically creates functions based on a JSON file with keys linking to API routes. A friend of mine asked me to create a wrapper for his API, with the intention of putting it on NPM.

I created the module and pushed to NPM, only recently I had an issue posted on the repo saying that a user couldn't get any intellisense to show when using it in VSC. I immediately knew that VSC had nothing to base it off of and VSC couldn't generate anything itself without the right information.

The module is A lot of the endpoints are NSFW, but like I said it's just a wrapper for my friend's API. If you take a look at the repo, you'll see that there is a typings folder containing the type file. You can also take a look at main file (index.js) to see what I mean when I say that VSC has nothing to base the intellisense off of without the type file. When you install the lib, VSC will grab the typings file and use it for intellisense. As you can see, the lib itself has no reference to any of the functions. The typings file is the MVP here. You can download the lib and see for yourself if you'd like and see the intellisense rendered from the typings file.

After taking a look at VSC's documentation, there are different ways to get the typings files. VSC will first look to see if they are contained in your package, after that there is a repo called DefinitelyTyped that it is then able to retrieve from if you don't have any typings files in the lib/package you are downloading.

Some links I got the information from:

Clarification on my comment about not having to go full TypeScript:
You are still using TypeScript, but you don't have to fool around with tsc or any config files to create a typings file to use with JS.
Also, if anything I said here was incorrect please let me know :)