IssueRaiser

Add option to include default typeRoots when overriding typeRoots

## Search Terms default typeRoots ## Suggestion By default, when `typeRoots` is unspecified, TypeScript looks for `node_modules/@types` in the project's directory and all ancestor directories, similar to Node's module resolution algorithm. This is covered in [the tsconfig.json docs](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) and is implemented [here](https://github.com/Microsoft/TypeScript/blob/b534fb4849eca0a792199fb6c0cb8849fece1cfd/src/compiler/moduleNameResolver.ts#L240-L260). When specifying `typeRoots` in tsconfig.json, this overrides the default `typeRoots` entirely. You can include `"node_modules/@types"` in your `typeRoots` array, but that does not include ancestor directories. This is a feature request to provide a way, such as a new option, to include the default type roots in addition to the overridden values. ## Use Cases The primary use case is within a repository using Yarn workspaces. Yarn hoists npm packages to the workspace root. This means you can end up with a directory hierarchy like this: ``` . ├── node_modules │   └── @types │   └── dependency └── packages └── example ├── example.ts ├── package.json └── tsconfig.json ``` If `tsconfig.json` wants to include `node_modules/@types` in the workspace root (in addition to other type declaration directories specified in `typeRoots`), it needs to look like this: ``` { "compilerOptions": { "typeRoots": ["../../node_modules/@types", ...] } } `

Posted by ide on Apr 11, 2019, 1:47 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments

github (Software)

Add option to include default typeRoots when overriding typeRoots

ideApr 11, 2019, 1:47 AM

## Search Terms default typeRoots ## Suggestion By default, when `typeRoots` is unspecified, TypeScript looks for `node_modules/@types` in the project's directory and all ancestor directories, similar to Node's module resolution algorithm. This is covered in [the tsconfig.json docs](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) and is implemented [here](https://github.com/Microsoft/TypeScript/blob/b534fb4849eca0a792199fb6c0cb8849fece1cfd/src/compiler/moduleNameResolver.ts#L240-L260). When specifying `typeRoots` in tsconfig.json, this overrides the default `typeRoots` entirely. You can include `"node_modules/@types"` in your `typeRoots` array, but that does not include ancestor directories. This is a feature request to provide a way, such as a new option, to include the default type roots in addition to the overridden values. ## Use Cases The primary use case is within a repository using Yarn workspaces. Yarn hoists npm packages to the workspace root. This means you can end up with a directory hierarchy like this: ``` . ├── node_modules │   └── @types │   └── dependency └── packages └── example ├── example.ts ├── package.json └── tsconfig.json ``` If `tsconfig.json` wants to include `node_modules/@types` in the workspace root (in addition to other type declaration directories specified in `typeRoots`), it needs to look like this: ``` { "compilerOptions": { "typeRoots": ["../../node_modules/@types", ...] } } `

Comments (0)

No comments yet. Start the discussion.

Comment on this issue