Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chainable types do not work #12

Open
bendavies opened this issue Jun 7, 2020 · 0 comments
Open

Chainable types do not work #12

bendavies opened this issue Jun 7, 2020 · 0 comments

Comments

@bendavies
Copy link

bendavies commented Jun 7, 2020

the following code:

<?php

declare(strict_types=1);

use Assert\Assert;

class Result
{
    private ?float $percent;

    private function __construct()
    {
    }

    /** @param array<string, mixed> $payload */
    public static function fromQueryResults(array $payload): self
    {
        Assert::that($payload['percent'])
            ->nullOr()
            ->string()
            ->numeric();

        $floatOrNull = static fn (?string $value): ?float => null === $value ? null : (float) $value;

        $instance = new self();
        $instance->percent = $floatOrNull($payload['percent']);

        return $instance;
    }
}

Produces the error:
Parameter #1 $value of closure expects string|null, float|int|string|null given.

The type of $payload['percent'] should be infered to string|null, not float|int|string|null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant