How To Use the Built-In ThisParameterType Type in TypeScript
You’re really a code mapache if you know TypeScript’s ThisParameterType
type!
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…