1
1
/* tslint:disable: no-shadowed-variable */
2
- import { Mutator } from 'final-form' ;
2
+ /* eslint-disable @typescript-eslint/no-unused-vars */
3
+
4
+ import { Decorator , Mutator } from 'final-form' ;
3
5
import * as React from 'react' ;
4
6
import { Field , Form } from 'react-final-form' ;
5
7
@@ -131,15 +133,20 @@ function mutated() {
131
133
) ;
132
134
}
133
135
134
- const typedOnSubmit = ( values : { firstName : string } ) => {
136
+ interface UserForm {
137
+ firstName : string ;
138
+ lastName : string ;
139
+ }
140
+
141
+ const typedOnSubmit = ( values : UserForm ) => {
135
142
// tslint:disable-next-line no-console
136
143
console . log ( values ) ;
137
144
} ;
138
145
139
146
// with typed form data and field
140
147
function withTypedFormData ( ) {
141
148
return (
142
- < Form < { firstName : string } > onSubmit = { typedOnSubmit } >
149
+ < Form < UserForm > onSubmit = { typedOnSubmit } >
143
150
{ ( { handleSubmit } ) => (
144
151
< form onSubmit = { handleSubmit } >
145
152
< div >
@@ -157,3 +164,25 @@ function withTypedFormData() {
157
164
</ Form >
158
165
) ;
159
166
}
167
+
168
+ const decorator : Decorator < UserForm > = form => {
169
+ return form . subscribe ( ( { values : { firstName } } ) => firstName , {
170
+ values : true
171
+ } ) ;
172
+ } ;
173
+
174
+ // with typed decorator
175
+ function withTypedDecorator ( ) {
176
+ return < Form < UserForm > decorators = { [ decorator ] } onSubmit = { typedOnSubmit } /> ;
177
+ }
178
+
179
+ // with wrong typed decorator
180
+ function withWrongTypedDecorator ( ) {
181
+ return (
182
+ < Form < Omit < UserForm , 'firstName' > >
183
+ // $ExpectError
184
+ decorators = { [ decorator ] }
185
+ onSubmit = { noop }
186
+ />
187
+ ) ;
188
+ }
0 commit comments