From 9f64912d7d1cd83fe8e695a5cede426f29c88f22 Mon Sep 17 00:00:00 2001 From: John Gee Date: Sat, 26 Aug 2023 18:07:41 +1200 Subject: [PATCH] Make OptionValueSource a string with well-known values for auto-complete. --- typings/index.d.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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;