const program = {
morgning: ['breakfast', 'mingle'],
evning: ['mingle', 'eat', 'party']
} as const
const namespaceEvent = Object.entries(program).reduce(
(acc, [namespace, events]) => [...acc, ...events.map(event => `${namespace}.${event}`)],
[] as string[]
) // can't do 'as const' here;
type Namespace = typeof namespaceEvent[number] // sees the type as 'string' and not "morgning.breakfast" | "morgning.mingle" | "evning.mingle" | "evning.eat" | "evning.party"
const test: Namespace = 'foo.bar' // would like this to error
console.log(namespaceEvent) // ["morgning.breakfast", "morgning.mingle", "evning.mingle", "evning.eat", "evning.party"]
How do I make this work and why doesn't it work?