@@ -3,7 +3,9 @@ import cloneDeep from 'lodash.clonedeep'
3
3
import isEqual from 'lodash.isequal'
4
4
import { reactive , watch } from 'vue'
5
5
6
- interface InertiaFormProps < TForm > {
6
+ type FormDataType = object ;
7
+
8
+ interface InertiaFormProps < TForm extends FormDataType > {
7
9
isDirty : boolean
8
10
errors : Record < keyof TForm , string >
9
11
hasErrors : boolean
@@ -29,16 +31,16 @@ interface InertiaFormProps<TForm> {
29
31
cancel ( ) : void
30
32
}
31
33
32
- export type InertiaForm < TForm > = TForm & InertiaFormProps < TForm >
34
+ export type InertiaForm < TForm extends FormDataType > = TForm & InertiaFormProps < TForm >
33
35
34
36
export interface InertiaFormTrait {
35
- form < TForm > ( data : TForm ) : InertiaForm < TForm >
36
- form < TForm > ( rememberKey : string , data : TForm ) : InertiaForm < TForm >
37
+ form < TForm extends FormDataType > ( data : TForm ) : InertiaForm < TForm >
38
+ form < TForm extends FormDataType > ( rememberKey : string , data : TForm ) : InertiaForm < TForm >
37
39
}
38
40
39
- export default function useForm < TForm > ( data : TForm | ( ( ) => TForm ) ) : InertiaForm < TForm >
40
- export default function useForm < TForm > ( rememberKey : string , data : TForm | ( ( ) => TForm ) ) : InertiaForm < TForm >
41
- export default function useForm < TForm > ( ...args ) : InertiaForm < TForm > {
41
+ export default function useForm < TForm extends FormDataType > ( data : TForm | ( ( ) => TForm ) ) : InertiaForm < TForm >
42
+ export default function useForm < TForm extends FormDataType > ( rememberKey : string , data : TForm | ( ( ) => TForm ) ) : InertiaForm < TForm >
43
+ export default function useForm < TForm extends FormDataType > ( ...args ) : InertiaForm < TForm > {
42
44
const rememberKey = typeof args [ 0 ] === 'string' ? args [ 0 ] : null
43
45
const data = ( typeof args [ 0 ] === 'string' ? args [ 1 ] : args [ 0 ] ) || { }
44
46
const restored = rememberKey ? ( router . restore ( rememberKey ) as { data : any ; errors : any } ) : null
0 commit comments