Somewhat inspired by Jest and some other tools, I'm working on a program which loads small source files, written in TypeScript, and compiles and runs them in a separate VM context within Node.js. (No, it's not a competitor to Jest).
Similar to what Jest does with describe and test, this program "injects" certain predefined globals into the script before running it, so that the script doesn't need to explicitly import those symbols. This works surprisingly well, except for the dreaded "red squiggles" in VSCode.
The problem is that VSCode doesn't know about the injected symbols. Now, with Jest the solution is to install @types/jest into your projects, and then add a "types": ["jest"] property to your project's tsconfig.json. However, I really don't want to have to maintain a separate package just for the ambient types, and I don't want to have to bother the DefinitelyTyped people to add support for my little project.
Is there a way I can configure my project so that VSCode (or rather the TypeScript language service) knows that certain types are always present? I've tried mucking around with tsconfig.json, /// reference, "types" in package.json, and so on, but nothing I have tried seems to work.
To be clear, what I am talking about is a relationship between two separate npm packages - a "providing" package that provides the type definitions, and a "consuming" package that uses them. So just as in Jest, a package which depends on Jest can have a test file that uses Jest symbols without needing to explicitly import them.
GitHub repo is here if anyone wants to take a look: https://github.com/viridia/overrun
@typespackage on DefinitelyTyped. Is it possible to self-host ambient types? That is, can a tsconfig "types" property reference type definitions that are bundled with the installed package, such that those types are implicitly imported, rather than having to be explicitly imported?typeRoots(e. g.typeRoots: ["@types", "@your-namespace", "./node_modules/or-even-your-package-maybe"]). I'm not sure this will work, hence the comment instead of the answer.