From the course: React: Using TypeScript (2019)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Review best practices interfaces

Review best practices interfaces

From the course: React: Using TypeScript (2019)

Start my 1-month free trial

Review best practices interfaces

- [Instructor] Let's quickly review best practices for interfaces. As mentioned before, interfaces won't show in your compiled javascript code. They are simply there to help you shape your data, especially useful for props in your components. As we've explored in this chapter, when you define your props and your component you define them first in the interface then pass them into your functional component, and then as you use them, if the props passed the component aren't using the right types you'll get an error. This is the best way to define the expected data and prevent any security or execution issues with your data. Also, what do you do when you need to use optional properties, and the data passed is missing one or two properties. For example, with our Warrior, we have a token or a money property but this one could be empty. Well you can use a question mark at the end of a property name if the Warrior doesn't have money yet. Then you don't need to pass a value for this one. If…

Contents