formio / formio.js

JavaScript powered Forms with JSON Form Builder
https://formio.github.io/formio.js
MIT License
1.83k stars 1.05k forks source link

Typing issue with emptyValue property on Component #5481

Open hisuwh opened 5 months ago

hisuwh commented 5 months ago

I'm creating a custom component and need to override emptyValue to set the default to an array for my component (as per the example: https://help.form.io/developers/form-development/custom-components#checkmatrix-component).

However, Typescript is giving me errors:

image

I can resolve the first one by saying return ([] as any);

But the only way around the second one is use // @ts-ignore or equiv which I don't like. Looking at the source I can see this is a property in the base so there must be an issue in the generated types. https://github.com/formio/formio.js/blob/master/src/components/_classes/component/Component.js#L2443

Jameskmonger commented 5 months ago

It looks like all the accessors are actually declared as just properties in the types. If there is no associated set, then they are also marked as readonly.

In this instance, it is declared as readonly emptyValue: null; whereas we would need it declared as get emptyValue(): null; (or, ideally, to fix both issues, get emptyValue(): any;)