[Typescript]106. Medium - OnPropChangedMethods

type OnPropChangedMethods<T> = {
  [Key in keyof T & string as `${Key}Changed`]: (cb: (newValue: T[Key]) => void) => void
}
declare function makeWatchedObject<T>(obj: T): T & OnPropChangedMethods<T>;
let homer = makeWatchedObject({
  firstName: "Homer",
  age: 33,
  location: "Springfield"
})

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