Skip to content

Commit eaebf87

Browse files
committed
chore: more fixes
1 parent 946f3f0 commit eaebf87

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

‎src/fiber/typeGuards.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
Lane,
1717
Lanes,
1818
PortalStateNode,
19+
Update,
1920
UpdateQueue,
2021
} from "./types";
2122
import { NoFlags, NoLanes, WorkTag } from "./types";
@@ -251,7 +252,7 @@ export function isHookState(value: unknown): value is Hook {
251252
"memoizedState" in obj &&
252253
"baseState" in obj &&
253254
"baseQueue" in obj &&
254-
(obj["baseQueue"] === null || isUpdateQueue(obj["baseQueue"])) &&
255+
(obj["baseQueue"] === null || isUpdate(obj["baseQueue"])) &&
255256
"queue" in obj &&
256257
(obj["queue"] === null || isUpdateQueue(obj["queue"])) &&
257258
"next" in obj &&
@@ -368,6 +369,30 @@ export function assertTextProps(fiber: Fiber): TextProps {
368369
return props;
369370
}
370371

372+
// ============================================
373+
// Update Type Guards
374+
// ============================================
375+
376+
/**
377+
* Type guard for Update.
378+
*/
379+
export function isUpdate<S>(value: unknown): value is Update<S> {
380+
if (value === null || typeof value !== "object") {
381+
return false;
382+
}
383+
const obj = value as Record<string, unknown>;
384+
return (
385+
"lane" in obj &&
386+
typeof obj["lane"] === "number" &&
387+
"action" in obj &&
388+
"hasEagerState" in obj &&
389+
typeof obj["hasEagerState"] === "boolean" &&
390+
"eagerState" in obj &&
391+
"next" in obj &&
392+
(obj["next"] === null || typeof obj["next"] === "object")
393+
);
394+
}
395+
371396
// ============================================
372397
// Update Queue Type Guards
373398
// ============================================

0 commit comments

Comments
 (0)