Skip to content

Commit 0d432ba

Browse files
authored
Make OptionValueSource a string with well-known values for auto-complete. (#1983)
1 parent f5413db commit 0d432ba

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

typings/index.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
/* eslint-disable @typescript-eslint/method-signature-style */
66
/* eslint-disable @typescript-eslint/no-explicit-any */
77

8+
// This is a trick to encourage editor to suggest the known literals while still
9+
// allowing any BaseType value.
10+
// References:
11+
// - https://github.com/microsoft/TypeScript/issues/29729
12+
// - https://github.com/sindresorhus/type-fest/blob/main/source/literal-union.d.ts
13+
// - https://github.com/sindresorhus/type-fest/blob/main/source/primitive.d.ts
14+
type LiteralUnion<LiteralType, BaseType extends string | number> = LiteralType | (BaseType & Record<never, never>);
15+
816
export class CommanderError extends Error {
917
code: string;
1018
exitCode: number;
@@ -272,7 +280,8 @@ export interface OutputConfiguration {
272280

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

277286
export type OptionValues = Record<string, any>;
278287

0 commit comments

Comments
 (0)