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.

disable certain global types for specific files, or specify type roots for specific files.

See original GitHub issue

This continues some ideas from https://github.com/microsoft/TypeScript/issues/17042, which was closed by @microsoft (for inactivity, I think?).

Search Terms

disable certain global types for specific files, specific type roots for certain files

Suggestion

Ability to specify which @types (or in general, which specified typeRoots) apply to which files in a project.

Use Cases

My project’s src folder contains both .ts and .test.ts files, and I’d like an easy way for globals like describe to be defined only for the .test.ts files.

Examples

Not sure, but maybe some sort of new options in tsconfig.json for specifying which types items, lib items, or typeRoots items apply to which files.

This would be a beneficial feature because various editors (VS Code aside) look for a tsconfig.json file at the root of a project, and at the moment the only way to make types work in all files is to just provides all types for all files, which is undesirable because describe is not a function that is available in source files (as an example).

Example configuration: maybe instead of a typeRoots array, it can be an object like:

"typeRoots": {
  "./src/**/*.test.ts": ["../path/to/test/types"], // test-only types
  "./src/**/*.ts": ["../path/to/@types"] // other types other files
}

Or something. That’s just an example to get the idea rolling.

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:135
  • Comments:25 (2 by maintainers)

github_iconTop GitHub Comments

18reactions
aleclarsoncommented, Nov 12, 2020

Can we get an official response on this?

It’s very annoying when I’m working on a browser-related project, and @types/node leaks in because a package in devDependencies depends on it.

I tried the “solution project” approach described in #37239 without success.

Related: #22331

12reactions
luxalpacommented, Jan 29, 2022

I don’t have any suggestions, but another use case:

I want to use Storybook which internally adds @types/react with a vue.js project. Unfortunately the React types are overriding / merging the vue shims, therefore Vue’s JSX syntax can not be used anymore 😦 Not sure what the solution to that problem is?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global types in typescript - Stack Overflow
Let me know if it doesn't work and I will remove this answer). Create a definition file in a suitable folder. I will...
Read more >
TSConfig Reference - Docs on every TSConfig option
This feature differs from typeRoots in that it is about specifying only the exact types you want included, whereas typeRoots supports saying you...
Read more >
The mypy configuration file - mypy 0.991 documentation
Some of the config options may be set either globally (in the [mypy] section) ... To use this config file, place it at...
Read more >
Restrictions and limitations in OneDrive and SharePoint
If you're a global admin or SharePoint admin in Microsoft 365, ... If you are a OneDrive for work or school user, some...
Read more >
Content roots | IntelliJ IDEA Documentation - JetBrains
Java files and binaries cannot be excluded. If you don't need specific files, but you don't want to completely remove them, you can...
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