I want to define a type for the following data structure
[
{
type:'email',
email:'test@gmai.com'
},
{
type:'username',
username:'user@123'
},
{
type:'ssoId',
ssoId:'client@123'
}
]
As we can see the other keys in the object are based on the type. What is the best way to define type for such structures.
I was thinking of the following
interface Email{
type:'email',
email: string;
}
interface UserName{
type:'username',
username: string;
}
interface SSOId{
type:'ssoId',
ssoId: string;
}
type FinalType=Email|UserName|SSOId
Is this the best way to define FinalType? I want to use this interface in other places too.