Menu

1 / 2

`Awaited<T>`, `ReturnType<T>`, `Parameters<T>`: When You're Reaching for the Wrong One

DEV Community·Gabriel Anhaia·6 months ago
#ClVkvS1Y
#trap#typescript#javascript#programming#type
Reading 0:00
15s threshold

Book: The TypeScript Type System — From Generics to DSL-Level Types

Also by me: The TypeScript Library — the 5-book collection

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

A team I talked to last month shipped a typed API client. The

handler reads ReturnType<typeof fetchUser> and binds that to

its response shape. The endpoint compiles, the test for the

happy path passes, the staging deploy goes out. Two days later a

UI engineer opens a ticket: every field on user.profile is

undefined . The function was async. The aliased shape was a

Promise<User> that nobody noticed. The renderer was reading

.profile off something the alias claimed was a User .

Every TypeScript codebase that has been alive for two years has

this bug somewhere. The four utility types from the handbook

page

that get reached for the most: Awaited<T> , ReturnType<T> ,

Parameters<T> , and ConstructorParameters<T> .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.