function-types
ThisParameterType<T>
Extracts the explicit `this` parameter type from a function T, or `unknown` if none is declared. Useful for reflecting on method-style callbacks that require a specific caller.
type ThisParameterType<T> = T extends (this: infer U, ...args: never) => any ? U : unknown Usage patterns
| Pattern | Purpose |
|---|---|
| ThisParameterType<typeof fn> | Read a function's this parameter |
| OmitThisParameter<T> | Companion that strips the this parameter |
| function fn(this: X, ...) | The declaration form that supplies a this parameter |
| fn.bind(x) | Runtime companion for binding this |
Examples
function toHex(this: number) { return this.toString(16); }
type T = ThisParameterType<typeof toHex>; Result: number
function plain(x: number) { return x; }
type T = ThisParameterType<typeof plain>; Result: unknown — no this parameter is declared
type M = ThisParameterType<Array<number>['map']>; Reflects the this-binding of a built-in method
type X = ThisParameterType<{ f(this: Date): void }['f']>; Result: Date
Gotcha
Only reads the `this: T` pseudo-parameter — arrow functions cannot declare one, so ThisParameterType always returns unknown for them. Enable `noImplicitThis` to make this parameter meaningful.
Related utility types
OmitThisParameter<T>
Returns a function type identical to T but without its explicit `this` parameter. Commonly paired with `Function.prototype.bind` to model the bound function's signature.
Parameters<T>
Extracts the parameters of a function type T as a tuple. Enables reusing a function's argument list for wrappers, currying, or higher-order utilities.
ReturnType<T>
Infers the return type of a function type T using `infer R`. Widely used to derive types from existing functions without redeclaring them.
ThisType<T>
A marker interface with no members that, when used in a contextual type, sets the `this` type inside method-like properties of an object literal. Requires `noImplicitThis` to be genuinely useful and is a compile-time only hint.
ConstructorParameters<T>
Extracts the parameter tuple of a class constructor T. Mirrors Parameters but operates on `new (...)` signatures instead of call signatures.
← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never