From c44cc2d4ac4daf79a95b144fd56e5db0f61ced3c Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Tue, 3 Sep 2024 10:31:31 -0300 Subject: [PATCH] pass Answers to PromptSession --- packages/inquirer/src/index.mts | 7 ++----- packages/inquirer/src/types.mts | 10 +++++----- packages/inquirer/src/ui/prompt.mts | 6 +++--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/inquirer/src/index.mts b/packages/inquirer/src/index.mts index 7f5b3c2cff..68058b7a20 100644 --- a/packages/inquirer/src/index.mts +++ b/packages/inquirer/src/index.mts @@ -29,6 +29,7 @@ import type { BuiltInQuestion, StreamOptions, QuestionMap, + PromptSession, } from './types.mjs'; import { Observable } from 'rxjs'; @@ -98,11 +99,7 @@ export function createPromptModule< opts?: { signal?: AbortSignal }, ): PromptReturnType; function promptModule( - questions: - | NamedQuestion[] - | Record> - | Observable> - | NamedQuestion, + questions: PromptSession, answers?: Partial, opts: { signal?: AbortSignal } = {}, ): PromptReturnType { diff --git a/packages/inquirer/src/types.mts b/packages/inquirer/src/types.mts index 1a3d49da95..4607518d93 100644 --- a/packages/inquirer/src/types.mts +++ b/packages/inquirer/src/types.mts @@ -92,10 +92,10 @@ export type CustomQuestion< [key in Extract]: Readonly>; }[Extract]; -export type PromptSession> = - | Q[] - | Record> - | Observable - | Q; +export type PromptSession = + | AnyQuestion[] + | Record, 'name'>> + | Observable> + | AnyQuestion; export type StreamOptions = Prettify; diff --git a/packages/inquirer/src/ui/prompt.mts b/packages/inquirer/src/ui/prompt.mts index abbba616fa..29f3c8a67f 100644 --- a/packages/inquirer/src/ui/prompt.mts +++ b/packages/inquirer/src/ui/prompt.mts @@ -155,13 +155,13 @@ function setupReadlineOptions(opt: StreamOptions) { } function isQuestionArray( - questions: PromptSession>, + questions: PromptSession, ): questions is AnyQuestion[] { return Array.isArray(questions); } function isQuestionMap( - questions: PromptSession>, + questions: PromptSession, ): questions is Record, 'name'>> { return Object.values(questions).every( (maybeQuestion) => @@ -199,7 +199,7 @@ export default class PromptsRunner { } async run( - questions: PromptSession>, + questions: PromptSession, answers?: Partial, opts: { signal?: AbortSignal } = {}, ): Promise {