what is const/type pattern in Typescript

Viewed 15360
export const INCREMENT_ENTHUSIASM = 'INCREMENT_ENTHUSIASM';
export type INCREMENT_ENTHUSIASM = typeof INCREMENT_ENTHUSIASM;


export const DECREMENT_ENTHUSIASM = 'DECREMENT_ENTHUSIASM';
export type DECREMENT_ENTHUSIASM = typeof DECREMENT_ENTHUSIASM;

what is happening here? I am not able to understand this.It is very confusing This is from here https://github.com/Microsoft/TypeScript-React-Starter under Adding actions section.

I know what type keyword do but it seems very confusing here.

enter image description here

2 Answers

By the way, to avoid repeating (and get rid off possible spelling mistakes) I worked out such an idiom:

export namespace ShowIdEnum {
  export const ALWAYS = 'always';
  export const LABEL = 'label';
  export const NEVER = 'never';
};
export type ShowIdEnum = typeof ShowIdEnum[keyof typeof ShowIdEnum];

Hope it helps ;)

Related