首页 > 其他分享 >[Typescript] Identity function - Reverse mapped types with identity function 02

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

时间:2023-02-24 15:12:40浏览次数:31  
标签:function 02 Typescript obj name makeEventHandlers Expect type

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

 

标签:function,02,Typescript,obj,name,makeEventHandlers,Expect,type
From: https://www.cnblogs.com/Answer1215/p/17151515.html

相关文章