Skip to content

Question: type definitions for dual packages #41296

@xiaoxiangmoe

Description

@xiaoxiangmoe

Search Terms

esm, commonjs, dual packages

Question

foo/package.json
    foo/index.mjs   (this is ESM)
    foo/index.cjs  (this is CJS)
    foo/index.d.ts (this is type definitions)

for example, index.mjs and index.cjs has function declare function arch(): 'x64' | 'x86';

For cjs, index.d.ts should be

declare function arch(): 'x64' | 'x86';
export = arch;

For mjs, index.d.ts should be

declare function arch(): 'x64' | 'x86';
export default arch;

For both, index.d.ts should be

declare function arch(): 'x64' | 'x86';
 

declare const Arch: typeof arch & {
  readonly default: typeof arch;
}
export = Arch;

But If I use export = Arch;

import arch = require('arch');

arch.default() // This has no error. But `arch.default` is not exists.

Metadata

Metadata

Assignees

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions