-
Notifications
You must be signed in to change notification settings - Fork 668
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
Add support for array{foo: string, ...<int>} and array{foo: string, ...<int, int>} syntax #8804
Comments
I feel like it's already kinda decided since the psalm-trace is described as |
Friendly ping @ondrejmirtes to know if this is a syntax PHPStan would be ok with ? |
|
Oh, I didn't see it like this... I thought this could have been understood like
and it was shorter than |
What I'd prefer is something like |
Or maybe even |
Are we sure that we need a separate syntax for this?
All realistic examples I can think of go something like And for edge cases like |
Psalm added Sure, there are better way to write those arrays. For example: |
I'm coming here from PhpStan side at phpstan/phpstan#4703. Just to add to examples where this is very useful: in my code I need to serialize object identity in a way that it will always unserialize if needed. Most objects will have a serialized form of While I like the @ondrejmirtes syntax suggestion of |
The syntax described in the issue description now works: https://psalm.dev/r/6d3a83fd93 |
I found these snippets: https://psalm.dev/r/6d3a83fd93<?php
/** @return array{a: mixed, ...<array-key, mixed>} */
function test(): array {
return ['a' => 1, 'b' => 'b'];
}
/** @psalm-trace $a */
$a = test();
|
Awesome, PHPStan will eventually also add syntax for |
In the example https://psalm.dev/r/d9b4b19a18,
the type is described as
array{a: mixed, ...<array-key, mixed>}
by psalm.But if we use the same syntax in the phpdoc, there is a syntax error
https://psalm.dev/r/6d3a83fd93
I would say it could be great to move from
to
And in the same way we could have
array{foo: string, ...<int>}
instead ofarray{foo: string}&array<int>
@AndrolGenhald @orklah I saw you were taking in #8744 (comment)
about the syntax
array{foo: string, ...mixed}
, but I would say it's not supported/correct sincearray{a: mixed, ...int}
is stillarray{a: mixed, ...<array-key, mixed>}
, cf https://psalm.dev/r/2a3b3d25a3.array{foo: string, ...<int>}
might be more natural thanarray{foo: string, ...int}
sincearray{foo: string, ...<int, int>}
<int>
meansarray<int>
)The text was updated successfully, but these errors were encountered: