我想对Ds\Map变量进行类型检查。为了做到这一点,我声明了一个虚拟接口,并在那里声明了类型:
/**
* @method OtherType offsetGet(MyType $offset)
* @method void offsetSet(MyType $offset, OtherType $value)
*/
interface MyMap extends ArrayAccess, Iterator
{
}但是当我使用它的时候:
/** @var Map|MyMap $map */
$map = new Ds\Map();
$map[$offset] = $value;PhpStorm无法识别它,并显示警告:Illegal array key type MyType。我该怎么解决这个问题呢?
发布于 2021-01-24 22:02:03
在你的第一段代码中使用类似这样的东西来告诉phpstorm你的接口在哪里:
use nampespace\MyMap;https://stackoverflow.com/questions/65871304
复制相似问题