Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#424·prompts

The method passed into question is executed automatically

Author: hcl-zCreated Nov 14, 2024Updated Nov 14, 2024

Is your feature request related to a problem?

I'd like to pass a callback-like method in question and get it and execute it when Onsubmit, but the current code will pre-execute all the methods that aren't in special functions`

javascript
  for (question of questions) {
    ({ name, type } = question);

    // evaluate type first and skip if type is a falsy value
    if (typeof type === 'function') {
      type = await type(answer, { ...answers }, question)
      question['type'] = type
    }
    if (!type) continue;

    // if property is a function, invoke it unless it's a special function
    for (let key in question) {
      if (passOn.includes(key)) continue;
      let value = question[key];
      question[key] = typeof value === 'function' ? await value(answer, { ...answers }, lastPrompt) : value;
    }

Describe the solution you'd like

Don't handle the method passed in in question, leave it intact in onSubmit

Source: terkelg/prompts

View original on GitHubView discussion on GitHub