---
title: "TS utility types"
date: "2026-02"
category: "TS"
tags: ["TS"]
description: "If you want the type a method returns, there's a quick way to get it. typeof A means: get the type of the value A that follows it..."
source: "https://enriquemark.com/en/posts/TS%E7%B1%BB%E5%9E%8B%E5%B7%A5%E5%85%B7%E5%87%BD%E6%95%B0"
---

If you want the type a method returns, there's a quick way to get it.

```ts
// means: the type of prisma = the type of whatever getPrisma() returns
prisma: ReturnType<typeof getPrisma>
```

`typeof A` means: get the type of the value A that follows it. The ReturnType in front is one of the big pile of type inference tools TypeScript has built in. Here it means the type of the result value of the `getPrisma` method.

```ts
ReturnType<T>    // outputs the return type of the given object T
Parameters<T>    // outputs the parameter types of the given object T (a tuple)
Awaited<T>       // outputs the return type of a Promise object
Partial<T>       // makes every property of object T optional, so they all get ?:
Required<T>      // makes every property of object T required
Pick<T, K>       // picks part of object T's properties, K
Omit<T, K>       // excludes part of object T's properties, K
```

You can treat this whole pile as a kind of built-in type function: you put in a type, you get back a processed type. If the T inside is itself a method rather than an object, you need `typeof T` to get the object of that method's value, then feed that into the type function as input. Type in, type out.

---

**Translation note.** I wrote this in Chinese. This English version is an LLM translation, so the wording is not mine even though the thinking is. Original: [TS类型工具函数](</zh-hant/posts/TS类型工具函数>).
