Skip to content

Start using a union for FunctionLike things #16988

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

Merged
merged 2 commits into from
Jul 6, 2017

Conversation

weswigham
Copy link
Member

We have a type, FunctionLikeDeclaration, which is used a lot internally. We also have a function isFunctionLike 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 a FunctionLikeDeclaration 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 if node.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).

Verified

This commit was signed with the committer’s verified signature.
weswigham Wesley Wigham
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. One naming suggestion, although I'm not sure it's an improvement.

| SetAccessorDeclaration
| FunctionExpression
| ArrowFunction;
export type FunctionLikeTypes =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just FunctionLike?

Verified

This commit was signed with the committer’s verified signature.
weswigham Wesley Wigham
@weswigham weswigham merged commit 07e8263 into microsoft:master Jul 6, 2017
@ghost ghost mentioned this pull request Mar 6, 2018
@weswigham weswigham deleted the function-like-in-unison branch March 7, 2018 02:22
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants