Skip to content

Commit

Permalink
feat: hard types in createPubSub
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Czigler committed Sep 15, 2023
1 parent 7acd8a5 commit 788fa2b
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions packages/pubsub/src/lib/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ export const createPubsub = <
>() => {
type TopicName = keyof Topics

const topic = (
name: TopicName,
const topic = <T extends TopicName>(
name: T,
config?: ClientConfig,
): PubSubTopic<Topics[TopicName], Topics> => {
): PubSubTopic<Topics[T], Topics> => {
return {
publish: publisher<Topics[TopicName], TopicName, Record<string, unknown>>(
name,
config,
),
subscribe: subscriber<Topics[TopicName], TopicName>(name, config),
publish: publisher<Topics[T], T, Record<string, unknown>>(name, config),
subscribe: subscriber<Topics[T], T>(name, config),
name: name,
}
}
Expand Down

0 comments on commit 788fa2b

Please sign in to comment.