-
-
Notifications
You must be signed in to change notification settings - Fork 934
Closed
phpstan/phpstan-src
#800Description
Feature request
A third party lib I'm using has defined an array shape that uses the key-of feature of Psalm. Unfortunately, PHPStan does not support it and therefore is not able to import the type and use it properly, giving back a bunch of errors. It would be cool if this feature was added, and because PHPStan already supports referencing the constant values as types I think that the foundation on top of which this feature could be built is already here. Would you accept a contribution to add such feature?
class Airports {
const JFK = 'jfk';
const LGA = 'lga';
const EWR = 'ewr';
const ALL = [
self::JFK => 'John F. Kennedy Airport',
self::LGA => 'La Guardia Airport',
self::EWR => 'Newark Liberty International',
];
/**
* @psalm-param key-of<self::ALL> $code
*/
public static function getName(string $code) : string {
return self::ALL[$code];
}
}
Airports::getName(Airports::JFK); // good
Airports::getName('lga'); // good
Airports::getName('sfo'); // type errorExample taken from the blog post linked above
canvural, ZebulanStanphill and MatanYadaev
Metadata
Metadata
Assignees
Labels
No labels