diff --git a/src/services/refactors/extractMethod.ts b/src/services/refactors/extractMethod.ts index 3b8ea19a9f0..8e97b145aac 100644 --- a/src/services/refactors/extractMethod.ts +++ b/src/services/refactors/extractMethod.ts @@ -934,12 +934,8 @@ namespace ts.refactor.extractMethod { * Otherwise, return `undefined`. */ function getNodeToInsertBefore(minPos: number, scope: Scope): Node | undefined { - const children = getStatementsOrClassElements(scope); - for (const child of children) { - if (child.pos >= minPos && isFunctionLike(child) && !isConstructorDeclaration(child)) { - return child; - } - } + return find(getStatementsOrClassElements(scope), child => + child.pos >= minPos && isFunctionLike(child) && !isConstructorDeclaration(child)); } function getPropertyAssignmentsForWrites(writes: ReadonlyArray): ShorthandPropertyAssignment[] {