Skip to content
← Back to rules

typescript/no-useless-default-assignment Correctness

This rule is turned on by default when type-aware linting is enabled.
💭 This rule requires type information.

What it does

Disallow default assignments that can never be used.

Why is this bad?

A default assignment is redundant when the value can never be undefined. This adds runtime logic and noise without changing behavior.

Examples

Examples of incorrect code for this rule:

ts
[1, 2, 3].map((a = 0) => a + 1);

Examples of correct code for this rule:

ts
[1, 2, 3].map((a) => a + 1);

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "options": {
    "typeAware": true
  },
  "rules": {
    "typescript/no-useless-default-assignment": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  options: { typeAware: true },
  rules: {
    "typescript/no-useless-default-assignment": "error",
  },
});
bash
oxlint --type-aware --deny typescript/no-useless-default-assignment

Version

This rule was added in v1.49.0.

References