Option<T>.safeCast constructor

  1. dynamic value

Safely cast a value to type T.

If value is not of type T, then return a None.

Less strict version of Option.safeCastStrict, since safeCast assumes the value to be dynamic.

Note: Make sure to specify the type of Option (Option<T>.safeCast instead of Option.safeCast), otherwise this will always return Some!


factory Option.safeCast(dynamic value) =>
    Option.safeCastStrict<T, dynamic>(value);