Skip to content

Commit b8ec87e

Browse files
byCedricmeta-codesync[bot]
authored andcommitted
fix(react-native): add missing AssetRegistry TypeScript types (#58964)
Summary: #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: #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
1 parent d026c0f commit b8ec87e

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎packages/react-native/types_DEPRECATED/index.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export * as CodegenTypes from './Libraries/Types/CodegenTypesNamespace';
144144
export * from './Libraries/Types/CoreEventTypes';
145145
export * from './Libraries/Utilities/Appearance';
146146
export * from './Libraries/Utilities/BackHandler';
147+
export * from './src/private/assets/AssetRegistry';
147148
export * from './src/private/devsupport/devmenu/DevMenu';
148149
export * from './Libraries/Utilities/DevSettings';
149150
export * from './Libraries/Utilities/Dimensions';
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
export type AssetDestPathResolver = 'android' | 'generic';
11+
12+
export interface PackagerAsset {
13+
readonly __packager_asset: boolean;
14+
readonly fileSystemLocation: string;
15+
readonly httpServerLocation: string;
16+
readonly width: number | null | undefined;
17+
readonly height: number | null | undefined;
18+
readonly scales: number[];
19+
readonly hash: string;
20+
readonly name: string;
21+
readonly type: string;
22+
readonly resolver?: AssetDestPathResolver | undefined;
23+
}
24+
25+
/**
26+
* Runtime registry that maps asset IDs generated in a Metro bundle to asset
27+
* metadata. It backs `<Image>`, `Image.resolveAssetSource()`, and any code
28+
* that resolves `require('./img.png')` on native.
29+
*
30+
* Most apps do not use this directly — assets are handled through `<Image>`.
31+
*/
32+
export interface AssetRegistry {
33+
/**
34+
* Register an asset. Returns the asset ID.
35+
*/
36+
registerAsset(asset: PackagerAsset): number;
37+
38+
/**
39+
* Retrieve a registered asset by ID.
40+
*/
41+
getAssetByID(assetId: number): PackagerAsset;
42+
}
43+
44+
export declare const AssetRegistry: AssetRegistry;

0 commit comments

Comments
 (0)