diff --git a/types/node/globals.d.ts b/types/node/globals.d.ts index 8734eeb55f..d9505f16df 100644 --- a/types/node/globals.d.ts +++ b/types/node/globals.d.ts @@ -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; diff --git a/types/node/node-tests.ts b/types/node/node-tests.ts index 8ada562a2a..9acf5f6117 100644 --- a/types/node/node-tests.ts +++ b/types/node/node-tests.ts @@ -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; } /////////////////////////////////////////////////////////