如何在 angular-cli 1.0.1 应用程序中使用 chrome-app.d.ts 类型? [英] How to use chrome-app.d.ts type in angular-cli 1.0.1 app?

查看:37
本文介绍了如何在 angular-cli 1.0.1 应用程序中使用 chrome-app.d.ts 类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 @types/chrome 并将其添加到 tsconfig.app.json

I've installed @types/chrome and add it in tsconfig.app.json

"types": [
  "chrome"
]

但是当我在组件中使用 chrome.app 时,它显示一个错误:

But when i use chrome.app in component, it show an error:

typeof chrome"类型不存在app"属性

Property 'app' does not exist on type 'typeof chrome'

@types/chrome 文件夹包含 chrome-app.d.ts 是我需要的文件,我该如何参考

@types/chrome folder contains chrome-app.d.ts is a file which i need, how can I refer to this

来源 https://github.com/DefinitelyTyped/DefinitelyTyped/tree/主/类型/铬

推荐答案

由于此类型定义模块的创建者已选择不在 index 中包含 chrome.app.* 定义@types/chrome 模块的 .d.ts 文件,而是将它们分开到 chrome-app.d.ts 中,您需要明确地在使用这些 API 的文件中引用它:

Since the creators of this typings definition module have chosen not to include the chrome.app.* definitions in the index.d.ts file of the @types/chrome module but instead separate them out into chrome-app.d.ts, you'll need to explicitly reference it in the file that uses those APIs:

///

请注意,根据 TypeScript 中三斜杠指令的文档,这必须位于文件的顶部:

Note that this must be at the top of the file, per the documentation for triple-slash directives in TypeScript:

https://www.typescriptlang.org/docs/handbook/三重斜线指令.html

另请注意,在 tsconfig.json 中添加 "types": ["chrome"] 引用 不必文件,因为最新版本的 TypeScript 编译器应该自动导入 node_modules/@types 中的所有类型定义模块.通过将此添加到您的配置中,您告诉它导入该模块.有关更多信息,您可以参考配置文档:

Also note that it should not be necessary to add a "types": ["chrome"] reference in your tsconfig.json file, as the latest version of the TypeScript compiler should automatically import all typings definition modules found in node_modules/@types. By adding this to your config, you are telling it to only import that one module. For more on this, you can refer to the config docs:

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

这篇关于如何在 angular-cli 1.0.1 应用程序中使用 chrome-app.d.ts 类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆