【问题标题】:How to use TypeScript definitions @types in ionic2 project如何在ionic2项目中使用TypeScript定义@types
【发布时间】:2017-02-12 10:18:31
【问题描述】:

Ionic2 现在使用 @types 来支持第三方库。

我安装了

npm install --save @types/gapi.auth2

但我不知道如何添加我的项目来使用它。请帮帮我

【问题讨论】:

    标签: typescript ionic2 google-api-js-client


    【解决方案1】:

    安装@types/gapi.auth2 后应该很容易,只需在compilerOptions 部分的tsconfig.json 中添加以下行:

    "types": ["gapi.auth2"]
    

    并确保您使用的是 typescript 2.x

    希望这会有所帮助。

    【讨论】:

    • 导入后如何在项目中使用?例如,我是否需要在代码中再次导入,例如 import { GoogleAuth } from '@types/gapi.auth2';
    • 是的,你应该像这样导入它:import { GoogleAuth } from 'gapi.auth2';
    • 我在添加到 tsconfig.json 后尝试 import { GoogleAuth } from 'gapi.auth2' 但它有错误?
    • 原因是您只添加了定义 - 这将允许您的程序编译并通过所有类型检查。模块本身丢失了——你必须告诉你的模块加载器如何找到和加载它。我对 ionic2 没有经验 - 但请尝试将此线程作为 systemjs 配置的示例进行检查:github.com/DefinitelyTyped/DefinitelyTyped/issues/8215
    • 你的ide应该支持typescript 2.0
    猜你喜欢
    • 2017-10-07
    • 1970-01-01
    • 2019-10-06
    • 1970-01-01
    • 2017-07-13
    • 2016-12-16
    • 1970-01-01
    • 2017-08-13
    • 2016-10-30
    相关资源
    最近更新 更多