typescript枚举字符串型不能使用函数问题

数字型枚举

enum OrderStatus {
    Start = 1,
    Unpaid,
    Shipping,
    Shipped,
    Complete
}

或者

enum OrderStatus {
    Start = 1,
    Unpaid,
    Shipping,
    Shipped = aNumber(),
    Complete = 25
}

function aNumber(): number{
    return 21
}

都可以

但是当使用字符串类型时,只允许确定值,不允许使用函数

比如

function one(): string{
    return "this"
}


enum Functions {
    a = one(),
    b = 'aaaa'
}

就会报错

猜你喜欢

转载自www.cnblogs.com/punkrocker/p/11667834.html
今日推荐