示例工程 13-declaration-files
13-declaration-files/02-global-augmentation/types.test-d.ts
点击「运行示例」后,左侧显示源码、右侧显示运行结果;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;
// declare global 之后,Window 上出现 appVersion
type Case1 = Expect<Equal<Window['appVersion'], string>>;
type Case2 = Expect<Equal<ReturnType<typeof window.appVersion.toUpperCase>, string>>;