psalm
psalm copied to clipboard
Inherit `value-of` class constant (static behavior)
How could I realize the follow (if at all)?
https://psalm.dev/r/e2f5c88bc0
Where in class B
the template T
would be of BItem
as declared by the ITEM_CLASS
const?
I found these snippets:
https://psalm.dev/r/e2f5c88bc0
<?php
class Item {}
class BItem extends Item {}
/**
* @template T
*/
class Base {
}
/**
* @extends Base<value-of<self::ITEM_CLASS>>
*/
class A extends Base {
public const ITEM_CLASS = Item::class;
}
/**
* @extends A
*/
class B extends A {
public const ITEM_CLASS = BItem::class;
}
Psalm output (using commit ef3b018):
ERROR: InvalidDocblock - 23:1 - @template-extends has invalid class A
INFO: InvalidClassConstantType - 24:18 - The type "BItem::class" for B::ITEM_CLASS does not satisfy the type "Item::class" inherited from A::ITEM_CLASS