microsoft / microsoft/TypeScript

Compiler API to resolve path from ImportDeclaration

Open
#28,276 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi there, since TS supports paths in tsconfig.json, is there an API in the compiler (Program, CompilerHost or something) to programmatically resolve real path of an import?

I wrote this transformer https://github.com/longlho/ts-transform-css-modules and it's tripping up on paths that are aliased in tsconfig.json, e.g:

import * as css from 'alias/foo.css'

tsconfig.json

{
  "compilerOptions": {
    "paths": {
      "alias/*": "../../../some_location/*"
    }
  }
}

I can try to manually reconstruct TS resolver but rather not to.

Thanks!

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 by reviewing the compiler's Program and CompilerHost APIs alongside the paths configuration behavior described in the issue. Compare the requested ImportDeclaration resolution with the existing TypeScript resolver, using the linked CSS-modules transformer as context. Done means the compiler exposes a supported way to resolve aliased import paths without manually reconstructing resolution.

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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.