Свойство 'x' отсутствует в типе '() => x', но требуется в типе 'x' - PullRequest
0 голосов
/ 30 мая 2019

Ошибка: Property 'Control' is missing in type '() => Controls' but required in type 'Controls'.

export class Controls {
   Control: Control[];
}

page.Sections.push({
    ....
    Controls: () => {
      const c = new Controls();
      c.Control = new Array<Ctrl>();
      section.VisualComponents.forEach(vc => {
          c.Control.push({
            ....
            ....

        });
      });
      return c;
    }
  });

Что я делаю не так?

1 Ответ

1 голос
/ 30 мая 2019

Вы должны иметь массив Controls[], но назначаете функцию Controls: () => {:

export class Controls {
   Control: Control[]; /// HERE
}

page.Sections.push({
    ....
    Controls: () => { // HERE 
      const c = new Controls();
      c.Control = new Array<Ctrl>();
      section.VisualComponents.forEach(vc => {
          c.Control.push({
            ....
            ....

        });
      });
      return c;
    }
  });

Fix

Вызовите функцию, чтобы получить ее возвращаемое значение, например:

const createControls = () => {
      const c = new Controls();
      c.Control = new Array<Ctrl>();
      section.VisualComponents.forEach(vc => {
          c.Control.push({
            ....
            ....

        });
      });
      return c;
    };
export class Controls {
   Control: Control[];
}

page.Sections.push({
    ....
    Controls: createControls()
  });
...