Dev Helpers
← Back

Describe an explicit this parameter

Describe an explicit this parameter using TypeScript.

Open this example in the interactive library

Source code

type Task = (name: string, attempt?: number) => string;
const task: Task = (name, attempt = 1) => name + " #" + attempt;
console.log(
  function (this: { name: string }) {
    return this.name;
  }.call({ name: "Ada" }),
);

Sample output

Ada