diff --git a/packages/core/src/prompts/prompt.ts b/packages/core/src/prompts/prompt.ts index be21f65f..a314b148 100644 --- a/packages/core/src/prompts/prompt.ts +++ b/packages/core/src/prompts/prompt.ts @@ -42,7 +42,7 @@ export interface PromptOptions { render(this: Omit): string | void; placeholder?: string; initialValue?: any; - validate?: ((value: any) => string | void) | undefined; + validate?: ((value: any) => string | Error | void) | undefined; input?: Readable; output?: Writable; debug?: boolean; @@ -180,7 +180,7 @@ export default class Prompt { if (this.opts.validate) { const problem = this.opts.validate(this.value); if (problem) { - this.error = problem; + this.error = problem instanceof Error ? problem.message : problem; this.state = 'error'; this.rl.write(this.value); } diff --git a/packages/prompts/src/index.ts b/packages/prompts/src/index.ts index 02e29d77..9bc9f39a 100644 --- a/packages/prompts/src/index.ts +++ b/packages/prompts/src/index.ts @@ -98,7 +98,7 @@ export interface TextOptions { placeholder?: string; defaultValue?: string; initialValue?: string; - validate?: (value: string) => string | void; + validate?: (value: string) => string | Error | void; } export const text = (opts: TextOptions) => { return new TextPrompt({ @@ -134,7 +134,7 @@ export const text = (opts: TextOptions) => { export interface PasswordOptions { message: string; mask?: string; - validate?: (value: string) => string | void; + validate?: (value: string) => string | Error | void; } export const password = (opts: PasswordOptions) => { return new PasswordPrompt({