Repository: typeorm/typeorm
File: src/query-builder/SelectQueryBuilder.ts (TypeScript)

Code before:
                count = await this.executeCountQuery(queryRunner)
            }
            const results: [Entity[], number] = [entitiesAndRaw.entities, count]

            // close transaction if we started it
            if (transactionStartedByUs) {
                await queryRunner.commitTransaction()
            }

            return results
        } catch (error) {
            // rollback transaction if we started it
            if (transactionStartedByUs) {
                try {
                    await queryRunner.rollbackTransaction()
                } catch (rollbackError) {}
            }
            throw error
        } finally {
            if (queryRunner !== this.queryRunner)
                // means we created our own query runner
                await queryRunner.release()
        }
    }

    private lazyCount(entitiesAndRaw: { entities: Entity[]; raw: any[] }) {
        const hasLimit =
            this.expressionMap.limit !== undefined &&
            this.expressionMap.limit !== null
        if (this.expressionMap.joinAttributes.length > 0 && hasLimit) {
            return undefined
        }

        let maxResults = undefined

        const hasTake =
            this.expressionMap.take !== undefined &&
            this.expressionMap.take !== null
        if (hasTake) {
            maxResults = this.expressionMap.take
        }

        if (hasLimit) {
            // limit overrides take when no join is defined
            maxResults = this.expressionMap.limit
        }

        if (
            maxResults !== undefined &&
            entitiesAndRaw.entities.length == maxResults
        ) {

Review comment (suggestion):
Method should declare its return type:

```suggestion
    private lazyCount(entitiesAndRaw: { entities: Entity[]; raw: any[] }): number | undefined {
```

Code after:

            // close transaction if we started it
            if (transactionStartedByUs) {
                await queryRunner.commitTransaction()
            }

            return results
        } catch (error) {
            // rollback transaction if we started it
            if (transactionStartedByUs) {
                try {
                    await queryRunner.rollbackTransaction()
                } catch (rollbackError) {}
            }
            throw error
        } finally {
            if (queryRunner !== this.queryRunner)
                // means we created our own query runner
                await queryRunner.release()
        }
    }

    private lazyCount(entitiesAndRaw: {
        entities: Entity[]
        raw: any[]
    }): number | undefined {
        const hasLimit =
            this.expressionMap.limit !== undefined &&
            this.expressionMap.limit !== null
        if (this.expressionMap.joinAttributes.length > 0 && hasLimit) {
            return undefined
        }

        const hasTake =
            this.expressionMap.take !== undefined &&
            this.expressionMap.take !== null

        // limit overrides take when no join is defined
        const maxResults = hasLimit
            ? this.expressionMap.limit
            : hasTake
            ? this.expressionMap.take
            : undefined

        if (
            maxResults !== undefined &&
            entitiesAndRaw.entities.length === maxResults
        ) {
            // stop here when the result set contains the max number of rows; we need to execute a full count
            return undefined
        }