Skip to content

Commit

Permalink
Update README and type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
ulken committed Oct 19, 2020
1 parent cfd8343 commit 69de916
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
38 changes: 21 additions & 17 deletions index.d.ts
Expand Up @@ -125,7 +125,11 @@ declare namespace meow {
readonly inferType?: boolean;

/**
Value of `boolean` flags not defined in `argv`. If set to `undefined` the flags not defined in `argv` will be excluded from the result. The `default` value set in `boolean` flags take precedence over `booleanDefault`.
Value of `boolean` flags not defined in `argv`.
If set to `undefined` the flags not defined in `argv` will be excluded from the result. The `default` value set in `boolean` flags take precedence over `booleanDefault`.
_Note: If used in conjunction with `isMultiple`, the default flag value is set to `[]`._
__Caution: Explicitly specifying undefined for `booleanDefault` has different meaning from omitting key itself.__
Expand Down Expand Up @@ -198,24 +202,24 @@ declare namespace meow {

type TypedFlag<Flag extends AnyFlag> =
Flag extends {type: 'number'}
? number
: Flag extends {type: 'string'}
? string
: Flag extends {type: 'boolean'}
? boolean
: unknown;
? number
: Flag extends {type: 'string'}
? string
: Flag extends {type: 'boolean'}
? boolean
: unknown;

type PossiblyOptionalFlag<Flag extends AnyFlag, FlagType> =
Flag extends {isRequired: true}
? FlagType
: Flag extends {default: any}
? FlagType
: FlagType | undefined;
? FlagType
: Flag extends {default: any}
? FlagType
: FlagType | undefined;

type TypedFlags<Flags extends AnyFlags> = {
[F in keyof Flags]: Flags[F] extends {isMultiple: true}
? PossiblyOptionalFlag<Flags[F], Array<TypedFlag<Flags[F]>>>
: PossiblyOptionalFlag<Flags[F], TypedFlag<Flags[F]>>
? PossiblyOptionalFlag<Flags[F], Array<TypedFlag<Flags[F]>>>
: PossiblyOptionalFlag<Flags[F], TypedFlag<Flags[F]>>
};

interface Result<Flags extends AnyFlags> {
Expand Down Expand Up @@ -269,14 +273,14 @@ import foo = require('.');
const cli = meow(`
Usage
$ foo <input>
$ foo <input>
Options
--rainbow, -r Include a rainbow
--rainbow, -r Include a rainbow
Examples
$ foo unicorns --rainbow
🌈 unicorns 🌈
$ foo unicorns --rainbow
🌈 unicorns 🌈
`, {
flags: {
rainbow: {
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Expand Up @@ -239,9 +239,12 @@ Type: `boolean | null | undefined`\
Default: `false`
Value of `boolean` flags not defined in `argv`.
If set to `undefined` the flags not defined in `argv` will be excluded from the result.
The `default` value set in `boolean` flags take precedence over `booleanDefault`.
_Note: If used in conjunction with `isMultiple`, the default flag value is set to `[]`._
Example:
```js
Expand Down

0 comments on commit 69de916

Please sign in to comment.