fix(react-native): add missing AssetRegistry TypeScript types (#58964)

Summary:
https://github.com/react/react-native/issues/57369 moved the AssetRegistry into the public API of React Native starting from `0.87`. Unfortunately, it seems that the TypeScript types were not updated to include this API, resulting in type issues when trying to use:

```ts
import { AssetRegistry, type AssetDestPathResolver, type PackagerAsset } from 'react-native'
```

This PR fixes the typing issues for `0.88`.

The [Flow types were updated correctly](https://github.com/react/react-native/blob/2d913c7292088a7bc4482a6febb2ee4903d6f32f/packages/react-native/index.js.flow#L282-L286) in `0.87-rc.0`.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[GENERAL] [FIXED] Add missing TypeScript types for public `AssetRegistry` API

Pull Request resolved: https://github.com/react/react-native/pull/58964

Test Plan:
- Prepare any TypeScript project with React Native
- Run type checks for:
    `import { AssetRegistry, type AssetDestPathResolver, type PackagerAsset } from 'react-native'`
- Should succeed

Reviewed By: Abbondanzo

Differential Revision: D125060242

Pulled By: fabriziocucci

fbshipit-source-id: 4efadb3647afcac43ecd83472a88d9fb02882905
(cherry picked from commit b8ec87e457)
This commit is contained in:
Cedric van Putten authored and Fabrizio Cucci committed 2026-10-14 08:54:12 +01:00
1 parent 749c6e7c6f
commit 536c008de0
2 files changed
+45

No files matched your search

+1
View File
@@ -144,6 +144,7 @@ export * as CodegenTypes from './Libraries/Types/CodegenTypesNamespace';
export * from './Libraries/Types/CoreEventTypes';
export * from './Libraries/Utilities/Appearance';
export * from './Libraries/Utilities/BackHandler';
export * from './src/private/assets/AssetRegistry';
export * from './src/private/devsupport/devmenu/DevMenu';
export * from './Libraries/Utilities/DevSettings';
export * from './Libraries/Utilities/Dimensions';
@@ -0,0 +1,44 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
export type AssetDestPathResolver = 'android' | 'generic';
export interface PackagerAsset {
readonly __packager_asset: boolean;
readonly fileSystemLocation: string;
readonly httpServerLocation: string;
readonly width: number | null | undefined;
readonly height: number | null | undefined;
readonly scales: number[];
readonly hash: string;
readonly name: string;
readonly type: string;
readonly resolver?: AssetDestPathResolver | undefined;
}
/**
* Runtime registry that maps asset IDs generated in a Metro bundle to asset
* metadata. It backs `<Image>`, `Image.resolveAssetSource()`, and any code
* that resolves `require('./img.png')` on native.
*
* Most apps do not use this directly — assets are handled through `<Image>`.
*/
export interface AssetRegistry {
/**
* Register an asset. Returns the asset ID.
*/
registerAsset(asset: PackagerAsset): number;
/**
* Retrieve a registered asset by ID.
*/
getAssetByID(assetId: number): PackagerAsset;
}
export declare const AssetRegistry: AssetRegistry;