TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
Code
navigator.credentials
Expected behavior:
Actual behavior:
compiler error:
error TS2339: Property 'credentials' does not exist on type 'Navigator'.
Probably because the credentials API is considered experimental and does not have wide support. According to MDN, it is only supported in recent versions of Chrome https://developer.mozilla.org/en-US/docs/Web/API/Navigator/credentials.
You can add the declaration yourself if you plan to use it but note even the examples above suggest checking for its existence before use so it is best declared as optional.
interface Navigator {
credentials?: CredentialContainer;
}
interface CredentialContainer {
get(options?: {
password?: boolean,
unmediated?: boolean,
federated?: {
providers?: string[],
protocols?: string[]
}
}): Promise<Credential>;
store(credential: Credential): Promise<Credential>;
requireUserMediation(): Promise<void>;
}
interface Credential {
readonly iconURL: string;
readonly id: string;
readonly name: string;
readonly type: 'password' | 'federated';
}
Thank you my friend
Most helpful comment
Thank you my friend