# `ThisType<Type>`

> The `ThisType<Type>` utility type in TypeScript serves as a marker for the contextual type of `this`.

## What is ThisType in TypeScript and how does it work?

The utility type that does not transform a type but marks the contextual type of `this` inside an object literal. Requires the `noImplicitThis` option and is used for describing APIs with methods.

- Topic: Utility Types
- Type: utility type

## Example

Wrong:

```ts
type Options = {
  data: { count: number };
  methods: Record<string, (this: any) => void>;
};
```

Right:

```ts
type Options<D, M> = {
  data: D;
  methods: M & ThisType<D & M>;
};
```

Instead of `any`, `this` inside each method is typed as the data plus the other methods.

## Common mistakes

- Expecting `ThisType<T>` to add properties to the object, when it only types `this` inside it.

## Key points

- `noImplicitThis` is enabled, otherwise `ThisType` has no effect.
- `ThisType<T>` appears in the contextual type of an object literal, e.g. a parameter of an options builder.

## Interview questions

### Does ThisType exist at runtime?

No, it is an empty marker interface. It only changes how the compiler types `this` in an object literal.

### Why does ThisType have no effect in my project?

It needs `noImplicitThis`, which `strict` turns on, and it must be part of the object literal's contextual type.

## Related cards

- [`ThisParameterType<Type>`](https://wonderium.dev/ts/thisparametertype.md)
- [`OmitThisParameter<Type>`](https://wonderium.dev/ts/omitthisparameter.md)
- [this](https://wonderium.dev/js/this.md)
- [Intersection Type](https://wonderium.dev/ts/intersection-type.md)
- [Strictness](https://wonderium.dev/ts/strictness.md)

---

- Level: [TypeScript](https://wonderium.dev/ts.md)
- HTML version: https://wonderium.dev/ts/thistype
- Last updated: 2026-11-25
