示例工程 18-iife-module-pattern

18-iife-module-pattern/04-namespace-merging/types.test-d.ts

typescript · 0.4 KB

运行:18 · namespace-merging

点击「运行示例」后,左侧显示源码、右侧显示运行结果;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;
 
// 两个文件里的同名 namespace 合并
type Case1 = Expect<Equal<keyof App.Config, 'host'>>;
type Case2 = Expect<Equal<keyof App.State, 'ready'>>;
type Case3 = Expect<Equal<typeof App.version, string>>;
 
// 不存在的成员被拒绝
// @ts-expect-error: App 没有 Missing
type Bad = App.Missing;