Psalm: Fails to import namespaced type alias

Created on 22 Jul 2020  路  4Comments  路  Source: vimeo/psalm

Most helpful comment

ie use AA; doesn't import all the symbols in AA automatically

All 4 comments

I found these snippets:


https://psalm.dev/r/3fa54f51a1

<?php

namespace AA;
/**
* @psalm-type _A=array{a:string}
*/
class A {}

namespace BB;

use AA;

/**
* @psalm-import-type _A from A
*/
class B {
    /**
    * @psalm-param _A $a
    * @return void
    */
    public function ff(array $a){
        if (!empty($a)) {echo 'ss';}
    }
}
Psalm output (using commit eaae243):

ERROR: MismatchingDocblockParamType - 18:20 - Parameter $a has wrong type 'type-alias(BB\A::_A)', should be 'array<array-key, mixed>'

ERROR: RedundantConditionGivenDocblockType - 22:8 - Found a redundant condition when evaluating docblock-defined type $a and trying to reconcile type 'type-alias(BB\A::_A)' to !empty

You're using use incorrectly: https://psalm.dev/r/c95369392b

I found these snippets:


https://psalm.dev/r/c95369392b

<?php

namespace AA {
    /**
    * @psalm-type _A=array{a:string}
    */
    class A {}
}

namespace BB {
    use AA;

    /**
     * @psalm-import-type _A from AA\A
     */
    class B {
        /**
        * @psalm-param _A $a
        * @return void
        */
        public function ff(array $a){
            if (!empty($a)) {echo 'ss';}
        }
    }
}
Psalm output (using commit eaae243):

No issues!

ie use AA; doesn't import all the symbols in AA automatically

Was this page helpful?
0 / 5 - 0 ratings

Related issues

albe picture albe  路  3Comments

tux-rampage picture tux-rampage  路  3Comments

muglug picture muglug  路  3Comments

staabm picture staabm  路  3Comments

Pierstoval picture Pierstoval  路  3Comments