3 Types, Aliases and Interfaces

 

This chapter covers

  • Understanding the difference between type aliases and interfaces
  • Putting into practice type widening
  • Ordering type properties and extending interfaces suitably
  • Applying type guards appropriately
  • Making sense of the readonly property modifier
  • Utilizing the keyof and Extract uitlity types effectively

Getting to grips with TypeScript can feel a bit like being invited to an exclusive party where everyone is speaking a slightly different dialect of a language you thought you knew well. In this case, the language is JavaScript, and the dialect is TypeScript. Now, imagine walking into this party and hearing words like "types", "type aliases" and "interfaces" being thrown around. It might initially sound as though everyone is discussing an unusual art exhibition! But, once you get the hang of it, these terms will become as familiar as your favorite punchline.

3.1 Confusing Types Aliases and Interfaces

3.2 Misconceiving Type Widening

3.3 Ordering Type Properties Inconsistently

3.4 Extending Interfaces Unnecessarily

3.5 Missing on Opportunities to Use Type Aliases

3.6 Avoiding Type Guards

3.7 Overcomplicating Types

3.7.1 Nested types

3.7.2 Complex union and intersection types

3.7.3 Overuse of mapped and conditional types

3.8 Overlooking readonly Modifier

3.9 Forgoing keyof Utility Type

3.10 Underutilizing Utility Types Extract and Partial When Working with Object Types

3.10.1 Ignoring Extract for narrowing types

3.10.2 Avoiding Partial for marking properties as optional

3.11 Summary

sitemap