Új hozzászólás Aktív témák

  • _ak_
    addikt

    Szerintem: Az useAccount visszatérhet sima objecttel is (én erre következtetek a paraméterben átadott üres object miatt)? Akkor viszont a TS jogosan reklamál, hiszen ott az account típusa nem IAccount lesz, hanem IAccount | object “union”, az objecten pedig nem fogja megtalálni az adott propot.

    Illetve az az IAccount típusdeklaráció sincs szerintem jó helyen, annak az account konstanson kene legyen, a customProp az interface szerint string típusú

    Valóban, figyelmetlen voltam a customProp egy string a végére és rossz helyen deklaráltam.

    const account: IAccount = useAccount(accounts[0] || {});
    const customProp: string = account?.idTokenClaims?.extension_customProp;

    Így megoldódik a customProp kérdése, de az accountra ezt kapom:

    TS2322: Type 'AccountInfo | null' is not assignable to type 'IAccount'. Type 'null' is not assignable to type 'IAccount'.

    A useAccount:
    // Given 1 or more accountIdentifiers, returns the Account object if the user is signed-in
    export declare function useAccount(accountIdentifiers: AccountIdentifiers): AccountInfo | null;

Új hozzászólás Aktív témák