3 ms·
Exactly what I do, but I've found that I almost always will add a few things that come in handy. export const SMS_TYPE = Object.freeze({ BULK: 'bul
by ralusek 2y ago
Exactly what I do, but I've found that I almost always will add a few things that come in handy.
export const SMS_TYPE = Object.freeze({
BULK: 'bulk',
MARKETING: 'marketing',
PIN: 'pin',
SIGNUP: 'signup',
TRANSACTION: 'transaction',
TEST: 'test',
} as const);
export const SMS_TYPE_LIST = Object.freeze(Object.values(SMS_TYPE));
export const SMS_TYPE_SET = Object.freeze(new Set(SMS_TYPE_LIST));
export type SmsType = typeof SMS_TYPE[keyof typeof SMS_TYPE];
- joshstrange 2y agoNice, I will have to watch for cases where I could make use of that! I think I originally found the const-style on somewhere HN or SO but it has changed a bit over the years due to suggestions people have made so thank you for contributing to improvement of this pattern for me.
- ralusek 2y agoI end up using the sets a lot in particular for any case where you're dealing with unvalidated data. Type checks where you need to say, for example, SMS_TYPE_SET.has(someValue)
- recursive 2y agoYou can simplify the `SmsType` declaration a bit. export type SmsType = typeof SMS_TYPE_LIST[number];