From bdc80ba59fa13bc3025ce0a85e8bad9f9da24ea7 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Sat, 18 Jul 2020 19:12:52 -0700 Subject: [PATCH] fix(types): switch back to using Partial types (#293) --- index.ts | 6 +++--- lib/yargs-parser-types.ts | 36 ++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/index.ts b/index.ts index 558dcf71..f751c7b9 100644 --- a/index.ts +++ b/index.ts @@ -38,7 +38,7 @@ if (process && process.version) { import camelCase = require('camelcase') import decamelize = require('decamelize') -function parse (argsInput: ArgsInput, options?: Options): DetailedArguments { +function parse (argsInput: ArgsInput, options?: Partial): DetailedArguments { const opts: Partial = Object.assign({ alias: undefined, array: undefined, @@ -1109,14 +1109,14 @@ function sanitizeKey (key: string): string { return key } -const yargsParser: Parser = function Parser (args: ArgsInput, opts?: Options): Arguments { +const yargsParser: Parser = function Parser (args: ArgsInput, opts?: Partial): Arguments { const result = parse(args.slice(), opts) return result.argv } // parse arguments and return detailed // meta information, aliases, etc. -yargsParser.detailed = function (args: ArgsInput, opts?: Options): DetailedArguments { +yargsParser.detailed = function (args: ArgsInput, opts?: Partial): DetailedArguments { return parse(args.slice(), opts) } diff --git a/lib/yargs-parser-types.ts b/lib/yargs-parser-types.ts index 8edf6837..9d4b38b8 100644 --- a/lib/yargs-parser-types.ts +++ b/lib/yargs-parser-types.ts @@ -73,51 +73,51 @@ export type ConfigCallback = (configPath: string) => { [key: string]: any } | Er export interface Options { /** An object representing the set of aliases for a key: `{ alias: { foo: ['f']} }`. */ - alias?: Dictionary; + alias: Dictionary; /** * Indicate that keys should be parsed as an array: `{ array: ['foo', 'bar'] }`. * Indicate that keys should be parsed as an array and coerced to booleans / numbers: * { array: [ { key: 'foo', boolean: true }, {key: 'bar', number: true} ] }`. */ - array?: ArrayOption | ArrayOption[]; + array: ArrayOption | ArrayOption[]; /** Arguments should be parsed as booleans: `{ boolean: ['x', 'y'] }`. */ - boolean?: string | string[]; + boolean: string | string[]; /** Indicate a key that represents a path to a configuration file (this file will be loaded and parsed). */ - config?: string | string[] | Dictionary; + config: string | string[] | Dictionary; /** configuration objects to parse, their properties will be set as arguments */ - configObjects?: Dictionary[]; + configObjects: Dictionary[]; /** Provide configuration options to the yargs-parser. */ - configuration?: Partial; + configuration: Partial; /** * Provide a custom synchronous function that returns a coerced value from the argument provided (or throws an error), e.g. * `{ coerce: { foo: function (arg) { return modifiedArg } } }`. */ - coerce?: Dictionary; + coerce: Dictionary; /** Indicate a key that should be used as a counter, e.g., `-vvv = {v: 3}`. */ - count?: string | string[]; + count: string | string[]; /** Provide default values for keys: `{ default: { x: 33, y: 'hello world!' } }`. */ - default?: Dictionary; + default: Dictionary; /** Environment variables (`process.env`) with the prefix provided should be parsed. */ - envPrefix?: string; + envPrefix: string; /** Specify that a key requires n arguments: `{ narg: {x: 2} }`. */ - narg?: Dictionary; + narg: Dictionary; /** `path.normalize()` will be applied to values set to this key. */ - normalize?: string | string[]; + normalize: string | string[]; /** Keys should be treated as strings (even if they resemble a number `-x 33`). */ - string?: string | string[]; + string: string | string[]; /** Keys should be treated as numbers. */ - number?: string | string[]; + number: string | string[]; /** i18n handler, defaults to util.format */ - __?: (format: any, ...param: any[]) => string; + __: (format: any, ...param: any[]) => string; /** alias lookup table defaults */ - key?: Dictionary; + key: Dictionary; } export type OptionsDefault = ValueOf, 'default'>>; export interface Parser { - (args: ArgsInput, opts?: Options): Arguments; - detailed(args: ArgsInput, opts?: Options): DetailedArguments; + (args: ArgsInput, opts?: Partial): Arguments; + detailed(args: ArgsInput, opts?: Partial): DetailedArguments; } export type StringFlag = Dictionary;