Skip to content
ThisParameterType

    ↑↓ move · ⏎ open · esc close

    Functions

    ThisParameterType

    Extracts the explicit `this` parameter from a function type.

    What it is

    A conditional extractor for TypeScript’s special fake first parameter. An explicit `this` annotation participates in type checking but is erased from JavaScript and is not part of `Parameters<T>`, so it needs its own utility when a wrapper or binder wants to recover it.

    Examples

    • ThisParameterType<typeof toHex>
      Number
    • ThisParameterType<(this: { id: string }) => void>["id"]
      string
    • ThisParameterType<(value: number) => void>
      unknown

      No explicit `this` parameter means `unknown`, not the global object or the containing class.

    Each resolved type above was printed by TypeScript 6.0.3, not written by hand.

    What it does not do

    • It does not return the first ordinary parameter. `this` has dedicated syntax and never appears in the emitted argument list.
    • It cannot discover a run-time receiver when the function type has no explicit annotation; the safe answer in that case is `unknown`.

    Takeaway

    An explicit `this` parameter is type-only and separate from ordinary parameters; `ThisParameterType` is the extractor made for that separate slot.