Blog Logo

How Did I Not Know This TypeScript Trick Earlier??!

Duration : 00:09:11

In this video, the presenter demonstrates a useful TypeScript trick that was discovered recently in an open-source repository. The trick involves receiving conditional TypeScript properties in a child component from a parent component. The presenter provides an example use case where the parent component returns the child component and the desired properties are defined in the child component. However, simply defining the properties does not achieve the desired outcome. The presenter then shows how to use destructuring and conditional typing to achieve the desired behavior. The trick allows for the conditional inclusion of properties based on the gender of the person. The presenter concludes by showcasing the type safety and intellisense benefits of this approach.