Skip to content
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

Invalid narrowed type after coerce/assert #19

Open
p4veI opened this issue Sep 11, 2024 · 1 comment
Open

Invalid narrowed type after coerce/assert #19

p4veI opened this issue Sep 11, 2024 · 1 comment

Comments

@p4veI
Copy link

p4veI commented Sep 11, 2024

Hello, after upgrading to php-standard-library/phpstan-extension v1.1.0 I'm getting an invalid resolved type for array shapes narrowed by the psl type coerce/assert methods.

E.g.:

$type = shape([
  'name' => iterable(
    int(),
    shape([
      'id' => string(),
      ...
    ])
  )
]);

$data = $type->coerce($someMixedArray);

Then using PHPStan\dumpType I'm getting e.g. Dumped type: array{name?: mixed};

@judzi
Copy link

judzi commented Sep 12, 2024

Problem is probably with usage of iterable

This should work (if the integer key is sequential starting from 0):

$type = shape([
  'name' => vec(
    shape([
      'id' => string(),
      ...
    ])
  )
]);

$data = $type->coerce($someMixedArray);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants