Skip to content

Commit

Permalink
Add support for TypeScript (vercel#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey authored and nevilm-lt committed Apr 22, 2022
1 parent 39817ab commit d49135c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
21 changes: 21 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
declare function arg<T extends arg.Spec>(spec: T): arg.Result<T>;

declare namespace arg {
export type Handler = (value: string) => any;

export interface Spec {
[key: string]: string | Handler | [Handler];
}

export type Result<T extends Spec> = { _: string[] } & {
[K in keyof T]: T[K] extends string
? never
: T[K] extends Handler
? ReturnType<T[K]>
: T[K] extends [Handler]
? Array<ReturnType<T[K][0]>>
: never
};
}

export = arg;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"version": "2.0.1",
"description": "Another simple argument parser",
"main": "index.js",
"types": "index.d.ts",
"repository": "zeit/arg",
"author": "Josh Junon <[email protected]>",
"license": "MIT",
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"scripts": {
"pretest": "xo",
Expand Down

0 comments on commit d49135c

Please sign in to comment.