面试题答案
一键面试interface BaseInterface {
id: number;
}
interface ChildInterface1 extends BaseInterface {
email: string;
}
interface ChildInterface2 extends BaseInterface {
phone: string;
}
type MergedType = ChildInterface1 & ChildInterface2;
function printProperties(obj: MergedType) {
console.log(`id: ${obj.id}, email: ${obj.email}, phone: ${obj.phone}`);
}
你可以使用以下方式调用函数:
const testObj: MergedType = {
id: 1,
email: "test@example.com",
phone: "1234567890"
};
printProperties(testObj);