Psalm: Psalter: Erroneously fixing templated params

Created on 7 Dec 2019  路  2Comments  路  Source: vimeo/psalm

Problem

Psalm version: 3.7.2

See my simplified example here: https://psalm.dev/r/8c78332c09

_Note: The psalter warning doesn't show on the website, but I can see the warning when running psalm locally_


Psalm is recommending to use the psalter with --issues=MissingParamType on a library which is 100% typed.

In my library - I have 2 similar classes:
Result<TOkay, TError>
Either<TLeft, TRight>

Under the hood of Result<TOkay, TError> is actually composed of an Either<TLeft, TRight>.

Thus, in my codebase: Result<TOkay, TError> is essentially the same as Either<TOkay, TError>

The psalter notices this and suggests changing either from Either<TLeft, TRight> -> Either<TOkay, TError>.


The psalter is not wrong with its types.

However, I want the generics on both classes as both are public in my library.

The types are generic so they support more use cases than the ones limited to my library src. This allows consumers to type-check against my library.

The real problem is psalm notices I could be more strict given only my library src.

Possible Solutions

  • An annotation to suppress the psalter warning

    • Would be nice on the class as well

  • An annotation to indicate the code is a library

    • I suspect this might be heavy-handed

  • Psalm: Be less eager with it's typing in this case

Background

I have a library: https://github.com/iFixit/php7-optional
This master build is recommending to use the psalter with --alter --issues=MissingParamType --dry-run

bug

Most helpful comment

Thanks! It was just a bug around erroneously fixing templated params that default to mixed.

All 2 comments

Thanks! It was just a bug around erroneously fixing templated params that default to mixed.

Ah, that makes sense! Thanks @muglug for the fast fix

Was this page helpful?
0 / 5 - 0 ratings