Skip to content

CJS interop declaration transform produces invalid .d.cts when file has type-only named exports #66

@jandolezal71

Description

@jandolezal71

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 defaultexport = 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions