Skip to content

Commit 20035fd

Browse files
authored
Provide FormValues for createDecorator (#39)
If FormValues is specified for a form, then type 'Decorator<object>' is not assignable to type 'Decorator<FormValues>'
1 parent 409c261 commit 20035fd

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"eslint-plugin-import": "^2.16.0",
5353
"eslint-plugin-jsx-a11y": "^6.2.1",
5454
"eslint-plugin-react": "^7.12.4",
55-
"final-form": "^4.11.1",
55+
"final-form": "^4.19.1",
5656
"flow": "^0.2.3",
5757
"flow-bin": "^0.92.1",
5858
"glow": "^1.2.2",

src/decorator.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// @flow
2-
import type { Decorator, FormApi } from 'final-form'
2+
import type { Decorator, FormApi, FormValuesShape } from 'final-form'
33
import type { Calculation, Updates } from './types'
44
import { getIn } from 'final-form'
55
import isPromise from './isPromise'
66

77
const tripleEquals = (a: any, b: any) => a === b
8-
const createDecorator = (...calculations: Calculation[]): Decorator => (
9-
form: FormApi
10-
) => {
8+
const createDecorator = <FormValues: FormValuesShape>(
9+
...calculations: Calculation[]
10+
): Decorator<FormValues> => (form: FormApi<FormValues>) => {
1111
let previousValues = {}
1212
const unsubscribe = form.subscribe(
1313
({ values }) => {

src/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ export type Calculation = {
2323
isEqual?: (a: any, b: any) => boolean,
2424
}
2525

26-
export default function createDecorator(
26+
export default function createDecorator<FormValues = object>(
2727
...calculations: Calculation[]
28-
): Decorator
28+
): Decorator<FormValues>

src/index.js.flow

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
2-
import type { Decorator } from 'final-form'
2+
import type { Decorator, FormValuesShape } from 'final-form'
33
import type { Calculation } from './types'
44

5-
declare export default function createDecorator(
5+
declare export default function createDecorator<FormValues: FormValuesShape>(
66
...calculations: Calculation[]
7-
): Decorator
7+
): Decorator<FormValues>

0 commit comments

Comments
 (0)