diff --git a/typings/index.d.ts b/typings/index.d.ts index 0814eb050..bb5a5451e 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -483,8 +483,8 @@ export class Command { * * @returns `this` command for chaining */ - storeOptionsAsProperties(): this & OptionValues; - storeOptionsAsProperties(storeAsProperties: true): this & OptionValues; + storeOptionsAsProperties(): this & T; + storeOptionsAsProperties(storeAsProperties: true): this & T; storeOptionsAsProperties(storeAsProperties?: boolean): this; /** @@ -594,7 +594,7 @@ export class Command { /** * Return an object containing options as key-value pairs */ - opts(): OptionValues; + opts(): T; /** * Set the description. diff --git a/typings/index.test-d.ts b/typings/index.test-d.ts index bc45289ee..53f79b165 100644 --- a/typings/index.test-d.ts +++ b/typings/index.test-d.ts @@ -196,6 +196,15 @@ expectType(opts); expectType(opts.foo); expectType(opts['bar']); +// opts with generics +interface MyCheeseOption { + cheese: string; +} +const myCheeseOption = program.opts(); +expectType(myCheeseOption.cheese); +// @ts-expect-error Check that options strongly typed and does not allow arbitrary properties +expectType(myCheeseOption.foo); + // description expectType(program.description('my description')); expectType(program.description());