打字稿:使用枚举的自定义界面类型

时间:2020-10-09 18:46:26

标签: javascript node.js typescript types enums

我正在使用API​​端点处理类别,因此我为此创建了enum

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

现在我想用它来为数据库中的category属性设置接口。

interface

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

如何将类别接口类型指定为枚举中定义的值之一?

1 个答案:

答案 0 :(得分:1)

只需将枚举名称override rwxr-xr-x root/wheel restricted,compressed for python3? y rm: python3: Operation not permitted 像这样:

categories

这是工作中的demo