diff --git a/index.d.ts b/index.d.ts index 8fff34c4..d8082b4d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -23,9 +23,21 @@ import { Readable } from 'stream' type Mercurius = typeof mercurius declare namespace mercurius { - export interface PubSub { - subscribe(topics: string | string[]): Promise>; - publish(event: { topic: string; payload: TResult }, callback?: () => void): void; + export interface PubSubTopics { + [topic: string]: any; + } + + export interface PubSub { + subscribe>( + topics: TTopic | TTopic[], + ): Promise>; + publish>( + event: { + topic: TTopic; + payload: TPubSubTopics[TTopic]; + }, + callback?: () => void, + ): void; } export interface MercuriusContext { diff --git a/test/types/index.ts b/test/types/index.ts index 39e4b8b6..ccd845ee 100644 --- a/test/types/index.ts +++ b/test/types/index.ts @@ -398,7 +398,7 @@ app.graphql.pubsub.publish({ }) async () => { - const subscription = await app.graphql.pubsub.subscribe<{ newNotification: string }>('topic') + const subscription = await app.graphql.pubsub.subscribe('topic') subscription.on('data', (chunk) => { console.log(chunk)