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

Validation<T> is impossible to infer for failures #36

Open
ilario-pierbattista opened this issue Dec 2, 2021 · 2 comments · May be fixed by #37
Open

Validation<T> is impossible to infer for failures #36

ilario-pierbattista opened this issue Dec 2, 2021 · 2 comments · May be fixed by #37

Comments

@ilario-pierbattista
Copy link
Member

ilario-pierbattista commented Dec 2, 2021

    /**
     * @psalm-template T
     * @psalm-param mixed $value
     * @psalm-param Context $context
     * @psalm-param string|null $message
     * @psalm-return ValidationFailures<T>
     *
     * @param mixed $value
     */
    public static function failure($value, Context $context, ?string $message = null): self
    {
        return self::failures(
            [new VError($value, $context, $message)]
        );
    }

This constructor will never infer correctly Validation<T>.

@Jean85
Copy link
Member

Jean85 commented Dec 2, 2021

Wouldn't it be technically a ValidationFailure<never>? As a bottom type it should match with everything... Or not?

@ilario-pierbattista
Copy link
Member Author

Something like that @Jean85.

I think I've introduced a design error attempting to carrying on information about the decoder target type also in case of error.

In io-ts, the decode function gives an Either<Errors, T>.
ValidationFailure<T> is not isomorphic with Left<Errors>.

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

Successfully merging a pull request may close this issue.

2 participants