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

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'>>;
  },
});

 

posted @ 2023-02-24 15:02  Zhentiw  阅读(16)  评论(0编辑  收藏  举报