Using the popular node-fetch library, Intellisense doesn't understand the return value of fetch().
Vim with coc:

Same thing in VSCode:

For most other libraries I have type completion, but this one does not work.
jsconfig.json and tsconfig.json files@types/index.d.ts@types/node-fetch, which also falls out-of-date oftenimport syntax, which worksAs I mentioned, changing to import syntax fixes the issue, but I want it to work with require too.

How can I have type completion on this library with CommonJS?
const fetch = require('node-fetch').default
To bridge fundamental differences between CommonJS and ES module syntax, require('node-fetch') returns an object with this shape:

Notice the node-fetch type definition does export the fetch() function as the top level, but also exports a default property for compatibility with ES module syntax. Using this property fixes autocomplete issues.

This still seems like a bug to me, but this workaround does resolve the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With