include the types package in your root index.d.ts file. You can do this with any @types package that isn't paired with its sans @type/ dependency equivalent
you can use this approach for things like analytics and sdks
it compiles the defs into output making it available in production
you must also set "declaration": true` in tsconfig.json
{
"compilerOptions": {
"sourceMap": "true",
"declaration": true,
"...": "..."
},
"include": ["index.d.ts", "src/**/*", "..."]
}
here's my root index.d.ts from a current project
/// <reference types="facebook-js-sdk" />
/// <reference types="facebook-pixel" />
/// <reference types="google.maps" />
/// <reference types="google-libphonenumber" />
/// <reference types="gtag.js" />
/// <reference types="glob" />
declare module "facebook-js-sdk";
declare module "facebook-pixel";
declare module "google.maps";
declare module "google-libphonenumber";
declare module "gtag.js";
declare module "glob";
interface Window {
dataLayer?: object[];
}
In an additional tsconfig file (tsconfig.build.json),extend your main tscnfig.json then call for paths to exclude
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
}
Note:
once you declare the package, you no longer need to import types provided by that package. They are injected and available globally for consumption