Skip to content

Add support for Psl\Type\nullish() in shape types#31

Merged
ondrejmirtes merged 3 commits intophp-standard-library:2.0.xfrom
veewee:nullish
Mar 17, 2026
Merged

Add support for Psl\Type\nullish() in shape types#31
ondrejmirtes merged 3 commits intophp-standard-library:2.0.xfrom
veewee:nullish

Conversation

@veewee
Copy link
Contributor

@veewee veewee commented Mar 16, 2026

Summary

  • Add Psl\Type\nullish() support for shape type inference, where nullish(T) produces a required key with type T|null
  • Support combined optional(nullish(T)) producing an optional key with type T|null
  • Add stubs for NullishType and nullish() function, mirroring the existing OptionalType/optional() pattern

Aligns with azjezz/psl#618, mago#1391, and psalm-plugin#18.

Test plan

  • Existing tests pass (47/47)
  • nullish(string()) in shape → array{bio: string|null} (required, nullable)
  • optional(nullish(string())) in shape → array{bio?: string|null} (optional, nullable)
  • Tested across coerce, assert, and matches operations

Nullish wraps a type as T|null while keeping the key required,
unlike optional() which makes the key absent. Supports both
standalone nullish(T) and combined optional(nullish(T)).
- Use string literal instead of NullishType::class to avoid class-not-found
  errors on PSL versions without NullishType
- Move nullish tests to separate fixtures, gated by class_exists()
- Add PHP 8.2, 8.3, 8.4, 8.5 to CI matrix
- Restore NullishType::class instead of string literal
- Add baseline ignores for older PSL versions without NullishType
- Fix CS: add use statements for NullishType and class_exists in test
@ondrejmirtes ondrejmirtes merged commit e48f3f1 into php-standard-library:2.0.x Mar 17, 2026
36 checks passed
@ondrejmirtes
Copy link
Collaborator

Thank you.

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

Successfully merging this pull request may close these issues.

2 participants