From 603538040f72d613f528522d2c45741e16d7210c Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Tue, 4 Jun 2024 16:32:13 -0700 Subject: [PATCH] Remove an unnecessary `dynamic` (#2239) 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. --- pkgs/test_core/lib/src/runner/console.dart | 24 ++++++++-------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/pkgs/test_core/lib/src/runner/console.dart b/pkgs/test_core/lib/src/runner/console.dart index dc1bba5c1..3a4d6facf 100644 --- a/pkgs/test_core/lib/src/runner/console.dart +++ b/pkgs/test_core/lib/src/runner/console.dart @@ -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 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. @@ -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 Function() body, +});