testing-library / testing-library/user-event
Incorrect types are causing errors when using TypeScript with `moduleResolution` set to `node16` or `nodenext`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 258
- PR merge metrics
- No merged PRs in 30d
Description
@testing-library/reactversion: not relevant- Testing Framework and version: not relevant
- DOM Environment: not relevant
Relevant code or config:
See reproduction
What happened:
Property 'setup' does not exist on type 'typeof import("file:///node_modules/@testing-library/user-event/dist/types/index")'.
Reproduction:
Problem description:
Incorrect types are causing errors when using TypeScript with moduleResolution set to node16 or nodenext.
This is confirmed by Are The Types Wrong, which shows that "Import resolved to a CommonJS type declaration file, but an ESM JavaScript file.": https://arethetypeswrong.github.io/?p=%40testing-library%2Fuser-event%4014.4.3
Suggested solution:
Rather than shipping one set of types, separately from the codebase, ship types alongside of cjs and esm code.
Not sure if this will help, but @testing-library/react does not have this problem:
https://arethetypeswrong.github.io/?p=%40testing-library%2Freact%4014.0.0
And I can confirm that IRL.
Contributor guide
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.
Research direction
Start with the linked TypeScript playground reproduction and inspect the published CommonJS/ESM package and its type declarations. Compare the package layout with @testing-library/react and verify the result using Are the Types Wrong; done means TypeScript with moduleResolution set to node16 or nodenext no longer reports the incorrect type error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100