0

I am working with categories with my API endpoint and so I have created this enum for it :

export enum categories {
  DESIGN = 'design',
  ART = 'art',
  WRITING = 'writing',
  PHOTOGRAPHY = 'photography',
  MUSIC = 'music',
  DIGITAL = 'digital',
  MEDIA = 'media'
}

And now I want to use this to set an interface for the category attribute in my database.

interface for that :

interface ProjectAttrs {
  user: string;
  title: string;
  description: string;
  category:   // <== I want it to be either of those values defined above
}

How do I specify the category interface type to be either of the values defined in the enum?

1
  • 2
    Try category: categories and if that doesn't work for you, try to post a minimal reproducible example that shows what goes wrong and what you're trying to do. Commented Oct 9, 2020 at 18:49

1 Answer 1

1

Just put the enum name categories like this:

interface ProjectAttrs {
  user: string;
  title: string;
  description: string;
  category: categories;
}

Here is a working demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.