Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidDocblock: Invalid array key type type-alias(...) #10503

Closed
luukvhoudt opened this issue Dec 18, 2023 · 1 comment · Fixed by #10508
Closed

InvalidDocblock: Invalid array key type type-alias(...) #10503

luukvhoudt opened this issue Dec 18, 2023 · 1 comment · Fixed by #10508

Comments

@luukvhoudt
Copy link

When importing a type and using it as the array key in another type, then I get the following error:

InvalidDocblock - XYZ.php:XYZ:XYZ - array<ValueOfGreetings, string> is not a valid type (Invalid array key type type-alias(Greetings::ValueOfGreetings) in XYZ.php:XYZ) (see https://psalm.dev/008)

I didn't manage to reproduce it in the playground, probably because the psalm version differs with the one on my machine. I'm using version 5.18.0. In any case this is the reproduction I wrote at the playground:
https://psalm.dev/r/e02932aa33

Copy link

I found these snippets:

https://psalm.dev/r/e02932aa33
<?php

/**
 * @psalm-type ValueOfGreetings = Greetings::*
 */
class Greetings {
    public const HI = 'hi';
    public const HELLO = 'hello';
}

/**
 * @psalm-import-type ValueOfGreetings from Greetings
 */
class Greetor {
    /**
     * @return array<ValueOfGreetings, string>
     */
    public function getAll() {
        return [
            Greetings::HI => "mom",
            Greetings::HELLO => "world",
        ];
    }
}
Psalm output (using commit a75d26a):

No issues!

ging-dev added a commit to ging-dev/psalm that referenced this issue Dec 19, 2023
ging-dev added a commit to ging-dev/psalm that referenced this issue Dec 19, 2023
ging-dev added a commit to ging-dev/psalm that referenced this issue Dec 19, 2023
ging-dev added a commit to ging-dev/psalm that referenced this issue Dec 20, 2023
ging-dev added a commit to ging-dev/psalm that referenced this issue Dec 20, 2023
orklah added a commit that referenced this issue Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant