如何在 angular-cli 1.0.1 应用程序中使用 chrome-app.d.ts 类型? [英] How to use chrome-app.d.ts type in angular-cli 1.0.1 app?
问题描述
我已经安装了 @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.tschrome-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屋!