It is as it sounds: this function will create something similar to an enum (in this case, an object with a null prototype) from a tuple of string literals.
Even though native enums have some convenient benefits, they can get a little "wordy" when you wish them to work like holders of string constants.
export enum MyConfigConstants {
name = 'name',
DERP = 'DERP',
location = 'location',
WILL = 'WILL',
THIS = 'THIS',
NEVER = 'NEVER',
END = 'END',
}
So I figure why not do this in a simpler way?
import { enumFromTuple } from './enum-from-tuple'
export const MyConfigConstants = enumFromTuple([
'name',
'DERP',
'location',
'WILL',
'THIS',
'NEVER',
'END',
] as const) // <- `as const` is important!
This isn't purported to be a "good" solution. This is more a demonstration of the TupleToObject
type which is able to take a tuple of string literals and create keys with equivalent values from each of the tuple elements.