-
Notifications
You must be signed in to change notification settings - Fork 248
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) |
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [@testing-library/user-event](https://github.com/testing-library/user-event) | dependencies | minor | [`14.1.1` -> `14.5.2`](https://renovatebot.com/diffs/npm/@testing-library%2fuser-event/14.1.1/14.5.2) | --- ### Release Notes <details> <summary>testing-library/user-event (@​testing-library/user-event)</summary> ### [`v14.5.2`](https://github.com/testing-library/user-event/releases/tag/v14.5.2) [Compare Source](testing-library/user-event@v14.5.1...v14.5.2) ##### Bug Fixes - remove interop and deep DTL imports ([6a3c896](testing-library/user-event@6a3c896)) ### [`v14.5.1`](https://github.com/testing-library/user-event/releases/tag/v14.5.1) [Compare Source](testing-library/user-event@v14.5.0...v14.5.1) ##### Bug Fixes - incorrect default import from [@​testing-library/dom](https://github.com/testing-library/dom) ([#​1162](testing-library/user-event#1162)) ([d7483f0](testing-library/user-event@d7483f0)) ### [`v14.5.0`](https://github.com/testing-library/user-event/releases/tag/v14.5.0) [Compare Source](testing-library/user-event@v14.4.3...v14.5.0) ##### Bug Fixes - **exports:** add a named export for userEvent ([4019cee](testing-library/user-event@4019cee)), closes [#​1146](testing-library/user-event#1146) ##### Features - **types:** Add additional type exports for UserEvent & Options ([#​1112](testing-library/user-event#1112)) ([da00e8d](testing-library/user-event@da00e8d)) ### [`v14.4.3`](https://github.com/testing-library/user-event/releases/tag/v14.4.3) [Compare Source](testing-library/user-event@v14.4.2...v14.4.3) ##### Bug Fixes - **build:** add `types` field in `exports` ([#​1029](testing-library/user-event#1029)) ([5bed8c6](testing-library/user-event@5bed8c6)) - remove circular dependencies ([#​1027](testing-library/user-event#1027)) ([1aa2027](testing-library/user-event@1aa2027)) ### [`v14.4.2`](https://github.com/testing-library/user-event/releases/tag/v14.4.2) [Compare Source](testing-library/user-event@v14.4.1...v14.4.2) ##### Bug Fixes - **build:** add `exports` field ([#​1022](testing-library/user-event#1022)) ([7839e29](testing-library/user-event@7839e29)) ### [`v14.4.1`](https://github.com/testing-library/user-event/releases/tag/v14.4.1) [Compare Source](testing-library/user-event@v14.4.0...v14.4.1) ##### Bug Fixes - **build:** transpile to es2019 syntax ([#​1016](testing-library/user-event#1016)) ([4291cb8](testing-library/user-event@4291cb8)) ### [`v14.4.0`](https://github.com/testing-library/user-event/releases/tag/v14.4.0) [Compare Source](testing-library/user-event@v14.3.0...v14.4.0) ##### Features - **pointer**: dispatch `auxclick` events ([#​1003](testing-library/user-event#1003)) ([2852509](testing-library/user-event@2852509)) ##### Bug Fixes - **event:** be robust against incomplete event implementations ([#​1009](testing-library/user-event#1009)) ([289828b](testing-library/user-event@289828b)) - **upload:** be robust against missing FileList implementation ([#​1007](testing-library/user-event#1007)) ([a46b4d7](testing-library/user-event@a46b4d7)) - **keyboard**: switch modifier state of lock keys on the correct event ([#​1003](testing-library/user-event#1003)) ([2852509](testing-library/user-event@2852509)) - **keyboard**: remove platform-specific additional key events for `Control` on `AltGraph` ([#​1003](testing-library/user-event#1003)) ([2852509](testing-library/user-event@2852509)) - **pointer**: dispatch `contextmenu` events with `detail: 0` ([#​1003](testing-library/user-event#1003)) ([2852509](testing-library/user-event@2852509)) - **pointer**: always set `PointerEvent.isPrimary` ([#​1003](testing-library/user-event#1003)) ([2852509](testing-library/user-event@2852509)) - **pointer**: set `button` property on pointer events separately from legacy mouse events ([#​1003](testing-library/user-event#1003)) ([2852509](testing-library/user-event@2852509)) - **pointer**: click closest common ancestor if `mousedown` and `mouseup` happen on different elements ([#​1003](testing-library/user-event#1003)) ([2852509](testing-library/user-event@2852509)) - **pointer**: omit click event on release if another button is released first ([#​1003](testing-library/user-event#1003)) ([2852509](testing-library/user-event@2852509)) - **pointer**: dispatch `mouseover`, `mouseenter` and `mousemove` on disabled elements ([#​1003](testing-library/user-event#1003)) ([2852509](testing-library/user-event@2852509)) - **pointer**: prevent `mouse*` events per `pointerdown` event handler ([#​1003](testing-library/user-event#1003)) ([2852509](testing-library/user-event@2852509)) - **pointer**: dispatch `*out` and `*over` events when moving into / out of nested elements ([#​1003](testing-library/user-event#1003)) ([2852509](testing-library/user-event@2852509)) - **pointer**: dispatch `*enter` and `*leave` events on ancestors ([#​1003](testing-library/user-event#1003)) ([2852509](testing-library/user-event@2852509)) ### [`v14.3.0`](https://github.com/testing-library/user-event/releases/tag/v14.3.0) [Compare Source](testing-library/user-event@v14.2.6...v14.3.0) ##### Features - **keyboard:** change radio group per arrow keys ([#​995](testing-library/user-event#995)) ([e1c22af](testing-library/user-event@e1c22af)) ### [`v14.2.6`](https://github.com/testing-library/user-event/releases/tag/v14.2.6) [Compare Source](testing-library/user-event@v14.2.5...v14.2.6) ##### Bug Fixes - **document:** reduce impact of React@17 workaround ([#​992](testing-library/user-event#992)) ([9816d38](testing-library/user-event@9816d38)) - **pointer:** do not throw for `pointer-events: none` on previous target ([#​991](testing-library/user-event#991)) ([6e4058b](testing-library/user-event@6e4058b)) ### [`v14.2.5`](https://github.com/testing-library/user-event/releases/tag/v14.2.5) [Compare Source](testing-library/user-event@v14.2.4...v14.2.5) ##### Bug Fixes - **document:** do not track `value` on `HTMLSelectElement` ([#​989](testing-library/user-event#989)) ([77a7fa8](testing-library/user-event@77a7fa8)) ### [`v14.2.4`](https://github.com/testing-library/user-event/releases/tag/v14.2.4) [Compare Source](testing-library/user-event@v14.2.3...v14.2.4) ##### Bug Fixes - use `window.FileList` instead of implicit global ([c88865d](testing-library/user-event@c88865d)) ### [`v14.2.3`](https://github.com/testing-library/user-event/releases/tag/v14.2.3) [Compare Source](testing-library/user-event@v14.2.2...v14.2.3) ##### Bug Fixes - **document:** use setters/methods on element as default ([#​987](testing-library/user-event#987)) ([c40e614](testing-library/user-event@c40e614)) ### [`v14.2.2`](https://github.com/testing-library/user-event/releases/tag/v14.2.2) [Compare Source](testing-library/user-event@v14.2.1...v14.2.2) ##### Bug Fixes - **document:** track `HTMLInputElement.setRangeText()` ([#​984](testing-library/user-event#984)) ([73443ec](testing-library/user-event@73443ec)) ### [`v14.2.1`](https://github.com/testing-library/user-event/releases/tag/v14.2.1) [Compare Source](testing-library/user-event@v14.2.0...v14.2.1) ##### Performance Improvements - **tab:** avert visibility check on irrelevant elements ([#​967](testing-library/user-event#967)) ([d2d8a39](testing-library/user-event@d2d8a39)) ### [`v14.2.0`](https://github.com/testing-library/user-event/releases/tag/v14.2.0) [Compare Source](testing-library/user-event@v14.1.1...v14.2.0) ##### Features - report element with declaration in `pointerEventsCheck` ([#​950](testing-library/user-event#950)) ([31b7091](testing-library/user-event@31b7091)) ##### Bug Fixes - guard against selection without range ([#​953](testing-library/user-event#953)) ([ab78f3f](testing-library/user-event@ab78f3f)) - **selectOptions:** wait after each click ([#​951](testing-library/user-event#951)) ([7ea7a77](testing-library/user-event@7ea7a77)) - wait after each method before leaving `asyncWrapper` ([#​952](testing-library/user-event#952)) ([6f55fee](testing-library/user-event@6f55fee)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xNDIuNSIsInVwZGF0ZWRJblZlciI6IjM4LjE0Mi41IiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=--> Reviewed-on: https://gitea.bruyant.xyz/alexandre/PaletteSwitcher/pulls/47 Co-authored-by: Renovate <renovate@bruyant.xyz> Co-committed-by: Renovate <renovate@bruyant.xyz>
@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: