DEV Community

Abhay Nikam
Abhay Nikam

Posted on

Day 3/100 - The basics of types in TypeScript

On the third day of 100daysofcode challenge, learned the basics of types in TypeScript.

What are types?

Types in TypeScript are just a simple way to describe the properties and function of a value.

For example:

const name = "Abhay Nikam"

The variable name is of type string which has different properties and function.

// Example of some properties for type string value
name.charAt();
name.indexOf();

Types are of two categories:

  1. Primitive Types: number, boolean, void, undefined, string, symbol, null.
  2. Object Types: functions, arrays, classes, objects.

NOTE: I haven't yet studied all types in details. Will be learning
that in the next few days.

Why do we care about types?

There is a simple answer to this question. We care about types because types give the required information to the TypeScript compiler to analyze the value and throw an error if something is not as per type defined.

Types also help the other developers in the team to understand what properties and function value might have.

Where to use types?

EVERYWHERE!!

Happy Friday. Happy Coding.

Top comments (0)