-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect types are causing errors when using TypeScript with moduleResolution
set to node16
or nodenext
#1146
Incorrect types are causing errors when using TypeScript with moduleResolution
set to node16
or nodenext
#1146
Comments
- `compilerOptions.skipLibCheck` is set to `true` to get around Vite issues. See vitejs/vite#11552 for details. - `exclude` is set to `["src/**/*.spec.ts", "src/**/*.spec.tsx"]` to get around @testing-library/user-event issues. See https://github.com/testing-library/react-testing-library/issues/1224 for details.
Just spreading awareness, typescript-eslint has dropped node10 support meaning anyone using typescript-eslint@6 or above (which only supports node16 and above module resolution) and @testing-library/user-event (which only supports node10 resolution due to this bug) are incompatible with one another. @wojtekmaj FYI there seems to be a bug in the typescript playground (not the link you sent but the playground itself) preventing your reproduction from loading correctly. Some additional steps:
You should now see the error originally mentioned |
For anyone looking for a workaround until this is fixed, you can add this to the top of your test file: import userEventDefault from '@testing-library/user-event'
// https://github.com/testing-library/user-event/issues/1146
const userEvent =
userEventDefault as unknown as (typeof userEventDefault)['default']
const user = userEvent.setup() // <-- types! |
This workaround worked unblocked me and it should be forward compatible whenever it gets fixed.
|
I just pushed and published a quick fix in import { userEvent } from '@testing-library/user-event' And this won't have the same problems. We keep the default export for backward compatibility and there's still a bit of an issue with the types masquerading as ESM, but at least this should unblock most folks. Unfortunately I don't have any more time to improve things more officially. |
|
I have the same error as @sysmat when running StoryBook with version 14.5.0 of the @testing-library/user-event library. I will try to provide more details about that issue. |
Hey @kentcdodds as others have stated, this release ended up having unfortunate side effects. I created an issue with reproduction steps here: #1160 @michaelperrin (and any other Storybook users): I just released v0.2.1 with a temporary fix for this issue. |
There's a bug in 14.3.0 that causes types to not be resolved, testing-library/user-event#1146 (comment) provides a work around.
There's a bug in 14.3.0 that causes types to not be resolved, testing-library/user-event#1146 (comment) provides a work around.
There's a bug in 14.3.0 that causes types to not be resolved, testing-library/user-event#1146 (comment) provides a work around.
There's a bug in 14.3.0 that causes types to not be resolved, testing-library/user-event#1146 (comment) provides a work around.
I still can't make it work using 14.5.0. Anyone? |
This workaround worked for me #1146 (comment) |
@testing-library/react
version: not relevantRelevant code or config:
See reproduction
What happened:
Reproduction:
https://www.typescriptlang.org/play?target=99&moduleResolution=99&module=100&jsx=0#code/JYWwDg9gTgLgBAVwM4FMoFEBuKB28BmUEIcA5AAIwpIzA4DmAtADbABGUAhlAJ4D0yNIxTY8pANwAoSYIyiYAOlQwEYABQBKcUA
Problem description:
Incorrect types are causing errors when using TypeScript with
moduleResolution
set tonode16
ornodenext
.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.
The text was updated successfully, but these errors were encountered: