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.

Glob support for per pattern tsconfig configuration

See original GitHub issue

It’s common to have different configurations for files in the same directory with different name patterns. The most common is file.ts and file.test.ts. We usually have different configurations for test files. For instance the global "jest" type is needed in test files but not in source files.

To separate configuration for test and source we can have two separate tsconfig.json files which "include" only test and source:

// tsconfig.json

{
  "exclude": ["*.test.ts"]
} 

Exclude glob is pending https://github.com/Microsoft/TypeScript/issues/10202

// test.tsconfig.json

{
  "include": ["*.test.ts"],
  "compilerOptions": {
    "types": ["jest"]
  }
} 

But this is not optimal for IDEs and other tsc users.

Glob based tsconfig.json

I’m proposing a glob based tsconfig.json which has different config per glob pattern:

[
        {
                // Shared config
                "compilerOptions": {}
        },
        {
                "include": ["*.test.ts"],
                "compilerOptions": {
                        "lib": ["jest"]
                }
        }
]

Changes to tsconfig.json

  • It can be an array of configurations
  • Each item in the array can specify include or exclude for fine grained compiler options

Resolving compiler option per file pattern

TODO

Conflicting exclude and include pattern between compiler options

TODO

this way one tsconfig.json can serve for all files with different configs per pattern

TypeScript Version: 2.7 Search Terms:

  • TSConfig
  • Glob
  • Pattern

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:28
  • Comments:6

github_iconTop GitHub Comments

2reactions
lo1tumacommented, Jun 4, 2019

Unfortunately project references don’t solve this yet, because for project references to work you need a very specific folder structure. It doesn’t work with glob patterns.

1reaction
karlismelderiscommented, Oct 8, 2021

I would love to see this in production.

We found some unhealthy code in production where const [a] = data was attempted on possibly empty arrays. We tried to enable noUncheckedIndexedAccess (https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess)

But… Due to abnormal amount of TS errors from our test files (**/*.test.ts - like every other Jest case) enabling option would take way to much time so we couldn’t get our production code covered.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Reference - Docs on every TSConfig option
Specifies an array of filenames or patterns to include in the program. These filenames are resolved relative to the directory containing the tsconfig....
Read more >
Glob support in tsconfig.json - 《TypeScript 3.7 Document》
Glob -like file patterns are supported two properties "include" and "exclude" . Example. 复制代码. {; "compilerOptions": ...
Read more >
tsconfig-glob - npm
A lightweight npm package + cli that allows you to specify glob patterns for tsconfig files. Latest version: 0.4.3, last published: 7 years ......
Read more >
User and Workspace Settings - Visual Studio Code
The Search bar remembers your settings search queries and supports ... autoReveal": true, // Configure glob patterns for excluding files and folders from ......
Read more >
codegen.ts file - GraphQL Code Generator
Here are the supported options that you can define in the config file (see ... documents - Array of paths or glob patterns...
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