【发布时间】:2021-03-26 14:31:53
【问题描述】:
虽然权限 API 有一段时间处于草稿形式,但现在似乎得到了很好的支持。但是 typescript 仍然会给出 Property 'permissions' does not exist on type 'Navigator'. 这样的代码错误:
if (navigator.permissions) {
/* code */
}
或
navigator.permissions.query({name:'geolocation'})
.then((result) => {
/* code */
})
如何在 Angular 7+ 应用程序中处理这个问题?
这是我目前的tsconfig.json:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"resolveJsonModule": true,
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"types": [
"node"
],
"lib": [
"es2018",
"dom"
]
}
}
【问题讨论】:
-
您的 TS 配置的目标是什么?我在TS Playground试过,TS可以识别权限
-
请出示您的 tsconfig.json。您可能需要向
lib添加一些内容。 -
已将其添加到问题中
-
和那个问题差不多,但是不同浏览器的权限API的状态不同。
标签: angular typescript browser