Type in TypeScript

In TypeScript, “type” helps make new types. TypeScript is like an upgraded JavaScript that adds fixed types. This lets developers set and stick to types for things like variables and functions.

“Type” in TypeScript is mostly used in two ways: making types for objects and making types that can be one of multiple things (union types).

  1. Creating Object Types:You can use type to define an object type. For example:

In this example, the Person type is created with properties name (a string) and age (a number). Then, a variable Ayaka is declared with the Person type.

type Person = {
  name: string;
  age: number;
  // other properties can be added
};

const Ayaka: Person = {
  name: "ayaka",
  age: 17;
};
  1. Creating Union Types:

“Type” in TypeScript is also used to create union types, letting a variable have more than one possible type. For instance:

type Result = "Love" | "Happiness" | number;

const feeling1: Result = "Love";
const feeling2: Result = "Happiness";
const feeling3: Result = 42;

Here, “Result” type is a mix of string and number. Variables feeling1,feeling2 and feeling3 can get values of either type.

“Type” in TypeScript is not just for basic types. It’s also used for advanced features like making mapped types, conditional types, and more. This helps name complex type annotations, making code easier to read and maintain.


In TypeScript, “type” is a versatile keyword for different type tasks. It creates aliases for data types, makes union types, and defines complex structures. Let’s look at some common uses:

  1. Function Types:

You can use type to define function types:

type MathOperation = (x: number, y: number) => number;
const add: MathOperation = (a, b) => a + b;
const multiply: MathOperation = (a, b) => a * b;

The MathOperation type represents a function that takes two number parameters and returns a number.


In TypeScript, the “type” keyword is a versatile tool for crafting and handling types. It enhances expressiveness, enabling improved static analysis and tooling support.