Skip to main content

no-useless-default-assignment

Disallow default values that will never be used.

🔧

Some problems reported by this rule are automatically fixable by the --fix ESLint command line option.

💭

This rule requires type information to run, which comes with performance tradeoffs.

Default parameters and default values are only used if the parameter or property is undefined. That can happen when a value is missing, or when one is provided and set to undefined. If a non-undefined value is guaranteed to be provided, then there is no need to define a default.

eslint.config.mjs
export default tseslint.config({
rules: {
"@typescript-eslint/no-useless-default-assignment": "error"
}
});

Try this rule in the playground ↗

Examples

function Bar({ foo = '' }: { foo: string }) {
return foo;
}

const { foo = '' } = { foo: 'bar' };

const [foo = ''] = ['bar'];

[1, 2, 3].map((a = 42) => a + 1);
Open in Playground

Options

This rule is not configurable.

When Not To Use It

If you use default values defensively against runtime values that bypass type checking, or for documentation purposes, you may want to disable this rule.


Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.

See Troubleshooting > Linting with Type Information > Performance if you experience performance degradations after enabling type checked rules.

Resources