# no-useless-default-assignment

Disallow defaults that cannot be selected by the checked input type

A destructuring default can only run when its selected value is `undefined`.
Instead, you SHOULD remove the default when the checked input type excludes `undefined`.

- Category: suspicious
- Level: warning
- Fix: automatic
- Scope: module

## Reported

```ds title="main.ds"
function name(user: { name: string }): string {
    const { name = "anonymous" } = user;
    return name;
}
```

## Accepted

```ds title="main.ds"
function name(user: { name: string }): string {
    const { name } = user;
    return name;
}
```

## Prior art

- [typescript-eslint · no-useless-default-assignment](https://typescript-eslint.io/rules/no-useless-default-assignment)

[language/linter/src/rules/suspicious/no_useless_default_assignment.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/suspicious/no_useless_default_assignment.rs#L8)
