【问题标题】:Cannot find gapi functions with Angular2使用 Angular2 找不到 gapi 函数
【发布时间】:2017-02-16 08:57:27
【问题描述】:

我想使用 Google 的 JS API,所以我将它包含在我的 index.html 中并使用 typings install dt~gapi --global --save 安装了类型

我的 IDE (Webstorm) 显示变量 gapi 具有 authclient 作为函数,但它没有显示这两个函数的子函数。当我包括 /// <reference path="../../../typings/globals/gapi/index.d.ts" /> 在我的服务顶部一切正常。

/// <reference path="../../../typings/globals/gapi/index.d.ts" />
export class foo {
  constructor() {
    gapi.auth.authorize({
      //my config  
    });
  }
}

那么我错过了什么或者这是正确的方法吗?

【问题讨论】:

  • 我有(我认为)同样的问题。可以加点代码吗?
  • 添加了一些代码

标签: angular typescript typescript-typings google-api-js-client


【解决方案1】:

我最近遇到了这个问题,这里有一些对我有用的配置:

我正在使用DefiniteTyped @types/gapi 包。

npm install --save-dev @types/gapi

从 typescript docs,使用 /// &lt;reference types="..." /&gt; 指令在你的 typescript 文件中加载类型:

/// <reference types="gapi" />

我在项目根目录的tsconfig.json 文件中的其他配置:

{
  ...
  "compilerOptions": {
    // I thought this was enough to recognize the types
    // but that was not the case
    "typeRoots": ["node_modules/@types"],
    ...
  }
}

确保您使用 typescript v2.0 或更高版本。

【讨论】:

    猜你喜欢
    • 2018-08-21
    • 2017-12-15
    • 1970-01-01
    • 2018-07-31
    • 2016-04-14
    • 2016-07-13
    • 2019-12-09
    • 1970-01-01
    • 2018-10-20
    相关资源
    最近更新 更多