Skip to content

Commit

Permalink
Chore: Cleanup code & types
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Apr 24, 2024
1 parent e734cf4 commit 3550026
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/checkbox/checkbox.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ describe('checkbox prompt', () => {
const { answer, events, getScreen } = await render(checkbox, {
message: 'Select a number',
choices: numberedChoices,
validate(items: any) {
validate(items: ReadonlyArray<unknown>) {
if (items.length !== 1) {
return 'Please select only one choice';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/checkbox/src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function check(checked: boolean) {
}

export default createPrompt(
<Value extends unknown>(config: Config<Value>, done: (value: Array<Value>) => void) => {
<Value,>(config: Config<Value>, done: (value: Array<Value>) => void) => {
const {
instructions,
pageSize = 7,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/core.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ describe('Error handling', () => {
});

it('surface errors in useEffect cleanup functions', async () => {
const Prompt = (config: {}, done: (value: string) => void) => {
const Prompt = (config: object, done: (value: string) => void) => {
useEffect(() => {
done('done');

Expand All @@ -533,8 +533,8 @@ describe('Error handling', () => {
});

it('prevent returning promises from useEffect hook', async () => {
const Prompt = (config: {}, done: (value: string) => void) => {
// @ts-ignore: This is a test
const Prompt = (config: object, done: (value: string) => void) => {
// @ts-expect-error: Testing an invalid behavior.
useEffect(async () => {
done('done');
}, []);
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/lib/hook-engine.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint @typescript-eslint/no-explicit-any: ["off"] */

import { AsyncLocalStorage, AsyncResource } from 'node:async_hooks';
import type { InquirerReadline } from './read-line.type.mjs';
import { HookError, ValidationError } from './errors.mjs';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/make-theme.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Prettify, PartialDeep } from '@inquirer/type';
import { defaultTheme, type Theme } from './theme.mjs';

export function makeTheme<SpecificTheme extends {}>(
export function makeTheme<SpecificTheme extends object>(
...themes: ReadonlyArray<undefined | PartialDeep<Theme<SpecificTheme>>>
): Prettify<Theme<SpecificTheme>> {
return Object.assign({}, defaultTheme, ...themes, {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/theme.mts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type DefaultTheme = {
};
};

export type Theme<Extension extends {} = {}> = Prettify<Extension & DefaultTheme>;
export type Theme<Extension extends object = object> = Prettify<Extension & DefaultTheme>;

export const defaultTheme: DefaultTheme = {
prefix: chalk.green('?'),
Expand Down
1 change: 0 additions & 1 deletion packages/demo/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env node
/* eslint-disable no-await-in-loop */

import { select } from '@inquirer/prompts';
import checkboxDemo from './demos/checkbox.mjs';
Expand Down
5 changes: 2 additions & 3 deletions packages/inquirer/lib/prompts/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,15 @@ export default class Prompt {
* @return {Object} Object containing two observables: `success` and `error`
*/
handleSubmitEvents(submit) {
const self = this;
const validate = runAsync(this.opt.validate);
const asyncFilter = runAsync(this.opt.filter);
const validation = submit.pipe(
flatMap((value) => {
this.startSpinner(value, this.opt.filteringText);
return asyncFilter(value, self.answers).then(
return asyncFilter(value, this.answers).then(
(filteredValue) => {
this.startSpinner(filteredValue, this.opt.validatingText);
return validate(filteredValue, self.answers).then(
return validate(filteredValue, this.answers).then(
(isValid) => ({ isValid, value: filteredValue }),
(err) => ({ isValid: err, value: filteredValue }),
);
Expand Down
4 changes: 1 addition & 3 deletions packages/inquirer/lib/prompts/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ export default class ListPrompt extends Base {
_run(cb) {
this.done = cb;

const self = this;

const events = observe(this.rl);
events.normalizedUpKey.pipe(takeUntil(events.line)).forEach(this.onUpKey.bind(this));
events.normalizedDownKey
Expand All @@ -62,7 +60,7 @@ export default class ListPrompt extends Base {
take(1),
map(this.getCurrentValue.bind(this)),
flatMap((value) =>
runAsync(self.opt.filter)(value, self.answers).catch((err) => err),
runAsync(this.opt.filter)(value, this.answers).catch((err) => err),
),
)
.forEach(this.onSubmit.bind(this));
Expand Down
2 changes: 1 addition & 1 deletion packages/rawlist/src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function isSelectableChoice<T>(
}

export default createPrompt(
<Value extends unknown>(config: RawlistConfig<Value>, done: (value: Value) => void) => {
<Value,>(config: RawlistConfig<Value>, done: (value: Value) => void) => {
const { choices } = config;
const [status, setStatus] = useState<string>('pending');
const [value, setValue] = useState<string>('');
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class BufferedStream extends Stream.Writable {
}
}

export async function render<TestedPrompt extends Prompt<any, any>>(
export async function render<TestedPrompt extends Prompt<unknown, unknown>>(
prompt: TestedPrompt,
props: Parameters<TestedPrompt>[0],
options?: Parameters<TestedPrompt>[1],
Expand Down

0 comments on commit 3550026

Please sign in to comment.