Skip to content

Conversation

@Rezakarimzadeh98
Copy link

Summary

This PR improves TypeScript type definitions in scripts/jest/typescript/jest.d.ts to provide better type safety and IntelliSense support for React's internal test suite.

Changes

  • Add generic type parameters to expect() and Expect interface for better type inference
  • Add proper function signatures for test lifecycle functions (beforeEach, afterEach, etc.)
  • Add type-safe generic spy functions (spyOnDev, spyOnProd) with keyof constraints
  • Convert deprecated Object type to lowercase object (TypeScript best practice)
  • Fix parameter names (argumentsargs to avoid reserved keyword)
  • Add generic type parameter to MockFunction interface

Benefits

  • Better IntelliSense: Autocomplete shows correct types when writing tests
  • Catch errors early: TypeScript catches type mismatches at compile time
  • Modern TypeScript: Uses current best practices and conventions
  • Zero runtime impact: Pure compile-time improvement with no breaking changes

Testing

  • ✅ ESLint passes with no errors
  • ✅ TypeScript compilation successful
  • ✅ No breaking changes - fully backward compatible

Example

// Before: No type safety
const spy = spyOnDev(MyObject, 'myMethod'); // Returns 'any'

// After: Full type safety
const spy = spyOnDev(MyObject, 'myMethod'); // Fully typed with autocomplete
//                            ^^^^^^^^ TypeScript ensures this key exists

- 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.
Copilot AI review requested due to automatic review settings November 24, 2025 09:12
Copy link

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.

Copilot wasn't able to review any files in this pull request.


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

@meta-cla
Copy link

meta-cla bot commented Nov 24, 2025

Hi @Rezakarimzadeh98!

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 [email protected]. Thanks!

- 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.
@meta-cla meta-cla bot added the CLA Signed label Nov 24, 2025
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.

1 participant