字面量类型(声明的类型为写死的值)

type a1=1 | 0

let p:a1 = 1

p = 'string'//错误

对象里面也同样适用

    type resType = {
        code: 1001 | 1002 | 1003 //数字字面量联合类型
        msg: string
    }
    const res = {
        code: 1001,
        msg: "接口成功"
    }

  

posted @ 2024-06-19 19:26  light丶  阅读(13)  评论(0)    收藏  举报