【问题标题】:How to I use definitely typed(d.ts) files?如何使用明确类型的(d.ts)文件?
【发布时间】:2016-07-23 09:01:10
【问题描述】:

我正在开发一个 Angular2 网络应用程序,我想加入 Google 登录功能。具体文件就是这个; gapi.auth2.d.ts.

我已经使用这个命令在我的项目中安装了它;

tsd install gapi.auth2.

接下来我该怎么做?我在想我应该创建一个服务,并且在那个文件中我应该引用类型定义文件;

/// <reference path="./typings/gapi.auth2/gapi.auth2.d.ts />"

然后如何开始使用类型定义文件中的方法?语法是什么样的?

【问题讨论】:

    标签: angularjs typescript definitelytyped google-api-js-client


    【解决方案1】:

    该文件here 的编写方式会污染全局命名空间。所以假设你将一个脚本标签添加到gapi.auth2,然后像这样使用它:

    function test_init(){
      var auth = gapi.auth2.init({
        client_id: 'my-id',
        cookie_policy: 'single_host_origin',
        scope: 'https://www.googleapis.com/auth/plus.login',
        fetch_basic_profile: true
      });
    }
    

    注意:查看测试文件以了解预期用途总是一个好主意。在这种情况下:https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/gapi.auth2/gapi.auth2-tests.ts

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-21
      • 1970-01-01
      • 2022-01-18
      • 2017-02-02
      • 2017-07-09
      • 2023-03-06
      • 2023-02-03
      • 2020-03-23
      相关资源
      最近更新 更多