diff --git a/types/getopts/getopts-tests.ts b/types/getopts/getopts-tests.ts new file mode 100644 index 0000000000..e16d79effa --- /dev/null +++ b/types/getopts/getopts-tests.ts @@ -0,0 +1,20 @@ +import getopts = require('getopts'); + +getopts([]); // $ExpectType ParsedOptions +getopts(['one', 'two']); // $ExpectType ParsedOptions +getopts(['one', 'two'], { alias: { h: 'help' } }); // $ExpectType ParsedOptions +getopts(['one', 'two'], { alias: { verbose: ['v', '--v'] } }); // $ExpectType ParsedOptions +getopts(['one', 'two'], { boolean: ['verbose'] }); // $ExpectType ParsedOptions +getopts(['one', 'two'], { default: { a: 1, b: 'c', d: true } }); // $ExpectType ParsedOptions +getopts(['one', 'two'], { unknown: (name) => name === 'name' }); // $ExpectType ParsedOptions + +// $ExpectType ParsedOptions +getopts( + ['one', 'two'], + { + alias: { h: 'help' }, + boolean: ['verbose'], + default: { a: 1, b: 'c', d: true }, + unknown: (name) => name === 'name' + } +); diff --git a/types/getopts/index.d.ts b/types/getopts/index.d.ts new file mode 100644 index 0000000000..a4c14bd75c --- /dev/null +++ b/types/getopts/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for getopts 2.0 +// Project: https://github.com/getopts/getopts#readme +// Definitions by: Aleh Zasypkin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface ParsedOptions { + _: string[]; + [key: string]: any; +} + +interface Options { + alias?: { [key: string]: string | string[] }; + boolean?: string[]; + default?: { [key: string]: any }; + unknown?: (optionName: string) => boolean; +} + +declare function getopts(argv: string[], options?: Options): ParsedOptions; + +export = getopts; diff --git a/types/getopts/tsconfig.json b/types/getopts/tsconfig.json new file mode 100644 index 0000000000..1a127340e3 --- /dev/null +++ b/types/getopts/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "getopts-tests.ts" + ] +} diff --git a/types/getopts/tslint.json b/types/getopts/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/getopts/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }