I have organized all the type definitions that will be used in my application into a single file. I created a folder named @types
and an index.d.ts
file that exports every interface/type needed.
I updated my tsconfig.json to include the @types folder:
{
"compilerOptions": {
"outDir": "./built",
"allowJs": true,
"target": "es5",
"jsx": "react",
"allowSyntheticDefaultImports": true,
"lib": [
"es2015"
],
"typeRoots": [
"./@types"
],
},
"include": [
"./client/**/*",
"./@types/**/*"
],
"awesomeTypescriptLoaderOptions": {
"silent": true,
"errorsAsWarnings": true
}
}
However, when referencing one of the interfaces from index.d.ts within my code (inside client/...), VSCode shows a "Could not find name" error message.
Is there a better solution to address this issue?
Here is an example of an interface defined in @types/index.d.ts:
export interface Agent {
name: string;
...
}
Usage:
interface Props extends RouteComponentProps<any> {
agent?: types.Agent;
}