question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add option to include default typeRoots when overriding typeRoots

See original GitHub issue

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 and is implemented here.

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", ...]
  }
}

Examples

This feature request is a quality-of-life improvement to instead allow for:

{
  "compilerOptions": {
    "typeRoots": [...],
    "includeDefaultTypeRoots": true
  }
}

The default value of this option would be false and would not be a breaking change.

Checklist

My suggestion meets these guidelines:

  • This wouldn’t be a breaking change in existing TypeScript/JavaScript code
  • This wouldn’t change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript’s Design Goals.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:189
  • Comments:21

github_iconTop GitHub Comments

8reactions
jonrimmercommented, Mar 3, 2021

I have a fix for this on my fork, but I cannot PR it due to this issue not being on the backlog: https://github.com/jonrimmer/TypeScript/tree/include-default-type-roots-option

@RyanCavanaugh What feedback are you waiting for on this issue?

7reactions
kutsancommented, Sep 22, 2022

Can you please stop typing no value comments like “+1”? It certainly doesn’t help the development process of this issue and you’re sending useless notifications, emails to people who subscribed to this thread and waiting actual feedback.

Use 👍🏻 reaction instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Reference - Docs on every TSConfig option
# Type Roots - typeRoots. By default all visible ” @types ” packages are included in your compilation. Packages in node_modules/@types of ...
Read more >
TypeScript config typeRoots and types not working properly
When you have this option set, by not including a module in the types array it: Will not add globals to your project...
Read more >
tsconfig.json - TypeScript - JavaScript that scales.
Compiler options specified on the command line override those specified in the tsconfig.json file. @types , typeRoots and types #. By default all...
Read more >
ts-node - npm
Fortunately, there are other ways to include them in typechecking. For global definitions, you can use the typeRoots compiler option. This ...
Read more >
Setup - Nuxt TypeScript
All you need to do is add @nuxt/typescript-build to your buildModules in ... You can use an Object to override plugin options or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found