getopts: add library definitions.

This commit is contained in:
Aleh Zasypkin
2018-02-16 16:18:14 +01:00
parent 423ace8fe7
commit 8fdc2e7126
4 changed files with 64 additions and 0 deletions

View File

@@ -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'
}
);

20
types/getopts/index.d.ts vendored Normal file
View File

@@ -0,0 +1,20 @@
// Type definitions for getopts 2.0
// Project: https://github.com/getopts/getopts#readme
// Definitions by: Aleh Zasypkin <https://github.com/azasypkin>
// 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;

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }