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
{{ message }}
Repository navigation
Commit 4f7c44c
Browse filesBrowse the repository at this point in the historyBrowse files
Support type predicates on callable and Closure types
A conditional return type referencing the callable's own parameter, like
@PARAM callable(mixed $value): ($value is int ? true : false) $predicate
now declares a type predicate (TypeScript's "$value is int"), represented
as @phpstan-assert-if-true-style assertions on CallableType/ClosureType:
- Invoking such a callable in a condition narrows the passed argument
in both branches, including narrowing to template types of the
enclosing function.
- Template types in the asserted type are inferred from the assertions
of a passed callable, enabling filter()-style generics.
- First-class callables inherit predicates both from @phpstan-assert-*
tags and from conditional return types in function signatures, so
is_int(...), is_string(...) etc. work as predicates out of the box.
- Closures and arrow functions with their own @phpstan-assert-* PHPDoc
now carry those assertions on their ClosureType.
- One-sided predicates are expressed as ($value is int ? bool : false)
(only true is conclusive) and ($value is int ? true : bool) (only
false is conclusive).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
0 commit comments