Инструменты пользователя

Инструменты сайта


works:programmer:ts:object-by-enum

Формирование типов по Enum

enum ActionType {
    Str             = "string",
    Num             = "number",
    Bool            = "boolean"
}
 
type Action =
    | {type: ActionType.Str, payload: string}
    | {type: ActionType.Num, payload: number}
    | {type: ActionType.Bool, payload: boolean}
 
let x: Action = ({type: ActionType.Num, payload: 6})
 
console.log(typeof x.payload === x.type)
works/programmer/ts/object-by-enum.txt · Последнее изменение: 2023/01/18 20:24 — 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki