typed<T> method

StreamSubscription<T> typed <T>(
  1. StreamSubscription subscription
)

Creates a wrapper which throws if subscription's events aren't instances of T.

This soundly converts a StreamSubscription to a StreamSubscription<T>, regardless of its original generic type, by asserting that its events are instances of T whenever they're provided. If they're not, the subscription throws a CastError.

Implementation

static StreamSubscription<T> typed<T>(StreamSubscription subscription) =>
    subscription is StreamSubscription<T>
        ? subscription
        : TypeSafeStreamSubscription<T>(subscription);