Skip to content

Support templated @phpstan-type #3544

@AnrDaemon

Description

@AnrDaemon

I have this block in my code:

<?php

/**
 * API interop.
 *
 * @template T
 * @phpstan-type ResponsePayload array{
 *  data: T,
 *  links: ?array{
 *      self: string,
 *      first: string,
 *      last: string,
 *      next: string,
 *  },
 *  pager: ?array{
 *      total: int,
 *      current: int,
 *      limit: int,
 *  },
 * } API response template
 */
class X {
/** @return ResponsePayload<array> */
function x(): array {
    return ['data' => []];
}

function y() {
    $x = $this->x()['data'];
}
}

I can't complete the data key in the y() function, unless I remove the specifier.

What I'm doing wrong?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions