Skip to content

Commit f3c2898

Browse files
coadofacebook-github-bot
authored andcommitted
Move imported types from @react-native/assets-registry and @react-native/js-polyfills to react-native repo (#51192)
Summary: Pull Request resolved: #51192 The `build-types` script cannot currently resolve `react-native/assets-registry` and `react-native/js-polyfills`. This diff moves imported types from these packages to `react-native` to include them in generated types. Changelog: [Internal] Reviewed By: huntie Differential Revision: D74392568 fbshipit-source-id: cbce977b710f54dc53ce1b0fc080704b420490d4
1 parent 14cea6e commit f3c2898

3 files changed

Lines changed: 85 additions & 10 deletions

File tree

packages/react-native/Libraries/Image/AssetSourceResolver.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,23 @@ export type ResolvedAssetSource = {
1818
+scale: number,
1919
};
2020

21-
import type {
22-
AssetDestPathResolver,
23-
PackagerAsset,
24-
} from '@react-native/assets-registry/registry';
21+
// From @react-native/assets-registry
22+
type AssetDestPathResolver = 'android' | 'generic';
23+
24+
// From @react-native/assets-registry
25+
type PackagerAsset = $ReadOnly<{
26+
__packager_asset: boolean,
27+
fileSystemLocation: string,
28+
httpServerLocation: string,
29+
width: ?number,
30+
height: ?number,
31+
scales: Array<number>,
32+
hash: string,
33+
name: string,
34+
type: string,
35+
resolver?: AssetDestPathResolver,
36+
...
37+
}>;
2538

2639
const PixelRatio = require('../Utilities/PixelRatio').default;
2740
const Platform = require('../Utilities/Platform').default;

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4202,6 +4202,19 @@ exports[`public API should not change unintentionally Libraries/Image/AssetSourc
42024202
+uri: string,
42034203
+scale: number,
42044204
};
4205+
type AssetDestPathResolver = \\"android\\" | \\"generic\\";
4206+
type PackagerAsset = $ReadOnly<{
4207+
fileSystemLocation: string,
4208+
httpServerLocation: string,
4209+
width: ?number,
4210+
height: ?number,
4211+
scales: Array<number>,
4212+
hash: string,
4213+
name: string,
4214+
type: string,
4215+
resolver?: AssetDestPathResolver,
4216+
...
4217+
}>;
42054218
declare class AssetSourceResolver {
42064219
serverUrl: ?string;
42074220
jsbundleUrl: ?string;
@@ -8915,8 +8928,33 @@ declare export default typeof rejectionTrackingOptions;
89158928
`;
89168929

89178930
exports[`public API should not change unintentionally Libraries/vendor/core/ErrorUtils.js 1`] = `
8918-
"export type ErrorUtils = ErrorUtilsT;
8919-
declare export default ErrorUtilsT;
8931+
"type ErrorHandler = (error: mixed, isFatal: boolean) => void;
8932+
type Fn<Args, Return> = (...Args) => Return;
8933+
export type ErrorUtils = {
8934+
applyWithGuard<TArgs: $ReadOnlyArray<mixed>, TOut>(
8935+
fun: Fn<TArgs, TOut>,
8936+
context?: mixed,
8937+
args?: ?TArgs,
8938+
unused_onError?: null,
8939+
unused_name?: ?string
8940+
): ?TOut,
8941+
applyWithGuardIfNeeded<TArgs: $ReadOnlyArray<mixed>, TOut>(
8942+
fun: Fn<TArgs, TOut>,
8943+
context?: mixed,
8944+
args?: ?TArgs
8945+
): ?TOut,
8946+
getGlobalHandler(): ErrorHandler,
8947+
guard<TArgs: $ReadOnlyArray<mixed>, TOut>(
8948+
fun: Fn<TArgs, TOut>,
8949+
name?: ?string,
8950+
context?: mixed
8951+
): ?(...TArgs) => ?TOut,
8952+
inGuard(): boolean,
8953+
reportError(error: mixed): void,
8954+
reportFatalError(error: mixed): void,
8955+
setGlobalHandler(fun: ErrorHandler): void,
8956+
};
8957+
declare export default ErrorUtils;
89208958
"
89218959
`;
89228960

packages/react-native/Libraries/vendor/core/ErrorUtils.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,33 @@
88
* @flow strict
99
*/
1010

11-
import type {ErrorUtilsT} from '@react-native/js-polyfills/error-guard';
12-
13-
export type ErrorUtils = ErrorUtilsT;
11+
// From @react-native/js-polyfills
12+
type ErrorHandler = (error: mixed, isFatal: boolean) => void;
13+
type Fn<Args, Return> = (...Args) => Return;
14+
export type ErrorUtils = {
15+
applyWithGuard<TArgs: $ReadOnlyArray<mixed>, TOut>(
16+
fun: Fn<TArgs, TOut>,
17+
context?: mixed,
18+
args?: ?TArgs,
19+
unused_onError?: null,
20+
unused_name?: ?string,
21+
): ?TOut,
22+
applyWithGuardIfNeeded<TArgs: $ReadOnlyArray<mixed>, TOut>(
23+
fun: Fn<TArgs, TOut>,
24+
context?: mixed,
25+
args?: ?TArgs,
26+
): ?TOut,
27+
getGlobalHandler(): ErrorHandler,
28+
guard<TArgs: $ReadOnlyArray<mixed>, TOut>(
29+
fun: Fn<TArgs, TOut>,
30+
name?: ?string,
31+
context?: mixed,
32+
): ?(...TArgs) => ?TOut,
33+
inGuard(): boolean,
34+
reportError(error: mixed): void,
35+
reportFatalError(error: mixed): void,
36+
setGlobalHandler(fun: ErrorHandler): void,
37+
};
1438

1539
/**
1640
* The particular require runtime that we are using looks for a global
@@ -24,4 +48,4 @@ export type ErrorUtils = ErrorUtilsT;
2448
* that use it aren't just using a global variable, so simply export the global
2549
* variable here. ErrorUtils is originally defined in a file named error-guard.js.
2650
*/
27-
export default (global.ErrorUtils: ErrorUtilsT);
51+
export default global.ErrorUtils as ErrorUtils;

0 commit comments

Comments
 (0)