Dylan Hunn Profile picture
Software Engineer on the open source Angular team @ Google. Tweets about web development, SF housing politics, snowboarding 🥑🏳️‍🌈 Mastodon: dylhunn@towns.gay
Dec 8, 2022 5 tweets 2 min read
In #Angular Typed Forms, the `get` method takes a string with dot-separated control names, and returns a fully typed value. How is this possible?

We can actually parse the argument at compile time, using the magic of #TypeScript template literal types! Let's see how it works. 🧵 let party = fb.nonNullable.... Imagine you have a type listing various products, and you want to automatically generate a type for corresponding database columns.

We define a template literal type called DatabaseColumn. It takes any subtype of string, and maps each element onto a string with a column prefix. type Products = 'Food'|'Clo...