Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] Narrow our Form types when using hook_form_lib #60567

Closed
rylnd opened this issue Mar 18, 2020 · 5 comments
Closed

[SIEM] Narrow our Form types when using hook_form_lib #60567

rylnd opened this issue Mar 18, 2020 · 5 comments
Assignees
Labels
enhancement New value added to drive a business result Team:SIEM

Comments

@rylnd
Copy link
Contributor

rylnd commented Mar 18, 2020

Our current implementation has the following issue:

Schema are typed as FormSchema without specifying a generic type argument. example

This means the generic type defaults to FormData, which is just { [key: string]: any }, which causes most of our interactions with the form/library to be untyped (or, more specifically, to have the any type).

Instead, we should be declaring our schema similar to the following:

const schema: FormSchema<DefineStepRule> = { //...

And fixing all type errors that result from that.

There also seems to be an issue with the library itself, where providing a type parameter to FormSchema does not narrow the index signature of FormSchema, and so dealing with specific keys in the schema may still be untyped. My naive solution would start with this change:

-export interface FormSchema<T extends FormData = FormData> {
-  [key: string]: FormSchemaEntry<T>;
-}
+export type FormSchema<T extends FormData = FormData> = {
+  [K in keyof T]: FormSchemaEntry<T[K]>;
+};
@rylnd rylnd added enhancement New value added to drive a business result Team:SIEM labels Mar 18, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

@rylnd rylnd mentioned this issue Mar 18, 2020
7 tasks
@rylnd
Copy link
Contributor Author

rylnd commented Mar 18, 2020

Pinging @sebelga in case they have thoughts.

@sebelga
Copy link
Contributor

sebelga commented Mar 19, 2020

Thanks for raising the issue in the lib @rylnd! I created a separate issue to fix the FormSchema interface in the lib #60602

@rylnd
Copy link
Contributor Author

rylnd commented Oct 20, 2020

As mentioned above #60602 addressed the specific issue pointed out here. We still had a few ugly casts in our forms, but those were also addressed in #80842. IMO we're in a great position for now so I'm happy to close this. Thanks for all your help @sebelga !

@rylnd rylnd closed this as completed Oct 20, 2020
@sebelga
Copy link
Contributor

sebelga commented Oct 21, 2020

Thanks for your patience @rylnd ! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New value added to drive a business result Team:SIEM
Projects
None yet
Development

No branches or pull requests

3 participants