Methods of Strings keep right return type#335
Conversation
|
Thanks for the suggestion. You're technically correct that template types would preserve However, I'm a bit hesitant to add this complexity for what seems like a fairly niche use case. In practice, very few projects use The added template syntax would make the API more complex without much real-world benefit for most users. What do you think - do you have a concrete use case where this is causing significant issues? |
|
I didn't find edge case. At this moment I use wrapper only for lower function. But I can be more specific, phpstan support But phpstan does not support uppercase-string..., for other methods I would keep the template. Example: final class Strings
{
/**
* @return ($s is non-empty-string ? non-empty-lowercase-string : lowercase-string)
*/
public static function lower(string $s): string
{
return NetteStrings::lower($s);
}
}I can send a PR only for |
|
Isn't it better to create stub files than wrappers? |
|
Thanks for the PR, but I'm closing it. The problem is that the generic template |
Hello,
The
Stringsclass does not keep incoming type for few method and this implicated, then I have to use helpers in my projects.For example, in this case variables
$aand$bhave type stringThe methods does not change type from non-empty-string to string.
Now, variable
$bkeeps typenon-empty-string.