bombshell-dev / clack

Effortlessly build beautiful command-line apps
https://clack.cc
5.53k stars 90 forks source link

How to add return data type in TS #93

Closed devpenzil closed 1 year ago

devpenzil commented 1 year ago

Describe the bug

    appdetails.packagename = await text({
      message: "Enter the Package name:  ",
      placeholder: "placeholder",
      validate(value) {
        if (!packegeRegex.test(value)) {
          return "Invalid PackageName";
        }
      },
    });

Here the appdetails.packagename type is "string". and shows this error

Type 'string | symbol' is not assignable to type 'string'.

How to solve this

ulken commented 1 year ago

It's not a bug. You have to check if the prompt was cancelled by the user first (where a cancel symbol is returned). See https://github.com/natemoo-re/clack/blob/main/packages/prompts/README.md#cancellation:

import { isCancel, cancel, text } from '@clack/prompts';

const result = await text(...);

if (isCancel(result)) {
  cancel('Operation cancelled.');
  process.exit(0);
}

appdetails.packagename = result
devpenzil commented 1 year ago

Thanks @ulken for the quick response. Its working