-
Notifications
You must be signed in to change notification settings - Fork 13k
Use find
array helper
#18557
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
Use find
array helper
#18557
Conversation
@@ -909,7 +909,7 @@ namespace ts.refactor.extractMethod { | |||
} | |||
} | |||
|
|||
function getStatementsOrClassElements(scope: Scope): ReadonlyArray<Statement> | ReadonlyArray<ClassElement> { | |||
function getStatementsOrClassElements(scope: Scope): ReadonlyArray<Statement | ClassElement> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe these types are equivalent. Didn't the old version meant that the list was either all statements or all class elements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but we don't need that information and it breaks type inference on find
for some reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I would leave a comment explaining why we're not using the more accurate type.
return child; | ||
} | ||
} | ||
return find(getStatementsOrClassElements(scope), child => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a simple find loop, I think using a helper makes sense. In general though, in the absence of expression-level breakpoints (and I would be very happy to learn that these exist), loops are much easier to debug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think node.js recently started supporting column breakpoints -- should be in chrome too.
Just simplifying a method.