Multiple Types

Multiple Types
πŸ‘¨β€πŸ’Ό Sometimes a value can be one of several types. Union types let you express this.
🐨 Open
index.ts
and:
  1. Create a type for values that can be string or number
  2. Create a type for IDs that can be string or number
  3. Write functions that handle union types
typeof checks if a value is a string, number, boolean, or symbol. For example, typeof value === 'string' returns true if value is a string.
instanceof checks if an object was created from a particular class. For example, value instanceof Error returns true if value is an Error object.

Please set the playground first

Loading "Multiple Types"
Loading "Multiple Types"
Login to get access to the exclusive discord channel.
Loading Discord Posts