Introduction to TypeScript and its types

Maneet Lodha
1 min readMay 16, 2021

TypeScript is basically a powerful compiler that converts the Typescript code into JavaScript. TypeScript code is Javascript with types defined. TS runs during the compile time, as it is not supported by the browsers and is called statically typed whereas JS is dynamically typed, as it defines the type on compile-time whereas TS defines the type on run time, which helps us to prevent error while running the app locally.

Types in TS

  1. number (1,5.3, -10 ): All numbers, no differentiation between integers or floats.
  2. string (‘Hi’, ”Hi”,`Hi`): All text values

3. boolean (true, false ): Just these two, no “truthy” or “falsy” values.

4. object (age:30} ): Any JavaScript object, more specific types (type of object) are possible.

5. Array ([1,2,3]): Any JavaScript array, type can be flexible or strict(regarding the element types).

6. Tuple ([1,2]): Added by TypeScript: Fixed-length array.

7. Enum (enum{NEW,OLD}): Added by TypeScript: Automatically enumerated global constant identifiers.

8. Any: Any kind of value, no specific type assignment, but not recommended to use this a lot as using this makes no sense of typescript then.

--

--