Today I Learned

hashrocket A Hashrocket project

'as const' for making objects strictly typed

You can use as const in typescript to restrict an object's types.

const status = {
  SUCCESS: 'success',
  ERROR: 'error',
  LOADING: 'loading',
} as const;

Without using as const, both the keys and values of the object would be string types, but with as const, the value types are the exact literals:

 "success" | "error" | "loading"
See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.