Skip to content

fix: [TS] Sync .d.ts exports with runtime from .js files#56533

Closed
retyui wants to merge 1 commit into
react:mainfrom
retyui:strict-typescript-exports
Closed

fix: [TS] Sync .d.ts exports with runtime from .js files#56533
retyui wants to merge 1 commit into
react:mainfrom
retyui:strict-typescript-exports

Conversation

@retyui

@retyui retyui commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Summary:

I want this codebase to have strict TS types sync with JS impl.

I went through each exported getter in entry point file packages/react-native/index.js
and make sure that exported JS implementation exist on TypeScript side (in .d.ts. files)

Added missing types (with tests)

  • UTFSequence
  • ReactNativeVersion
  • unstable_TextAncestorContext

Example of bad types:

  1. Incorect location
// JS: packages/react-native/index.js
  get useWindowDimensions() {
    return require('./Libraries/Utilities/useWindowDimensions').default;
  },

// TS
// 1. packages/react-native/types/index.d.ts 
export * from '../Libraries/Utilities/Dimensions';
// 2. packages/react-native/Libraries/Utilities/Dimensions.d.ts
export function useWindowDimensions(): ScaledSize;
  1. Incorrect exports
// JS: packages/react-native/index.js
  get Button() {
    return require('./Libraries/Components/Button').default;
  },

// TS
// 1. packages/react-native/types/index.d.ts 
export * from '../Libraries/Components/Button';
// 2. packages/react-native/Libraries/Components/Button.d.ts
export class Button extends React.Component<ButtonProps> {} 
         // ^^^ No export default :(

P.S. I found that these exported items are still missing typescript types:

import {
  usePressability,
  Networking,
  NativeDialogManagerAndroid,
  DeviceInfo,
  unstable_NativeView,
  unstable_NativeText,
  VirtualizedSectionList,
} from 'react-native';

Changelog:

[GENERAL] [BREAKING] - Make typescript exports in .d.ts sync with real implementation in .js files

Test Plan:

yarn test-typescript

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 21, 2026
@retyui retyui force-pushed the strict-typescript-exports branch from 08916dc to dccde7f Compare April 21, 2026 11:18
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Apr 21, 2026
@retyui retyui force-pushed the strict-typescript-exports branch from dccde7f to d427f09 Compare April 28, 2026 08:47
@retyui retyui force-pushed the strict-typescript-exports branch from d427f09 to aade909 Compare May 11, 2026 15:00
@retyui retyui force-pushed the strict-typescript-exports branch from aade909 to c13eacc Compare May 11, 2026 15:07
@retyui

retyui commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

@huntie could you please review this PR ?

@huntie huntie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🚫 This is a wide-spanning breaking change to a legacy types system we want to leave (mostly) untouched. Its replacement will be the Strict TypeScript API in the near future, which already aligns all TS types with Flow source.

Problems with this change

  • Touches multiple API exports across individual type definitions, that will break importers of these inner modules (even though we want to eliminate subpath imports soon, so this is unwanted churn).
  • In index.d.ts, each export * from '../Libraries/...'; already present makes the added export {default as ...} from ... additions redundant — these were already accessible.

The big picture

The Strict TypeScript API is already our incoming version of (effectively) these changes.

  • Subpath imports become inaccessible.
  • Code is generated 1:1 from Flow types source.

Any misalignments that existed in these manual .d.ts types from before are unfortunately part of the public API that people know and depend on already. Our intended switchover to the above constraints is a planned per-project opt-in via "react-native-strict-api".

@retyui retyui closed this May 11, 2026
@retyui retyui deleted the strict-typescript-exports branch May 11, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Callstack Partner: Callstack Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants