Skip to content

test(types): update internal TypeScript stub for React 19.2 APIs#36557

Open
me-saurabhkohli wants to merge 2 commits into
facebook:mainfrom
me-saurabhkohli:fix/ts-types-react19-activity-api
Open

test(types): update internal TypeScript stub for React 19.2 APIs#36557
me-saurabhkohli wants to merge 2 commits into
facebook:mainfrom
me-saurabhkohli:fix/ts-types-react19-activity-api

Conversation

@me-saurabhkohli
Copy link
Copy Markdown

Summary

The testDefinitions/React.d.ts stub used by internal TypeScript tests (ReactTypeScriptClass-test.ts) was last updated for the class-component era. It had no type declarations for any React hooks or any API introduced after React 16, which means the React team cannot write internal TypeScript tests against modern APIs without hitting compile errors.

This PR brings the stub up to date so internal TypeScript tests can cover React 19.2 APIs.

All changes are purely additive — no existing declarations were removed or altered.

Changes

testDefinitions/React.d.ts

Added missing type declarations:

  • ReactNode and Context<T> helper types
  • Usable<T> union type (PromiseLike<T> | Context<T>)
  • Activity + ActivityProps (React 19.2, @see https://react.dev/reference/react/Activity)
  • ViewTransition (React 19.2)
  • use<T>() with Usable<T> (React 19, @see https://react.dev/reference/react/use)
  • useActionState() — no-payload and typed-payload overloads (React 19)
  • useOptimistic() — pass-through and reducer overloads (React 19)
  • useTransition(), startTransition(), useDeferredValue(), useId() (React 18+)
  • addTransitionType(), captureOwnerStack() (React 19.2)
  • Standard hooks: useState, useEffect, useLayoutEffect, useInsertionEffect, useCallback, useMemo, useContext, useReducer, useRef, useDebugValue, useImperativeHandle, useSyncExternalStore

New test files

  • ReactTypeDefinitions-test.js — runtime export verification confirming every new API is actually exported from the react package (Activity, use, useActionState, useOptimistic, ViewTransition, captureOwnerStack, addTransitionType, concurrent-mode hooks)
  • ReactHooks19TypeScript-test.ts — compile-time type-shape validation that exercises the new declarations in the stub

How did you test this?

node ./scripts/jest/jest-cli.js --testPathPattern "ReactHooks19TypeScript|ReactTypeDefinitions|ReactTypeScriptClass" --no-coverage

The one pre-existing failure in ReactClassEquivalence-test.js reproduces on upstream/main without any local modifications and is unrelated to this change.

Checklist

  • Read CONTRIBUTING.md
  • No existing declarations removed or modified — purely additive
  • New tests cover every API added to the stub
  • All 49 tests pass
  • Pre-existing baseline failure confirmed unrelated
  • CLA will be signed upon bot prompt

Copilot AI review requested due to automatic review settings May 28, 2026 01:18
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 28, 2026

Hi @me-saurabhkohli!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Expands the internal React test TypeScript declaration stub to cover React 19/19.2 APIs and adds regression tests to ensure both runtime exports and TypeScript typings are present.

Changes:

  • Add React 19/19.2 API declarations (e.g., Activity, use, useActionState, useOptimistic, ViewTransition, transition utilities) to the test React.d.ts stub.
  • Add Jest coverage verifying the corresponding runtime exports exist on react.
  • Add a TypeScript compile-time test that exercises the new typings.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/react/src/tests/testDefinitions/React.d.ts Adds missing React 19/19.2 and standard hook typings for the test TypeScript stub.
packages/react/src/tests/ReactTypeDefinitions-test.js Adds runtime-export regression tests for the newly declared APIs.
packages/react/src/tests/ReactHooks19TypeScript-test.ts Adds TS compile-time checks that exercise the new type declarations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +108 to +136
describe('standard hooks present for completeness', () => {
it('exports useState', () => {
expect(typeof React.useState).toBe('function');
});

it('exports useEffect', () => {
expect(typeof React.useEffect).toBe('function');
});

it('exports useCallback', () => {
expect(typeof React.useCallback).toBe('function');
});

it('exports useMemo', () => {
expect(typeof React.useMemo).toBe('function');
});

it('exports useContext', () => {
expect(typeof React.useContext).toBe('function');
});

it('exports useReducer', () => {
expect(typeof React.useReducer).toBe('function');
});

it('exports useRef', () => {
expect(typeof React.useRef).toBe('function');
});
});
@meta-cla meta-cla Bot added the CLA Signed label May 28, 2026
The testDefinitions/React.d.ts stub used by internal TypeScript tests
was last updated for the class-component era. It was missing type
declarations for all React hooks and every API introduced since React 16.

This PR brings the stub up to date so the React team can write internal
TypeScript tests against modern APIs without hitting compile errors.

Changes are purely additive — no existing declarations were removed or
altered.

New declarations added to testDefinitions/React.d.ts:
- ReactNode and Context<T> helper types
- Usable<T> union type (PromiseLike<T> | Context<T>)
- Activity component + ActivityProps interface (React 19.2)
- ViewTransition component (React 19.2)
- use<T>(usable: Usable<T>): T (React 19)
- useActionState() with no-payload and typed-payload overloads (React 19)
- useOptimistic() with pass-through and reducer overloads (React 19)
- useTransition(), startTransition(), useDeferredValue(), useId() (React 18+)
- addTransitionType(), captureOwnerStack() (React 19.2)
- Standard hooks: useState, useEffect, useLayoutEffect, useInsertionEffect,
  useCallback, useMemo, useContext, useReducer, useRef, useDebugValue,
  useImperativeHandle, useSyncExternalStore

New test files:
- ReactTypeDefinitions-test.js: runtime export verification for all
  React 19.2 APIs (Activity, use, useActionState, useOptimistic,
  ViewTransition, captureOwnerStack, addTransitionType, and
  concurrent-mode hooks)
- ReactHooks19TypeScript-test.ts: compile-time type-shape validation
  exercising the new declarations in the updated stub

All 49 tests across the three test files pass. The one pre-existing
failure in ReactClassEquivalence-test.js is unrelated to this change
(reproduced on upstream/main without any local modifications).
Per reviewer feedback: the test suite must assert every export declared
in testDefinitions/React.d.ts so that exports cannot silently disappear
without failing this suite.

Previously missing assertions (now added):
- useLayoutEffect
- useInsertionEffect
- useDebugValue
- useImperativeHandle
- useSyncExternalStore
- ViewTransition (moved to its own describe block, in declaration order)

Each describe block now carries a comment referencing the corresponding
declaration(s) in testDefinitions/React.d.ts, making the sync
requirement explicit for future contributors.

Tests: 29 passed (was 24)
@me-saurabhkohli me-saurabhkohli force-pushed the fix/ts-types-react19-activity-api branch from 9387711 to ba5c4f5 Compare May 28, 2026 01:26
@me-saurabhkohli
Copy link
Copy Markdown
Author

Hi @rickhanlonii and @kassens — would either of you have bandwidth to take a look at this PR? It's a purely additive update to the internal TypeScript test stub (`testDefinitions/React.d.ts`) to cover React 19.2 APIs (`use`, `useActionState`, `useOptimistic`, `Activity`, `ViewTransition`, `addTransitionType`, `captureOwnerStack`, etc.), plus two new test files to validate both runtime exports and compile-time types. Happy to adjust anything. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants