TypeScript Version: 3.6.4
Search Terms:
navigator.credentials.get
navigator.credentials
credentials
navigator
Code
navigator.credentials.get({
password: true,
mediation: 'optional'
}).then(c => {
});
The above code throws below error:
Severity Code Description Project File Line Suppression State
Error TS2345 (TS) Argument of type '{ password: boolean; mediation: "optional"; }' is not assignable to parameter of type 'CredentialRequestOptions'.
Object literal may only specify known properties, and 'password' does not exist in type 'CredentialRequestOptions'. D:\MyProject\ClientApp (tsconfig or jsconfig project) D:\MyProject\ClientApp\src\app\shared\services\global.service.ts 230 Active
Expected behavior:
It should compile successfully.
Actual behavior:
It throws below error:
Severity Code Description Project File Line Suppression State
Error TS2345 (TS) Argument of type '{ password: boolean; mediation: "optional"; }' is not assignable to parameter of type 'CredentialRequestOptions'.
Object literal may only specify known properties, and 'password' does not exist in type 'CredentialRequestOptions'. D:\MyProject\ClientApp (tsconfig or jsconfig project) D:\MyProject\ClientApp\src\app\shared\services\global.service.ts 230 Active
The correct place to report this is https://github.com/microsoft/TSJS-lib-generator
This was actually excluded on purpose. See note regarding PasswordCredential at: https://github.com/microsoft/TSJS-lib-generator/pull/711
I'm not sure what are the browser-support/spec requirements for an API to be included in lib.dom.d.ts, and whether the PasswordCredential API is currently meeting them.
@saschanaz
Currently I'm adding types only when multiple independent browser engines support them. PasswordCredential is a Chrome-only API as of now, so I excluded it.
The relevant sentence in README:
When should a DOM API be included here?
A feature is considered highly experimental if a DOM API lacks multiple implementations or a formal specification from W3C or WHATWG. Such a feature belongs on DefinitelyTyped. When it gets multiple implementations and a proper specification, it can be added here and removed from DefinitelyTyped.
makes sense. thanks.
@naveedahmed1 npm i or yarn add the @types/webappsec-credential-management package, which contains these definitions.
Thank you so much @AviVahl and @saschanaz for the clarification, really appreciate.
@AviVahl I tired npm i @types/webappsec-credential-management --save-dev but its still throwing error, any idea what's missing now (it's an Angular project)?
Argument of type '{ password: boolean; mediation: "optional"; }' is not assignable to parameter of type 'CredentialRequestOptions'.
Object literal may only specify known properties, and 'password' does not exist in type 'CredentialRequestOptions'.
230 password: true,
It seems that its still picking type definitions from C:\Program Files (x86)\Microsoft SDKs\TypeScript\3.6\lib.dom.d.ts instead of D:\MyProject\ClientApp\node_modules\@types\webappsec-credential-management\index.d.ts
I added this to the tsconfig file and it fixed the issue.
{
...
"compilerOptions": {
...
"types": [
"@types/webappsec-credential-management"
]
...
}
This issue has been marked as 'External' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
Most helpful comment
I added this to the tsconfig file and it fixed the issue.