示例工程 08-unions-intersections

08-unions-intersections/03-intersection/demo/missing-side.ts

typescript · 0.3 KB

运行:08 · intersection

点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。

// 故意写错:交叉类型要求两侧都满足,缺少 age。
// 期望 tsc 报 TS2741(由 tsconfig.fail.json 触发)。
type Named = { name: string };
type Aged = { age: number };
type Person = Named & Aged;
 
const person: Person = { name: 'Ada' };
 
export { person };