-
Notifications
You must be signed in to change notification settings - Fork 653
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
Invalid class-string<T> where T as A|B #8582
Comments
I found these snippets: https://psalm.dev/r/41dd38b32b<?php
class A {}
class B {}
/**
* @template T as A|B
*
* @param class-string<T> $_class
*/
function test(string $_class): void {}
|
IIRC, Psalm doesn't support |
Maybe this has changed since your comment, but currently it does work. Also, here's a reproduction case that might be able to prove the usefulness of this feature: Psalm playground link / PHPStan playground link Edit: changed the links |
I found these snippets: https://psalm.dev/r/369cccaf3b<?php
class A {}
class B {}
/**
* @param class-string<A|B> $_class
*/
function test(string $_class): void {}
https://psalm.dev/r/f9eb38c536<?php
final class Add {}
final class Remove {}
final class Modify {}
class ChangeUtil
{
/**
* @template T of Add | Remove | Modify
* @param iterable<mixed, T> $changes
* @param class-string<T> $class
* @return list<T>
*/
public static function changeByType(iterable $changes, string $class): array
{
$filtered = [];
foreach ($changes as $change) {
if (!$change instanceof $class) {
continue;
}
$filtered[] = $change;
}
return $filtered;
}
}
|
https://psalm.dev/r/41dd38b32b
The text was updated successfully, but these errors were encountered: