Context
This came up while evaluating @clack/prompts as a potential replacement for enquirer.js, comparing it with enquirer.js and @inquirer/prompts.
Split out from: #550
Problem
isCancel(value) identifies cancellation values, but the actual cancel symbol is not exported.
This makes a few things harder:
- Tests cannot easily create a cancellation value that behaves like clack's own cancel result
- Prompt return types use the broad
symbol type isCancel narrows to symbol rather than a specific cancel symbol type
Proposal
Export the cancel symbol and a corresponding type from @clack/core and @clack/prompts:
import{CANCEL_SYMBOL,isCancel}from'@clack/prompts'importtype{CancelSymbol}from'@clack/prompts'Prompt return types could then use CancelSymbol instead of symbol:
Promise<string|CancelSymbol>
This would allow more precise narrowing:
constresult=awaittext({message: 'Name?'})if(isCancel(result)){// result: CancelSymbol}else{// result: string}
Context
This came up while evaluating
@clack/promptsas a potential replacement forenquirer.js, comparing it withenquirer.jsand@inquirer/prompts.Split out from: #550
Problem
isCancel(value)identifies cancellation values, but the actual cancel symbol is not exported.This makes a few things harder:
symboltypeisCancelnarrows tosymbolrather than a specific cancel symbol typeProposal
Export the cancel symbol and a corresponding type from
@clack/coreand@clack/prompts:Prompt return types could then use
CancelSymbolinstead ofsymbol:This would allow more precise narrowing: