Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

typescript - How to use chrome-app.d.ts type in angular-cli 1.0.1 app?

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

"types": [
  "chrome"
]

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

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

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

Source https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/chrome

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

/// <reference types="chrome/chrome-app"/>

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/triple-slash-directives.html

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...