@@ -31,10 +31,12 @@ export async function prompt<T extends string>(
31
31
options ?: prompts . Options
32
32
) {
33
33
const singleChoiceAnswers = { } ;
34
- const promptQuestions = [ ] ;
34
+ const promptQuestions : Question < T > [ ] = [ ] ;
35
35
36
36
if ( Array . isArray ( questions ) ) {
37
37
for ( const question of questions ) {
38
+ let promptQuestion = question ;
39
+
38
40
// Skip questions which are passed as parameter and pass validation
39
41
const argValue = argv ?. [ question . name ] ;
40
42
@@ -62,25 +64,28 @@ export async function prompt<T extends string>(
62
64
63
65
// Don't prompt dynamic questions with a single choice
64
66
if ( type === 'select' && typeof choices === 'function' ) {
65
- question . type = ( prev , values ) => {
66
- const dynamicChoices = choices ( prev , { ...argv , ...values } ) ;
67
+ promptQuestion = {
68
+ ...question ,
69
+ type : ( prev , values ) => {
70
+ const dynamicChoices = choices ( prev , { ...argv , ...values } ) ;
67
71
68
- if ( dynamicChoices && dynamicChoices . length === 1 ) {
69
- const onlyChoice = dynamicChoices [ 0 ] ;
72
+ if ( dynamicChoices && dynamicChoices . length === 1 ) {
73
+ const onlyChoice = dynamicChoices [ 0 ] ;
70
74
71
- if ( onlyChoice ?. value ) {
72
- // @ts -expect-error assume the passed value is correct
73
- singleChoiceAnswers [ question . name ] = onlyChoice . value ;
74
- }
75
+ if ( onlyChoice ?. value ) {
76
+ // @ts -expect-error assume the passed value is correct
77
+ singleChoiceAnswers [ question . name ] = onlyChoice . value ;
78
+ }
75
79
76
- return null ;
77
- }
80
+ return null ;
81
+ }
78
82
79
- return type ;
83
+ return type ;
84
+ } ,
80
85
} ;
81
86
}
82
87
83
- promptQuestions . push ( question ) ;
88
+ promptQuestions . push ( promptQuestion ) ;
84
89
}
85
90
} else {
86
91
promptQuestions . push ( questions ) ;
0 commit comments