如何表示一个非空数组?

How to represent a non-empty array?

我尝试使用类型的交集

/**
 * @param array&nonEmpty $users
 */
function sayHello($users): void {
    echo 'Hello, ' . $users[0];
}

但它抱怨:

PHPDoc tag @param for parameter $users contains unresolvable type.

(live demo)

如果我将注释剥离为 nonEmpty,错误将变为

Parameter $users of function sayHello() has invalid typehint type nonEmpty

我确实看到 class 负责 source tree as well as mentioned several times in the tests and issues 中的 nonEmpty 类型,但我无法让它工作。

只是为来自搜索引擎的人提供答案:

PHPStan 现在有 non-empty-array 类型可供您使用。 Here 是一个例子。