Typescript: message
type on SubscriptionCallback<T>
based on isRaw
#1013
Labels
message
type on SubscriptionCallback<T>
based on isRaw
#1013
Description
createSubscription()
takes a callback of typeSubscriptionCallback<T>
, which is(message: MessageType<T> | Buffer) => void;
. However, my understanding ismessage
for a given callback will actually only be one ofMessageType<T>
orBuffer
, depending on the value of the optionisRaw
passed tocreateSubscription()
.Therefore, instead of having
message
be the union ofMessageType<T> | Buffer
, there should be twoSubscriptionCallback
types (or a generic), one withmessage: MessageType<T>
and one withmessage: Buffer
, and the correct one is used depending on theisRaw
option value.The workaround for the current implementation is to add discriminator checks at the top of all callbacks:
Steps To Reproduce
Expected Behavior
No Typescript error.
Actual Behavior
Typescript error, or discriminator required.
The text was updated successfully, but these errors were encountered: