diff --git a/.changeset/bright-wolves-export-cancel.md b/.changeset/bright-wolves-export-cancel.md new file mode 100644 index 00000000..0cd29724 --- /dev/null +++ b/.changeset/bright-wolves-export-cancel.md @@ -0,0 +1,9 @@ +--- +"@clack/core": minor +"@clack/prompts": minor +--- + +Export `CANCEL_SYMBOL` constant and `CancelSymbol` type from both packages. + +This allows consumers to create synthetic cancel values in tests and write +precise TypeScript types without reimplementing internals. diff --git a/.changeset/shaggy-boxes-crash.md b/.changeset/shaggy-boxes-crash.md new file mode 100644 index 00000000..f017edcd --- /dev/null +++ b/.changeset/shaggy-boxes-crash.md @@ -0,0 +1,6 @@ +--- +"@clack/core": minor +"@clack/prompts": minor +--- + +Export `CANCEL_SYMBOL` constant and `CancelSymbol` type from `@clack/core` and `@clack/prompts`. Update `isCancel` type guard to narrow to `CancelSymbol` instead of the broad `symbol` type. diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 4383a3df..a98c0a3e 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -21,7 +21,7 @@ export { default as SelectKeyPrompt } from './prompts/select-key.js'; export type { TextOptions } from './prompts/text.js'; export { default as TextPrompt } from './prompts/text.js'; export type { ClackState as State } from './types.js'; -export { block, getColumns, getRows, isCancel, wrapTextWithPrefix } from './utils/index.js'; +export { block, getColumns, getRows, isCancel, CANCEL_SYMBOL, wrapTextWithPrefix } from './utils/index.js'; export type { ClackSettings } from './utils/settings.js'; export { settings, updateSettings } from './utils/settings.js'; export type { Validate } from './utils/validation.js'; diff --git a/packages/core/src/utils/index.ts b/packages/core/src/utils/index.ts index 84ddd611..96199a8b 100644 --- a/packages/core/src/utils/index.ts +++ b/packages/core/src/utils/index.ts @@ -14,7 +14,7 @@ const isWindows = globalThis.process.platform.startsWith('win'); export const CANCEL_SYMBOL = Symbol('clack:cancel'); -export function isCancel(value: unknown): value is symbol { +export function isCancel(value: unknown): value is typeof CANCEL_SYMBOL { return value === CANCEL_SYMBOL; } diff --git a/packages/prompts/src/index.ts b/packages/prompts/src/index.ts index d12551b7..61b10917 100644 --- a/packages/prompts/src/index.ts +++ b/packages/prompts/src/index.ts @@ -1,5 +1,5 @@ export type { ClackSettings } from '@clack/core'; -export { isCancel, settings, updateSettings } from '@clack/core'; +export { isCancel, CANCEL_SYMBOL, settings, updateSettings } from '@clack/core'; export * from './autocomplete.js'; export * from './box.js';