zl程序教程

您现在的位置是:首页 >  前端

当前栏目

[Typescript] Identity function - Reverse mapped types with identity function 02

typescript with 02 Function types identity reverse mapped
2023-09-14 09:00:42 时间
import { Equal, Expect } from '../helpers/type-utils';

export function makeEventHandlers<
  T extends { [Key in keyof T]: (key: Key) => void }
>(obj: T) {
  return obj;
}

const obj = makeEventHandlers({
  click: (name) => {
    console.log(name);

    type test = Expect<Equal<typeof name, 'click'>>;
  },
  focus: (name) => {
    console.log(name);

    type test = Expect<Equal<typeof name, 'focus'>>;
  },
});