Skip to main content

CommandPayloadType

type

Type helper for extracting the payload type from a command.

type CommandPayloadType<TCommand extends AnyLexicalCommand> = TCommand extends LexicalCommand<infer TPayload> ? TPayload : never

Import

import { CommandPayloadType } from '@modular/sdk/editor';

Notes

example
```ts const MY_COMMAND = createCommand<SomeType>(); // ... editor.registerCommand(MY_COMMAND, payload => { // Type of `payload` is inferred here. But lets say we want to extract a function to delegate to $handleMyCommand(editor, payload); return true; }); function $handleMyCommand(editor: LexicalEditor, payload: CommandPayloadType<typeof MY_COMMAND>) { // `payload` is of type `SomeType`, extracted from the command. } ```