Page 2 of 2

Re: Define multiple model subclass type via crud manager for a single store

Posted: Fri Jan 27, 2023 11:55 pm
by jarmen

I was able to make this work by using @ts-ignore, the constructor should be exposed in such a way we can use it for this purpose.

export class AppResourceModel
  extends ResourceModel
{
  static get $$name(): string {
    return 'AppResourceModel';
  }

  static override get fields(): Partial<DataFieldConfig>[] {
    return [
      { name: 'newfield', type: 'string' },
  }

  constructor(
    config: Partial<AppResourceModelConfig>,
    a = null,
    b = null,
    c = null,
    d = null
  ) {
    // @ts-ignore
    super(config, a, b, c, d);
  }
  

Re: Define multiple model subclass type via crud manager for a single store

Posted: Mon Jan 30, 2023 11:11 am
by alex.l

Thanks for informing us, I've opened a ticket to fix typings for that https://github.com/bryntum/support/issues/6077
For now, please use the code you posted as a workaround.


Re: Define multiple model subclass type via crud manager for a single store

Posted: Mon Jan 30, 2023 12:41 pm
by alex.l

There is another valid workaround for this case:

resourceStore: {
  modelClass: Gate,
  createRecord(data, skipExpose = false, rawData = false) {
        let modelClass = this.modelClass as typeof Model;
        if (data.type === 'terminal') {
            modelClass = Terminal as typeof Model;
        }

    return new modelClass(data, this);
  }
},