Skip to content

Commit

Permalink
pass Answers to PromptSession
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 3, 2024
1 parent dec6a98 commit c44cc2d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
7 changes: 2 additions & 5 deletions packages/inquirer/src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type {
BuiltInQuestion,
StreamOptions,
QuestionMap,
PromptSession,
} from './types.mjs';
import { Observable } from 'rxjs';

Expand Down Expand Up @@ -98,11 +99,7 @@ export function createPromptModule<
opts?: { signal?: AbortSignal },
): PromptReturnType<PrefilledAnswers & A>;
function promptModule<A extends Answers>(
questions:
| NamedQuestion<A>[]
| Record<keyof A, Question<A>>
| Observable<NamedQuestion<A>>
| NamedQuestion<A>,
questions: PromptSession<A>,
answers?: Partial<A>,
opts: { signal?: AbortSignal } = {},
): PromptReturnType<A> {
Expand Down
10 changes: 5 additions & 5 deletions packages/inquirer/src/types.mts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ export type CustomQuestion<
[key in Extract<keyof Q, string>]: Readonly<QuestionWithGetters<key, Q[key], A>>;
}[Extract<keyof Q, string>];

export type PromptSession<Q extends AnyQuestion<any>> =
| Q[]
| Record<string, Omit<Q, 'name'>>
| Observable<Q>
| Q;
export type PromptSession<A extends Answers> =
| AnyQuestion<A>[]
| Record<string, Omit<AnyQuestion<A>, 'name'>>
| Observable<AnyQuestion<A>>
| AnyQuestion<A>;

export type StreamOptions = Prettify<Context & { skipTTYChecks?: boolean }>;
6 changes: 3 additions & 3 deletions packages/inquirer/src/ui/prompt.mts
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ function setupReadlineOptions(opt: StreamOptions) {
}

function isQuestionArray<A extends Answers>(
questions: PromptSession<AnyQuestion<A>>,
questions: PromptSession<A>,
): questions is AnyQuestion<A>[] {
return Array.isArray(questions);
}

function isQuestionMap<A extends Answers>(
questions: PromptSession<AnyQuestion<A>>,
questions: PromptSession<A>,
): questions is Record<string, Omit<AnyQuestion<A>, 'name'>> {
return Object.values(questions).every(
(maybeQuestion) =>
Expand Down Expand Up @@ -199,7 +199,7 @@ export default class PromptsRunner<A extends Answers> {
}

async run(
questions: PromptSession<AnyQuestion<A>>,
questions: PromptSession<A>,
answers?: Partial<A>,
opts: { signal?: AbortSignal } = {},
): Promise<A> {
Expand Down

0 comments on commit c44cc2d

Please sign in to comment.