mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 23:37:04 +00:00
[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
This commit is contained in:
Vendored
+3
-3
@@ -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 <https://github.com/Berkays>
|
||||
// Daniel Perez Alvarez <https://github.com/danielpa9708>
|
||||
@@ -60,13 +60,13 @@ declare namespace prompts {
|
||||
}
|
||||
|
||||
interface PromptObject<T extends string = string> {
|
||||
type: ValueOrFunc<PromptType> | Falsy;
|
||||
type: PromptType | Falsy | PrevCaller<T, PromptType | Falsy>;
|
||||
name: ValueOrFunc<T>;
|
||||
message?: ValueOrFunc<string>;
|
||||
initial?: string | number | boolean | Date;
|
||||
style?: string;
|
||||
format?: PrevCaller<T, void>;
|
||||
validate?: PrevCaller<T, void>;
|
||||
validate?: PrevCaller<T, boolean | string>;
|
||||
onState?: PrevCaller<T, void>;
|
||||
min?: number;
|
||||
max?: number;
|
||||
|
||||
@@ -12,3 +12,23 @@ type HasProperty<T, K> = K extends keyof T ? true : false;
|
||||
const HasPropValue: HasProperty<typeof response, "value"> = true;
|
||||
const DoesntHavePropAsdf: HasProperty<typeof response, "asdf"> = 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<typeof values, "language"> = true;
|
||||
const DoesntHavePromptTypes: HasProperty<typeof values, "text"> = false;
|
||||
|
||||
return prev === 'javascript' ? 'confirm' : null;
|
||||
},
|
||||
name: 'confirmation',
|
||||
message: "Have you tried TypeScript?"
|
||||
}
|
||||
]);
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user