Skip to content

Commit

Permalink
Cast dimensions defaults to TDimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickDeVries committed May 15, 2024
1 parent 33dc61b commit 84dc4fb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
11 changes: 4 additions & 7 deletions src/hooks/UseForm/useForm/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,10 @@ import {
* @template {FieldsData} TData
* @returns {{ register: Register<TData>; errors: Errors<TData>; touched: Touched<TData>; handleSubmit: HandleSubmit<TData>; }}
*/
const useForm: UseForm = <TData extends FieldsData, TDimensions extends number = 0>(
{
dimensions,
isRequiredErrorMessageOverride,
// @ts-expect-error TDimensions defaults to 0 if dimensions is not defined, so this is okay
}: UseFormOptions<TDimensions> = { dimensions: 0 },
): UseFormReturn<TData, TDimensions> => {
const useForm: UseForm = <TData extends FieldsData, TDimensions extends number = 0>({
dimensions = 0 as TDimensions,
isRequiredErrorMessageOverride,
}: UseFormOptions<TDimensions> = {}): UseFormReturn<TData, TDimensions> => {
const fieldsGraph = useRef<FormData<Fields<TData, TDimensions>, TDimensions>>(
new Graph<Fields<TData, TDimensions>, TDimensions>({ dimensions }),
)
Expand Down
3 changes: 1 addition & 2 deletions src/hooks/UseGraph/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,7 @@ export class Graph<TData, TDimensions extends number = 0> implements IGraph<TDat
} else if (dimensions !== undefined) {
this.dimensions = dimensions
} else {
// @ts-expect-error TDimensions defaults to 0 if dimensions is not defined, so this is okay
this.dimensions = 0
this.dimensions = 0 as TDimensions
}
}
// #endregion
Expand Down
11 changes: 4 additions & 7 deletions src/hooks/UseGraph/useGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,10 @@ export type UseGraph = <TData, TDimensions extends number = 0>(
* @param {Graph<TData, TDimensions>} param0.initial
* @returns {UseGraphReturn<TData, TDimensions>}
*/
const useGraph: UseGraph = <TData, TDimensions extends number = 0>(
{
dimensions,
initial,
// @ts-expect-error TDimensions defaults to 0 if dimensions is not defined, so this is okay
}: UseGraphOptions<TData, TDimensions> = { dimensions: 0 },
): UseGraphReturn<TData, TDimensions> => {
const useGraph: UseGraph = <TData, TDimensions extends number = 0>({
dimensions = 0 as TDimensions,
initial,
}: UseGraphOptions<TData, TDimensions> = {}): UseGraphReturn<TData, TDimensions> => {
const [data, setData] = useState<Graph<TData, TDimensions>>(
initial ?? new Graph<TData, TDimensions>({ dimensions }),
)
Expand Down

0 comments on commit 84dc4fb

Please sign in to comment.