Reputation: 951
Somehow I need to include a d.ts file for every files in a specify folder while not polluting other files' global namespace, how can I achieve this without import(there is lots of typing in that d.ts) or triple slash(this is disabled by eslint)?
It imports some typing from dependencies so simply include it won't have any effect
Upvotes: 2
Views: 1568
Reputation: 10967
Best practice to do this is define typeRoots
property in tsconfig.json
:
"typeRoots": [
"src/@types",
"node_modules/@types"
]
And in src/@types
directory add custom .d.ts
files look like below:
// in src/@types/scss.d.ts
declare module '*.scss' {
const styles: { [className: string]: string };
export default styles;
}
Upvotes: 0
Reputation: 197
In your tsconfig.json
, you can add the include
property and add a reference to the files you want included. E.g.
"include": [
"./src/**/*.ts",
"./definitions/**/*.d.ts"
]
This is not going to create a dependency, or import the file in your project, but will look for the types inside it, same way as the triple slash method.
Upvotes: 3