-
Notifications
You must be signed in to change notification settings - Fork 663
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
Allow importing type aliases on methods/functions #4807
Comments
I found these snippets: https://psalm.dev/r/138af4f19d<?php
namespace A {
/** @psalm-type _AType=int|string */
final class Types {}
}
namespace B {
use A\Types;
/**
* @psalm-import-type _AType from Types as _Q
* @param _Q $p
*/
function f($p): void {}
class C {
/**
* @psalm-import-type _AType from Types as _Z
* @param _Z $p
*/
public function f($p): void {}
}
}
|
I think it could be related to #4290, it's not even possibile to use them with templates for classes. |
Also related to #3511 |
Is there any workaround for this?
|
For functions, there is a not-very-elegant work around. Given a file of functions, it's possible to declare an empty, throwaway class at the top where you can import types, which can then be used by any other functions in the file. Example: /**
* @psalm-import-type Type from Types
*/
class ImportedTypes
{
}
/**
* @param Generator<int, Type> $xs
* @return Generator<int, Type>
*/
function something(Generator $xs): Generator
{
// ...
} |
Currently Psalm processes
@psalm-import-type
in docblocks of classlikes only. It would be useful to be able to import types in function docblocks as well.https://psalm.dev/r/138af4f19d
Expected: no issues
The text was updated successfully, but these errors were encountered: