-
Notifications
You must be signed in to change notification settings - Fork 556
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
feat(core): improve Formly config structure #3242
Conversation
9a29f0c
to
e678517
Compare
✅ Deploy Preview for formly-dev ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
e678517
to
78d5197
Compare
✅ Deploy Preview for formly-dev ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for formly-dev ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
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.
@aitboudad I tried to look at some changes.
@@ -56,6 +57,18 @@ export class CoreExtension implements FormlyExtension { | |||
this.getFieldComponentInstance(field).postPopulate?.(field); | |||
} | |||
|
|||
private initFieldProps(field: FormlyFieldConfigCache) { | |||
if (!field.props) { |
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.
if (!field.props) { | |
field.props ??= field.templateOptions |
@@ -34,7 +34,10 @@ export interface FormlyFieldConfig { | |||
/** | |||
* This is reserved for the templates. Any template-specific options go in here. Look at your specific template implementation to know the options required for this. | |||
*/ | |||
templateOptions?: FormlyTemplateOptions; | |||
props?: FormlyFieldProps; |
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.
export interface FormlyFieldConfig<Props extends FormlyFieldProps> {
…
props?: Props;
This could be a generic. Then you could make union types of the fields and get better type autocompletion.
E.g:
export interface TextareaFieldConfig extends FormFieldConfig<TextareaProps> {
type: "textarea";
}
export interface TextareaProps extends FormlyFieldProps {
row: number;
cols: number;
}
export type FieldConfigTypes = TextareaFieldConfig | TelephoneFieldConfig | …;
And then I would urgently remove additionalProps as this makes accurate typing much more difficult.
For the transition I would allow these additionalProps only at templateOptions
and not at props
.
get props() { | ||
return (this.field.props || {}) as NonNullable<F['props']>; |
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.
get props() { | |
return (this.field.props || {}) as NonNullable<F['props']>; | |
get props(): NonNullable<F['props']> { | |
this.field.props ??= {}; | |
return this.field.props; |
Is this not needed?
@manuelmeister would you like provide a PR for these changes? |
I'm currently quite busy, so I'm don't know when I have time to implement this. |
Ok, will do it then! |
fix #2853