-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Type guards in array find #38945
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
Comments
You can fix it by adding a type annotation to make it a type guard: Alternative just add a comfort function:
Also your playground link does not work. |
But your code works fine thanks ! As for the playground link I used the "Export->Report GitHub issue on TypeScript" menu of typescript Playground... |
no, The problem is that typescript can't really return guard-like expressions from a function without explicitly stating that the function is a guard. I've wrote the #37868 issue in an attempt to address that situation; hopefully someone more knowledgable than me can work that into the language. |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 3.9.2
Search Terms:
Expected behavior: No error
Actual behavior: Error
Type 'string | null | undefined' is not assignable to type 'string | undefined'.
Typescript doesn't take into account the type guard in find arrow function.Related Issues:
Code
Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: