You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This changed in commit or PR [api] Provide module resolution overrides聽#64299, which added module resolution overrides to the API. I reproduced it with typescript@7.1.0-dev.20261004.1 (built from main at 50d70a3) and typescript@7.1.0-dev.20261003.1, with the synchronous API on linux-x64.
A static entry and a callback that both return the default resolution of ./b.ts make the checker report TS2876 on the import:
default answer resolvedUsingTsExtension: true
no resolver: []
static entry repeating it: [
'TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "./b.ts".'
]
callback passing it through: [
'TS2876: This relative import path is unsafe to rewrite because it looks like a file name, but actually resolves to "./b.ts".'
]
馃檪 Expected behavior
A resolver that returns the default resolution gives the same result as no resolver, with no TS2876.
Additional information about the issue
Impact: a tool that answers module resolution itself, which #64299 added for resolving workspace packages from source, shows a false TS2876 on every ./x.ts import in a project that uses rewriteRelativeImportExtensions, where tsc reports none.
StaticModuleResolution carries resolvedFileName, originalPath and packageId, and staticModuleResolutionToResolvedModule builds the module.ResolvedModule from those alone, so ResolvedUsingTsExtension is always false for a static entry and for a callback result. Under rewriteRelativeImportExtensions, the checker then reports TS2876 on a ./x.ts import that such a resolver answers. The fix I propose adds an optional resolvedUsingTsExtension to StaticModuleResolution and copies it into the resolved module.
I met this while building deadset-ts, the TypeScript analyzer of deadset, on the TypeScript 7 API. A pull request with the fix and a test follows.
馃攷 Search Terms
createModuleResolver, moduleResolutions, resolveModuleName callback, StaticModuleResolution, resolvedUsingTsExtension, rewriteRelativeImportExtensions, TS2876
馃晽 Version & Regression Information
typescript@7.1.0-dev.20261004.1(built frommainat 50d70a3) andtypescript@7.1.0-dev.20261003.1, with the synchronous API on linux-x64.馃捇 Code
馃檨 Actual behavior
A static entry and a callback that both return the default resolution of
./b.tsmake the checker report TS2876 on the import:馃檪 Expected behavior
A resolver that returns the default resolution gives the same result as no resolver, with no TS2876.
Additional information about the issue
Impact: a tool that answers module resolution itself, which #64299 added for resolving workspace packages from source, shows a false TS2876 on every
./x.tsimport in a project that usesrewriteRelativeImportExtensions, wheretscreports none.StaticModuleResolutioncarriesresolvedFileName,originalPathandpackageId, andstaticModuleResolutionToResolvedModulebuilds themodule.ResolvedModulefrom those alone, soResolvedUsingTsExtensionis always false for a static entry and for a callback result. UnderrewriteRelativeImportExtensions, the checker then reports TS2876 on a./x.tsimport that such a resolver answers. The fix I propose adds an optionalresolvedUsingTsExtensiontoStaticModuleResolutionand copies it into the resolved module.I met this while building deadset-ts, the TypeScript analyzer of deadset, on the TypeScript 7 API. A pull request with the fix and a test follows.