diff --git a/typings/index.d.ts b/typings/index.d.ts index c9d3c314c..36682191c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -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 & Record); + export class CommanderError extends Error { code: string; exitCode: number; @@ -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;