microsoft / microsoft/TypeScript

Glob support for per pattern tsconfig configuration

Open
#21,951 6 comments 31 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed tsconfig.json array format and the unresolved sections on resolving compiler options per file pattern and conflicting include/exclude patterns. The issue names no source files or tests, so first define the configuration semantics and conflict behavior before identifying the relevant implementation and test entry points.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.