diff --git a/index.d.ts b/index.d.ts index 8ee568d..c4dce28 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,8 +1,21 @@ import {PackageJson} from 'type-fest'; -import {Options as MinimistOptions} from 'minimist-options'; declare namespace meow { - interface Options { + type FlagType = 'string' | 'boolean' | 'number'; + + interface Flag { + readonly type?: Type; + readonly alias?: string; + readonly default?: Default; + } + + type StringFlag = Flag<'string', string>; + type BooleanFlag = Flag<'boolean', boolean>; + type NumberFlag = Flag<'number', number>; + + type AnyFlags = {[key: string]: StringFlag | BooleanFlag | NumberFlag}; + + interface Options { /** Define argument flags. @@ -159,7 +172,7 @@ declare namespace meow { readonly hardRejection?: boolean; } - type TypedFlags = { + type TypedFlags = { [F in keyof Flags]: Flags[F] extends {type: 'number'} ? number : Flags[F] extends {type: 'string'} @@ -169,7 +182,7 @@ declare namespace meow { : unknown; }; - interface Result { + interface Result { /** Non-flag arguments. */ @@ -246,7 +259,7 @@ const cli = meow(` foo(cli.input[0], cli.flags); ``` */ -declare function meow(helpMessage: string, options?: meow.Options): meow.Result; -declare function meow(options?: meow.Options): meow.Result; +declare function meow(helpMessage: string, options?: meow.Options): meow.Result; +declare function meow(options?: meow.Options): meow.Result; export = meow; diff --git a/index.test-d.ts b/index.test-d.ts index a18615a..791c8cf 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -33,7 +33,8 @@ expectType>(meow({hardRejection: false})); const result = meow('Help text', { flags: { foo: {type: 'boolean', alias: 'f'}, - 'foo-bar': {type: 'number'} + 'foo-bar': {type: 'number'}, + bar: {type: 'string', default: ''} }} ); @@ -42,10 +43,12 @@ expectType(result.pkg); expectType(result.help); expectType(result.flags.foo); +expectType(result.flags.fooBar); +expectType(result.flags.bar); expectType(result.unnormalizedFlags.foo); expectType(result.unnormalizedFlags.f); expectType(result.unnormalizedFlags['foo-bar']); -expectType(result.flags.fooBar); +expectType(result.unnormalizedFlags.bar); result.showHelp(); result.showHelp(1);