File tree 2 files changed +12
-3
lines changed
2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -483,8 +483,8 @@ export class Command {
483
483
*
484
484
* @returns `this` command for chaining
485
485
*/
486
- storeOptionsAsProperties ( ) : this & OptionValues ;
487
- storeOptionsAsProperties ( storeAsProperties : true ) : this & OptionValues ;
486
+ storeOptionsAsProperties < T extends OptionValues > ( ) : this & T ;
487
+ storeOptionsAsProperties < T extends OptionValues > ( storeAsProperties : true ) : this & T ;
488
488
storeOptionsAsProperties ( storeAsProperties ?: boolean ) : this;
489
489
490
490
/**
@@ -594,7 +594,7 @@ export class Command {
594
594
/**
595
595
* Return an object containing options as key-value pairs
596
596
*/
597
- opts ( ) : OptionValues ;
597
+ opts < T extends OptionValues > ( ) : T ;
598
598
599
599
/**
600
600
* Set the description.
Original file line number Diff line number Diff line change @@ -196,6 +196,15 @@ expectType<commander.OptionValues>(opts);
196
196
expectType ( opts . foo ) ;
197
197
expectType ( opts [ 'bar' ] ) ;
198
198
199
+ // opts with generics
200
+ interface MyCheeseOption {
201
+ cheese : string ;
202
+ }
203
+ const myCheeseOption = program . opts < MyCheeseOption > ( ) ;
204
+ expectType < string > ( myCheeseOption . cheese ) ;
205
+ // @ts -expect-error Check that options strongly typed and does not allow arbitrary properties
206
+ expectType ( myCheeseOption . foo ) ;
207
+
199
208
// description
200
209
expectType < commander . Command > ( program . description ( 'my description' ) ) ;
201
210
expectType < string > ( program . description ( ) ) ;
You can’t perform that action at this time.
0 commit comments