TypeScript
Enum vs. Type

by Benny Neugebauer

export enum SelfTradePrevention {
  CANCEL_BOTH = 'cb',
  CANCEL_NEWEST = 'cn',
  CANCEL_OLDEST = 'co',
  DECREMENT_AND_CANCEL = 'dc',
}

export type SelfTradePrevention = 'cb' | 'cn' | 'co' | 'dc';

Only problem with enums in TypeScript is that you can't extend them while types are extendable with &.

See https://github.com/Microsoft/TypeScript/issues/17592.

Florian Keller

Sign in to comment!