Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.prototype.find does not narrow return type #61238

Closed
EvgenyMuryshkin opened this issue Feb 21, 2025 · 2 comments
Closed

Array.prototype.find does not narrow return type #61238

EvgenyMuryshkin opened this issue Feb 21, 2025 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@EvgenyMuryshkin
Copy link

πŸ”Ž Search Terms

Array.prototype.find

Something similar might be here
#19456

πŸ•— Version & Regression Information

Currently migrating codebase strictNullChecks on 5.7.3. Potentially an old issue.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABBOBDANgUwM4UwCgDpiYpMBbbALkX2ygCcYwBzRAH0TBHXQ8XAATTMGaZBASgDaAXQk16TVvyEixgxAG8AUIj2IGmKCAZJSFbIVFhB+GIgC8APkT2AhA4dcefAGS-XRA8vVWtxRH9Aj0QAIhiJAG5tAF8gA

πŸ’» Code

function coalesce(...items: (string | null | undefined)[]): string | undefined {
    return items.find(i => i !== null && i !== undefined && i != "");
}

πŸ™ Actual behavior

Type 'string | null | undefined' is not assignable to type 'string | undefined'.
  Type 'null' is not assignable to type 'string | undefined'.(2322)

πŸ™‚ Expected behavior

null values are filtered out, so return type should exclude null

Additional information about the issue

No response

@MartinJohns
Copy link
Contributor

https://github.com/Microsoft/typescript/issues?q=is%3Aissue%20state%3Aclosed%20array%20find%20in%3Atitle

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 24, 2025
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants