I've been trying to add webauthn to an Angular app. This MDN page outlines the necessary steps: https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API
The important thing is that using the APIs requires access to navigator.credentials
. However, Angular does not compile when I try to reference that. For example, this line of code:
await navigator.credentials.create({...});
...produces this error:
error TS2339: Property 'credentials' does not exist on type 'Navigator'.
Now I know I can do something like this:
declare global {
interface Navigator {
credentials: {
create(): void,
get(): void
}
}
}
But it's really tedious to have to write all that TypeScript for the entire CredentialsContainer
API. Besides, someone already did all that work in DefinitelyTyped
, right?
So I added @types/webappsec-credential-management
to my project with npm install --save-dev @types/webappsec-credential-management
.
Now Visual Studio Code knows what to do; I've got autocomplete and everything.
But Angular still won't compile. It gives the same error above.
What do I need to do to get Angular to recognize navigator.credentials
?