How to make PhpStorm understand Ds\Map key type?

Viewed 80

I want to have type checking on a Ds\Map variable. In order to do this I've declared a dummy interface and declared types there:

/**
 * @method OtherType offsetGet(MyType $offset)
 * @method void offsetSet(MyType $offset, OtherType $value)
 */
interface MyMap extends ArrayAccess, Iterator
{
}

But when I use it:

/** @var Map|MyMap $map */
$map = new Ds\Map();
$map[$offset] = $value;

- PhpStorm doesn't recognize it and shows a warning: Illegal array key type MyType. How do I fix that?

1 Answers

Use sth like this in the first of your code to say to the phpstorm where is your interface:

use nampespace\MyMap;
Related