From b8ec87e457c72377dab85599e1ae8c176eb242e7 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Tue, 13 Oct 2026 15:19:40 -0700 Subject: [PATCH] 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: [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 --- .../react-native/types_DEPRECATED/index.d.ts | 1 + .../src/private/assets/AssetRegistry.d.ts | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 packages/react-native/types_DEPRECATED/src/private/assets/AssetRegistry.d.ts diff --git a/packages/react-native/types_DEPRECATED/index.d.ts b/packages/react-native/types_DEPRECATED/index.d.ts index b5541260cb6..a98e1f00451 100644 --- a/packages/react-native/types_DEPRECATED/index.d.ts +++ b/packages/react-native/types_DEPRECATED/index.d.ts @@ -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'; diff --git a/packages/react-native/types_DEPRECATED/src/private/assets/AssetRegistry.d.ts b/packages/react-native/types_DEPRECATED/src/private/assets/AssetRegistry.d.ts new file mode 100644 index 00000000000..2546f142247 --- /dev/null +++ b/packages/react-native/types_DEPRECATED/src/private/assets/AssetRegistry.d.ts @@ -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.resolveAssetSource()`, and any code + * that resolves `require('./img.png')` on native. + * + * Most apps do not use this directly — assets are handled through ``. + */ +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;