Backbencher.dev

Type Aliases or Custom Type in TypeScript

Last updated on 16 Jan, 2023

If we have a union type like below:

let a: number | string;
let b: number | string;

It is difficult to repeat number | string every time. Type aliases makes this easy.

type numstr = number | string;

After declaring our custom type, we can use it as below:

let a: numstr;
let b: numstr;
--- ○ ---
Joby Joseph
Web Architect