#2516·larastan

commit 41db11d7d6 introduced regressions in map() / mapWithKeys()

Author: d-javuCreated Jul 16, 2026Updated Jul 16, 2026
Labelsbug
  • Larastan Version: 3.9.4+ (commit: 41db11d7d6)
  • Laravel Version: does not matter

Description

The change in #2466 introduced regressions as documented in the comments of that PR.

Laravel code where the issue was found

From the PR, thanks to @calebdw

php
/** @return Collection<int, array{id: int, press_id: int, name: string}> */
public function stations(): Collection
{
    return ProductionStation::query()
        ->get()
        ->map(fn ($station) => [
            'id'       => $station->id,
            'press_id' => $station->press->id,
            'name'     => $station->name,
        ]);
}

The new warning:

Method <class>::stations()
should return Illuminate\\Support\\Collection<int, array{id: int, press_id: int, name: string}>
  but returns Illuminate\\Support\\Collection<int, array{id: mixed, press_id: mixed, name: mixed}>

I have a more complicated case, but the crux of the matter is that the property types in the map()/mapWithKeys() call resolve to mixed where it previously resolved to the correct type.

Can this commit be reverted?