【问题标题】:create interface of specific options (rating interface, allow only numbers between 1-5) [duplicate]创建特定选项的界面(评级界面,只允许1-5之间的数字)[重复]
【发布时间】:2020-01-19 22:52:38
【问题描述】:

我想创建只允许 1-5 之间的数字的oneToFive 接口。

你如何正确地写这个?

// this line gives me error
interface oneToFive = 1 | 2 | 3 | 4 | 5;

interface sectionFeedback {
  howMuchDoYouRelate?: oneToFive;
  howWellWasThisTextWritten?: oneToFive;
}

【问题讨论】:

  • 使用type oneToFive = 1 | 2 | 3 | 4 | 5;
  • 我会将您的问题标记为正确 :) 谢谢!

标签: angular typescript types interface angular-cli


【解决方案1】:

使用type 而不是interface

type oneToFive = 1 | 2 | 3 | 4 | 5;

感谢您的回答! @异端猴子

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    相关资源
    最近更新 更多