Builder and hassers or generics #10188
-
Hi, I'm trying to achieve type narrowing of the output from a builder.
I know that My idea was to solve this using generics. In my case I would not call |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi,
But if the builder works alright from the outside type-wise I'd just use it like this while ignoring or avoiding the error in |
Beta Was this translation helpful? Give feedback.
Hi,
@return
above the constructor does not achieve anything.T
at all in the method body soT
can really be different thanEntity
.But if the builder works alright from the outside type-wise I'd just use it like this while ignoring or avoiding the error in
create()
. PHPStan itself employs a similar pattern here https://github.com/phpstan/phpstan-src/blob/1.11.x/src/Rules/RuleErrorBuilder.php and it works around this problem with/** @var class-string<T> $className */
in thebuild()
method.