示例工程 04-object-types-structural

04-object-types-structural/02-excess-property-check/types.test-d.ts

typescript · 0.4 KB

运行:04 · excess-property-check

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

type Equal<A, B> =
  (<T>() => T extends A ? 1 : 2) extends (<T>() => T extends B ? 1 : 2) ? true : false;
type Expect<T extends true> = T;
 
import type { User } from './src/main.js';
 
type Case1 = Expect<Equal<keyof User, 'id' | 'name'>>;
type Case2 = Expect<Equal<Pick<User, 'name'>, { name: string }>>;
 
// 变量形式允许多余属性
declare const row: { id: number; name: string; email: string };
const accepted: User = row;
 
export { accepted };