ComethTheNerd ComethTheNerd - 10 months ago 58
TypeScript Question

Inject Implicit Ambient Typings via Visual Studio Code Extension

I want to modify the ambient typings that intellisense uses for a user's typescript file(s) via my VS code extension, ie. the ones that get loaded via

and related auto-generated files.

eg. adding an implicit declaration of a
function so that the user could write:


without the typechecker complaining!

I want my extension to inject some new ambient declarations into the global namespace upon load rather than have the user have to boilerplate each file with reference tags.

Any ideas?


Answer Source

It should be possible but it will require you to update/write a file on/to disk. That's because tsserver only works with real files. Accepting that leaves you with the question where to put that file? It depends. To be really sure you must look at (and understand) what's in tsconfig or jsconfig - most likely tho you want to write to the @types or typings folders in which other tools also write. Often it might just work, but you might also be required to update the tsconfig file then, like adding the new file to the include-array.