Start using a union for FunctionLike things #16988
Merged
+73
−45
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.
We have a type,
FunctionLikeDeclaration
, which is used a lot internally. We also have a functionisFunctionLike
which, prior to this PR, guarded to that type. However, what the type guard checked for and what was based on that type were not the same set of types. This PR clarifies the relationship between what that guard checks for and what is considered aFunctionLikeDeclaration
by moving everything over to using unions of the correct types (isFunctionLike
now guards to a union of the type associated with the syntax kinds it actually checks) - this has the added advantage that in places where usage is correct, fewer casts are required. (Although, in many cases we unsafely check ifnode.body
exists when the node's type indicates it should never have a body - in these places we now need a cast to assert that we'd like to check the potentially nonexistent property)It also breaks the property signature interface into two interfaces so they may be union-ed together and properly discriminated in our current checker.
I mentioned I had done this in one of my branches to @sandersn as I was working because I was becoming annoyed by lots of small gotchyas when attempting to use these types as they existed prior (and attempting to remember what was/was not safe to cast to).