Skip to content

Commit

Permalink
Remove an unnecessary dynamic (#2239)
Browse files Browse the repository at this point in the history
The `dynamic` was used to satisfy the purpose that is more directly
expressed with `FutureOr`.

Replace the private `_Command` class with a typedef record with
named fields.
  • Loading branch information
natebosch committed Jun 4, 2024
1 parent 43ad4cd commit 6035380
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions pkgs/test_core/lib/src/runner/console.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ class Console {
///
/// The [description] should be a one-line description of the command to print
/// in the help output. The [body] callback will be called when the user types
/// the command, and may return a [Future].
/// the command.
void registerCommand(
String name, String description, dynamic Function() body) {
String name, String description, FutureOr<void> Function() body) {
if (_commands.containsKey(name)) {
throw ArgumentError('The console already has a command named "$name".');
}

_commands[name] = _Command(name, description, body);
_commands[name] = (name: name, description: description, body: body);
}

/// Starts running the console.
Expand Down Expand Up @@ -102,16 +102,8 @@ class Console {
}
}

/// An individual console command.
class _Command {
/// The name of the command.
final String name;

/// The single-line description of the command.
final String description;

/// The callback to run when the command is invoked.
final dynamic Function() body;

_Command(this.name, this.description, this.body);
}
typedef _Command = ({
String name,
String description,
FutureOr<void> Function() body,
});

0 comments on commit 6035380

Please sign in to comment.