-
Hi there! Am I doing this right? /** @param array{id: string, created_at: string, data: string} $result */
private function decodeResults(array $result): array
{
$result['data'] = Json\typed($result['data'], Type\shape([
'start_time' => Type\non_empty_string(),
'end_time' => Type\non_empty_string(),
'entities' => Type\dict(Type\string(), Type\mixed()),
]));
return $result;
} psalm doesn't like it, and complains: Any idea? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 1 reply
-
Hey @bendavies, are you using the PSL plugin with Psalm? Also, what version of Psalm are you using? |
Beta Was this translation helpful? Give feedback.
-
hey! version |
Beta Was this translation helpful? Give feedback.
-
it seems that the type inference is working: /** @param array{id: string, data: string} $data */
public static function fromArray(array $data): self
{
$data['data'] = Json\typed($data['data'], Type\shape([
'start_time' => Type\non_empty_string(),
'end_time' => Type\non_empty_string(),
'entities' => Type\mixed(),
], true));
/** @psalm-trace $data */
} ERROR: InvalidArgument - MigrationResult.php:19:51 - Incompatible types found for Tv (see https://psalm.dev/004)
$data['data'] = Json\typed($data['data'], Type\shape([
'start_time' => Type\non_empty_string(),
'end_time' => Type\non_empty_string(),
'entities' => Type\mixed(),
], true));
ERROR: Trace - MigrationResult.php:27:9 - $data: array{data: array{end_time: non-empty-string, entities: mixed, start_time: non-empty-string}, id: string} (see https://psalm.dev/224)
/** @psalm-trace $data */ |
Beta Was this translation helpful? Give feedback.
-
no error: $data['data'] = Json\typed($data['data'], Type\shape([
'start_time' => Type\non_empty_string(),
'end_time' => Type\non_empty_string(),
], true)); no error: $data['data'] = Json\typed($data['data'], Type\shape([
'start_time' => Type\mixed(),
'end_time' => Type\mixed(),
'entities' => Type\mixed(),
], true)); but this does error: $data['data'] = Json\typed($data['data'], Type\shape([
'start_time' => Type\non_empty_string(),
'entities' => Type\mixed(),
], true)); so, if all the |
Beta Was this translation helpful? Give feedback.
-
Huh, i had a similar issue recently with a different library, and now i think this is a bug in psalm: https://psalm.dev/r/e80523194f |
Beta Was this translation helpful? Give feedback.
-
reported: vimeo/psalm#6563 |
Beta Was this translation helpful? Give feedback.
-
thanks for the help! |
Beta Was this translation helpful? Give feedback.
-
actually, this is not a bug in psalm, |
Beta Was this translation helpful? Give feedback.
-
aha! we were on 1.7.2. thanks! |
Beta Was this translation helpful? Give feedback.
-
are you able to move on to 1.8? if not, you can send a PR to 1.7.x branch for a fix :) |
Beta Was this translation helpful? Give feedback.
-
i we can, we're on php 8 :) |
Beta Was this translation helpful? Give feedback.
actually, this is not a bug in psalm,
TypeInterface
ofPsl\Type
needs to be marked covariant, this was done recently and released as part of 1.8.0, I'm assuming you are using an older version of PSL?