microsoft / microsoft/TypeScript

Allow specifying regex for module alias paths

Open
#27,298 4 comments 15 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
2d 4h
Merged PRs (30d)
132

Description

Search Terms

alias regex, import alias regex, regex

Suggestion

Allow specifying path alias using regex with match replacement.

Use Cases

Using path alias when they are automatically generated by custom script in webpack or more fine grained control over path resolution with more complex directories. Current approach does not allow having dynamic alias which consists of 1 or more intermediate path variables.

Examples

Having this path: <projectDir>/modules/Users/resources/js should be resolvable with a regex, e.g.

RegEx: ^#(.+?)\/(.*)$
Resolve: ./modules/$1/resources/js/$2

So that importing from '#Users/manage' would be resolved to modules/Users/resources/js/manage(.ts|.js) etc..

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. new expression-level syntax)

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

No source file or test is named. Start by locating TypeScript's existing path-alias and module-resolution handling, then compare it with the regex capture and replacement examples in the issue. Add coverage for resolving '#Users/manage' while preserving current alias behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, webpack
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.