---
title: "lint/dead-code/no-useless-cast"
pagination: false
---

{/* Generated by scripts/gen-rule-docs.py. Edit mapping.toml, not this file. */}

<RuleId id="lint/dead-code/no-useless-cast" />

In the [`dead-code`](/docs/rules/sets/dead-code) set. Safe fix. Upstream gates: `strictRules.uselessCast`.

## What it does

Remove casts to the type the value already has, including (string) inside concatenation.

## Configuration

```toml title="pun.toml"
[lint.rules]
"dead-code/no-useless-cast" = "error"
```

To skip it in some files or lines, add an [override](/docs/configuration/pun-toml#lint) or an [ignore comment](/docs/configuration/ignore-comments).

## Replaces

- [`RecastingRemoval`](https://getrector.com/rule-detail/recasting-removal-rector) (rector)
- [`UselessCastRule`](https://github.com/phpstan/phpstan-strict-rules#readme) (phpstan-classes)
- [`RedundantCast`](https://mago.carthage.software/1.61.0/en/tools/analyzer/overview/) (mago-analyzer)
- [`cast.useless`](https://phpstan.org/error-identifiers/cast.useless) (phpstan-strict-rules)

[More lint/dead-code rules](/docs/rules/lint/dead-code) · [Edit this page](https://github.com/shipfastlabs/pun/edit/main/crates/pun-config/rules/mapping.toml)
