-
Notifications
You must be signed in to change notification settings - Fork 6
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
fix: replace any in TS defs with generics #79
Conversation
If I understand this correctly this assumes that the value type of custom field itself is the same as the value type of all of it's children/fields which makes this not so useful. Imo you should be able to have a e.g. a custom field that contains fields with different value types and also the value type of the custom field itself can differ from those. I'm not sure if there's any practical way to describe that more strictly than using Maybe we could have a generic class The user can still extend We could also say that all the types are |
This is how it currently works out of the box. That's why I wanted to reflect that in TS defs. Of course, we could switch to use generics a bit differently: export type CustomFieldParseValueFn<I, O> = (value: I) => Array<O>;
export type CustomFieldFormatValueFn<I, O> = (inputValues: Array<I>) => O;
export type CustomFieldI18n = {
parseValue: CustomFieldParseValueFn<string, string>;
formatValue: CustomFieldFormatValueFn<string, string>;
}; That would still cover the current logic, and should also allow what you requested. |
Here is a playground link illustrating the alternatives:
|
After some more research, I came to the conclusion that we have to choose in what way our TS definitions would affect developer experience:
My current proposal is to change TS definitions like this: export type CustomFieldParseValueFn = (value: string) => Array<unknown>;
export type CustomFieldFormatValueFn = (inputValues: Array<unknown>) => string; Here is another playground link to try it out. I will update the PR as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your examples. I think this is a good compromise.
This should better describe our current API and allow developers to provide their own helpers while keeping type checking support, instead of disabling it completely with
any
.