Home > Blockchain >  how to deal with enum data model with other data model type script?
how to deal with enum data model with other data model type script?

Time:11-30

I have these different data models. I used enum type in other data models. now can I compare __typename?

enum ActivtiyCardType  {
    Dance,
    ReferralTransaction,
  }

  type ActivityCardData = {
    __typename:ActivtiyCardType,
            id:string,
            from:{
                __typename:string,
                from:string,
                id:string
            }
            to:{
                __typename:string,
                to:string,
                id:string
            }
            date:Date,
            message:string,
            danceSuccessful:boolean,
            amount?: number
  }
    
  type ActivityCardsProps = {
    data: ActivityCardData[]
}

{data?.map((activity:ActivityCardData) => {
       
                return (
                    <Paper
                        key={activity.id}
                        sx={{
                            m: 1,
                            p: 3,
                        }}
                    >
                      
                            <Box>
                                **{activity.__typename === 'Dance' ? (**

How to compare __typename in this context?

CodePudding user response:

Well why not just this?

activity.__typename === ActivtiyCardType.Dance
  • Related