when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. String? name,
    3. String? resourceType,
    4. String? resourceId,
    5. String? userId,
    6. String? agentId,
    7. String? errorMessage,
    8. String? errorCode,
    9. int? pullRequestNumber,
    10. String? pullRequestUrl,
    11. String? pullRequestId,
    12. String? pullRequestBaseRef,
    13. GithubCopilotSessionStatus status,
    14. ModelTimestamp? completedAt,
    15. ModelTimestamp createdAt,
    16. ModelTimestamp updatedAt,
    17. bool fromServer,
    )
)

A switch-like method, using callbacks.

As opposed to map, this offers destructuring. It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case Subclass2(:final field2):
    return ...;
}

Implementation

@optionalTypeArgs
TResult when<TResult extends Object?>(
  TResult Function(
          String id,
          String? name,
          String? resourceType,
          String? resourceId,
          String? userId,
          String? agentId,
          String? errorMessage,
          String? errorCode,
          int? pullRequestNumber,
          String? pullRequestUrl,
          String? pullRequestId,
          String? pullRequestBaseRef,
          GithubCopilotSessionStatus status,
          ModelTimestamp? completedAt,
          ModelTimestamp createdAt,
          ModelTimestamp updatedAt,
          bool fromServer)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _GithubCopilotSessionModel():
      return $default(
          _that.id,
          _that.name,
          _that.resourceType,
          _that.resourceId,
          _that.userId,
          _that.agentId,
          _that.errorMessage,
          _that.errorCode,
          _that.pullRequestNumber,
          _that.pullRequestUrl,
          _that.pullRequestId,
          _that.pullRequestBaseRef,
          _that.status,
          _that.completedAt,
          _that.createdAt,
          _that.updatedAt,
          _that.fromServer);
    case _:
      throw StateError('Unexpected subclass');
  }
}