Skip to content

FlagBuilder

Immutable flag schema builder.

The type parameter C is a phantom that tracks the value type and presence through the fluent chain. Each modifier returns a new builder — the original is never mutated.

Signatures

ts
class FlagBuilder<C extends FlagConfig> {}

Members

Constructors

constructor

ts
constructor();

Properties

_config

Type brand — exists only in the type system (declare produces no runtime property). Used by InferFlag / InferFlags.

ts
_config: FlagBuilder.C;

schema

Runtime schema descriptor.

ts
schema: FlagSchema;

Methods

alias

ts
alias(name: string, options?: { hidden?: boolean; }): FlagBuilder<FlagBuilder.C>;

config

ts
config(path: string): FlagBuilder<FlagBuilder.C>;

default

ts
default<V extends unknown>(value: V): FlagBuilder<WithPresence<FlagBuilder.C, "defaulted">>;

deprecated

ts
deprecated(message?: string): FlagBuilder<FlagBuilder.C>;

describe

ts
describe(description: string): FlagBuilder<FlagBuilder.C>;

env

ts
env(varName: string): FlagBuilder<FlagBuilder.C>;

prompt

ts
prompt(config: PromptConfig): FlagBuilder<FlagBuilder.C>;

propagate

ts
propagate(): FlagBuilder<FlagBuilder.C>;

required

ts
required(): FlagBuilder<WithPresence<FlagBuilder.C, "required">>;

Examples

ts
const port = flag.number().default(8080);
type Port = InferFlag<typeof port>; // number

const region = flag.enum(['us', 'eu', 'ap']);
type Region = InferFlag<typeof region>; // 'us' | 'eu' | 'ap' | undefined

See Also

Released under the MIT License.