Skip to content

Commit a49db27

Browse files
committed
Fix types for compose validators
1 parent 778f072 commit a49db27

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { Validator } from './validate';
22
import AnyObject from './any-object';
33

4-
export type ComposeValidators = (validators: Validator[]) => (value: any, allValues: AnyObject) => Promise<any> | any;
4+
export interface WarningObject<T = string | undefined> {
5+
type: string;
6+
error: T;
7+
}
8+
9+
export type ComposeValidators<T = WarningObject | string | undefined> = (
10+
validators: Validator[]
11+
) => (value: any, allValues: AnyObject) => Promise<T> | T;
512

613
export default ComposeValidators;

packages/form-state-manager/src/utils/manager-api.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import CreateManagerApi, {
2424
import AnyObject from '../types/any-object';
2525
import FieldConfig, { IsEqual } from '../types/field-config';
2626
import { Meta } from '../types/use-field';
27+
import { WarningObject } from '../types/compose-validators';
2728
import { formLevelValidator, isPromise } from './validate';
2829
import { FormValidator, FormLevelError, Validator } from '../types/validate';
2930
import findDifference from './find-difference';
@@ -323,12 +324,12 @@ const createManagerApi: CreateManagerApi = ({
323324
});
324325
listener.registerValidator(result as Promise<string | undefined>);
325326
} else {
326-
if (result?.type === 'warning') {
327+
if ((result as WarningObject)?.type === 'warning') {
327328
setFieldState(name, (prev: FieldState) => ({
328329
...prev,
329330
meta: {
330331
...prev.meta,
331-
warning: result.error
332+
warning: (result as WarningObject)?.error
332333
}
333334
}));
334335
} else {

0 commit comments

Comments
 (0)