Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度+;webauthn=Property';证书';不存在于类型';导航器';?_Angular_Definitelytyped_Webauthn - Fatal编程技术网

Angular 角度+;webauthn=Property';证书';不存在于类型';导航器';?

Angular 角度+;webauthn=Property';证书';不存在于类型';导航器';?,angular,definitelytyped,webauthn,Angular,Definitelytyped,Webauthn,我一直在尝试将webauthn添加到Angular应用程序中。此MDN页面概述了必要的步骤: 重要的是,使用API需要访问navigator.credentials。然而,当我试图引用Angular时,它不会编译。例如,这行代码: await navigator.credentials.create({...}); …产生以下错误: error TS2339: Property 'credentials' does not exist on type 'Navigator'. 现在我知道我可

我一直在尝试将webauthn添加到Angular应用程序中。此MDN页面概述了必要的步骤:

重要的是,使用API需要访问
navigator.credentials
。然而,当我试图引用Angular时,它不会编译。例如,这行代码:

await navigator.credentials.create({...});
…产生以下错误:

error TS2339: Property 'credentials' does not exist on type 'Navigator'.
现在我知道我可以这样做:

declare global {
  interface Navigator {
    credentials: {
      create(): void,
      get(): void
    }
  }
}
但是为整个API编写所有类型脚本真的很乏味。除此之外,有人已经在
中完成了所有的工作,明确地键入了
,对吗

因此,我在我的项目中添加了
npm安装--save dev@types/webappsec credential management

现在VisualStudio代码知道该做什么;我有自动完成和一切

但Angular仍然无法编译。它给出了上述相同的错误


我需要做什么才能识别
navigator.credentials

我的.ts文件顶部缺少以下内容:

//

我还需要
ng update typescript
ng update@angular/cli

您可以按照以下步骤进行:

npm install --save-dev @types/webappsec-credential-management
然后编辑angular的
/src/tsconfig.app.json

{
  ...
  "compilerOptions": {
    ...
    "types": [
      "@types/webappsec-credential-management"
    ]
    ...
}
有必要编辑angular自己的
tsconfig.app.json
,因为它将用于编译angular的代码。root
tsconfig.json
用于引导和常规(vscode)类型脚本配置。因此,如果您只是将
@types/webappsec凭证管理
添加到您的类型中,它将在编辑器中被识别,但angular自己的编译器将忽略它,从而产生此键入错误:

错误TS2339:类型“Navigator”上不存在属性“credentials”。