简体   繁体   中英

Pagerfanta template causing error in psalm

I am trying to move from phpdoc to psalm and I am getting weird error with its template based returns.

class Message {}

interface FooInterface
{
    /** @return Pagerfanta|Message[] */
    public function getMessages(): Pagerfanta;
}

This is showing TooManyTemplateParams error even though I am setting exactly one and Pagerfanta also has exactly one parameter set in its definition.

Even psalm online validator is showing this error: https://psalm.dev/r/68b22e896f

What am I doing wrong?

The Pagerfanta class (as presented in the linked snippet) does indeed have no type parameters - it has 0 @template tags.

You need to upgrade to a later version of Pagerfanta that has this issue fixed. 2.7.2 seems to have the fix in place.

Sidenote: Pagerfanta|Message[] form is a legacy PHPStorm syntax and I would recommend to avoid it due to ambiguity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM