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

@psalm-check-type is not aware of the type defined using @psalm-type #10323

Open
lens0021 opened this issue Oct 27, 2023 · 2 comments
Open

@psalm-check-type is not aware of the type defined using @psalm-type #10323

lens0021 opened this issue Oct 27, 2023 · 2 comments

Comments

@lens0021
Copy link
Contributor

https://psalm.dev/r/8ccac2ea55

@psalm-github-bot
Copy link

I found these snippets:

https://psalm.dev/r/8ccac2ea55
<?php

class SomeWeb
{
    /**
     * @api
     * @psalm-type ResponseType = array{
     *   status: int,
     *   message: string,
     * }
     */
    public function someApi(): void
    {
        $response = [
            'status' => 0,
            'message' => 'success',
        ];

        /** @psalm-check-type $response = ResponseType */
        print_r(json_encode($response));

        /** @psalm-check-type $response = array{status?: int, message?: string} */
        print_r(json_encode($response));

        /**
         * @psalm-check-type $response = array{
         *   status?: int,
         *   message?: string,
         * }
         */
        print_r(json_encode($response));
    }
}
Psalm output (using commit 147505c):

ERROR: CheckType - 20:9 - Checked variable $response = ResponseType does not match $response = array{message: 'success', status: 0}

ERROR: InvalidDocblock - 31:9 - Invalid type '
*'

@robchett
Copy link
Contributor

robchett commented Nov 2, 2023

The multiline type issue will be fixed with #10326, the aliasing issue is still present

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants