-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Feature/variadic union type improvemence #184
Conversation
I think I've chosen wrong branch to merge to. @azjezz do you have 2.0 branch? |
As mentioned in the issue, renaming parameters is not considered a BC break ( for me ), we can merge this into 1.7 |
@zour228 can you apply the same change to intersection? I think these two should stay consistent with each other. |
Sure, but maybe next day, it's late time on my watch |
About named parameters and BC: |
@azjezz didn't know that psalm has an issues with intersection types (even with such a simple example) Therefore the following example have type inference issues too: $first = shape(['first' => string()]);
$second = shape(['second' => string()]);
$res = intersection($first, $second);
// inferred type of $res is TypeInterface<array{first: string}>
// but I was expecting TypeInterface<array{first: string, second: string}> So, I am not sure if I know hot to implement function with variadic parameters. |
I found these snippets: https://psalm.dev/r/737e004fcd<?php
/**
* @template Tf
* @template Ts
*
* @param Tf $first
* @param Ts $second
*
* @return Tf&Ts
*/
function intersection(
mixed $first,
mixed $second
): mixed {
throw new RuntimeException();
}
$first = ['f' => 1];
$second = ['s' => 2];
/** @psalm-trace $result1 */
$result1 = intersection($first, $second);
/** @psalm-trace $result2 */
$result2 = intersection($second, $first);
|
Intersection types work only with objects |
Pull Request Test Coverage Report for Build 787060807
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, you can send a separate PR for intersection types later on.
Thank you 🎉
[Type] add support for variadic union types (azjezz#184)
#183
Changelog
Psl\Type\union
now takes variadic third parameterPsl\Type\union
arguments$left_type
and$right_type
were renamed to$first
and$second
This is a breaking change, because if somebody uses PHP8+ and does
union(left_type: $left, right_type: $right)
- this would trigger runtimeError
.Future scope
@no-named-arguments
psalm's annotationI haven't used this in my PR, cause I think it should be discussed and (if accepted) added atomically for all possible functions and methods
Psl\Type\intersection