How To Use the Built-In ThisParameterType Type in TypeScript

You’re really a code mapache if you know TypeScript’s ThisParameterType type!

Dr. Derek Austin 🥳
Totally TypeScript
Published in
3 min readJan 3, 2024

--

I’ll happily track down that this keyword for you in this mess of lights! Photo by Rebecca Campbell on Unsplash

When I’m exploring the vast terrains of TypeScript á la Dune the remake, doing the research for this series on TypeScript’s built-in types for Totally TypeScript, it’s not uncommon for me to stumble across advanced features tucked away in the language’s intricate corners. The spice must flow!

Among these “WTF” gems is the ThisParameterType. Unlike our nocturnal friend, the mapache 🦝, which loves to be in the spotlight, ThisParameterType remains somewhat in the shadows, often overlooked. Yet, understanding it might simplify some tricky type scenarios.

What Is ThisParameterType in TypeScript?

ThisParameterType is a built-in utility type that “extracts the type of the this parameter for a function,” according to the TS Docs.

This comes in handy especially when the this parameter is defined implicitly, but really it’s great any…

--

--

Dr. Derek Austin 🥳
Totally TypeScript

I write about real-world programming career advice, MongoDB vs. PostgreSQL, Git, React, JavaScript, VS Code, TypeScript, and Next.js. Doctor of Physical Therapy