> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# prefer-return-this-type

[Added in v0.1.4](https://github.com/web-infra-dev/rslint/releases/tag/v0.1.4)
## Configuration

| Preset                         | Configured Value |
| ------------------------------ | ---------------- |
| ✅ ts.configs.strictTypeChecked | `"error"`        |


```ts title=rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/prefer-return-this-type': 'error',
    },
  },
]);
```

## Rule Details

Enforce that `this` is used when only `this` type is returned. If a class method's return type is the class itself and the method only returns `this`, then it is better to use `this` as the return type. Using the `this` return type enables proper type narrowing in subclasses, since `this` refers to the current class type rather than a fixed class name.

Examples of **incorrect** code for this rule:

```typescript
class Foo {
  doStuff(): Foo {
    return this;
  }
  chain(): Foo {
    return this;
  }
}
```

Examples of **correct** code for this rule:

```typescript
class Foo {
  doStuff(): this {
    return this;
  }
  chain(): this {
    return this;
  }
}
```

## Original Documentation

- [typescript-eslint: prefer-return-this-type](https://typescript-eslint.io/rules/prefer-return-this-type)
- [Source code](https://github.com/typescript-eslint/typescript-eslint/blob/v8.29.0/packages/eslint-plugin/src/rules/prefer-return-this-type.ts)
