Typescript: Property 'credentials' does not exist on type 'Navigator'.

Created on 30 Jun 2017  路  2Comments  路  Source: microsoft/TypeScript



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'.

Most helpful comment

Thank you my friend

All 2 comments

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

Was this page helpful?
0 / 5 - 0 ratings