RecipesChapter 6: String Template Literal Types

Creating Event Callbacks with String Manipulation Types and Key Remapping

Recipe 6.2 from The TypeScript Cookbook

let person = {
  name: "Stefan",
  age: 40,
};

const watchedPerson = system.watch(person);

watchedPerson.onAgeChanged((ev) => {
  console.log(ev.val, "changed!!");
});

watchedPerson.age = 41; // logs "41 changed!!"
Open in TypeScript Playground →