From 885c960d07223b83fc8d91ed8fbcdea99fa25c3e Mon Sep 17 00:00:00 2001 From: Matan Borenkraout Date: Mon, 29 Apr 2024 20:50:11 +0300 Subject: [PATCH 1/3] fix: export new act when available --- package.json | 3 ++- types/index.d.ts | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 3c38a74e..5d496449 100644 --- a/package.json +++ b/package.json @@ -51,12 +51,13 @@ }, "devDependencies": { "@testing-library/jest-dom": "^5.11.6", + "@types/react": "^18.3.1", "chalk": "^4.1.2", "dotenv-cli": "^4.0.0", "jest-diff": "^29.7.0", "kcd-scripts": "^13.0.0", "npm-run-all": "^4.1.5", - "react": "^18.3.0", + "react": "^18.3.1", "react-dom": "^18.3.0", "rimraf": "^3.0.2", "typescript": "^4.1.2" diff --git a/types/index.d.ts b/types/index.d.ts index 099bbe84..b1604944 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -7,7 +7,8 @@ import { prettyFormat, Config as ConfigDTL, } from '@testing-library/dom' -import {act as reactAct} from 'react-dom/test-utils' +import {act as reactDeprecatedAct} from 'react-dom/test-utils' +import {act as reactAct} from 'react' export * from '@testing-library/dom' @@ -245,10 +246,10 @@ export function renderHook< export function cleanup(): void /** - * Simply calls ReactDOMTestUtils.act(cb) + * Simply calls React.act(cb) * If that's not available (older version of react) then it - * simply calls the given callback immediately + * simply calls the deprecated version which is ReactTestUtils.act(cb) */ export const act: typeof reactAct extends undefined - ? (callback: () => void) => void + ? typeof reactDeprecatedAct : typeof reactAct From cd586876517426c9943bbe3f8d9c90027b30c8cd Mon Sep 17 00:00:00 2001 From: Matan Borenkraout Date: Tue, 30 Apr 2024 10:55:08 +0300 Subject: [PATCH 2/3] add ts-ignore and extend never --- types/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index b1604944..c1cb345f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -8,6 +8,7 @@ import { Config as ConfigDTL, } from '@testing-library/dom' import {act as reactDeprecatedAct} from 'react-dom/test-utils' +//@ts-ignore import {act as reactAct} from 'react' export * from '@testing-library/dom' @@ -250,6 +251,6 @@ export function cleanup(): void * If that's not available (older version of react) then it * simply calls the deprecated version which is ReactTestUtils.act(cb) */ -export const act: typeof reactAct extends undefined +export const act: typeof reactAct extends never ? typeof reactDeprecatedAct : typeof reactAct From 5ee9d3d2be9f5c7126540c262e6d9ed1f60e1e2a Mon Sep 17 00:00:00 2001 From: Matan Borenkraout Date: Tue, 30 Apr 2024 11:14:13 +0300 Subject: [PATCH 3/3] add @types/react to peerDeps --- package.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/package.json b/package.json index 5d496449..0b7876a8 100644 --- a/package.json +++ b/package.json @@ -63,9 +63,15 @@ "typescript": "^4.1.2" }, "peerDependencies": { + "@types/react": "^18.0.0", "react": "^18.0.0", "react-dom": "^18.0.0" }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + }, "eslintConfig": { "extends": "./node_modules/kcd-scripts/eslint.js", "parserOptions": {