Skip to content

Commit

Permalink
fix: better type for ValidatorType
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-efremoff committed Mar 18, 2024
1 parent c6bba62 commit 9d0bcc1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- main
- release-v*
- release/v*

jobs:
release:
Expand Down
6 changes: 3 additions & 3 deletions src/dialog/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ import {CollapsibleSection} from '../CollapsibleSection/CollapsibleSection';
const bDialog = dfCN('dialog');
const bPage = dfCN('page-dialog');

function composeValidators<T>(...validators: Array<ValidatorType<T>>) {
return async (value: T, allValues: object | undefined, state?: FieldState<T>) => {
function composeValidators<T, FormValuesT>(...validators: Array<ValidatorType<T, FormValuesT>>) {
return async (value: T, allValues: FormValuesT, state?: FieldState<T>) => {
for (const validate of validators) {
try {
const res = await validate(value, allValues, state);
Expand Down Expand Up @@ -179,7 +179,7 @@ export interface ControlField<
tooltip?: React.ReactNode;
warning?: React.ReactNode;

validator?: ValidatorType<V>;
validator?: ValidatorType<V, FormValues>;
validateFields?: string[];

subscribers?: Updates;
Expand Down
6 changes: 3 additions & 3 deletions src/dialog/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {FieldState} from 'final-form';

export type ValidatorType<T> = (
export type ValidatorType<T, FormValues> = (
value: T,
allValues?: Record<string, any>,
allValues?: FormValues,
fieldState?: FieldState<T>,
) => PromiseOrValue<string | undefined>;

Expand All @@ -23,7 +23,7 @@ export interface ControlStaticApi<V> {
isEmpty?: (value: V) => boolean;
getDefaultValue: () => V;
hasErrorRenderer?: boolean;
validate?: ValidatorType<V>;
validate?: ValidatorType<V, any>;
format?: (value: V, name: string) => any;
isEqual?: (a: V, b: V) => boolean;

Expand Down
2 changes: 1 addition & 1 deletion src/stories/dialog/register/RegisterControls.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function Demo() {
'\n isEmpty?: (value: V) => boolean;' +
'\n getDefaultValue: () => V;' +
'\n hasErrorRenderer?: boolean;' +
'\n validate?: ValidatorType<V>;' +
'\n validate?: ValidatorType<V, any>;' +
'\n format?: (value: V, name: string) => any;' +
'\n }\n\n'}
</code>
Expand Down

0 comments on commit 9d0bcc1

Please sign in to comment.