From c18f05627f270a62f6dac415feda096e7ceccae4 Mon Sep 17 00:00:00 2001 From: Berkay GURSOY Date: Thu, 25 Oct 2018 18:44:24 +0300 Subject: [PATCH 1/5] Add types for prompts --- types/prompts/index.d.ts | 78 ++++++++++++++++++++++++++++++++++ types/prompts/prompts-tests.ts | 15 +++++++ types/prompts/tsconfig.json | 23 ++++++++++ types/prompts/tslint.json | 3 ++ 4 files changed, 119 insertions(+) create mode 100644 types/prompts/index.d.ts create mode 100644 types/prompts/prompts-tests.ts create mode 100644 types/prompts/tsconfig.json create mode 100644 types/prompts/tslint.json diff --git a/types/prompts/index.d.ts b/types/prompts/index.d.ts new file mode 100644 index 0000000000..44d70c0098 --- /dev/null +++ b/types/prompts/index.d.ts @@ -0,0 +1,78 @@ +// Type definitions for prompts v1.1.1 +// Project: https://github.com/terkelg/prompts +// Definitions by: Berkay GURSOY +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = prompts; + +declare function prompts(questions: prompts.PromptObject | Array, options?: prompts.Options): any; + +declare namespace prompts { + // Circular reference from prompts + const prompt: any; + + function inject(obj: any): void; + + namespace inject { + const prototype: { + }; + + } + + namespace prompts { + function autocomplete(args: PromptObject): any; + + function confirm(args: PromptObject): void; + + function invisible(args: PromptObject): any; + + function list(args: PromptObject): any; + + function multiselect(args: PromptObject): any; + + function number(args: PromptObject): void; + + function password(args: PromptObject): any; + + function select(args: PromptObject): void; + + function text(args: PromptObject): void; + + function toggle(args: PromptObject): void; + + } + + interface Choice { + title: string, + value: string + } + + interface Options { + onSubmit: Function, + onCancel: Function + } + + interface PromptObject { + type: string | Function, + name: string | Function, + message?: string | Function, + initial?: string, + style?: string, + format?: Function, + validate?: Function, + onState?: Function, + min?: number, + max?: number, + float?: boolean, + round?: number, + increment?: number, + seperator?: string, + active?: string, + inactive?: string, + choices?: Array, + hint?: string, + suggest?: Function, + limit?: number + } +} + diff --git a/types/prompts/prompts-tests.ts b/types/prompts/prompts-tests.ts new file mode 100644 index 0000000000..068a5823ae --- /dev/null +++ b/types/prompts/prompts-tests.ts @@ -0,0 +1,15 @@ +import * as prompts from "prompts"; + +ask(); + +async function ask(): Promise { + const response = await prompts({ + type: 'number', + name: 'value', + message: 'Input value to double:', + validate: (value: any) => value < 0 ? `Cant be less than zero` : true + }); + + return Number.parseInt(response.value) * 2; +} + diff --git a/types/prompts/tsconfig.json b/types/prompts/tsconfig.json new file mode 100644 index 0000000000..e8a46be254 --- /dev/null +++ b/types/prompts/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "prompts-tests.ts" + ] +} \ No newline at end of file diff --git a/types/prompts/tslint.json b/types/prompts/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/prompts/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file From 93d512c832fff0327ef06a6f9e65aa73b9c55007 Mon Sep 17 00:00:00 2001 From: Berkay GURSOY Date: Thu, 25 Oct 2018 19:14:41 +0300 Subject: [PATCH 2/5] Fix travis errors --- types/prompts/index.d.ts | 58 ++++++++++++++++------------------ types/prompts/prompts-tests.ts | 19 ++++------- 2 files changed, 34 insertions(+), 43 deletions(-) diff --git a/types/prompts/index.d.ts b/types/prompts/index.d.ts index 44d70c0098..9dee6245f1 100644 --- a/types/prompts/index.d.ts +++ b/types/prompts/index.d.ts @@ -1,11 +1,12 @@ -// Type definitions for prompts v1.1.1 +// Type definitions for prompts 1.1 // Project: https://github.com/terkelg/prompts // Definitions by: Berkay GURSOY // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 3.1 export = prompts; -declare function prompts(questions: prompts.PromptObject | Array, options?: prompts.Options): any; +declare function prompts(questions: prompts.PromptObject | prompts.PromptObject[], options?: prompts.Options): any; declare namespace prompts { // Circular reference from prompts @@ -16,7 +17,6 @@ declare namespace prompts { namespace inject { const prototype: { }; - } namespace prompts { @@ -39,40 +39,38 @@ declare namespace prompts { function text(args: PromptObject): void; function toggle(args: PromptObject): void; - } interface Choice { - title: string, - value: string + title: string; + value: string; } interface Options { - onSubmit: Function, - onCancel: Function + onSubmit: (prompt: PromptObject, answer: any, answers: any[]) => void; + onCancel: (prompt: PromptObject, answers: any) => void; } interface PromptObject { - type: string | Function, - name: string | Function, - message?: string | Function, - initial?: string, - style?: string, - format?: Function, - validate?: Function, - onState?: Function, - min?: number, - max?: number, - float?: boolean, - round?: number, - increment?: number, - seperator?: string, - active?: string, - inactive?: string, - choices?: Array, - hint?: string, - suggest?: Function, - limit?: number + type: string | ((prev: any, values: any, prompt: PromptObject) => void); + name: string | ((prev: any, values: any, prompt: PromptObject) => void); + message?: string | ((prev: any, values: any, prompt: PromptObject) => void); + initial?: string; + style?: string; + format?: ((prev: any, values: any, prompt: PromptObject) => void); + validate?: ((prev: any, values: any, prompt: PromptObject) => void); + onState?: ((prev: any, values: any, prompt: PromptObject) => void); + min?: number; + max?: number; + float?: boolean; + round?: number; + increment?: number; + seperator?: string; + active?: string; + inactive?: string; + choices?: Choice[]; + hint?: string; + suggest?: ((prev: any, values: any, prompt: PromptObject) => void); + limit?: number; } -} - +} \ No newline at end of file diff --git a/types/prompts/prompts-tests.ts b/types/prompts/prompts-tests.ts index 068a5823ae..966753ab41 100644 --- a/types/prompts/prompts-tests.ts +++ b/types/prompts/prompts-tests.ts @@ -1,15 +1,8 @@ import * as prompts from "prompts"; -ask(); - -async function ask(): Promise { - const response = await prompts({ - type: 'number', - name: 'value', - message: 'Input value to double:', - validate: (value: any) => value < 0 ? `Cant be less than zero` : true - }); - - return Number.parseInt(response.value) * 2; -} - +const response = prompts({ + type: 'number', + name: 'value', + message: 'Input value to double:', + validate: (value: any) => value < 0 ? `Cant be less than zero` : true +}); From 6d557bb095ffa828ed8629462dc8201b1bc44014 Mon Sep 17 00:00:00 2001 From: Berkay GURSOY Date: Thu, 25 Oct 2018 19:19:09 +0300 Subject: [PATCH 3/5] typescript version header 2.1 fix --- types/prompts/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/prompts/index.d.ts b/types/prompts/index.d.ts index 9dee6245f1..968b8edc52 100644 --- a/types/prompts/index.d.ts +++ b/types/prompts/index.d.ts @@ -2,7 +2,7 @@ // Project: https://github.com/terkelg/prompts // Definitions by: Berkay GURSOY // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.1 +// TypeScript Version: 2.1 export = prompts; From 987aa81f4871a19361591e7c2a4ea3b2f18769dd Mon Sep 17 00:00:00 2001 From: Berkay GURSOY Date: Thu, 25 Oct 2018 19:22:57 +0300 Subject: [PATCH 4/5] added newline --- types/prompts/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/prompts/index.d.ts b/types/prompts/index.d.ts index 968b8edc52..152d6326e8 100644 --- a/types/prompts/index.d.ts +++ b/types/prompts/index.d.ts @@ -73,4 +73,4 @@ declare namespace prompts { suggest?: ((prev: any, values: any, prompt: PromptObject) => void); limit?: number; } -} \ No newline at end of file +} From 8b729b3819ee93713379bcfb11050107e0c205a6 Mon Sep 17 00:00:00 2001 From: Berkay GURSOY Date: Fri, 26 Oct 2018 18:48:18 +0300 Subject: [PATCH 5/5] apply import suggestion --- types/prompts/prompts-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/prompts/prompts-tests.ts b/types/prompts/prompts-tests.ts index 966753ab41..0b89cb3721 100644 --- a/types/prompts/prompts-tests.ts +++ b/types/prompts/prompts-tests.ts @@ -1,4 +1,4 @@ -import * as prompts from "prompts"; +import prompts = require("prompts"); const response = prompts({ type: 'number',