From 2f99d67a54ac228701a7a01d5ab494be5ccb13e9 Mon Sep 17 00:00:00 2001 From: Reza Karimzadeh Date: Mon, 24 Nov 2025 12:07:28 +0330 Subject: [PATCH 1/2] Improve TypeScript type definitions in jest.d.ts - Add generic type parameters to expect() and Expect interface - Add proper function signatures for test lifecycle functions - Add type-safe generic spy functions with keyof constraints - Convert Object to lowercase object (TypeScript best practice) - Fix parameter names (arguments -> args) - Add generic type parameter to MockFunction interface These improvements provide better type safety and IntelliSense support for React's internal test suite with zero runtime impact. --- scripts/jest/typescript/jest.d.ts | 71 +++++++++++++++++-------------- 1 file changed, 40 insertions(+), 31 deletions(-) diff --git a/scripts/jest/typescript/jest.d.ts b/scripts/jest/typescript/jest.d.ts index ff450acf53395..07f69e1311438 100644 --- a/scripts/jest/typescript/jest.d.ts +++ b/scripts/jest/typescript/jest.d.ts @@ -2,28 +2,37 @@ declare const __DEV__: boolean; declare const __TEST__: boolean; declare const __EXTENSION__: boolean; -declare function afterEach(fn: any): any; -declare function beforeEach(fn: any): any; -declare function describe(name: string, fn: any): void; +declare function afterEach(fn: () => void | Promise): void; +declare function beforeEach(fn: () => void | Promise): void; +declare function describe(name: string, fn: () => void): void; declare const it: { - (name: string, fn: any): void; - only: (name: string, fn: any) => void; + (name: string, fn: () => void | Promise): void; + only: (name: string, fn: () => void | Promise) => void; }; -declare function expect(val: any): Expect; +declare function expect(val: T): Expect; declare const jest: Jest; -declare function pit(name: string, fn: any): void; -declare function spyOnDev(obj: any, key: string): any; -declare function spyOnDevAndProd(obj: any, key: string): any; -declare function spyOnProd(obj: any, key: string): any; -declare function xdescribe(name: string, fn: any): void; -declare function xit(name: string, fn: any): void; +declare function pit(name: string, fn: () => Promise): void; +declare function spyOnDev( + obj: T, + key: M +): MockFunction; +declare function spyOnDevAndProd( + obj: T, + key: M +): MockFunction; +declare function spyOnProd( + obj: T, + key: M +): MockFunction; +declare function xdescribe(name: string, fn: () => void): void; +declare function xit(name: string, fn: () => void | Promise): void; -interface Expect { - not: Expect; +interface Expect { + not: Expect; toThrow(message?: string): void; toThrowError(message?: string): void; - toBe(value: any): void; - toEqual(value: any): void; + toBe(value: T): void; + toEqual(value: T): void; toBeFalsy(): void; toBeTruthy(): void; toBeNull(): void; @@ -35,8 +44,8 @@ interface Expect { toBeGreaterThan(number: number): void; toBeLessThan(number: number): void; toBeCalled(): void; - toBeCalledWith(...arguments): void; - lastCalledWith(...arguments): void; + toBeCalledWith(...args: any[]): void; + lastCalledWith(...args: any[]): void; } interface Jest { @@ -44,28 +53,28 @@ interface Jest { autoMockOn(): void; clearAllTimers(): void; dontMock(moduleName: string): void; - genMockFromModule(moduleObj: Object): Object; - genMockFunction(): MockFunction; - genMockFn(): MockFunction; + genMockFromModule(moduleObj: object): object; + genMockFunction(): MockFunction; + genMockFn(): MockFunction; mock(moduleName: string): void; runAllTicks(): void; runAllTimers(): void; runOnlyPendingTimers(): void; - setMock(moduleName: string, moduleExports: Object): void; + setMock(moduleName: string, moduleExports: object): void; } -interface MockFunction { - (...arguments): any; +interface MockFunction { + (...args: any[]): any; mock: { calls: Array>; - instances: Array; + instances: Array; }; - mockClear(): void; - mockImplementation(fn: Function): MockFunction; - mockImpl(fn: Function): MockFunction; - mockReturnThis(): MockFunction; - mockReturnValue(value: any): MockFunction; - mockReturnValueOnce(value: any): MockFunction; + mockClear(): MockFunction; + mockImplementation(fn: (...args: any[]) => any): MockFunction; + mockImpl(fn: (...args: any[]) => any): MockFunction; + mockReturnThis(): MockFunction; + mockReturnValue(value: any): MockFunction; + mockReturnValueOnce(value: any): MockFunction; } declare const check: any; From 3cb6f45cd994ca3e0821f2217176aba8e7990ce5 Mon Sep 17 00:00:00 2001 From: Reza Karimzadeh Date: Mon, 24 Nov 2025 13:03:20 +0330 Subject: [PATCH 2/2] Update outdated reactjs.org URLs to react.dev in README files - Update react package README production build link - Update useSyncExternalStore documentation link - Update react-test-renderer documentation link - Update react-devtools-inline release channel link - Update react-devtools React website link All links now point to the current react.dev documentation instead of the deprecated reactjs.org domain. --- packages/react-devtools-inline/README.md | 2 +- packages/react-devtools/README.md | 2 +- packages/react-test-renderer/README.md | 2 +- packages/react/README.md | 2 +- packages/use-sync-external-store/README.md | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/react-devtools-inline/README.md b/packages/react-devtools-inline/README.md index cd242236c7644..662968c1bbdef 100644 --- a/packages/react-devtools-inline/README.md +++ b/packages/react-devtools-inline/README.md @@ -6,7 +6,7 @@ If you're looking for the standalone React DevTools UI, **we suggest using [`rea --- -> **Note** that this package (and the DevTools UI) relies on several _experimental_ APIs that are **only available in the [experimental release channel](https://reactjs.org/docs/release-channels.html#experimental-channel)**. This means that you will need to install `react@experimental` and `react-dom@experimental`. +> **Note** that this package (and the DevTools UI) relies on several _experimental_ APIs that are **only available in the [experimental release channel](https://react.dev/community/versioning-policy#experimental-channel)**. This means that you will need to install `react@experimental` and `react-dom@experimental`. --- diff --git a/packages/react-devtools/README.md b/packages/react-devtools/README.md index 8c436c1fb2b4d..b60a97b08188d 100644 --- a/packages/react-devtools/README.md +++ b/packages/react-devtools/README.md @@ -99,7 +99,7 @@ By default DevTools listen to port `8097` on `localhost`. The port can be modifi Or you could develop with a local HTTP server like [`serve`](https://www.npmjs.com/package/serve). -**The React tab won't show up if the site doesn't use React**, or if React can't communicate with the devtools. When the page loads, the devtools sets a global named `__REACT_DEVTOOLS_GLOBAL_HOOK__`, then React communicates with that hook during initialization. You can test this on the [React website](https://reactjs.org/) or by inspecting [Facebook](https://www.facebook.com/). +**The React tab won't show up if the site doesn't use React**, or if React can't communicate with the devtools. When the page loads, the devtools sets a global named `__REACT_DEVTOOLS_GLOBAL_HOOK__`, then React communicates with that hook during initialization. You can test this on the [React website](https://react.dev/) or by inspecting [Facebook](https://www.facebook.com/). **If your app is inside of CodePen**, make sure you are registered. Then press Fork (if it's not your pen), and then choose Change View > Debug. The Debug view is inspectable with DevTools because it doesn't use an iframe. diff --git a/packages/react-test-renderer/README.md b/packages/react-test-renderer/README.md index c39e7a98ce51f..5247b64c95291 100644 --- a/packages/react-test-renderer/README.md +++ b/packages/react-test-renderer/README.md @@ -20,7 +20,7 @@ This package provides an experimental React renderer that can be used to render Essentially, this package makes it easy to grab a snapshot of the "DOM tree" rendered by a React DOM or React Native component without using a browser or jsdom. -Documentation: [https://reactjs.org/docs/test-renderer.html](https://reactjs.org/docs/test-renderer.html) +Documentation: [https://react.dev/reference/react-dom/test-utils](https://react.dev/reference/react-dom/test-utils) Usage: diff --git a/packages/react/README.md b/packages/react/README.md index 20a855efd3c06..82f9bf1b1fa22 100644 --- a/packages/react/README.md +++ b/packages/react/README.md @@ -4,7 +4,7 @@ React is a JavaScript library for creating user interfaces. The `react` package contains only the functionality necessary to define React components. It is typically used together with a React renderer like `react-dom` for the web, or `react-native` for the native environments. -**Note:** by default, React will be in development mode. The development version includes extra warnings about common mistakes, whereas the production version includes extra performance optimizations and strips all error messages. Don't forget to use the [production build](https://reactjs.org/docs/optimizing-performance.html#use-the-production-build) when deploying your application. +**Note:** by default, React will be in development mode. The development version includes extra warnings about common mistakes, whereas the production version includes extra performance optimizations and strips all error messages. Don't forget to use the [production build](https://react.dev/learn/render-and-commit#optimizing-performance) when deploying your application. ## Usage diff --git a/packages/use-sync-external-store/README.md b/packages/use-sync-external-store/README.md index e9987a399b65f..6291aade211b7 100644 --- a/packages/use-sync-external-store/README.md +++ b/packages/use-sync-external-store/README.md @@ -1,5 +1,5 @@ # use-sync-external-store -Backwards-compatible shim for [`React.useSyncExternalStore`](https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore). Works with any React that supports Hooks. +Backwards-compatible shim for [`React.useSyncExternalStore`](https://react.dev/reference/react/useSyncExternalStore). Works with any React that supports Hooks. See also https://github.com/reactwg/react-18/discussions/86.