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

Add generic for value types #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 14 additions & 14 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ export type FieldName = string

export type FieldPattern = FieldName | RegExp | (FieldName | RegExp)[]

export type UpdatesByName = {
[FieldName: string]: (value: any, allValues?: Object, prevValues?: Object) => any
export type UpdatesByName<T> = {
[FieldName: string]: (value: any, allValues?: T, prevValues?: T) => any
}

export type UpdatesForAll = (
value: any,
export type UpdatesForAll<T> = (
value: T[keyof T],
field: string,
allValues?: Object,
prevValues?: Object,
allValues?: T,
prevValues?: T
) => { [FieldName: string]: any }

export type Updates = UpdatesByName | UpdatesForAll
export type Updates<T> = UpdatesByName<T> | UpdatesForAll<T>

export type Calculation = {
field: FieldPattern,
updates: Updates,
isEqual?: (a: any, b: any) => boolean,
export type Calculation<T extends object = Object> = {
field: FieldPattern
updates: Updates<T>
isEqual?: (a: any, b: any) => boolean
}

export default function createDecorator<FormValues = object>(
...calculations: Calculation[]
): Decorator<FormValues>
export default function createDecorator<T extends Object>(
...calculations: Calculation<T>[]
): Decorator