Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
/* @flow */
import { Record } from 'immutable';
interface $EnumInterface<T: Object> extends Record<T> {
items: Function;
fromValue: Function;
const createEnum = <T: Object>(items: T): $EnumInterface<T> => {
class Enum extends Record(items) {
// `this` here is an instance of Record so all instance methods are available!
items = () => this.toArray();
fromValue = value => this.find(item => item.value === value);
return new Enum();
export default createEnum;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment