typed<T> method Null safety

  1. @Deprecated('Use Stream.cast instead')
StreamSubscription<T> typed<T>(
  1. StreamSubscription subscription
)
Deprecated('Use Stream.cast instead')">@Deprecated('Use Stream.cast instead')

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 TypeError.

Implementation

@Deprecated('Use Stream.cast instead')
// TODO - Remove `TypeSafeStreamSubscription` and tests when removing this.
static StreamSubscription<T> typed<T>(StreamSubscription subscription) =>
    subscription is StreamSubscription<T>
        ? subscription
        : TypeSafeStreamSubscription<T>(subscription);