> 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-reduce-type-parameter

[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-reduce-type-parameter': 'error',
    },
  },
]);
```

## Rule Details

Enforce using type parameters for `Array#reduce` instead of type assertions on the initial value. When calling `Array#reduce`, it is common to use a type assertion (`as`) on the initial value to specify the result type. However, `Array#reduce` accepts a type parameter that achieves the same result in a cleaner way without requiring a type assertion.

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

```typescript
[1, 2, 3].reduce(
  (acc, val) => ({ ...acc, [val]: true }),
  {} as Record<number, boolean>,
);
['a', 'b'].reduce((acc, val) => [...acc, val], [] as string[]);
```

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

```typescript
[1, 2, 3].reduce<Record<number, boolean>>(
  (acc, val) => ({ ...acc, [val]: true }),
  {},
);
['a', 'b'].reduce<string[]>((acc, val) => [...acc, val], []);
```

## Original Documentation

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