You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[TypeScript] Provide two types of callback for a subscription (#1028)
Currently, the type of callback for a subscription is defined as:
```ts
type SubscriptionCallback<T extends TypeClass<MessageTypeClassName>> =
(message: MessageType<T> | Buffer) => void
```
which causes a type error when pass a callback either for a normal message or raw message.
This patch provides two types of callback for a subscription, which are:
1. For a normal message
```ts
type SubscriptionCallback<T extends TypeClass<MessageTypeClassName>> =
(message: MessageType<T>) => void;
```
2. For a raw message:
```ts
type SubscriptionWithRawMessageCallback =
(message: Buffer) => void;
```
After this patch, we can use the correct callback type for a subscription, like:
```ts
subscription = node.createSubscription(
TYPE_CLASS,
TOPIC,
{ isRaw: true },
(message: Buffer) => {
const receivedRawMessage = message;
}
);
```
Fix: #1013
0 commit comments