-
Notifications
You must be signed in to change notification settings - Fork 53
Description
Hey great extension. This is a good way to try out/play with new libraries.
This may be a long shot but worth asking.
Is it technically possible to get completions for libraries added in the "script.js" pane? I can imagine this isn't easy but would be awesome if doable.
So "jQuery" for example. Its added in my "scripts" array. Can definitions be pull down on the fly and used by VSCode?
Automatic Type Acquisition
We can rely on VSCodes Automatic Type Acquisition it sounds like we can force this in a jsconfig.json file and VSCode does the rest. Just auto generate the file and place it in the same directory as the script.js. Below ive done it manually.
Then in the same folder I add jsconfig.json
{
"typeAcquisition": {
"include": ["jquery"]
}
}
That works well!
The only downside here is we can't force a specific version. I think VSCode just grabs the latest.
Automatic type acquisition will always download the declaration file for the latest version of a library. If you're using a different version, there may be mismatches between what's shown in Intellisense and what's actually available at runtime
https://ticehurst.com/jsdocs/articles/types/ata.html
skypack
I just found that Skypack supports typescript declarations in its CDN. It sends the path in its header response. More info here:
https://docs.skypack.dev/skypack-cdn/api-reference/lookup-urls#typescript-declarations
jQuery: https://cdn.skypack.dev/jquery
jQuery Type: https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=types/index.d.ts
I'm not sure how easy it is to traverse those types and download them
It would also be nice to point directly to type declarations but I don't think that's possible right now.
microsoft/TypeScript#28985 might be a blocker
@FredKSchott can Skypack/Snowpack be utilised here in anyway?
Other ideas:
Auto generating something like this https://dev.to/patarapolw/cdn-and-typescript-support-also-javascript-typing-for-ide-1bko, adding a package.json, then
There's also https://github.com/tokilabs/autotypes