Declaration Merging Grows Config Types

Two interface declarations with the same name merge into one: fields from every declaration become required together and keyof unions reflect the full set.

TypescriptConfig Management

Code

typescriptsnippet
24 lines
interface PipelineConfig {
  name: string;
  retries: number;
}

// 同名 interface 自动合并:不同模块可以各自补充字段
interface PipelineConfig {
  timeoutMs: number;
  verbose?: boolean;
}

// 合并后的类型要求全部必填字段齐全(缺一个都过不了编译)
const config: PipelineConfig = {
  name: 'nightly-sync',
  retries: 2,
  timeoutMs: 30000,
  verbose: true,
};

// 键名联合也是合并后的全集
type ConfigKeys = keyof PipelineConfig;
const keys: ConfigKeys[] = ['name', 'retries', 'timeoutMs', 'verbose'];
console.log(keys.join(', '));
console.log(`${config.name}: retries=${config.retries} timeout=${config.timeoutMs}ms`);

Output

Captured from a sandboxed run of this snippet in the build pipeline.

name, retries, timeoutMs, verbose
nightly-sync: retries=2 timeout=30000ms

What the code does

The top-level object literal pins name, retries, timeoutMs, verbose as plain values — no derivation, no imports behind them.

Statements that matter

type ConfigKeys = keyof PipelineConfig;

Interactive Tools for This Topic

FAQ

Is there an install step between copy and run?
No. Between copying and running there is nothing left to do.