Fix isModule check not working for new class modules

This commit is contained in:
Michael Telatynski
2025-01-30 10:57:18 +00:00
parent 776d07730a
commit 06fcf783a1
+6 -6
View File
@@ -40,13 +40,13 @@ export interface ModuleExport {
} }
const moduleExportSignature: Record<keyof ModuleExport, Type> = { const moduleExportSignature: Record<keyof ModuleExport, Type> = {
default: "object", default: "function",
}; };
type Type = "function" | "string" | "number" | "boolean" | "object"; type Type = "function" | "string" | "number" | "boolean" | "object";
function isInterface<T>(obj: unknown, keys: Record<keyof T, Type>): obj is T { function isInterface<T>(obj: unknown, type: "object" | "function", keys: Record<keyof T, Type>): obj is T {
if (obj === null || typeof obj !== "object") return false; if (obj === null || typeof obj !== type) return false;
for (const key in keys) { for (const key in keys) {
if (typeof (obj as Record<keyof T, unknown>)[key] !== keys[key]) return false; if (typeof (obj as Record<keyof T, unknown>)[key] !== keys[key]) return false;
} }
@@ -55,9 +55,9 @@ function isInterface<T>(obj: unknown, keys: Record<keyof T, Type>): obj is T {
export function isModule(module: unknown): module is ModuleExport { export function isModule(module: unknown): module is ModuleExport {
return ( return (
isInterface(module, moduleExportSignature) && isInterface(module, "object", moduleExportSignature) &&
isInterface(module.default, moduleFactorySignature) && isInterface(module.default, "function", moduleFactorySignature) &&
isInterface(module.default.prototype, moduleSignature) isInterface(module.default.prototype, "object", moduleSignature)
); );
} }