Scoping Variables with Different Patterns

In this chapter, we see the most basic concept that is a variable. Knowing what is the exact type, from a primitive to an object, is essential for accessing specific members. Scoping down the exact type at runtime and design time is crucial, to have consistency between the two environments and to have feedback about what is possible and what is not. The variety of configurations among the different types of variable requires many different patterns that are covered in this chapter.

This chapter will cover the following:

  • How to compare at runtime and design time with typeof
  • How to check with a guarantee for undefined and null
  • Do I need to check every possibility of a union to have the right type?
  • What is the limitation of instanceof?
  • Why a discriminator is essential for type identification
  • Why using user defined guard
  • How and why to cast
  • What is a type assertion?
  • How to compare classes
  • How to narrow type for function with a union in signatures

..................Content has been hidden....................

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