Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
feat(types): export more types
Browse files Browse the repository at this point in the history
  • Loading branch information
wellyshen committed Dec 21, 2020
1 parent 5df6e96 commit 8af3145
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-apricots-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-cool-form": patch
---

feat(types): export more types
30 changes: 20 additions & 10 deletions src/types/react-cool-form.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,33 @@ declare module "react-cool-form" {
): any;
}

export interface PreviousErrorsFn {
(previousErrors: Errors<V>): Errors<V> | undefined;
}

interface SetErrors<V> {
(
errors?:
| Errors<V>
| ((previousErrors: Errors<V>) => Errors<V> | undefined)
): void;
(errors?: Errors<V> | PreviousErrorsFn): void;
}

export interface PreviousErrorFn {
(previousError?: any): any;
}

interface SetFieldError {
(name: string, error?: any | ((previousError?: any) => any)): void;
(name: string, error?: any | PreviousErrorFn): void;
}

type ValuesArg<V> = V | ((previousValues: V) => V);
export interface PreviousValuesFn<V = any> {
(previousValues: V): V;
}

export interface FieldNamesFn {
(fieldNames: string[]): string[];
}

interface SetValues<V> {
(
values: ValuesArg<V>,
values: V | PreviousValuesFn<V>,
options?: {
shouldValidate?: boolean;
touchedFields?: string[] | FieldNamesFn;
Expand All @@ -121,10 +127,14 @@ declare module "react-cool-form" {
): void;
}

export interface PreviousValueFn {
(previousValue: any): any;
}

interface SetFieldValue {
(
name: string,
value: any | ((previousValue: any) => any),
value: any | PreviousValueFn,
options?: {
[k in "shouldValidate" | "shouldTouched" | "shouldDirty"]?: boolean;
}
Expand All @@ -141,7 +151,7 @@ declare module "react-cool-form" {

interface Reset<V> {
(
values?: ValuesArg<V> | null,
values?: V | PreviousValuesFn<V> | null,
exclude?: (keyof FormState<V>)[] | null,
event?: SyntheticEvent<any>
): void;
Expand Down

0 comments on commit 8af3145

Please sign in to comment.