Unleashing the Power of Type with Objects

TypeScript can be overwhelming with all the different objects. In this chapter, we illustrate the difference between an object, Object, object literal, and an object built with a constructor. This chapter also discusses the notion of a union between types that will allow an infinite combination of types for a single value. Furthermore, the concept of an intersection looms, giving the possibility of manipulating type differently. At the end of this chapter, the reader will be able to create complex combinations of objects that hold advanced structures. We will dissect how to create a dictionary with a strongly typed index signature, understand how type can be beneficial with a map, and learn how to use the right object to be as accurate as possible when defining an object that can have a broad reach.

This chapter covers the following topics:

  • How to strongly type a set/dictionary with an index signature
  • TypeScript and map
  • The difference between an index signature and a map
  • The difference between object and Object
  • When to use object, Object, or any
  • What is an object literal
  • How to create a constructed object
  • The difference between an explicit type or a cast
  • Variable with many types
  • Combining a type with an intersection
  • Intersecting with something other than a type
  • Intersecting with an optional type
  • Merging a type with inheritance
  • The difference between a type and an interface
  • Destructuring a type and an array
  • Tuple
  • The difference between declare and let/const/var
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.239.166