示例工程 24-module-resolution
24-module-resolution/03-exports-conditions/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;
import { hello } from 'pkg';
// exports 的 "types" 条件被解析
type Case1 = Expect<Equal<ReturnType<typeof hello>, string>>;
// exports 未暴露的深层路径被封锁
// @ts-expect-error: pkg/internal.js 不在 exports 里
type Deep = typeof import('pkg/internal.js');