Skip to content

Commit

Permalink
fix(types): infer the model value prop name correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Sep 9, 2023
1 parent 4465fe7 commit f683e90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-knives-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vee-validate': patch
---

fix(types): infer the model value prop name correctly
20 changes: 13 additions & 7 deletions packages/vee-validate/src/types/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,20 +285,26 @@ export type PublicPathState<TValue = unknown> = Omit<
'bails' | 'label' | 'multiple' | 'fieldsCount' | 'validate' | 'id' | 'type' | '__flags'
>;

export interface ComponentBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject> {
export interface ComponentBindsConfig<
TValue = unknown,
TExtraProps extends GenericObject = GenericObject,
TModel extends string = 'modelValue',
> {
mapProps: (state: PublicPathState<TValue>) => TExtraProps;
validateOnBlur: boolean;
validateOnModelUpdate: boolean;
model: string;
model: TModel;
}

export type LazyComponentBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject> = (
state: PublicPathState<TValue>,
) => Partial<{
export type LazyComponentBindsConfig<
TValue = unknown,
TExtraProps extends GenericObject = GenericObject,
TModel extends string = 'modelValue',
> = (state: PublicPathState<TValue>) => Partial<{
props: TExtraProps;
validateOnBlur: boolean;
validateOnModelUpdate: boolean;
model: string;
model: TModel;
}>;

export interface BaseInputBinds<TValue = unknown> {
Expand Down Expand Up @@ -353,7 +359,7 @@ export interface FormContext<TValues extends GenericObject = GenericObject, TOut
TExtras extends GenericObject = GenericObject,
>(
path: MaybeRefOrGetter<TPath>,
config?: Partial<ComponentBindsConfig<TValue, TExtras>> | LazyComponentBindsConfig<TValue, TExtras>,
config?: Partial<ComponentBindsConfig<TValue, TExtras, TModel>> | LazyComponentBindsConfig<TValue, TExtras, TModel>,
): Ref<BaseComponentBinds<TValue, TModel> & TExtras>;
defineInputBinds<
TPath extends Path<TValues>,
Expand Down
2 changes: 1 addition & 1 deletion packages/vee-validate/src/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ export function useForm<
TExtras extends GenericObject = GenericObject,
>(
path: MaybeRefOrGetter<TPath>,
config?: Partial<ComponentBindsConfig<TValue, TExtras>> | LazyComponentBindsConfig<TValue, TExtras>,
config?: Partial<ComponentBindsConfig<TValue, TExtras, TModel>> | LazyComponentBindsConfig<TValue, TExtras, TModel>,
) {
const pathState = findPathState(toValue(path)) || createPathState(path);
const evalConfig = () => (isCallable(config) ? config(omit(pathState, PRIVATE_PATH_STATE_KEYS)) : config || {});
Expand Down

0 comments on commit f683e90

Please sign in to comment.