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 93aa5cd
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions packages/react-native/types/index.d.ts
Expand Up @@ -161,11 +161,38 @@ export * from './public/ReactNativeTypes';
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 93aa5cd

Please sign in to comment.