Skip to content

Commit 02f2e9c

Browse files
committed
fix(node): loosen type of LoadFnOutput
A `LoadHook` accepts a `LoadHookContext` object having a `format` of `string | null | undefined`. `LookHook` implementors often want to pass this value through ([example from docs](https://nodejs.org/api/module.html\#asynchronous-version), which suggests to me that a) it can be falsy, and b) it should be a looser type as established for `ResolveFnOutput` in DefinitelyTyped#71493). A consequence of this is that `ModuleFormat` is no longer referenced anywhere; it can be removed.
1 parent 56fa141 commit 02f2e9c

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

types/node/module.d.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,6 @@ declare module "module" {
334334
interface ImportAttributes extends NodeJS.Dict<string> {
335335
type?: string | undefined;
336336
}
337-
type ModuleFormat =
338-
| "builtin"
339-
| "commonjs"
340-
| "commonjs-typescript"
341-
| "json"
342-
| "module"
343-
| "module-typescript"
344-
| "wasm";
345337
type ModuleSource = string | ArrayBuffer | NodeJS.TypedArray;
346338
/**
347339
* The `initialize` hook provides a way to define a custom function that runs in
@@ -419,7 +411,7 @@ declare module "module" {
419411
importAttributes: ImportAttributes;
420412
}
421413
interface LoadFnOutput {
422-
format: ModuleFormat;
414+
format: string | null | undefined;
423415
/**
424416
* A signal that this hook intends to terminate the chain of `resolve` hooks.
425417
* @default false

types/node/test/module.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ Module.Module === Module;
204204
};
205205
}
206206

207+
if (format === null) {
208+
return {
209+
format,
210+
shortCircuit: true,
211+
source: "...",
212+
};
213+
}
214+
207215
return nextLoad(url);
208216
};
209217
}

0 commit comments

Comments
 (0)