MST

星途 面试题库

面试题:TypeScript交叉类型在复杂对象中如何合并属性

假设有两个接口`InterfaceA`和`InterfaceB`,`InterfaceA`有属性`name: string`,`InterfaceB`有属性`age: number`。请使用交叉类型创建一个新类型`CombinedType`,使其同时拥有`name`和`age`属性,并实例化一个符合该类型的对象。
36.6万 热度难度
前端开发TypeScript

知识考点

AI 面试

面试题答案

一键面试
interface InterfaceA {
    name: string;
}
interface InterfaceB {
    age: number;
}
type CombinedType = InterfaceA & InterfaceB;
const obj: CombinedType = { name: 'John', age: 30 };