Closed skratchdot closed 10 months ago
@kasperpeulen I am pretty sure you would have avoided any
if possible. Do you know why we type all these properties with any
?
I'm also getting this error, here are some relevant screenshots and using latest version of @storybook/test: ^7.6.6
I updated my description and title to point out that this is an issue for v8. ~i think v7.6 "works".~ actually, @Christian-Garrison pointed out that 7.6 is not working.
@skratchdot Hey-O so v7.6.x is the current version I've been using and it has the same type issues.
Feel free to refer to my comment to update the title and description.
Same here. The userEvent
type looks correct though: in spite of hovering indicating any
, when I follow the definition, the IDE gets me to a proper one:
->
So there seems to be a problem with eslint/TS processing the referenced definitions.
Can be related to this: https://github.com/testing-library/user-event/discussions/978.
@testing-library/user-event@14.3.0
alone also throws weird TS errors:
TS7016: Could not find a declaration file for module '@testing-library/user-event'. 'xxx/node_modules/@testing-library/user-event/dist/index.mjs' implicitly has an 'any' type. There are types at 'xxx/node_modules/@testing-library/user-event/dist/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@testing-library/user-event' library may need to update its package.json or typings.
That error is fixed by the version 14.5.2
, but sadly pinning it in the project so that @storybook/test
uses that version as well, does not help in getting rid of the any
s error.
Ok I managed to fix it with this change:
diff --git a/node_modules/@storybook/test/dist/index.d.ts b/node_modules/@storybook/test/dist/index.d.ts
index 880b7ec..4f3174e 100644
--- a/node_modules/@storybook/test/dist/index.d.ts
+++ b/node_modules/@storybook/test/dist/index.d.ts
@@ -3,7 +3,7 @@ import * as matchers from '@testing-library/jest-dom/matchers';
import { MaybeMocked, MaybeMockedDeep, MaybePartiallyMocked, MaybePartiallyMockedDeep } from '@vitest/spy';
export * from '@vitest/spy';
export { fn, isMockFunction, spies as mocks, spyOn } from '@vitest/spy';
-import * as _testing_library_user_event_dist_types_setup_directApi from '@testing-library/user-event/dist/types/setup/directApi';
+import _testing_library_user_event_dist_types_setup_directApi from '@testing-library/user-event';
import * as _testing_library_user_event_dist_types_setup_setup from '@testing-library/user-event/dist/types/setup/setup';
import * as domTestingLibrary from '@testing-library/dom';
@jalooc - thanks!
i used the following package.json
changes:
"pnpm": {
"overrides": {
"@testing-library/user-event": "^14.5.2"
},
"patchedDependencies": {
"@storybook/test@7.6.7": "patches/@storybook__test@7.6.7.patch"
}
}
the patchedDependencies
section was auto-added when i ran pnpm patch @storybook/test@7.6.7
.
my patches/@storybook__test@7.6.7.patch
file is:
diff --git a/dist/index.d.ts b/dist/index.d.ts
index 880b7ec16674fb512a2e21f85256cd0298ce1060..377a2835b153418bd7142846c08655635e80e05d 100644
--- a/dist/index.d.ts
+++ b/dist/index.d.ts
@@ -3,8 +3,7 @@ import * as matchers from '@testing-library/jest-dom/matchers';
import { MaybeMocked, MaybeMockedDeep, MaybePartiallyMocked, MaybePartiallyMockedDeep } from '@vitest/spy';
export * from '@vitest/spy';
export { fn, isMockFunction, spies as mocks, spyOn } from '@vitest/spy';
-import * as _testing_library_user_event_dist_types_setup_directApi from '@testing-library/user-event/dist/types/setup/directApi';
-import * as _testing_library_user_event_dist_types_setup_setup from '@testing-library/user-event/dist/types/setup/setup';
+import _userEvent from '@testing-library/user-event';
import * as domTestingLibrary from '@testing-library/dom';
type Promisify<Fn> = Fn extends (...args: infer A) => infer R ? (...args: A) => R extends Promise<any> ? R : Promise<R> : Fn;
@@ -152,26 +151,7 @@ declare const waitFor: typeof domTestingLibrary.waitFor;
declare const waitForElementToBeRemoved: typeof domTestingLibrary.waitForElementToBeRemoved;
declare const within: typeof domTestingLibrary.getQueriesForElement;
declare const prettyFormat: typeof domTestingLibrary.prettyFormat;
-declare const userEvent: {
- readonly setup: typeof _testing_library_user_event_dist_types_setup_setup.setupMain;
- readonly clear: typeof _testing_library_user_event_dist_types_setup_directApi.clear;
- readonly click: typeof _testing_library_user_event_dist_types_setup_directApi.click;
- readonly copy: typeof _testing_library_user_event_dist_types_setup_directApi.copy;
- readonly cut: typeof _testing_library_user_event_dist_types_setup_directApi.cut;
- readonly dblClick: typeof _testing_library_user_event_dist_types_setup_directApi.dblClick;
- readonly deselectOptions: typeof _testing_library_user_event_dist_types_setup_directApi.deselectOptions;
- readonly hover: typeof _testing_library_user_event_dist_types_setup_directApi.hover;
- readonly keyboard: typeof _testing_library_user_event_dist_types_setup_directApi.keyboard;
- readonly pointer: typeof _testing_library_user_event_dist_types_setup_directApi.pointer;
- readonly paste: typeof _testing_library_user_event_dist_types_setup_directApi.paste;
- readonly selectOptions: typeof _testing_library_user_event_dist_types_setup_directApi.selectOptions;
- readonly tripleClick: typeof _testing_library_user_event_dist_types_setup_directApi.tripleClick;
- readonly type: typeof _testing_library_user_event_dist_types_setup_directApi.type;
- readonly unhover: typeof _testing_library_user_event_dist_types_setup_directApi.unhover;
- readonly upload: typeof _testing_library_user_event_dist_types_setup_directApi.upload;
- readonly tab: typeof _testing_library_user_event_dist_types_setup_directApi.tab;
-};
-
+declare const userEvent: typeof _userEvent;
declare const expect: Expect;
export { buildQueries, clearAllMocks, configure, createEvent, expect, findAllByAltText, findAllByDisplayValue, findAllByLabelText, findAllByPlaceholderText, findAllByRole, findAllByTestId, findAllByText, findAllByTitle, findByAltText, findByDisplayValue, findByLabelText, findByPlaceholderText, findByRole, findByTestId, findByText, findByTitle, fireEvent, getAllByAltText, getAllByDisplayValue, getAllByLabelText, getAllByPlaceholderText, getAllByRole, getAllByTestId, getAllByText, getAllByTitle, getByAltText, getByDisplayValue, getByLabelText, getByPlaceholderText, getByRole, getByTestId, getByText, getByTitle, getConfig, getDefaultNormalizer, getElementError, getNodeText, getQueriesForElement, getRoles, getSuggestedQuery, isInaccessible, logDOM, logRoles, mocked, prettyDOM, prettyFormat, queries, queryAllByAltText, queryAllByAttribute, queryAllByDisplayValue, queryAllByLabelText, queryAllByPlaceholderText, queryAllByRole, queryAllByTestId, queryAllByText, queryAllByTitle, queryByAltText, queryByAttribute, queryByDisplayValue, queryByLabelText, queryByPlaceholderText, queryByRole, queryByTestId, queryByText, queryByTitle, queryHelpers, resetAllMocks, restoreAllMocks, screen, userEvent, waitFor, waitForElementToBeRemoved, within };
I am still seeing errors even with 8.0.0-alpha.10
so I commented here:
https://github.com/storybookjs/storybook/pull/25547#issuecomment-1892702725
Respectfully @kasperpeulen NS 😕 why this is closed? Have I missed something?
import { userEvent, waitForElementToBeRemoved, within } from "@storybook/test";
"@storybook/addon-essentials": "^7.6.16",
"@storybook/addon-interactions": "^7.6.16",
"@storybook/addon-links": "^7.6.16",
"@storybook/blocks": "^7.6.16",
"@storybook/react": "^7.6.16",
"@storybook/react-vite": "^7.6.16",
"@storybook/test": "^7.6.16",
I just merged a PR that should fix this: https://github.com/storybookjs/storybook/issues/25853
Shall be part of beta.3.
Describe the bug
In v8, all the types for
userEvent
from@storybook/test
are typed asany
instead of keeping/wrapping the@testing-library/user-event
types during instrumentation.@storybook/test
:@testing-library/user-event
:To Reproduce
on a codebase that implements the
@typescript-eslint/no-unsafe-call
lint rule, upgrade from@storybook/jest
and@storybook/testing-library
to use@storybook/test
instead. notice all the new eslint errors:due to
userEvent
System
Additional context
No response