You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
we are in the process of updating psalm from 4.7.2 to 5.3 and I ran into the following issue. From an external dependency, we often get arrays back, that are either empty, or have a structure that we want to provide as a docblock annotation. So I tried different things. The closest I got was defining the type as array{a: string}|array{} and then do an empty check. This actually works, when the array has only one specified type. However when having more than one, I'll get an error again, that the offsets are optional.
Thanks, but I was hoping to get arround checking if each and every value is set, because If the array is not empty I can safely assume that all the fields are present. So in my example, if I know that the array is not empty, I would know for a fact, that the structure is array{a: string, b:string}
This would require adding support for disjoint array types, which is something I've wanted to do for a very long time now, will see if I can make a PR soon!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
we are in the process of updating psalm from 4.7.2 to 5.3 and I ran into the following issue. From an external dependency, we often get arrays back, that are either empty, or have a structure that we want to provide as a docblock annotation. So I tried different things. The closest I got was defining the type as
array{a: string}|array{}
and then do an empty check. This actually works, when the array has only one specified type. However when having more than one, I'll get an error again, that the offsets are optional.Here is an example of what I am trying to achieve: https://psalm.dev/r/e0bdedbe9b
Is there a way to implement this with psalm?
Thanks in advande!
Beta Was this translation helpful? Give feedback.
All reactions