将参数封装到一个对象中,然后将对象作为单个参数传递。
示例代码:
export interface ConstructorOptions {
name: string;
age: number;
gender: string;
...
}
export class ExampleComponent {
constructor(private options: ConstructorOptions) {
...
}
}
// 调用
const options: ConstructorOptions = {
name: 'Tom',
age: 18,
gender: 'Male',
...
};
const exampleComponent = new ExampleComponent(options);