Function: lazyWithTypes()
Define a lazy command with specific type parameters.
This helper function allows specifying the type parameter of GunshiParams while inferring the Args type, ExtendContext type from the definition.
Since
v0.27.0
Signature
ts
export function lazyWithTypes<G extends GunshiParamsConstraint>(): LazyWithTypesReturn<
NormalizeToGunshiParams<G>
>Type Parameters
| Name | Description |
|---|---|
G extends GunshiParamsConstraint | A GunshiParams type |
Returns
LazyWithTypesReturn<NormalizeToGunshiParams<G>> — A function that takes a lazy command definition via lazy
Examples
ts
type MyExtensions = { logger: { log: (message: string) => void } }
const command = lazyWithTypes<{ extensions: MyExtensions }>()(
() => {
return ctx => {
// Command runner implementation
ctx.extensions.logger?.log('Command executed')
},
{
name: 'lazy-command',
args: {
opt: {
type: 'string',
description: 'An optional string argument',
required: false,
},
},
)