types: `export default` is wrong under moduleResolution NodeNext
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- developer-experience, tooling
Research direction
Start with types/index.d.ts and inspect its export declaration alongside package.json's types, import, and require entries. Verify the declaration with a minimal TypeScript consumer using moduleResolution NodeNext, checking both new PptxGenJS() and PptxGenJS.TableCell. Done means those examples typecheck while the package continues to describe its published builds.
Written by the indexing model from the issue text.
Description
Category
- Bug
- Enhancement
Version
- pptxgenjs 4.0.1 (also current
mastertypes/index.d.ts) - TypeScript
module/moduleResolution:NodeNext - Consumer package is native ESM (
"type": "module")
Observed behavior
types/index.d.ts ships:
export as namespace PptxGenJS
export default PptxGenJS
declare class PptxGenJS { … }
declare namespace PptxGenJS { … }
The npm package is not "type": "module". package.json exposes both builds:
"main": "dist/pptxgen.cjs.js",
"module": "dist/pptxgen.es.js",
"exports": {
"types": "./types/index.d.ts",
"import": "./dist/pptxgen.es.js",
"require": "./dist/pptxgen.cjs.js"
}
Under moduleResolution: NodeNext, TypeScript reads that single .d.ts as a CommonJS module. In that mode export default PptxGenJS means module.exports.default, which neither published build has (the CJS build is module.exports = PptxGenJS).
That makes both of these fail typechecking:
import PptxGenJS from 'pptxgenjs';
const pptx = new PptxGenJS(); // not constructable
const cell: PptxGenJS.TableCell = …; // namespace merge is also wrong
This is a known class of CJS + export default mismatch (see SO: pptxgenjs is not constructable).
Expected behavior
The declarations should describe the actual CJS export shape so new PptxGenJS() and PptxGenJS.TableCell typecheck under NodeNext, while still supporting the ESM build.
Changing the types line to export = PptxGenJS matches module.exports = PptxGenJS and keeps the class/namespace merge. That is the workaround we are using via a package patch today.
Suggested fix
In types/index.d.ts:
-export default PptxGenJS
+export = PptxGenJS
Happy to open a PR if that direction looks right. Once this ships we can drop the downstream patch.
- Dominant language
- TypeScript
- Stars
- 6.2k
- Forks
- 953
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from gitbrent/PptxGenJS
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
All issues in gitbrent/PptxGenJS
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100