Laravel Builder mixin and generics

Recently updated my Laravel app and was disappointed to see PHPStorm still isn't quite “there” with regards to code completion despite Laravel improving their documentation blocks. Wondering if I'm missing something in my setup?

My model has a mixin in its docblock:

/**
 * @mixin Builder<MyModel>
 */
 class MyModel extends Model {...}

And Laravel's Builder class has this:

/**
 * @template TModel of \Illuminate\Database\Eloquent\Model
 */
class Builder implements BuilderContract
{
    /**
     * @return ($id is (Arrayable<array-key, mixed>|array<mixed>) ? Collection<int, TModel> : TModel)
     */
    public function findOrFail($id){...}
}

But still when I call $model = MyModel::findOrFail(23); PHPStorm thinks $model is of type Collection|Model|null and not MyModel as expected.

I know about the laravel-ide-helper package, but given all this info in the source files, and support for all this added per issues WI-64022, WI-69638, and WI-66465 I expected it to work without any extra help.

0

请先登录再写评论。