RecipesChapter 2: Basic Types

Defining this Parameter Types

Recipe 2.6 from The TypeScript Cookbook

function handleToggle(this: HTMLElement) {
  this.classList.toggle("clicked");
}

type ToggleFn = typeof handleToggle;
// (this: HTMLElement) => void

type WithoutThis = OmitThisParameter<ToggleFn>
// () = > void

type ToggleFnThis = ThisParameterType<ToggleFn>
// HTMLElement
Open in TypeScript Playground →