class User {
constructor(public readonly name: string, public readonly value: Function) {}
}
class Data {
values: any[] = [];
register(name: string, value: Function): void;
register(user: User): void;
register(name: string | User, value?: Function) {
if (name instanceof User) {
this.values.push(name);
} else {
this.values.push(new User(name, value!));
}
}
}
const data = new Data();
data.register("a", () => {});
data.register(new User('b', () => {}));
console.assert( data.values.length === 2 )