whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. bool? abort,
    2. bool? assert_,
    3. bool? asyncHooks,
    4. bool? buffer,
    5. bool? childProcess,
    6. bool? console,
    7. bool? crypto,
    8. bool? dgram,
    9. bool? dns,
    10. bool? events,
    11. bool? exceptions,
    12. bool? fetch,
    13. bool? fs,
    14. bool? https,
    15. bool? intl,
    16. bool? navigator,
    17. bool? net,
    18. bool? os,
    19. bool? path,
    20. bool? perfHooks,
    21. bool? process,
    22. bool? streamWeb,
    23. bool? stringDecoder,
    24. bool? temporal,
    25. bool? timers,
    26. bool? tty,
    27. bool? url,
    28. bool? util,
    29. bool? zlib,
    30. bool? json,
    )?
)

A variant of when that fallback to returning null

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return null;
}

Implementation

@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( bool? abort,  bool? assert_,  bool? asyncHooks,  bool? buffer,  bool? childProcess,  bool? console,  bool? crypto,  bool? dgram,  bool? dns,  bool? events,  bool? exceptions,  bool? fetch,  bool? fs,  bool? https,  bool? intl,  bool? navigator,  bool? net,  bool? os,  bool? path,  bool? perfHooks,  bool? process,  bool? streamWeb,  bool? stringDecoder,  bool? temporal,  bool? timers,  bool? tty,  bool? url,  bool? util,  bool? zlib,  bool? json)?  $default,) {final _that = this;
switch (_that) {
case _JsBuiltinOptions() when $default != null:
return $default(_that.abort,_that.assert_,_that.asyncHooks,_that.buffer,_that.childProcess,_that.console,_that.crypto,_that.dgram,_that.dns,_that.events,_that.exceptions,_that.fetch,_that.fs,_that.https,_that.intl,_that.navigator,_that.net,_that.os,_that.path,_that.perfHooks,_that.process,_that.streamWeb,_that.stringDecoder,_that.temporal,_that.timers,_that.tty,_that.url,_that.util,_that.zlib,_that.json);case _:
  return null;

}
}