TypeScript: Type aliases and interfaces

Join the AI Workshop to learn more about AI and how it can be applied to web development. Next cohort February 1st, 2026

The AI-first Web Development BOOTCAMP cohort starts February 24th, 2026. 10 weeks of intensive training and hands-on projects.


We’ve seen types for basic values.

For more complex structures we can use type aliases:

type Dog = {
  name: string
  age: number
}

Then when you create an object, you set this to be its type:

const jack: Dog = {
  name: 'Jack',
  age: 3
}

Note that we can have an optional property using ?: when defining the type, like this:

type Dog ={
  name: string,
  age?: number //optional
}

To do the same thing we can also use interfaces:

interface Dog {
  name: string
  age: number
}

They work in the same way as type aliases:

const jack: Dog = {
  name: 'Jack',
  age: 3
}

Why use one vs another? There are a few differences, but generally you can use one, or another, no big deal.

Type aliases or interfaces are not limited to typing objects, of course:

interface Pair {
  a: number;
  b: number;
}

const multiply = (nums: Pair) => {
  return nums.a * nums.b
}

multiply({ a:1, b: 2 })

If you pass a third parameter, TS will raise an error:

“Object literal may only specify known properties, and c does not exist in type Pair”

Lessons in this unit:

0: Introduction
1: Your first TypeScript program
2: Types
3: Typing functions
4: The editor helps you with type errors
5: Running TypeScript code
6: Valid types
7: ▶︎ Type aliases and interfaces
8: Union types
9: Typing arrays with generics
10: The DX of editing TypeScript
11: There's more...
12: TypeScript declare a type that can be a string or array of strings
13: TypeScript, disable checks for `declared but its value is never read`
14: Object destructuring with types in TypeScript
15: TypeScript Tutorial
16: Zod: Type-Safe Schema Validation for TypeScript
17: How I fixed some trouble importing types in .d.ts files