@@ -31,10 +31,12 @@ export async function prompt<T extends string>(
3131 options ?: prompts . Options
3232) {
3333 const singleChoiceAnswers = { } ;
34- const promptQuestions = [ ] ;
34+ const promptQuestions : Question < T > [ ] = [ ] ;
3535
3636 if ( Array . isArray ( questions ) ) {
3737 for ( const question of questions ) {
38+ let promptQuestion = question ;
39+
3840 // Skip questions which are passed as parameter and pass validation
3941 const argValue = argv ?. [ question . name ] ;
4042
@@ -62,25 +64,28 @@ export async function prompt<T extends string>(
6264
6365 // Don't prompt dynamic questions with a single choice
6466 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 } ) ;
6771
68- if ( dynamicChoices && dynamicChoices . length === 1 ) {
69- const onlyChoice = dynamicChoices [ 0 ] ;
72+ if ( dynamicChoices && dynamicChoices . length === 1 ) {
73+ const onlyChoice = dynamicChoices [ 0 ] ;
7074
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+ }
7579
76- return null ;
77- }
80+ return null ;
81+ }
7882
79- return type ;
83+ return type ;
84+ } ,
8085 } ;
8186 }
8287
83- promptQuestions . push ( question ) ;
88+ promptQuestions . push ( promptQuestion ) ;
8489 }
8590 } else {
8691 promptQuestions . push ( questions ) ;
0 commit comments