Skip to content

[Bug] isCancel no longer narrows prompt results after 1.5.0 #600

Description

@dreyfus92

Environment

  • OS: macOS
  • Node Version: v24.20.0
  • Package: @clack/core, @clack/prompts
  • Package Version: core 1.5.0, prompts 1.8.0

Describe the bug

#592 changed isCancel from value is symbol to value is typeof CANCEL_SYMBOL, but every prompt still returns Promise<T | symbol> (core Prompt.prompt() and the 11 as Promise<... | symbol> casts in prompts). typescript can't subtract a unique symbol from symbol, so after the guard the result still has symbol in its type and any downstream use errors. this breaks code that type-checked fine on 1.7.0.

To Reproduce

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

const p = await path({ message: 'pick a file' });
if (isCancel(p)) process.exit(0);
console.log(`selected: ${p}`);
// TS2731: Implicit conversion of a 'symbol' to a 'string' will fail at runtime.

same snippet passes on prompts 1.7.0 / core 1.4.3. assigning the result to a string fails with TS2322 instead.

Expected behavior

isCancel narrows the cancel case away like it did before. #554 asked for the specific cancel type on prompt return types, and #592 only did the guard half, which is what left the two out of sync.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions