Implement resolveFromTypeRoot fallback in module resolution#3306
Draft
Implement resolveFromTypeRoot fallback in module resolution#3306
resolveFromTypeRoot fallback in module resolution#3306Conversation
…oots When a module cannot be found via regular node_modules resolution, fall back to looking in the configured typeRoots (from tsconfig.json). This implements the resolveFromTypeRoot function that was previously commented out with '// !!!'. This fixes the issue where 'import gql from "graphql-tag"' fails to resolve when the type declarations are only available in a custom typeRoots directory (e.g. '../assets/node_modules/@types'). The fix also updates test baselines for three tests: - moduleResolutionAsTypeReferenceDirective.ts: No longer errors, a2 is now typed as number - moduleResolutionAsTypeReferenceDirectiveAmbient.ts: Trace updated - moduleResolutionAsTypeReferenceDirectiveScoped.ts: Fewer errors, matching TS reference Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/63d20d26-9900-496c-8ccd-72f81619aa4e Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/63d20d26-9900-496c-8ccd-72f81619aa4e Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix VSCode extension issue with typeRoots
Implement Apr 1, 2026
resolveFromTypeRoot fallback in module resolution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
typeRootspoints to a non-ancestor directory (e.g.../assets/node_modules/@types), imports of packages whose types live exclusively in those custom roots failed withTS2307: Cannot find module— even thoughtscresolves them correctly.Root cause
TypeScript's node-like module resolver falls back to
resolveFromTypeRootafter exhaustingnode_modulestraversal. In the Go port, this call was stubbed out:Changes
internal/module/resolver.go— ImplementsresolveFromTypeRootonresolutionState, mirroring the TypeScript original: iteratescompilerOptions.TypeRoots, attemptsloadModuleFromFilethenloadNodeModuleFromDirectorywithextensionsDeclaration, and attachespackageIdfrom the nearestpackage.json. Only activates whenTypeRootsis explicitly configured (not the default computed roots). Uncomments the call site inresolveNodeLikeWorker.Baseline impact
Three compiler test baselines now match the TypeScript reference exactly:
moduleResolutionAsTypeReferenceDirectiveTS2307error,a2: anya2: numbermoduleResolutionAsTypeReferenceDirectiveScopedmoduleResolutionAsTypeReferenceDirectiveAmbient