Skip to content

Generic typing of Option::fromValue results in Option<valueType|null> #63

@arnaud-lb

Description

@arnaud-lb

Option::fromValue uses the same type parameter C for the $value and $noneValue parameters. As a result, the type of C is inferred to a union of the types of $value and $noneValue:

https://phpstan.org/r/af2d3270-93fe-463a-9a29-4dd584012cc3

Typing $noneValue to mixed fixes the problem:

https://phpstan.org/r/c105ea3e-21e2-4dbc-a119-36fd1154ef3e

I believe that this would be ok since $noneValue doesn't contribute to type of Option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions