Skip to content

Commit

Permalink
πŸ”„ [chore]: Automated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
brunotot committed Sep 6, 2023
1 parent a7a5416 commit 6c5598e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
5 changes: 2 additions & 3 deletions packages/react/src/hooks/useForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ import ns from "./types";
* const [form, setForm, {
* isValid,
* isSubmitted,
* cachedHandlers,
* onSubmit,
* handleChange,
* errors,
* providerProps
* providerProps,
* mutations
* }] = useForm(MyClass)
* ```
*
Expand Down
42 changes: 21 additions & 21 deletions packages/react/src/hooks/useForm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,6 @@ import { Dispatch, SetStateAction } from "react";
import { Condition, Errors, TypeUtils, ValidationGroup } from "tdv-core";
import FormContextNamespace from "../../contexts/FormContext/types";

// prettier-ignore
type ObjectPathEvaluator<T, K extends string> = K extends keyof T
? K extends TypeUtils.WritableKeys<T>
? K | `${K}.${PayloadFieldPath<T[K]>}`
: ''
: never;

// prettier-ignore
type PayloadFieldPathEvaluator<T> = {
[K in keyof T]-?: K extends string
? Condition.isFunction<T[K]> extends true ? never :
Condition.isArray<T[K]> extends true ? K :
Condition.isObject<T[K]> extends true ? ObjectPathEvaluator<T, K> :
K extends TypeUtils.WritableKeys<T> ? K : never : never;
}

// prettier-ignore
type PayloadFieldPath<T> =
Condition.isFunction<T> extends true ? '' :
Condition.isObject<T> extends true ? PayloadFieldPathEvaluator<T>[keyof T] : '';

namespace UseFormHook {
export type UseFormConfig<TClass, TBody = TClass> = {
defaultValue?: TBody;
Expand Down Expand Up @@ -62,6 +41,27 @@ namespace UseFormHook {
export type UseFormChangeHandlerMap<TBody> = {
[TKey in keyof TBody]: (value: TBody[TKey]) => void;
};

// prettier-ignore
export type ObjectPathEvaluator<T, K extends string> = K extends keyof T
? K extends TypeUtils.WritableKeys<T>
? K | `${K}.${PayloadFieldPath<T[K]>}`
: ''
: never;

// prettier-ignore
export type PayloadFieldPathEvaluator<T> = {
[K in keyof T]-?: K extends string
? Condition.isFunction<T[K]> extends true ? never :
Condition.isArray<T[K]> extends true ? K :
Condition.isObject<T[K]> extends true ? ObjectPathEvaluator<T, K> :
K extends TypeUtils.WritableKeys<T> ? K : never : never;
}

// prettier-ignore
export type PayloadFieldPath<T> =
Condition.isFunction<T> extends true ? '' :
Condition.isObject<T> extends true ? PayloadFieldPathEvaluator<T>[keyof T] : '';
}

export default UseFormHook;

0 comments on commit 6c5598e

Please sign in to comment.