typescript
/

TypeScript Type Alias

Last Sync: Today

On this page

10
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

typescript

TypeScript Type Alias

What is a Type Alias?

A type alias allows you to create a custom name for a type, making complex types easier to reuse and manage.

Basic Example

TypeScriptRead-only
1
type Name = string;
let userName: Name = 'John';

Object Type Alias

TypeScriptRead-only
1
type User = {
  name: string;
  age: number;
};

Union Type Alias

TypeScriptRead-only
1
type ID = string | number;

Function Type Alias

TypeScriptRead-only
1
type AddFn = (a: number, b: number) => number;

Intersection Types

TypeScriptRead-only
1
type A = { name: string };
type B = { age: number };

type Person = A & B;

Type Alias vs Interface

FeatureType AliasInterface
Union TypesYesNo
ExtendableYesYes
Object StructureYesYes

Best Practices

  • Use type aliases for unions and primitives
  • Keep types simple and reusable
  • Use meaningful names
  • Avoid overly complex types

Common Mistakes

  • Overcomplicating type definitions
  • Confusing with interfaces
  • Not reusing type aliases
  • Using any unnecessarily

Conclusion

Type aliases improve readability and reusability in TypeScript, especially for complex and union types.

Try it yourself

type ID = string | number;
let id: ID = 1;

Test Your Knowledge

Q1
of 3

Alias keyword?

A
interface
B
type
C
class
D
var
Q2
of 3

Union supported?

A
No
B
Yes
C
Only interface
D
Only class
Q3
of 3

Intersection symbol?

A
|
B
&
C
:
D
=

Frequently Asked Questions

What is type alias?

A custom name for a type.

Can alias define unions?

Yes, it supports union types.

Alias vs interface?

Alias is more flexible for unions.

Previous

ts interfaces

Next

ts union intersection

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.