TypeScript Use Values Of Object As Keys Of Type Link to heading
/**
* Object whose keys are the values from T
*/
type ValoueOf<T extends object> = [T keyof T]
/**
Example: use values of object as keys of type
*/
const topics = {
NewMessages: "messages:new"
}
type Topics = ValueOf<typeof topics>
const pubSub = createPubSub<{
[key in Topics]: [string]
}>()
pubSub.publish(topics.NewMessages, newMessage)