【问题标题】:aurelia-fetch-client.d.ts undefined symbolsaurelia-fetch-client.d.ts 未定义符号
【发布时间】:2016-10-13 06:58:52
【问题描述】:

当我在我的项目中包含 aurelia-fetch-client 时,我遇到了一些我无法解决的错误。它说它找不到:Request、Response、Headers、BufferSource、URLSearchParams,如下图所示:

我该如何解决?

【问题讨论】:

    标签: javascript aurelia


    【解决方案1】:

    为 whatwg-fetch 添加 typescript 定义文件:

    https://github.com/borisyankov/DefinitelyTyped/blob/master/whatwg-fetch/whatwg-fetch.d.ts

    以下是有关 fetch 规范的更多信息:

    https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API

    【讨论】:

    【解决方案2】:

    安装 whatwg-fetch 类型和类型。

    可以使用typings 来安装whatwg-fetch 类型。

    npm install typings --global
    typings install dt~whatwg-fetch --global
    

    以上从DefinitelyTyped (dt) 安装它们。

    使用 npm (TypeScript 2.0) 安装 whatwg-fetch 类型。

    npm install --save @types/whatwg-fetch
    

    进一步调整

    注意:TypeScript 可能仍会抱怨它“找不到名称 'URLSearchParams'”。我们可以通过将接口添加到我们的一个类型文件中来解决这个问题。例如:

    custom_typings/adhoc_interfaces.d.ts

    interface URLSearchParams {}
    

    【讨论】:

    • 我还必须添加接口 ReadableStream {}
    猜你喜欢
    • 1970-01-01
    • 2017-11-06
    • 2016-03-12
    • 2021-07-16
    • 2016-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    相关资源
    最近更新 更多