mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
* 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
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import prompts = require("prompts");
|
|
|
|
type HasProperty<T, K> = K extends keyof T ? true : false;
|
|
|
|
(async () => {
|
|
const response = await prompts({
|
|
type: "number",
|
|
name: "value",
|
|
message: "Input value to double:",
|
|
validate: (value: any) => (value < 0 ? `Cant be less than zero` : true)
|
|
});
|
|
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?"
|
|
}
|
|
]);
|
|
})();
|