mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Improve node module types (#40456)
Add missing APIs on require.resolve from createRequire.
This commit is contained in:
parent
0e9f7eb3a2
commit
f4e58f2e65
10
types/node/globals.d.ts
vendored
10
types/node/globals.d.ts
vendored
@ -193,9 +193,13 @@ interface NodeRequireFunction {
|
||||
(id: string): any;
|
||||
}
|
||||
|
||||
interface NodeRequireCache {
|
||||
[path: string]: NodeModule;
|
||||
}
|
||||
|
||||
interface NodeRequire extends NodeRequireFunction {
|
||||
resolve: RequireResolve;
|
||||
cache: any;
|
||||
cache: NodeRequireCache;
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
@ -1134,8 +1138,8 @@ declare namespace NodeJS {
|
||||
/**
|
||||
* @deprecated Deprecated since: v12.2.0. Please use createRequire() instead.
|
||||
*/
|
||||
static createRequireFromPath(path: string): NodeRequireFunction;
|
||||
static createRequire(path: string): NodeRequireFunction;
|
||||
static createRequireFromPath(path: string): NodeRequire;
|
||||
static createRequire(path: string): NodeRequire;
|
||||
static builtinModules: string[];
|
||||
|
||||
static Module: typeof Module;
|
||||
|
||||
@ -817,7 +817,23 @@ import moduleModule = require('module');
|
||||
let paths: string[] = module.paths;
|
||||
paths = m1.paths;
|
||||
|
||||
moduleModule.createRequireFromPath('./test')('test');
|
||||
const customRequire1 = moduleModule.createRequireFromPath('./test');
|
||||
const customRequire2 = moduleModule.createRequire('./test');
|
||||
|
||||
customRequire1('test');
|
||||
customRequire2('test');
|
||||
|
||||
const resolved1: string = customRequire1.resolve('test');
|
||||
const resolved2: string = customRequire2.resolve('test');
|
||||
|
||||
const paths1: string[] | null = customRequire1.resolve.paths('test');
|
||||
const paths2: string[] | null = customRequire2.resolve.paths('test');
|
||||
|
||||
const cachedModule1: Module = customRequire1.cache['/path/to/module.js'];
|
||||
const cachedModule2: Module = customRequire2.cache['/path/to/module.js'];
|
||||
|
||||
const main1: Module | undefined = customRequire1.main;
|
||||
const main2: Module | undefined = customRequire2.main;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
Loading…
Reference in New Issue
Block a user