type Equal = (() => T extends A ? 1 : 2) extends (() => T extends B ? 1 : 2) ? true : false; type Expect = T; import type { Config, Point, ReadonlyConfig } from './src/main.js'; // 两个 interface 声明合并成一个 type Case1 = Expect>; type Case2 = Expect>; // 工具类型都是对键空间的映射 type Case3 = Expect, { x?: number; y?: number }>>; type Case4 = Expect, { x: number }>>; type Case5 = Expect, { x: number }>>; // readonly 只约束赋值,不阻止创建新对象 const config: ReadonlyConfig = { id: 1 }; // @ts-expect-error: readonly 属性不可写 config.id = 2; // exactOptionalPropertyTypes 下不能显式传 undefined // @ts-expect-error: label 不能是 undefined const explicit: ReadonlyConfig = { id: 2, label: undefined }; export { config, explicit };