-
Notifications
You must be signed in to change notification settings - Fork 44
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
Collection not typed when using EntityRepository::matching #63
Comments
I found these snippets: https://psalm.dev/r/678bf40ce6<?php
use Doctrine\ORM\EntityRepository;
class Entity {}
/**
* @extends EntityRepository<Entity>
*/
class MyRepository extends EntityRepository {
/**
* @return Collection<int, Entity>
*/
function foo(): Collection {
return $this->matching(Criteria::create());
}
}
|
It's not just you. It can be reproduced with the following scenario (after adding necessary @EntityRepository::matching
Scenario: matching is typed
Given I have the following code
"""
/** @return Collection<int, I> */
function f(): Collection {
return repo(I::class)->matching(Criteria::create());
}
"""
When I run Psalm
Then I see no errors
The plugin supports fairly wide range of doctrine versions, including those that did not have Psalm types.
PRs are more than welcome!
You can also submit a PR against doctrine repo. It can even be backported to older branches (but of course it will only be available with new releases). |
TL;DR:
EntityRepository<T>::matching
has return typeCollection
, should beCollection<int, T>
How to reproduce
Code: https://psalm.dev/r/678bf40ce6
Error:
The type 'Doctrine\Common\Collections\Collection' is more general than the declared return type 'Doctrine\Common\Collections\Collection<int, Entity>' for MyRepository::foo
Versions of my packages:
Is it reproducible or is it just me?
The case for adding
matching
to the stubI started digging a bit and found that:
BUT:
Therefore I'd like to add
matching
to theEntityRepository
-stub. I'm happy to provide a PR, just let me know.Thank you for taking the time and have a nice day!
The text was updated successfully, but these errors were encountered: