menu

prefer-maybe

Prefer the maybe operator over manual propagation

Explicit branching that immediately propagates a Result error or nullish value repeats the behavior of the maybe operator. Instead, you SHOULD use the maybe operator to propagate absence or failure.

Reported

1function value(result: Result<int32, string>): Result<int32, string> {2    const value = match (result) {3        Ok { value } => value4        Err { error } => return Result.err(error)5    };6    return Result.ok(value);7}

Accepted

1function value(result: Result<int32, string>): Result<int32, string> {2    const value = result?;3    return Result.ok(value);4}