Fix isModule check not working for new class modules
This commit is contained in:
@@ -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)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user