Skip to content

Commit f683e90

Browse files
committed
fix(types): infer the model value prop name correctly
1 parent 4465fe7 commit f683e90

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

.changeset/tame-knives-trade.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'vee-validate': patch
3+
---
4+
5+
fix(types): infer the model value prop name correctly

packages/vee-validate/src/types/forms.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,26 @@ export type PublicPathState<TValue = unknown> = Omit<
285285
'bails' | 'label' | 'multiple' | 'fieldsCount' | 'validate' | 'id' | 'type' | '__flags'
286286
>;
287287

288-
export interface ComponentBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject> {
288+
export interface ComponentBindsConfig<
289+
TValue = unknown,
290+
TExtraProps extends GenericObject = GenericObject,
291+
TModel extends string = 'modelValue',
292+
> {
289293
mapProps: (state: PublicPathState<TValue>) => TExtraProps;
290294
validateOnBlur: boolean;
291295
validateOnModelUpdate: boolean;
292-
model: string;
296+
model: TModel;
293297
}
294298

295-
export type LazyComponentBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject> = (
296-
state: PublicPathState<TValue>,
297-
) => Partial<{
299+
export type LazyComponentBindsConfig<
300+
TValue = unknown,
301+
TExtraProps extends GenericObject = GenericObject,
302+
TModel extends string = 'modelValue',
303+
> = (state: PublicPathState<TValue>) => Partial<{
298304
props: TExtraProps;
299305
validateOnBlur: boolean;
300306
validateOnModelUpdate: boolean;
301-
model: string;
307+
model: TModel;
302308
}>;
303309

304310
export interface BaseInputBinds<TValue = unknown> {
@@ -353,7 +359,7 @@ export interface FormContext<TValues extends GenericObject = GenericObject, TOut
353359
TExtras extends GenericObject = GenericObject,
354360
>(
355361
path: MaybeRefOrGetter<TPath>,
356-
config?: Partial<ComponentBindsConfig<TValue, TExtras>> | LazyComponentBindsConfig<TValue, TExtras>,
362+
config?: Partial<ComponentBindsConfig<TValue, TExtras, TModel>> | LazyComponentBindsConfig<TValue, TExtras, TModel>,
357363
): Ref<BaseComponentBinds<TValue, TModel> & TExtras>;
358364
defineInputBinds<
359365
TPath extends Path<TValues>,

packages/vee-validate/src/useForm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ export function useForm<
963963
TExtras extends GenericObject = GenericObject,
964964
>(
965965
path: MaybeRefOrGetter<TPath>,
966-
config?: Partial<ComponentBindsConfig<TValue, TExtras>> | LazyComponentBindsConfig<TValue, TExtras>,
966+
config?: Partial<ComponentBindsConfig<TValue, TExtras, TModel>> | LazyComponentBindsConfig<TValue, TExtras, TModel>,
967967
) {
968968
const pathState = findPathState(toValue(path)) || createPathState(path);
969969
const evalConfig = () => (isCallable(config) ? config(omit(pathState, PRIVATE_PATH_STATE_KEYS)) : config || {});

0 commit comments

Comments
 (0)