Skip to content

Commit 8bd9129

Browse files
authored
fix: correctly specify return type of CANCEL_SYMBOL (#601)
1 parent c681d2b commit 8bd9129

12 files changed

Lines changed: 28 additions & 16 deletions

File tree

‎.changeset/lucky-plums-tell.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@clack/core": patch
3+
"@clack/prompts": patch
4+
---
5+
6+
Return type for prompts now correctly specifies `CANCEL_SYMBOL` instead of `symbol`

‎packages/core/src/prompts/prompt.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export default class Prompt<TValue> {
144144
}
145145

146146
public prompt() {
147-
return new Promise<TValue | symbol | undefined>((resolve) => {
147+
return new Promise<TValue | typeof CANCEL_SYMBOL | undefined>((resolve) => {
148148
if (this._abortSignal) {
149149
if (this._abortSignal.aborted) {
150150
this.state = 'cancel';

‎packages/prompts/src/autocomplete.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { styleText } from 'node:util';
2-
import type { Validate } from '@clack/core';
2+
import type { CANCEL_SYMBOL, Validate } from '@clack/core';
33
import { AutocompletePrompt, settings } from '@clack/core';
44
import {
55
type CommonOptions,
@@ -268,7 +268,7 @@ export const autocomplete = <Value>(opts: AutocompleteOptions<Value>) => {
268268
});
269269

270270
// Return the result or cancel symbol
271-
return prompt.prompt() as Promise<Value | symbol>;
271+
return prompt.prompt() as Promise<Value | typeof CANCEL_SYMBOL>;
272272
};
273273

274274
/**
@@ -452,5 +452,5 @@ export const autocompleteMultiselect = <Value>(opts: AutocompleteMultiSelectOpti
452452
});
453453

454454
// Return the result or cancel symbol
455-
return prompt.prompt() as Promise<Value[] | symbol>;
455+
return prompt.prompt() as Promise<Value[] | typeof CANCEL_SYMBOL>;
456456
};

‎packages/prompts/src/confirm.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { styleText } from 'node:util';
2+
import type { CANCEL_SYMBOL } from '@clack/core';
23
import { ConfirmPrompt, settings, wrapTextWithPrefix } from '@clack/core';
34
import {
45
type CommonOptions,
@@ -107,5 +108,5 @@ export const confirm = (opts: ConfirmOptions) => {
107108
}
108109
}
109110
},
110-
}).prompt() as Promise<boolean | symbol>;
111+
}).prompt() as Promise<boolean | typeof CANCEL_SYMBOL>;
111112
};

‎packages/prompts/src/date.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { styleText } from 'node:util';
2-
import type { DateFormat, State, Validate } from '@clack/core';
2+
import type { CANCEL_SYMBOL, DateFormat, State, Validate } from '@clack/core';
33
import { DatePrompt, runValidation, settings } from '@clack/core';
44
import { type CommonOptions, S_BAR, S_BAR_END, symbol } from './common.js';
55

@@ -133,7 +133,7 @@ export const date = (opts: DateOptions) => {
133133
}
134134
}
135135
},
136-
}).prompt() as Promise<Date | symbol>;
136+
}).prompt() as Promise<Date | typeof CANCEL_SYMBOL>;
137137
};
138138

139139
function renderDate(prompt: Omit<InstanceType<typeof DatePrompt>, 'prompt'>, state: State): string {

‎packages/prompts/src/group-multi-select.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { styleText } from 'node:util';
2+
import type { CANCEL_SYMBOL } from '@clack/core';
23
import { GroupMultiSelectPrompt, settings, wrapTextWithPrefix } from '@clack/core';
34
import {
45
type CommonOptions,
@@ -315,5 +316,5 @@ export const groupMultiselect = <Value>(opts: GroupMultiSelectOptions<Value>) =>
315316
}
316317
}
317318
},
318-
}).prompt() as Promise<Value[] | symbol>;
319+
}).prompt() as Promise<Value[] | typeof CANCEL_SYMBOL>;
319320
};

‎packages/prompts/src/multi-line.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { styleText } from 'node:util';
2+
import type { CANCEL_SYMBOL } from '@clack/core';
23
import { MultiLinePrompt, settings, wrapTextWithPrefix } from '@clack/core';
34
import { S_BAR, S_BAR_END, symbol } from './common.js';
45
import type { TextOptions } from './text.js';
@@ -98,5 +99,5 @@ export const multiline = (opts: MultiLineOptions) => {
9899
}
99100
}
100101
},
101-
}).prompt() as Promise<string | symbol>;
102+
}).prompt() as Promise<string | typeof CANCEL_SYMBOL>;
102103
};

‎packages/prompts/src/multi-select.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { styleText } from 'node:util';
2+
import type { CANCEL_SYMBOL } from '@clack/core';
23
import { MultiSelectPrompt, settings, wrapTextWithPrefix } from '@clack/core';
34
import {
45
type CommonOptions,
@@ -204,5 +205,5 @@ export const multiselect = <Value>(opts: MultiSelectOptions<Value>) => {
204205
}
205206
}
206207
},
207-
}).prompt() as Promise<Value[] | symbol>;
208+
}).prompt() as Promise<Value[] | typeof CANCEL_SYMBOL>;
208209
};

‎packages/prompts/src/password.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { styleText } from 'node:util';
2-
import type { Validate } from '@clack/core';
2+
import type { CANCEL_SYMBOL, Validate } from '@clack/core';
33
import { PasswordPrompt, settings } from '@clack/core';
44
import { type CommonOptions, S_BAR, S_BAR_END, S_PASSWORD_MASK, symbol } from './common.js';
55

@@ -88,5 +88,5 @@ export const password = (opts: PasswordOptions) => {
8888
}
8989
}
9090
},
91-
}).prompt() as Promise<string | symbol>;
91+
}).prompt() as Promise<string | typeof CANCEL_SYMBOL>;
9292
};

‎packages/prompts/src/select-key.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { styleText } from 'node:util';
2+
import type { CANCEL_SYMBOL } from '@clack/core';
23
import { SelectKeyPrompt, settings, wrapTextWithPrefix } from '@clack/core';
34
import { type CommonOptions, S_BAR, S_BAR_END, symbol } from './common.js';
45
import type { Option } from './select.js';
@@ -83,5 +84,5 @@ export const selectKey = <Value extends string>(opts: SelectKeyOptions<Value>) =
8384
}
8485
}
8586
},
86-
}).prompt() as Promise<Value | symbol>;
87+
}).prompt() as Promise<Value | typeof CANCEL_SYMBOL>;
8788
};

0 commit comments

Comments
 (0)