0Pricing
TypeScript Academy · Lesson

Readonly, Exclude, Extract, NonNullable

Apply more utility types for immutability and filtering.

Readonly, Exclude, Extract, NonNullable is a free TypeScript Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Welcome

TypeScript's standard library includes several utility types beyond Partial, Required, Pick, and Omit. This lesson covers Readonly, Exclude, Extract, and NonNullable.

Readonly<T>

Makes all properties of T readonly. Prevents any property reassignment after creation.
interface Config { host: string; port: number; }
const cfg: Readonly<Config> = { host: 'localhost', port: 3000 };
// cfg.host = 'remote'; // Error!

Exclude<T, U>

Removes from union T all members that are assignable to U.
type Status = 'pending' | 'active' | 'banned' | 'deleted';
type ActiveStatus = Exclude<Status, 'banned' | 'deleted'>;
// 'pending' | 'active'

Extract<T, U>

Keeps only union members of T that are assignable to U. The opposite of Exclude.
type StringOrNumber = string | number | boolean;
type JustStrNum = Extract<StringOrNumber, string | number>;
// string | number

NonNullable<T>

Removes null and undefined from T.
type MaybeString = string | null | undefined;
type DefinitelyString = NonNullable<MaybeString>; // string

ReturnType<T>

Extracts the return type of a function type T.
function fetchUser() { return { id: 1, name: 'Alice' }; }
type User = ReturnType<typeof fetchUser>; // { id: number; name: string }

Parameters<T>

Extracts the parameter types of a function as a tuple.
function add(a: number, b: number): number { return a + b; }
type AddParams = Parameters<typeof add>; // [number, number]

InstanceType<T>

Gets the instance type produced by a constructor function type.
class HttpClient { get(url: string) { return fetch(url); } }
type Client = InstanceType<typeof HttpClient>; // HttpClient

Awaited<T>

Unwraps nested Promise types.
type A = Awaited<Promise<string>>;          // string
type B = Awaited<Promise<Promise<number>>>;  // number

Using Multiple Utilities Together

Chain utility types for complex transformations.
type SafeInput<T> = Readonly<Partial<NonNullable<T>>>;

Utility Types Are Just Type Aliases

Every built-in utility type is implemented using mapped types, conditional types, and infer. You can create your own.

Quick Check

What does `Exclude<'a' | 'b' | 'c', 'b'>` produce?

Recap

Readonly prevents mutation. Exclude removes union members. Extract keeps matching members. NonNullable removes nullables. ReturnType, Parameters, and InstanceType extract function and class type information.

Frequently asked questions

Is the “Readonly, Exclude, Extract, NonNullable” lesson free?

Yes — the full text of “Readonly, Exclude, Extract, NonNullable” is free to read here on the web, and the TypeScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “Readonly, Exclude, Extract, NonNullable”?

Apply more utility types for immutability and filtering. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start TypeScript Academy?

No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Readonly, Exclude, Extract, NonNullable” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this TypeScript Academy lesson?

Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Partial and Required: Toggling Optionality
  2. Pick and Omit: Selecting Properties
  3. Record: Mapping Keys to Value Types
  4. Readonly, Exclude, Extract, NonNullable
← Back to TypeScript Academy