gunshi / definition / lazyWithTypes
Function: lazyWithTypes()
ts
function lazyWithTypes<G>(): LazyWithTypesReturn<NormalizeGunshiParams<G>>;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.
Type Parameters
| Type Parameter | Description |
|---|---|
G extends GunshiParamsConstraint | A GunshiParams type |
Returns
LazyWithTypesReturn<NormalizeGunshiParams<G>>
A function that takes a lazy command definition via lazy
Example
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,
},
},
)Since
v0.27.0
