Add @ignore-var
and @psalm-ignore-var
#5488
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This annotation is used to ignore the
@var
annotation written in the same docblock.Background
To take advantage of the IDE's auto-completion, you may sometimes want to use explicit
@var
annotations even when psalm can infer the type well enough. This weakens the effectiveness of type checking in many cases since the explicit@var
annotation overrides the types inferred by psalm.See this example for more detail.
https://psalm.dev/r/c19d749dbe
What is changed if this PR is merged
Psalm ignores the
@var
annotation which is co-located with@psalm-ignore-var
. Then IDEs that don't fully understand complex types like generics can use the manually specified types with@var
for auto-completion, while psalm can still use its own inferred types for type checking.Disclaimer
I'm not confident about my English skills. The sentences may seem odd to you. I know you aren't my English teacher, but if any wordings of the added doc or this PR sounds unnatural, please feel free to correct them. Then I can train myself better.