Skip to content

Commit

Permalink
mod
Browse files Browse the repository at this point in the history
  • Loading branch information
irishcarbomb777 committed May 3, 2024
1 parent 60e4592 commit 6f21eba
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/base/defineNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type Concrete<T extends Record<string, any>> = {
[P in keyof T]: NonNullable<T[P]>;
};


type DefaultType<T> = T extends ZodTypeAny ? InferZodSchema<T> : never;
export class NodeDefinition<T extends string, StateDefinition extends ZodObject<any>, StateDefaults extends ZodObject<any> = ZodObject<{}>> {
nodeType: T;
stateDefinition: StateDefinition;
Expand All @@ -26,7 +28,9 @@ export class NodeDefinition<T extends string, StateDefinition extends ZodObject<

defaults<Defaults extends { [K in keyof TypeOf<StateDefinition>]?: TypeOf<StateDefinition>[K] }>(
defaults: Defaults
): NodeDefinition<T, StateDefinition, ZodObject<Concrete<Defaults>, any, any, Concrete<Defaults>>> {
): NodeDefinition<T, StateDefinition, ZodObject<{
[K in keyof Defaults]: StateDefinition['shape'][K]
}>> {
const defaultsDefinition = Object.entries(this.stateDefinition.shape).reduce((acc, [key, value]) => ({
...acc,
[key]: (value as any).default(defaults[key])
Expand Down

0 comments on commit 6f21eba

Please sign in to comment.