【问题标题】:typedef expected call-signature error for Angular2 tutorial with VS2015带有 VS2015 的 Angular2 教程的 typedef 预期调用签名错误
【发布时间】:2016-10-28 18:20:02
【问题描述】:

我正在 VS2015 中学习 Angular2 教程,但遇到一个警告,阻止我的一个 TypeScript 文件编译。教程链接如下。

https://angular.io/docs/ts/latest/tutorial/toh-pt4.html

警告是代码 typedef,描述 expected call-signature: 'getHeroes' to have a typedef

import { Injectable } from "@angular/core";

import { HEROES } from "./mock-heroes";

@Injectable()

export class HeroService {
    getHeroes() {
        return Promise.resolve(HEROES);
    }
}

我进行了一些搜索,但找不到任何对我有意义的内容...我很新并且正在学习...

有人可以帮我解决我应该如何更改上面的 TypeScript 代码来设置 getHeroes 方法返回的 Promise 的返回类型定义。

【问题讨论】:

  • 我在您的文件中看不到任何 getHeroes 吗?

标签: typescript angular


【解决方案1】:

我想通了...需要导入 Hero,然后将函数返回类型设置为 Promise

import { Injectable } from "@angular/core";

import { HEROES } from "./mock-heroes";
import { Hero } from "./hero";

@Injectable()
export class HeroService {
    getHeroes(): Promise<Hero[]> {
        return Promise.resolve(HEROES);
    }
}

【讨论】:

    猜你喜欢
    • 2021-08-18
    • 1970-01-01
    • 2014-12-26
    • 2019-05-22
    • 2019-12-07
    • 2020-07-07
    • 1970-01-01
    • 2023-03-15
    • 2016-04-21
    相关资源
    最近更新 更多