@@ -5,11 +5,11 @@ import {mapValues} from './utils/map-values'
5
5
import noop from './utils/noop'
6
6
import { ValidateError , ValidationRule } from "./typing"
7
7
import { actions , reducer } from "./reducer"
8
- import { FiledType } from "./filed-type"
8
+ import { FiledType } from "./filed-type"
9
9
10
10
export interface FieldOption {
11
11
rules ?: ValidationRule [ ] ,
12
- type ?: 'text' | 'checkbox' | 'boolean' | 'radio'
12
+ type ?: FiledType
13
13
}
14
14
15
15
export type UseForm = < T > ( initialData : Partial < T > ) => [
@@ -42,7 +42,7 @@ const getFieldData = (value) => {
42
42
}
43
43
}
44
44
45
- export function getResetValue ( type ) {
45
+ export function getResetValue ( type ?: FiledType ) {
46
46
switch ( type ) {
47
47
case FiledType . text :
48
48
return ''
@@ -89,7 +89,6 @@ const useForm: UseForm = <T>(intial: Partial<T>) => {
89
89
if ( option ) {
90
90
fieldOptions [ name ] = option
91
91
}
92
- return null
93
92
}
94
93
95
94
const getValidateDescriptor = useCallback ( ( type ) => {
@@ -160,12 +159,12 @@ const useForm: UseForm = <T>(intial: Partial<T>) => {
160
159
}
161
160
}
162
161
163
- const field = < K extends keyof T > ( name : K , option : FieldOption = { } ) => {
162
+ const field = < K extends keyof T > ( name : K , option ? : FieldOption ) => {
164
163
setOption ( name , option )
165
164
return {
166
165
get value ( ) {
167
166
const value = get ( state , `fields.${ name } .value` )
168
- return value === undefined ? getResetValue ( option . type ) : value
167
+ return value === undefined ? getResetValue ( option && option . type ) : value
169
168
} ,
170
169
set value ( value ) {
171
170
this . onChange ( value )
0 commit comments