Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TypeScript · Type Alias

string

A type alias gives a reusable name to a type expression. Unlike a class or runtime value, it is erased during compilation and does not create a distinct type identity.

How it works

A type alias binds a name to an existing type expression. It can represent primitives, unions, tuples, object shapes, and generic compositions, so large codebases can give reusable names to complex types without introducing a distinct runtime or nominal type.

Syntax

type Name<Parameters> = Type;

Key points

  • The type declaration introduces a reusable name for a type expression.
  • Aliases can capture both simple types and composed forms, which makes them useful for shared domain vocabulary.
  • A type alias may declare type parameters, allowing one reusable definition to work with multiple concrete types.
  • Generic parameters are available inside the right-hand side, where they can shape the resulting type.

Common mistakes

  • An alias is not a nominal type: the compiler treats it as the aliased type, so a string alias does not prevent ordinary strings from being passed.
  • Primitive aliases mainly improve readability and documentation; they do not add runtime behavior or stronger identity.
  • Generic aliases require type parameters to be declared and then used in the right-hand type expression.

Example: A documented primitive alias

type UserId = string;

function loadUser(id: UserId): User {
  return { id, name: "Ada" };
}

interface User {
  id: UserId;
  name: string;
}

const user = loadUser("u-42");
console.log(user.name);

The alias documents that user identifiers are strings while allowing the existing string type wherever UserId is used.

When to use it

Name complex types

Replace repeated unions, tuples, or object shapes with one readable name shared across APIs.

Document domain primitives

Document the intended role of a primitive such as an identifier without adding runtime code.

Build generic helpers

Define reusable type-level utilities that transform or combine types through parameters.

Interview questions

QWhat is a type alias?

A type alias gives another name to a type expression. It can name primitives, unions, tuples, object types, and other combinations, but it does not create a separate runtime type.

Follow-up: How would you make an identifier distinct from string? Use a branded or otherwise intersected type pattern rather than a plain alias, because a plain alias remains equivalent to string.

QHow do you declare a generic type alias?

Use the type keyword followed by the alias name, optional type parameters, an equals sign, and the type expression. For example, type Result<T> = T | Error names a generic union.

Follow-up: What must a generic alias do with its type parameter? It should reference the parameter in the aliased expression, such as T in T | Error, so instantiation can substitute a concrete type.

QWhen is a type alias preferable to an interface?

Type aliases are more flexible when the named type is not an object shape: they can describe primitives, unions, tuples, and other types. Interfaces are another way to describe object-oriented contracts, but the page emphasizes the broader forms available to aliases.

Follow-up: Can an interface extend a primitive alias? No; an interface cannot add to a primitive alias such as type S = string.

  • interface
  • union types
  • tuple types
  • generic types

Source: Advanced Types. Checked 2026-10-15.