Fix CommonJS type export so the default import resolves under node16/nodenext - #47
Merged
Merged
Conversation
`index.js` is CommonJS (`module.exports = fn`), but `index.d.ts` typed it as an ES `export default` alongside an empty `declare module 'robots-parser';`. The empty ambient declaration types the whole module as `any`, so the `Robot` interface is never actually applied. And `export default` does not describe `module.exports = fn` under `moduleResolution: node16`/`nodenext`. Replace both with `export = robotsParser`, matching the runtime. No code changes. Since the module currently resolves to `any`, this only adds accurate types and breaks nothing that type-checks today.
samclarke
approved these changes
Aug 7, 2026
Owner
|
Thanks for the PR! 👍 Looks to be the right way based on the TypeScript docs. Merged, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
index.d.tsdoesn't match the runtime.index.jsis CommonJS:but the types say:
declare module 'robots-parser';has an empty body, so TypeScript types the whole module asany. TheRobotinterface right below it is never applied to what you import — every consumer getsanytoday.export defaultdoesn't describemodule.exports = fn. UndermoduleResolution: node16/nodenext(the modern default), the default import doesn't line up with the CommonJS export.Fix
Describe the actual CommonJS shape. One file, no runtime change:
Why this doesn't need a major version bump
Because
declare module 'robots-parser';currently resolves the module toany, no one has working type-checking against this package today. This PR adds accurate types over what was effectively untyped — it can't break a type contract that never existed.Every import style that works today keeps working:
import r from 'robots-parser'(withesModuleInterop, ornode16/nodenext)anyimport r = require('robots-parser')anyconst r = require('robots-parser')The only case that changes is
import r from 'robots-parser'withesModuleInterop: falseon classic module resolution — which is already broken at runtime (module.exportshas no.default, sorisundefined). After this change that becomes a clear compile error pointing toimport r = require('robots-parser'), instead of failing silently.Strictly better types, nothing that currently type-checks breaks → patch release.