'Promise'不能分配给类型错误'Promise'



我是 Angular 2 和 Angular 的新手,我遇到了与承诺相关的问题。

我有这个文件名模块.服务.ts

import { Injectable } from '@angular/core';
import { Module } from './module.entity';
@Injectable()
export class ModuleService {
  getModules(): Promise<Module[]> {
    // TODO: Switch to a real service.
    return Promise.resolve([{
      uiid: "text",
      type: "ahahaha"
    }]);
  }
}

哪个调用包含此代码的 module.entity:

export class Module {
  uuid: string = '00000';
  type: string = 'TextComponent';
  // Maps ModuleSlots to modules
  submodules: {[key: string]: [Module]} = {};
}

但是运行npm starts会向我返回此错误:

键入 'Promise<{ uiid: string; type: string; }[]>' 不可分配给 键入"承诺"。 键入 '{ uiid: string; type: string; }[]' 不能分配给类型"模块[]"。 类型"{ uiid: string; type: string; }' 不能分配给类型"模块"。 属性 'uuid' 在类型 '{ uiid: string; type: string; }' 中缺失。

任何人都可以给我一个关于什么不起作用的提示吗?

错误消息已经给你一个提示

Property 'uuid' is missing in type '{ uiid: string; type: string; }'

声明:

uuid: string = '00000';
 ^^

价值:

uiid: "text",
 ^^

最新更新