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
Implement api for conditional type #1120
Conversation
5eea9c0
to
a5dcf8e
Compare
I've been thinking about this for the past few days and I think that representing the "conditional return type" using I see this feature to be similar to generics, and for generics we had to add TemplateTypeMap getters to ParametersAcceptor, so that GenericParametersAcceptorResolver could read it and decide to act upon it. With conditional types I want to be able to add them without any BC breaks. See the following path forward:
Each of these items can roughly be a separate PR. In the end we should have something working :) I'd welcome if you could do the Easy items one after another. When it's time for the Hard ones, I'm gonna take over the work. We can then discuss who should do the last "Medium" one. Thanks :) |
a5dcf8e
to
86c7d1e
Compare
I've added a few more items :) |
Part of implementation for phpstan/phpstan#3853, together with phpstan/phpdoc-parser#106. This is a prototype implementation. Comments are welcome, and if I'm too ambitious consider just closing this :)
86c7d1e
to
c48d262
Compare
Linking phpstan/phpstan#3853 |
I'm a bit stuck here: given that conditional types can be anywhere in the return type node (e.g. It's easy enough if the top type node is a conditional, but that won't cover all cases. |
Are you sure that conditional type inside a normal type is supported by Psalm? I've never seen an example like that. |
Sure: https://psalm.dev/r/e07dd9374d. Psalm's stubs also contain nested conditionals |
It's possible to solve that - But we'd have to revert #1133 and rethink what to do about these types in places that don't care about them. |
How about:
This will at least allow inspecting the type completely. But I'm not entirely convinced that subclassing Looking forward to hearing your thoughts. :) |
Still a proof of concept, but possibly slightly more useful than phpstan#1120
I've implemented this in #1140 |
Still a proof of concept, but possibly slightly more useful than phpstan#1120
Still a proof of concept, but possibly slightly more useful than phpstan#1120
Still a proof of concept, but possibly slightly more useful than phpstan#1120
Part of implementation for phpstan/phpstan#3853, together with phpstan/phpdoc-parser#106.
This is a prototype implementation. Comments are welcome, and if I'm too ambitious consider just closing this :)