Skip to content

Commit

Permalink
Update types for require and require.context
Browse files Browse the repository at this point in the history
It's been 1½ years since the merge of facebook/metro#822 and my hope is that this feature is ready to be documented and made available through types.
  • Loading branch information
kraenhansen committed Nov 11, 2023
1 parent 1891d9e commit 3355ebc
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions packages/react-native/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,41 @@ export * from './public/Insets';
export * from './public/ReactNativeRenderer';
export * from './public/ReactNativeTypes';

import type {ErrorUtils} from '../Libraries/vendor/core/ErrorUtils';
import type { ErrorUtils } from '../Libraries/vendor/core/ErrorUtils';

declare global {
interface NodeRequire {
interface ReactNativeRequire {
(id: string): any;
/**
* Instructs Metro to generate a virtual module in the dependency graph,
* with dependencies on every file in the file map that matches the context params.
* This can be used to perform dynamic imports from files on disk at build time.
* @note Metro parses for `require.context()` calls in the code while building.
* @see https://github.com/facebook/metro/pull/822
* @see https://webpack.js.org/guides/dependency-management/#requirecontext
*/
context(
directory: string,
useSubdirectories?: boolean,
regExp?: RegExp,
mode?: 'sync' | 'lazy',
): MetroRequireContext;
}

/**
* Returned from `require.context` provided by Metro.
* @see https://github.com/facebook/metro/pull/822
* @see https://webpack.js.org/guides/dependency-management/#requirecontext
*/
interface MetroRequireContext {
(id: string): any;
/**
* @return an array of all possible requests that the context module can handle.
*/
keys(): string[];
}

var require: NodeRequire;
var require: ReactNativeRequire;

/**
* Console polyfill
Expand Down

0 comments on commit 3355ebc

Please sign in to comment.