formio / formio.js

JavaScript powered Forms with JSON Form Builder

Home Page:https://formio.github.io/formio.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typing issue with emptyValue property on Component

hisuwh opened this issue · comments

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

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;)