Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better type for ValidatorType #62

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@ -96,8 +96,8 @@
return isTabControl(field.type);
}

function isArrayOfTabs<F>(v: any): v is Array<TabbedField<F>> {

Check warning on line 99 in src/dialog/Dialog/Dialog.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
return Dialog.hasTabs(v);

Check warning on line 100 in src/dialog/Dialog/Dialog.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'Dialog' was used before it was defined
}

function isTabControl(type?: string) {
Expand Down Expand Up @@ -131,10 +131,10 @@
return undefined;
}

function checkFieldsSpec(props: {fields: Array<any>}) {

Check warning on line 134 in src/dialog/Dialog/Dialog.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
const error = checkTabSpecCorrectness(props.fields);
if (error) {
console.error(

Check warning on line 137 in src/dialog/Dialog/Dialog.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
'Tab specification is wrong, please recheck provided `field` property',
error,
);
Expand All @@ -145,8 +145,8 @@

export interface ControlField<
T extends string = string,
V = any,

Check warning on line 148 in src/dialog/Dialog/Dialog.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
E = Record<string, any>,

Check warning on line 149 in src/dialog/Dialog/Dialog.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
FormValues = unknown,
> {
name: string;
Expand All @@ -161,7 +161,7 @@
| ((
allValues: FormValues,
options: {
form: FormApi<any>;

Check warning on line 164 in src/dialog/Dialog/Dialog.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
input: FieldInputProps<V>;
field: ControlField<T, V, E, FormValues>;
},
Expand All @@ -170,7 +170,7 @@

visibilityCondition?: {
when: FieldName;
isActive: (v: any) => boolean;

Check warning on line 173 in src/dialog/Dialog/Dialog.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
};

className?: string;
Expand All @@ -179,7 +179,7 @@
tooltip?: React.ReactNode;
warning?: React.ReactNode;

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

subscribers?: Updates;
Expand All @@ -188,7 +188,7 @@
oldValue: V,
field: ControlField<T, V>,
fullName: string,
form: FormApi<any>,

Check warning on line 191 in src/dialog/Dialog/Dialog.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected any. Specify a different type
formValues: FormState<any>,
) => void;
error?: () => void;
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
Loading