File tree Expand file tree Collapse file tree 2 files changed +4
-4
lines changed Expand file tree Collapse file tree 2 files changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ export interface PromptOptions<Self extends Prompt> {
4242 render ( this : Omit < Self , 'prompt' > ) : string | void ;
4343 placeholder ?: string ;
4444 initialValue ?: any ;
45- validate ?: ( ( value : any ) => string | void ) | undefined ;
45+ validate ?: ( ( value : any ) => string | Error | void ) | undefined ;
4646 input ?: Readable ;
4747 output ?: Writable ;
4848 debug ?: boolean ;
@@ -180,7 +180,7 @@ export default class Prompt {
180180 if ( this . opts . validate ) {
181181 const problem = this . opts . validate ( this . value ) ;
182182 if ( problem ) {
183- this . error = problem ;
183+ this . error = problem instanceof Error ? problem . message : problem ;
184184 this . state = 'error' ;
185185 this . rl . write ( this . value ) ;
186186 }
Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ export interface TextOptions {
9898 placeholder ?: string ;
9999 defaultValue ?: string ;
100100 initialValue ?: string ;
101- validate ?: ( value : string ) => string | void ;
101+ validate ?: ( value : string ) => string | Error | void ;
102102}
103103export const text = ( opts : TextOptions ) => {
104104 return new TextPrompt ( {
@@ -134,7 +134,7 @@ export const text = (opts: TextOptions) => {
134134export interface PasswordOptions {
135135 message : string ;
136136 mask ?: string ;
137- validate ?: ( value : string ) => string | void ;
137+ validate ?: ( value : string ) => string | Error | void ;
138138}
139139export const password = ( opts : PasswordOptions ) => {
140140 return new PasswordPrompt ( {
You can’t perform that action at this time.
0 commit comments