microsoft / microsoft/TypeScript

Add API to query if SourceFile originated from typeRoots lookup

Open
#26,684 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

This proposes to add an API Program#isSourceFileFromTypeRoots that is similar to Program#isSourceFileFromExternalLibrary but for typeRoots.

Currently the only way to determine if a SourceFile comes from typeRoots is to use ts.getEffectiveTypeRoots and check if a given SourceFile#fileName starts with any of the paths.

That works if there are no symlinks. With symlinks one needs to use realpath on all of the typeRoots before comparing to fileName as that is already a realpath.
And even that doesn't cover cases where a subdirectory (like node_modules/@types/foo) or an individual file (node_modules/@types/foo/index.d.ts) is a symlink.

Related: https://github.com/fimbullinter/wotan/issues/387

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 reading Program#isSourceFileFromExternalLibrary, ts.getEffectiveTypeRoots, and SourceFile#fileName handling. Trace how typeRoots and symlinked directories or files are represented, then add the proposed Program#isSourceFileFromTypeRoots API with coverage for those cases. Done means callers no longer need to compare paths themselves.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.