Reputation: 10587
I am using TypeScript to type-check (without emitting) a JavaScript project. In the JavaScript project I am using JSDoc to make TypeScript's work easier, but I am also using 3rd party packages, which provide their own typings (not @types
) and TypeScript doesn't see these packages, because they are referred to using only a simple script
tag on the page.
I don't want to write typings for what the libraries contribute to window
by hand since the packages already come with their own typings, TypeScript just doesn't see them and I wonder if there is a way to make it aware of them.
I cannot use import
or /// <reference
, because the source files are JavaScript files, not TypeScript files and I have to stick with what JavaScript allows.
I cannot use @types
because the typings come from the packages directly, not @types
. I might npm install
the packages, but TypeScript has no way of knowing the project references them (no import etc.) so I assume there needs to be a compiler setting letting it know.
I have tried npm install
ing the NPM packages of the dependencies TypeScript gets at runtime using script
and setting up typeRoots
:
"compilerOptions": {
"typeRoots": [
"node_modules/package"
]
}
But this didn't have any effect.
I have also tried to configure "typeAcquisition" to do my bidding like this:
{
"typeAcquisition": {
"enable": true,
"include": [
"package"
]
}
}
This didn't work either, which is understandable, because I think this just enables automatic fetching of @types
, when in my case the typings are a part of the actual package like I said previously.
How can I make TypeScript aware my JavaScript project it typechecks references packages a way it can't see from the source so that it loads their typings and the global objects provided by the packages become recognized and type checked?
Upvotes: 1
Views: 806
Reputation: 25790
Try compilerOptions.types
. It contains type declaration files to be included in compilation.
"types": [
"package"
],
Upvotes: 1