Skip to content

Commit

Permalink
[Form lib] Improve TS typing for FormSchema
Browse files Browse the repository at this point in the history
The typings for the FromSchema was too permissive and did not limit the keys to the form interface provided.
Fixes elastic#60602
  • Loading branch information
sebelga committed Sep 24, 2020
1 parent d891eac commit 2d1f28a
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/plugins/es_ui_shared/static/forms/hook_form_lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,9 @@ export interface FormHook<T extends FormData = FormData> {
__getFieldDefaultValue: (fieldName: string) => unknown;
}

export interface FormSchema<T extends FormData = FormData> {
[key: string]: FormSchemaEntry<T>;
}

type FormSchemaEntry<T extends FormData> =
| FieldConfig<T>
| Array<FieldConfig<T>>
| { [key: string]: FieldConfig<T> | Array<FieldConfig<T>> | FormSchemaEntry<T> };
export type FormSchema<T extends FormData = FormData> = {
[K in keyof T]: FieldConfig<T, T[K]> | FormSchema<T[K]>;
};

export interface FormConfig<T extends FormData = FormData> {
onSubmit?: FormSubmitHandler<T>;
Expand Down

0 comments on commit 2d1f28a

Please sign in to comment.