From 29a267c55b7455cc9efea43f34230377a9f98ebe Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 20 May 2019 10:23:55 -0700 Subject: [PATCH] [prompts] Fix `type` and `validate` function definitions (#35510) * Allow `type` function to return `Falsy` As defined in the documentation here: https://github.com/terkelg/prompts#type The `type` field can be a function which returns a `Falsy` value to disable the prompt, which is currently not allowed by these type definitions: > If `type` is a falsy value the prompter will skip that question. * fix validate return type --- types/prompts/index.d.ts | 6 +++--- types/prompts/prompts-tests.ts | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/types/prompts/index.d.ts b/types/prompts/index.d.ts index 8e72a1a6bc..40a704a938 100644 --- a/types/prompts/index.d.ts +++ b/types/prompts/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for prompts 2.04 +// Type definitions for prompts 2.0 // Project: https://github.com/terkelg/prompts // Definitions by: Berkay GURSOY // Daniel Perez Alvarez @@ -60,13 +60,13 @@ declare namespace prompts { } interface PromptObject { - type: ValueOrFunc | Falsy; + type: PromptType | Falsy | PrevCaller; name: ValueOrFunc; message?: ValueOrFunc; initial?: string | number | boolean | Date; style?: string; format?: PrevCaller; - validate?: PrevCaller; + validate?: PrevCaller; onState?: PrevCaller; min?: number; max?: number; diff --git a/types/prompts/prompts-tests.ts b/types/prompts/prompts-tests.ts index bd35868c66..6d18acafbd 100644 --- a/types/prompts/prompts-tests.ts +++ b/types/prompts/prompts-tests.ts @@ -12,3 +12,23 @@ type HasProperty = K extends keyof T ? true : false; const HasPropValue: HasProperty = true; const DoesntHavePropAsdf: HasProperty = false; })(); + +(async () => { + await prompts([ + { + type: 'text', + name: 'language', + message: "What langauge is the next greatest thing since sliced bread?", + }, + { + type: (prev, values) => { + const HasPromptName: HasProperty = true; + const DoesntHavePromptTypes: HasProperty = false; + + return prev === 'javascript' ? 'confirm' : null; + }, + name: 'confirmation', + message: "Have you tried TypeScript?" + } + ]); +})();