From the course: TypeScript Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: The right type

Solution: The right type

(upbeat music) - For this challenge, I asked you to implement the same scenario that I've been showing you for the past two chapters, and to try to do it without going back to see what I've done in those videos. Now, I'm going to show you two ways to solve this problem. The first solution is simpler and easier to implement, but it doesn't actually solve the problem in its entirety. Regardless, it's worth showing. So I'll start with it. That solution I'm talking about is to use a record type, like this. This gives me the ability to create a record object whose property names match those of the target object. Then I can define the type for the query function. The thing that checks the value of the property, like this. And that's the end of that solution. Sure it works, but it only gets me part of the way there. This still says that the type of this name property can either be a string or a number, but that's just not true.…

Contents