Skip to content

no-useless-undefined: Flag return undefined for explicit undefined return types#2876

Merged
sindresorhus merged 1 commit into
mainfrom
useless-undefined
Feb 13, 2026
Merged

no-useless-undefined: Flag return undefined for explicit undefined return types#2876
sindresorhus merged 1 commit into
mainfrom
useless-undefined

Conversation

@sindresorhus
Copy link
Copy Markdown
Owner

Fixes #2747

@sindresorhus sindresorhus requested a review from fisker February 11, 2026 06:19
&& node.parent.argument === node
) {
const functionNode = getFunction(sourceCode.getScope(node));
if (functionNode?.returnType && !isUndefinedReturnType(functionNode)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check union types too.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand. Unions are already handled. isUndefinedReturnType() only matches exact : undefined, so : string | undefined skips autofix.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand either.

Unions are already handled.

You mean this is handled?

const foo = (): string | undefined => {
	if (foo) {
	  return undefined;
	}
	return 'string'
}

I didn't see related logic.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. sorry, misunderstood.

@sindresorhus sindresorhus merged commit 41fc9c2 into main Feb 13, 2026
35 checks passed
@sindresorhus sindresorhus deleted the useless-undefined branch February 13, 2026 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no-useless-undefined: should work when a function has a return type specified

2 participants