Replies: 1 comment 2 replies
-
This currently isn't possible. TypeScript can afford that because in JS But this is close to a feature I'd like to do one day: https://twitter.com/OndrejMirtes/status/1606017239882338304 Meanwhile you can implement this yourself using a TypeNodeResolverExtension: https://phpstan.org/writing-php-code/phpdoc-types So it could look like The Except the $variant = ParametersAcceptorSelector::selectSingle($this->type->getCallableParametersAcceptors(new OutOfClassScope()));
return $variant->getReturnType(); Feel free to ask more questions if you decide to implement it! |
Beta Was this translation helpful? Give feedback.
-
I'm using the action pattern with plain PHP Classes and hoping to create an
invoke($className)
helper to call the actions. For example here's a PHPStan link, https://phpstan.org/r/87a1c773-792a-492a-b474-00a2155951f4. The@return
of my helper is pseudo code because I'm not sure it's possible to type something to a method return?This is possible in Typescript via "indexed types" where you can specify the return is based on a method of the generic. Here the
T['handle']
works its magic. https://www.typescriptlang.org/play?#code/C4TwDgpgBAwg9gOwM7AE4FcDGw6oDwAqAfFALxQIQDuUAFAHSMCGqA5kgFxRMIgDaAXQCUZEgQDcAKACWCYBFQAzJpmgBBbNMRMARgBtoAb0lRTUABY8AJgdpCuPEJIC+kyZj1MkSKAFkQAOKoEEzAGsBaCFDGppYINhB2XCiosqzRJmbBwOioUQDkinBw+VKmrq6SiugImohQsgBucADWEIRQEAAe8vE+4ZG6BkS0MJ7eAHJMALYQXPDIaFg4+MT2UAR8+XEJ+QIZZlDZuVGUNGNeSFOzdvQ7tkJSlZiIKFApaQBqTHro0ORNVqJfxBEJhOoIR5AAIs something like this possible in PHPStan?
Beta Was this translation helpful? Give feedback.
All reactions