Skip to content

Export the cancel symbol #554

@aqeelat

Description

@aqeelat

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'
import type { CancelSymbol } from '@clack/prompts'

Prompt return types could then use CancelSymbol instead of symbol:

Promise<string | CancelSymbol>

This would allow more precise narrowing:

const result = await text({ message: 'Name?' })

if (isCancel(result)) {
  // result: CancelSymbol
} else {
  // result: string
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Needs triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions