Skip to content
typescript
enum DirectionEnum {
	left: 0,
	right: 1,
	top: 2,
	bottom: 3,
}
enum DirectionEnum {
	left: 0,
	right: 1,
	top: 2,
	bottom: 3,
}

获取DirectionEnum的key对应的类型:

typescript
type IKey = keyof typeof DirectionEnum; // 'left' | 'right' | 'top' | 'bottom'
type IKey = keyof typeof DirectionEnum; // 'left' | 'right' | 'top' | 'bottom'

获取DirectionEnum的value对应的类型:

typescript
type IValue = `${DirectionEnum}`; // 0 | 1 | 2 | 3
type IValue = `${DirectionEnum}`; // 0 | 1 | 2 | 3