Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

why repeat the names?

    // put this in some util.ts or enum.ts file
    function makeEnum<T extends readonly string[]>(keys: T) {
        return Object.fromEntries(keys.map((x) => [x, x])) as {
            [K in (typeof keys)[number]]: K
        };
    }

    const SMS_TYPES = makeEnum(['bulk', 'marketing', 'pin', 'signup', 'transaction', 'test'] as const);
    type SMS_TYPE = keyof typeof SMS_TYPES;


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: