Repository: typeorm/typeorm
File: src/entity-manager/EntityManager.ts (TypeScript)

Code before:
        entityClass: EntityTarget<Entity>,
        columnName: PickKeysByType<Entity, number>,
        where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
    ): Promise<number | null> {
        return this.callAggregateFun(entityClass, "MIN", columnName, where)
    }

    /**
     * Return the MAX of a column
     */
    maximum<Entity extends ObjectLiteral>(
        entityClass: EntityTarget<Entity>,
        columnName: PickKeysByType<Entity, number>,
        where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
    ): Promise<number | null> {
        return this.callAggregateFun(entityClass, "MAX", columnName, where)
    }

    private async callAggregateFun<Entity extends ObjectLiteral>(
        entityClass: EntityTarget<Entity>,
        fnName: "SUM" | "AVG" | "MIN" | "MAX",
        columnName: PickKeysByType<Entity, number>,
        where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[] = {},
    ): Promise<number | null> {
        const metadata = this.connection.getMetadata(entityClass)
        const { [fnName]: result } = await this.createQueryBuilder(
            entityClass,
            metadata.name,
        )
            .setFindOptions({ where })
            .select(
                `${fnName}(${this.connection.driver.escape(columnName)})`,
                fnName,
            )
            .getRawOne()
        return result === null ? null : parseFloat(result)
    }

    /**
     * Finds entities that match given find options.
     */
    async find<Entity extends ObjectLiteral>(
        entityClass: EntityTarget<Entity>,
        options?: FindManyOptions<Entity>,
    ): Promise<Entity[]> {
        const metadata = this.connection.getMetadata(entityClass)
        return this.createQueryBuilder<Entity>(
            entityClass as any,
            FindOptionsUtils.extractFindManyOptionsAlias(options) ||
                metadata.name,
        )

Review comment (refactor):
Can we simplify a bit and do it as `const result = ` instead `const { [fnName]: result } =`, and then just do `result[fnName]`. For my stupid brain it took a minute to figure out how it works, don't want to other peoples like me to think about this code, so I think simplification will be better for us, such people.

Code after:
        entityClass: EntityTarget<Entity>,
        columnName: PickKeysByType<Entity, number>,
        where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
    ): Promise<number | null> {
        return this.callAggregateFun(entityClass, "MIN", columnName, where)
    }

    /**
     * Return the MAX of a column
     */
    maximum<Entity extends ObjectLiteral>(
        entityClass: EntityTarget<Entity>,
        columnName: PickKeysByType<Entity, number>,
        where?: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],
    ): Promise<number | null> {
        return this.callAggregateFun(entityClass, "MAX", columnName, where)
    }

    private async callAggregateFun<Entity extends ObjectLiteral>(
        entityClass: EntityTarget<Entity>,
        fnName: "SUM" | "AVG" | "MIN" | "MAX",
        columnName: PickKeysByType<Entity, number>,
        where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[] = {},
    ): Promise<number | null> {
        const metadata = this.connection.getMetadata(entityClass)
        const result = await this.createQueryBuilder(entityClass, metadata.name)
            .setFindOptions({ where })
            .select(
                `${fnName}(${this.connection.driver.escape(
                    String(columnName),
                )})`,
                fnName,
            )
            .getRawOne()
        return result[fnName] === null ? null : parseFloat(result[fnName])
    }

    /**
     * Finds entities that match given find options.
     */
    async find<Entity extends ObjectLiteral>(
        entityClass: EntityTarget<Entity>,
        options?: FindManyOptions<Entity>,
    ): Promise<Entity[]> {
        const metadata = this.connection.getMetadata(entityClass)
        return this.createQueryBuilder<Entity>(
            entityClass as any,
            FindOptionsUtils.extractFindManyOptionsAlias(options) ||
                metadata.name,
        )
            .setFindOptions(options || {})