Closed IanDelMar closed 4 months ago
What does T[TOffset]
mean?
Index types like in https://www.typescriptlang.org/docs/handbook/2/indexed-access-types.html
Was implemented for / via https://github.com/phpstan/phpstan/issues/7094 but might have never been fully documented. I didn't use them in php yet tbh though :)
All right. I wouldn't use arrays for non-list data. Only objects.
Thank you both.
Tests for
array<string, string>
were still failing. For now, I don't know how to removenull
from the return type ofWP_REST_Request::get_parameter()
when used with an array shape. Either the array shape works, or the general array types work. The current version at least narrows down types without producing incorrect types, such asbool|int|string
, whenWP_REST_Request::get_parameter()
is called with a non-existent parameter. Maybe @lipemat has an idea.According to the doc blocks in WP core,
$key
is always a string. So, it might be reasonable to change'@phpstan-template' => 'T of array'
to'@phpstan-template' => 'T of array<string, mixed>'
.