Setting `default` with function does not work in `optionOrPrompt`
robinmanuelthiel opened this issue · comments
Robin-Manuel Thiel commented
When settings a default
property for questions, you can either pass a value or a function, which receives the previous answers as a parameter. (Hint: This is the same thing as we can do with the when
property).
When using our optionOrPrompt
instead of the original prompt
, the answers
parameter of the function is empty.
this.answers = await this.prompt([
{
type: 'list',
name: 'letter',
message: 'Choose a letter',
choices: ['A', 'B', 'C']
},
{
name: 'final',
message: 'Your final choice?',
default: (answers: any) => answers.letter // <-- Cool, this works and the default is the letter that has been chosen before
}
]);
this.answers = await this.optionOrPrompt([ // <-- Now let's use optionOrPrompt
{
type: 'list',
name: 'letter',
message: 'Choose a letter',
choices: ['A', 'B', 'C']
},
{
name: 'final',
message: 'Your final choice?',
default: (answers: any) => answers.letter // <-- This time, default does not work: answers in undefined
}
]);
Robin-Manuel Thiel commented
You can repoduce this in the robinmanuelthiel/issue32
branch by running
yo wemogy:testing-fail