fix(types): add typesVersions to support CommonJS imports in TypeScript#301
fix(types): add typesVersions to support CommonJS imports in TypeScript#301jbrun-hulo wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Confirmed the fix solves a real problem — reproduced the TS2307: Cannot find module 'n2words/en-US' error in a sandbox TS project with moduleResolution: "node" against main, and verified this patch clears it.
One thing worth tightening before merge: the catch-all "*": ["./src/*.d.ts"] mapping also makes n2words/utils/* type-check, even though exports explicitly walls it off with "./utils/*": null. At runtime the import still fails with ERR_PACKAGE_PATH_NOT_EXPORTED, so consumers get phantom types — TS green-lights an import that explodes when the code runs.
Suggested tighter pattern that preserves the existing privacy boundary:
"typesVersions": {
"*": {
"utils/*": [],
"*": ["./src/*.d.ts"]
}
}The more-specific utils/* key matches first; an empty array means no candidates, so TS falls through and errors — matching the exports behavior. I verified locally that:
n2words/en-US→ resolves (catch-all*matches)n2words/utils/parse-cardinal→ TS error (matches the runtime block)
fb088a6 to
20a24f9
Compare
Pull Request
What does this do?
Add typesVersions field to package.json to map type definitions, enabling proper CommonJS module resolution in TypeScript projects such as NestJS v10.
Without this, TypeScript fails to resolve types when importing n2words via require() or with moduleResolution set to Node.
Related Issue
Checklist
npm test)npm run lint)Adding a new language? (click to expand)
Recommended: Use the scaffolding tool to generate all files automatically:
Manual setup: If not using the scaffolding tool, ensure you have:
src/<code>.jsexportingtoCardinal(),toOrdinal(), and/ortoCurrency()test/fixtures/<code>.jswith matching exportsnpm test)Breaking change? (click to expand)
Describe what breaks and how users should update: