TS Type Definition Specify Location

I want TS to use all the .d.ts files in @types/ directory and also to consider .d.ts files that are located at specific places like ../library/library.d.ts

Can I do this in the tsconfig.json file?

Thanks!

1 answer

  • answered 2018-01-11 21:21 casieber

    You can use the typeRoots compiler option within your tsconfig.json to do this. However, this will disable the default inclusion of visible @types packages so you will need to manually add it to typeRoots as well.

    {
        "compilerOptions": {
            "typeRoots": [
                "./node_modules/@types",
                "./path/to/my/type/directory",
                "./other/path/to/type/dir",
                ...
            ],
            ...
        },
        ...
    }
    

    This is assuming that your tsconfig.json file is in the same directory level as node_modules. You'll need to change the ./node_modules/@types relative path specified in typeRoots otherwise.