import { Enum , EnumType , EnumConstNames } from "../ts/jenum" ; /** N1 ------------------------------------------------- **/ @ Enum < State > ( "text" ) class State extends EnumType < State > ( ) { static readonly NEW = new State ( 1 , "New" ) ; static readonly ACTIVE = new State ( 2 , "Active" ) ; static readonly BLOCKED = new State ( 3 , "Blocked" ) ; private constructor ( readonly code , readonly text ) { super ( ) ; } } type StateNames = EnumConstNames < typeof State > ; const states = State . values ( ) ; const enumNames = State . keys ( ) ; const newState = State . valueByName ( "NEW" ) ; const activeState = State . valueOf ( "Active" ) ; const blockedState = State . find ( "Blocked" ) ; const blocedByCode3 = State . find ( state => state . code === 3 ) ; const someStates = State . filter ( state => state . code >= 2 ) ; const activeText = State . ACTIVE . toString ( ) ; /** N2 ------------------------------------------------- **/ @ Enum < Person > ( "id" ) class Person < IdType extends 1 | 2 = 1 | 2 , NameType extends "Ivan" | "John" = "Ivan" | "John" > extends EnumType < Person > ( ) { static readonly IVAN = new Person ( 1 as const , "Ivan" as const ) ; static readonly JOHN = new Person ( 2 as const , "John" as const ) ; private constructor ( readonly id , readonly name ) { super ( ) ; } static doSomeWork ( ) { const name = Person . IVAN . name ; const id = Person . IVAN . id ; } }