3

I'm receiving a JSON object similar to below.

{
    "sub": "5354f0a7-b904-4831",
    "email_verified": true,
    "custom:group": "buyer",
    "aud": "30lhep4eammk443j1",
    "event_id": "93bf3295-2aa2-4dad-a0a4",
    "token_use": "id"
}

and to map the values of above, I have created an interface like this,

export interface Token {
    email?: string
    sub?: string
    aud?: string
    email_verified?: boolean
    token_use?: string
} 

when I try to access the value of custom:group, TypeScript is showing an error since the field is not defined in the interface.

const group = obj[custom:group];

to overcome this issue, is it possible to declare custom:group field in the interface since it is having a colon?

Lakmal
  • 247
  • 1
  • 9
  • 24

0 Answers0