66import { compact } from 'lodash-es' ;
77import pIsPromise from 'p-is-promise' ;
88
9- export type HandlerInput = ( ...args : unknown [ ] ) => unknown ;
9+ export type HandlerUnknownReturn = ( ...args : unknown [ ] ) => unknown ;
1010
11- export type Handler = ( ...args : unknown [ ] ) => void | Promise < void > ;
11+ export type HandlerNoReturn = ( ...args : unknown [ ] ) => void | Promise < void > ;
1212
1313export type Option = {
1414 name : string ;
@@ -21,7 +21,7 @@ export type Command = {
2121 name : string ;
2222 arguments ?: string ;
2323 description ?: string ;
24- handler : Handler ;
24+ handler : HandlerNoReturn ;
2525 options : Option [ ] ;
2626} ;
2727
@@ -33,32 +33,37 @@ export type Config = {
3333 arguments ?: string ;
3434 usage ?: string ;
3535 allowUnknownOption : boolean ;
36- action ?: Handler ;
36+ action ?: HandlerNoReturn ;
3737 defaultCommandName ?: string ;
3838} ;
3939
40- export type CommandObjectInput = Omit < Command , 'options' | 'handler' > & {
41- options ?: OptionsInput ;
42- handler : HandlerInput ;
40+ export type PartialCommandObject = Omit < Command , 'options' | 'handler' > & {
41+ options ?: PartialOptions ;
42+ handler : HandlerUnknownReturn ;
4343} ;
4444
45- export type CommandObjectInObjectInput = Omit < CommandObjectInput , 'name' > &
46- Partial < Pick < CommandObjectInput , 'name' > > ;
45+ export type PartialCommandObjectInObject = Omit < PartialCommandObject , 'name' > &
46+ Partial < Pick < PartialCommandObject , 'name' > > ;
4747
48- export type CommandInObjectInput = CommandObjectInObjectInput | HandlerInput ;
48+ export type PartialCommandInObject =
49+ | PartialCommandObjectInObject
50+ | HandlerUnknownReturn ;
4951
50- export type CommandsInput =
51- | CommandObjectInput [ ]
52- | Record < string , CommandInObjectInput > ;
52+ export type PartialCommands =
53+ | PartialCommandObject [ ]
54+ | Record < string , PartialCommandInObject > ;
5355
54- export type OptionInObjectInput = Omit < Option , 'name' > &
56+ export type PartialOptionInObject = Omit < Option , 'name' > &
5557 Partial < Pick < Option , 'name' > > ;
5658
57- export type OptionsInput = Option [ ] | Record < string , OptionInObjectInput > ;
58- type ConfigInput = Omit < Partial < Config > , 'commands' | 'options' | 'action' > & {
59- commands ?: CommandsInput ;
60- options ?: OptionsInput ;
61- action ?: HandlerInput ;
59+ export type PartialOptions = Option [ ] | Record < string , PartialOptionInObject > ;
60+ type PartialConfig = Omit <
61+ Partial < Config > ,
62+ 'commands' | 'options' | 'action'
63+ > & {
64+ commands ?: PartialCommands ;
65+ options ?: PartialOptions ;
66+ action ?: HandlerUnknownReturn ;
6267} ;
6368
6469const applyOptions = ( program , options : Option [ ] = [ ] ) => {
@@ -78,7 +83,7 @@ const applyOptions = (program, options: Option[] = []) => {
7883 }
7984} ;
8085
81- const getNormalizedOptions = ( options ?: OptionsInput ) : Option [ ] => {
86+ const getNormalizedOptions = ( options ?: PartialOptions ) : Option [ ] => {
8287 if ( options === undefined ) {
8388 return [ ] ;
8489 }
@@ -92,7 +97,7 @@ const getNormalizedOptions = (options?: OptionsInput): Option[] => {
9297 ) ;
9398} ;
9499
95- const getNormalizedCommands = ( commands ?: CommandsInput ) : Command [ ] => {
100+ const getNormalizedCommands = ( commands ?: PartialCommands ) : Command [ ] => {
96101 if ( commands === undefined ) {
97102 return [ ] ;
98103 }
@@ -127,7 +132,7 @@ const ignoreReturn =
127132 }
128133 } ;
129134
130- export default ( configInput : ConfigInput = { } ) => {
135+ export default ( configInput : PartialConfig = { } ) => {
131136 const config : Config = defu (
132137 {
133138 ...configInput ,
0 commit comments