I'm struggling to get the generic to work for the Laravel 9 factories with psalm.
Doc block:
/**
* @extends Factory<Trip>
*/
class TripFactory extends Factory { ... }
Use case:
TripFactory::new()->create();
Error:
InvalidTemplateParam - app/Domains/Trips/Seeders/TripSeeder.php:23:9 - Extended template param TModel of Illuminate\Database\Eloquent\Collection<int, Illuminate\Database\Eloquent\Model> expects type Illuminate\Database\Eloquent\Model, type int given (see https://psalm.dev/183)
Where am I going wrong?
I was also dealing with the same issue. Which
vimeo/psalm
version are you using currently?There's seems to be a fix for this in newer
vimeo/psalm
releases.I was running:
after upgrading to
4.30.0
( presumably also ^5.x should be fine )the issue is resolved.
I can't pinpoint it exactly but i guess it's due to the fix in v4.25.0 which states:
This definitely seems to deal with this type of issue and I have to stop now because it's a deep rabbit hole ;-)