Add support for Partial in the command manager

The command manager types didn't fully support commands defined with
`Partial` because it deduced that the command function was `undefined`
when the function was not defined. However, if the command is not
present, the command registration will not be called. This fixes the
types by specifying that the command definition will never be
`undefined`.
This commit is contained in:
Koen Vlaswinkel
2023-03-22 15:27:18 +01:00
parent e74a2e4a15
commit c6d8a09f19

View File

@@ -30,7 +30,7 @@ export class CommandManager<
constructor(
private readonly commandRegister: <T extends CommandName>(
commandName: T,
fn: Commands[T],
fn: NonNullable<Commands[T]>,
) => Disposable,
private readonly commandExecute: <T extends CommandName>(
commandName: T,
@@ -43,7 +43,7 @@ export class CommandManager<
*/
register<T extends CommandName>(
commandName: T,
definition: Commands[T],
definition: NonNullable<Commands[T]>,
): void {
this.commands.push(this.commandRegister(commandName, definition));
}