Commit 72b40b0
committed
[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: #10131 parent 2581102 commit 72b40b0
3 files changed
Lines changed: 38 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
240 | 260 | | |
241 | 261 | | |
242 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | | - | |
| 327 | + | |
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
17 | 33 | | |
18 | 34 | | |
19 | 35 | | |
| |||
0 commit comments