Skip to content

Commit

Permalink
Make OptionValueSource a string with well-known values for auto-compl…
Browse files Browse the repository at this point in the history
…ete. (#1983)
  • Loading branch information
shadowspawn committed Aug 26, 2023
1 parent f5413db commit 0d432ba
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
/* eslint-disable @typescript-eslint/method-signature-style */
/* eslint-disable @typescript-eslint/no-explicit-any */

// This is a trick to encourage editor to suggest the known literals while still
// allowing any BaseType value.
// References:
// - https://github.com/microsoft/TypeScript/issues/29729
// - https://github.com/sindresorhus/type-fest/blob/main/source/literal-union.d.ts
// - https://github.com/sindresorhus/type-fest/blob/main/source/primitive.d.ts
type LiteralUnion<LiteralType, BaseType extends string | number> = LiteralType | (BaseType & Record<never, never>);

export class CommanderError extends Error {
code: string;
exitCode: number;
Expand Down Expand Up @@ -272,7 +280,8 @@ export interface OutputConfiguration {

export type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll';
export type HookEvent = 'preSubcommand' | 'preAction' | 'postAction';
export type OptionValueSource = 'default' | 'config' | 'env' | 'cli' | 'implied';
// The source is a string so author can define their own too.
export type OptionValueSource = LiteralUnion<'default' | 'config' | 'env' | 'cli' | 'implied', string> | undefined;

export type OptionValues = Record<string, any>;

Expand Down

0 comments on commit 0d432ba

Please sign in to comment.