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
Conditional return type for container #7141
Comments
But I think we might make this version work: https://phpstan.org/r/233f9fb4-884a-4d35-8807-66aa281c067b WDYT @rvanvelzen ? |
Your version looks better, but my works on psalm 🤔 |
To me it seems better to keep templated types when normalizing, which should make the original case work. I.e. That being said, inferring from conditional types would be nice too. |
I worry it’s not possible, string type contains all class-strings, even with generics. Changing that could break a lot of assumptions. But feel free to try it 😊 |
|
I think that we can make https://phpstan.org/r/233f9fb4-884a-4d35-8807-66aa281c067b work - |
I got here from #7513. This issue is very inconvenient for the general use case of PHP container libraries, but I agree that the phpstan/phpstan-src#1459 and phpstan/phpstan-src#1262 approaches are ugly hacks that make supertypes inconsistent. #7141 (comment) looks like a good way to do it. However, we also note that |
Implemented by phpstan/phpstan-src#1465 |
the initial example has less errors, but the return type seems still wrong? |
Only the one without |
Awesome! Great job! |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
I'd like to create stub for Container with conditional return type, however looks like is not possible to do that because bug or missing feature.
Code snippet that reproduces the problem
https://phpstan.org/r/b559c7cd-8851-4953-a7ec-0d8b5b3cc714
Expected output
No error and correct type
The text was updated successfully, but these errors were encountered: