Merge pull request #30033 from Berkays/master

Add types for prompts
This commit is contained in:
Daniel Rosenwasser
2018-10-30 12:30:33 -07:00
committed by GitHub
4 changed files with 110 additions and 0 deletions
+76
View File
@@ -0,0 +1,76 @@
// Type definitions for prompts 1.1
// Project: https://github.com/terkelg/prompts
// Definitions by: Berkay GURSOY <https://github.com/Berkays>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
export = prompts;
declare function prompts(questions: prompts.PromptObject | prompts.PromptObject[], 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: (prompt: PromptObject, answer: any, answers: any[]) => void;
onCancel: (prompt: PromptObject, answers: any) => void;
}
interface PromptObject {
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;
}
}
+8
View File
@@ -0,0 +1,8 @@
import prompts = require("prompts");
const response = prompts({
type: 'number',
name: 'value',
message: 'Input value to double:',
validate: (value: any) => value < 0 ? `Cant be less than zero` : true
});
+23
View File
@@ -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"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}