Skip to content
ThisType

    ↑↓ move · ⏎ open · esc close

    Functions

    ThisType

    Provides a contextual `this` type inside an object literal.

    What it is

    A marker interface with no members and compiler-defined meaning. Intersect it into the contextual type of an object’s methods and those method bodies see `this` as the supplied data-and-method shape. The marker itself contributes no property to the resulting value.

    Examples

    • (typeof point)["x"]
      number
    • ReturnType<typeof point.move>
      number
    • Parameters<typeof point.move>
      [dx: number, dy: number]

      The contextual receiver never becomes an ordinary parameter.

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

    What it does not do

    • It does not transform or return a useful standalone type. Its effect appears only while an object literal is contextually checked.
    • It requires `noImplicitThis` (included by `strict`) for the contextual receiver checking to matter.

    Takeaway

    `ThisType<T>` is an instruction to contextual checking, not a normal type transform; its proof is what method bodies may do with `this`.