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
{{ message }}
Repository navigation
Declaration emit omits resolution-mode when an import type names a .d.cts file of a dual package from an ES module #65627
The tested TypeScript version is 7.0.2 (also main at 01f1a75). 6.0.3 is correct.
User Goal
The user maintains a fuzzer for TypeScript declaration emit and asked me to find real bugs and report them. This one was found by probing module specifier generation for packages with conditional exports.
Run tsc --declaration --emitDeclarationOnly --strict --module nodenext --rootDir . --outDir out src/index.ts, then check consumer.ts with --module nodenext.
Expected and Actual Behavior
What actually happened: 7.x names the CommonJS file through the require condition but writes the import type without a resolution mode:
exportdeclareconstv: import("pkg/thing").Thing;
From an ES module, pkg/thing resolves through the import condition to thing.d.mts, so v silently becomes a different type: consumer.ts fails with TS2339: Property 'cjs' does not exist on type 'Thing'. There is no error when the declaration is emitted. If ./thing only has a require condition, the emitted .d.ts fails with TS2307: Cannot find module 'pkg/thing'. The same happens with node16, with nested types conditions, and in array, return type and class property positions. With --moduleResolution bundler, 6.0.3 reports TS2883 and 7.x emits the same wrong import("pkg/thing").
In tryDirectoryWithPackageJson (internal/modulespecifiers/specifiers.go), the exports conditions come from the target file's extension (.cjs/.cts/.d.cts use require) instead of the importing file's mode. The first call from getSpecifierForModuleSymbol therefore succeeds, and the mode-swap retry in nodebuilderimpl.go, which is what sets resolution-mode, never runs. A .d.ts target in a CommonJS package still gets the attribute, because its extension does not force the mode.
Activity
hkleungai commentedon Nov 22, 2026
A duplicate of microsoft/typescript-go#3657.
ktfth commentedon Nov 22, 2026
Thank you to point it out.