Skip to content

ChainGraph API Documentation / @badaitech/chaingraph-types / PortEnumFromNative

Function: PortEnumFromNative()

PortEnumFromNative<E>(nativeEnum, config?): PropertyDecorator

Defined in: packages/chaingraph-types/src/decorator/enum.decorator.ts:211

PortEnumFromNative decorator creates an enum port from a native TypeScript enum.

This helper extracts the enum keys and values, and builds an option configuration accordingly. In this implementation the enum keys will be used as the option title, while the corresponding enum value serves as the option id.

For example, given:

enum Direction { Up = '1', Down = '2', Left = '3', Right = '4', }

the generated enum options will have { id: '1', title: 'Up', ... } and so on.

Type Parameters

E

E extends Record<string, string | number>

Parameters

nativeEnum

E

A native TypeScript enum.

config?

Omit<EnumPortConfig, "options" | "type">

Optional configuration for the enum port (excluding the "type" property).

Returns

PropertyDecorator

Licensed under BUSL-1.1