typed<T> method Null safety

  1. @Deprecated('Use future.then((v) => v as T) instead.')
Future<T> typed<T>(
  1. Future future
)
Deprecated('Use future.then((v) => v as T) instead.')">@Deprecated('Use future.then((v) => v as T) instead.')

Creates a wrapper which throws if future's value isn't an instance of T.

This soundly converts a Future to a Future<T>, regardless of its original generic type, by asserting that its value is an instance of T whenever it's provided. If it's not, the future throws a TypeError.

Implementation

@Deprecated('Use future.then((v) => v as T) instead.')
static Future<T> typed<T>(Future future) =>
    future is Future<T> ? future : future.then((v) => v as T);