Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท Utility Types

TypeScript OmitThisParameter<T> utility type

Reference for TypeScript OmitThisParameter<T>: strip the this parameter from a function type, the type that bind() produces, and how to use it in wrappers.

OmitThisParameter<T> returns a function type identical to T except that the explicit this parameter is gone. If T has no this parameter, you simply get T back.

The classic use is describing a bound function: after fn.bind(obj), the this requirement is satisfied, so the result should no longer demand one. The built-in typing of bind relies on exactly this idea, and you can reuse it in your own helpers.

TypeScript
function area(this: { w: number; h: number }) {
  return this.w * this.h;
}

type Bound = OmitThisParameter<typeof area>;
// () => number

Try it

TypeScript Binding removes this

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript Your own bind helper

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

TypeScript
type OmitThisParameter<T> =
  unknown extends ThisParameterType<T>
    ? T
    : T extends (...args: infer A) => infer R
      ? (...args: A) => R
      : T;
Name Description
T A function type, possibly with a this parameter.

Result: a function type with the same parameters and return type but no this. If T declares no this, the result is T itself.

Edge cases: for a non-function T, the result is T. For overloaded functions only the last signature survives when a this parameter is removed.

Usage notes

  • Typed bind. With strictBindCallApply (part of strict), bind on a function with a this parameter returns a function without it. The effect is the same as OmitThisParameter.
  • Only the type changes. It does not bind anything; you still call bind, arrow-wrap or similar to supply the real this.
  • When this is unknown: if the function never declared this, the first branch returns T unchanged and nothing is rebuilt, so overloads and generics are kept.
  • Parameters survive: names, optional markers and rest elements carry over via infer A.
  • Reading, not removing: use ThisParameterType<T> to get the type of this.
  • Available since TypeScript 3.3.