Our state of the art Gantt chart


Post by beotech »

Hi, we are having Typescript compilation issues with custom fields of Model classes that we have extended.

Here is an example :

export default class CustomResourceModel extends ResourceModel {

  static get fields() {
    return [
      { name: 'type', type: 'number' },
      { name: 'subType', type: 'number' },
    ];
  }
}

const model = new CustomResourceModel();
model.type = 1; // Property 'type' does not exist on type 'CustomResourceModel '.ts(2339)

How can we make the compiler know the custom fields too ?


Post by marcio »

Hey beotech,

Thanks for reaching out.

To make the compiler know about the custom field on TypeScript, you need to declare the custom fields at the top of the class, like the following snippet

export default class CustomResourceModel extends ResourceModel {

declare type: Number;
declare subType: Number;

static get fields() {
    return [
      { name: 'type', type: 'number' },
      { name: 'subType', type: 'number' },
    ];
  }

Best regards,
Márcio

How to ask for help? Please read our Support Policy


Post Reply