Narrow subscription types using the `type` property
masterIn the next major version, client.getSubscription(channel) returns an AnySubscription (a union of StreamSubscription, MapSubscription, or SharedPollSubscription). To access methods specific to a subscription type (like publish on a MapSubscription), you must use a type guard on the type property.
Each subscription class has a readonly type property with a string literal value:
streamforStreamSubscriptionmapforMapSubscriptionshared_pollforSharedPollSubscription
const sub = client.getSubscription('my-channel');
if (sub?.type === 'map') {
// TypeScript now knows 'sub' is a MapSubscription
sub.publish('key', data);
} else if (sub?.type === 'shared_poll') {
// TypeScript now knows 'sub' is a SharedPollSubscription
sub.track(['key1', 'key2']);
}