# TypeScript 枚举类型

// 枚举类型
enum HTTPStatus {
    OK,
    NOT_FOUND,
    INTERNAL_SERVER_ERROR,
}

function processHttpStatus(s: HTTPStatus){
    console.log(s)
}

processHttpStatus(HTTPStatus.OK)  //0
processHttpStatus(HTTPStatus.INTERNAL_SERVER_ERROR) //2
processHttpStatus(HTTPStatus.NOT_FOUND) //1
// 枚举类型
enum HTTPStatus {
    OK = 200,
    NOT_FOUND = 404,
    INTERNAL_SERVER_ERROR = 500,
}

function processHttpStatus(s: HTTPStatus){
    console.log(s)						 // 枚举值
    console.log(HTTPStatus[s]) // 打印变量名
}

processHttpStatus(HTTPStatus.OK)
// 200
// OK
上次更新: 11/3/2021, 8:49:20 AM