microsoft / microsoft/TypeScript

Improve module resolution using "paths" of "tsconfig.json" file

Open
#60,133 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔍 Search Terms

Today the "paths" property only accepts the asterisk as a wildcard character, which means it is necessary to keep redeclaring other modules when they are in subdirectories, example:

{
  "compilerOptions": {
    "paths": {
      "libs/async": ["libs/async/src"],
      "libs/async/*": ["libs/async/src/*"],
      "libs/crypto": ["libs/crypto/src"],
      "libs/crypto/*": ["libs/crypto/src/*"],
      "libs/database": ["libs/database/src"],
      "libs/database/*": ["libs/database/src/*"],
      "libs/domain": ["libs/domain/src"],
      "libs/domain/*": ["libs/domain/src/*"],
      "libs/logger": ["libs/logger/src"],
      "libs/logger/*": ["libs/logger/src/*"],
    }
  }
}

Wouldn't it be interesting to accept other characters as it happens with regex? Example:

{
  "compilerOptions": {
    "paths": {
      "libs/$1": ["libs/$1/src"],
      "libs/$1/*": ["libs/$1/src/*"],
    }
  }
}

This would make TypeScript resolution more dynamic, making it easier to set up monorepos.

✅ Viability Checklist
⭐ Suggestion

Add more wildcards to "paths" property in tsconfig.json, like dynamic directory names ($0 for example), or create a way to use JS/TS to build and return the tsconfig object, with this I can trace the workspace folder extracting all directores needed.

📃 Motivating Example

Normally i'm use only one or 2 paths in tsconfig but I had started to work with NestJS using workspaces and each new app or library need to be added into a new element

💻 Use Cases
  1. What do you want to use this for?

Any project using workspaces and having lots of sub packages

  1. What shortcomings exist with current approaches?

Today is required to declare every directory manually every time when a new app or lib are created in NestJS workspace

  1. What workarounds are you using in the meantime?

Today i need to make every change manually...

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

The request concerns the paths option in tsconfig.json, but it names no compiler source file, test, or entry point. Start by locating the existing paths handling and its module-resolution tests, then define the supported substitution syntax and compatibility behavior. Done means workspace-style paths can avoid repeated declarations and the behavior is covered by tests.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.