CJS interop declaration transform produces invalid .d.cts when file has type-only named exports
When a source file has type-only named exports (export type, export interface, export enum) alongside export default, the CJS interop declaration transformer rewrites export default → export = but leaves the type-only exports with their export keyword. This produces an invalid .d.cts:
export type Foo = { bar: string };
export = MyLib; // TS2309: An export assignment cannot be used in a module with other exported elements. Consumers with skipLibCheck: false see TS2309 on every such file.
Reproduction
Any source file with this common pattern:
export type Foo = { bar: string };
export interface Bar { qux: number }
type MyLib = { (input: Foo): Bar };
export default MyLib;
Expected behavior
The .d.cts should either:
Keep export default (valid when esModuleInterop is enabled), or
Not apply the CJS interop transform at all for files with type-only exports
Actual behavior
The .d.cts has export = mixed with export type / export interface, which is invalid TypeScript.
CJS interop declaration transform produces invalid
.d.ctswhen file has type-only named exportsWhen a source file has type-only named exports (
export type,export interface,export enum) alongsideexport default, the CJS interop declaration transformer rewritesexport default→export =but leaves the type-only exports with theirexportkeyword. This produces an invalid.d.cts:Reproduction
Any source file with this common pattern:
Expected behavior
The .d.cts should either:
Keep export default (valid when esModuleInterop is enabled), or
Not apply the CJS interop transform at all for files with type-only exports
Actual behavior
The .d.cts has export = mixed with export type / export interface, which is invalid TypeScript.