Skip to content

Commit

Permalink
feat: export Question and Answers
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 18, 2024
1 parent bd45397 commit 3f3d96b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions packages/inquirer/inquirer.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,31 @@ beforeEach(() => {
inquirer.registerPrompt('failing', StubFailingPrompt);
});

describe('exported types', () => {
type Answers = import('./src/index.mjs').Answers;
type Question = import('./src/index.mjs').Question;

it('Question type is not any', () => {
expectTypeOf({}).not.toMatchTypeOf<Question>();
});

it('exported Question type requires type, name and message', () => {
expectTypeOf({ type: 'stub', name: 'q1', message: 'message' }).toMatchTypeOf<Question>();

Check failure on line 92 in packages/inquirer/inquirer.test.mts

View workflow job for this annotation

GitHub Actions / Linting

Replace `·type:·'stub',·name:·'q1',·message:·'message'` with `⏎······type:·'stub',⏎······name:·'q1',⏎······message:·'message',⏎···`
expectTypeOf({ name: 'q1', message: 'message' }).not.toMatchTypeOf<Question>();
expectTypeOf({ type: 'stub', message: 'message' }).not.toMatchTypeOf<Question>();
expectTypeOf({ type: 'stub', name: 'q1' }).not.toMatchTypeOf<Question>();
});

it('exported Answers type is not any', () => {
expectTypeOf(false).not.toMatchTypeOf<Answers>();
});

it('exported Answers type matches any object', () => {
expectTypeOf({}).toMatchTypeOf<Answers>();
expectTypeOf({ foo: 'bar' }).toMatchTypeOf<Answers>();
});
});

describe('inquirer.prompt(...)', () => {
describe('interfaces', () => {
it('takes a prompts array', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/src/index.mts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import type {
} from './types.mjs';
import { Observable } from 'rxjs';

export type { QuestionMap } from './types.mjs';
export type { QuestionMap, AnyQuestion as Question, Answers } from './types.mjs';

const builtInPrompts: PromptCollection = {
input,
Expand Down
2 changes: 1 addition & 1 deletion packages/inquirer/src/types.mts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface QuestionMap {
type KeyValueOrAsyncGetterFunction<T, k extends string, A extends Answers> =
T extends Record<string, any> ? T[k] | AsyncGetterFunction<T[k], A> : never;

export type AnyQuestion<A extends Answers, Type extends string = string> = {
export type AnyQuestion<A extends Answers = Answers, Type extends string = string> = {
type: Type;
name: string;
message: string | AsyncGetterFunction<string, A>;
Expand Down

0 comments on commit 3f3d96b

Please sign in to comment.