示例工程 16-js-to-ts-migration

16-js-to-ts-migration/02-allowjs-import/types.test-d.ts

typescript · 0.4 KB

运行:16 · allowjs-import

点击「运行示例」后,左侧显示源码、右侧显示运行结果;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 { format } from './js/format.js';
 
// JSDoc 的类型会进入推断:参数 string,返回 string
type Case1 = Expect<Equal<Parameters<typeof format>, [name: string]>>;
type Case2 = Expect<Equal<ReturnType<typeof format>, string>>;