prettier/prettier

Typescript regression in handling functions with generic types and method chaingin in 3.2.0 compared to 3.1.0

Aperta

#16.080 aperta il 16 feb 2024

 (5 commenti) (1 reazione) (0 assegnatari)JavaScript (4985 fork)batch import
help wantedstatus:needs investigation

Metriche repository

Star
 (52.203 stelle)
Metriche merge PR
 (Merge medio 6g) (186 PR mergiate in 30 g)

Descrizione

Prettier 3.2.5 Playground link

# Options (if any):
--single-quote
--print-width=120

Input:

export class Test  {
  public test() {

    return this.http
      .get<SettlementStatus[]>(
       'url so very long that will break line on 120       (we use 120 so here also)',
        { params },
      )

      .pipe(map((statuses) => statuses.map((status) => ({ value: status }))));

    return this.http
      .get<SettlementStatus[]>(
       'url so very long that will break line on 120       (we use 120 so here also)',
        { params },
      )
      .pipe(map((statuses) => statuses.map((status) => ({ value: status }))));

    return this.http
      .get<SettlementStatus[]>(
       'url so very long that will break line on 120       (we use 120 so here also)',
        { params },
      );
  }
}


export class Test  {
  public test() {

    return this.http
      .get<SettlementStatus[]>(
       'url short no break',
        { params },
      )

      .pipe(map((statuses) => statuses.map((status) => ({ value: status }))));

    return this.http
      .get<SettlementStatus[]>(
       'url short no break',
        { params },
      )
      .pipe(map((statuses) => statuses.map((status) => ({ value: status }))));



    return this.http
      .get<SettlementStatus[]>(
       'url short no break',
        { params },
      );

 
  }
}

Output:

export class Test {
  public test() {
    return this.http
      .get<SettlementStatus[]>("url so very long that will break line on 120       (we use 120 so here also)", {
        params,
      })

      .pipe(map((statuses) => statuses.map((status) => ({ value: status }))));

    return this.http
      .get<
        SettlementStatus[]
      >("url so very long that will break line on 120       (we use 120 so here also)", { params })
      .pipe(map((statuses) => statuses.map((status) => ({ value: status }))));

    return this.http.get<SettlementStatus[]>(
      "url so very long that will break line on 120       (we use 120 so here also)",
      { params },
    );
  }
}

export class Test {
  public test() {
    return this.http
      .get<SettlementStatus[]>("url short no break", { params })

      .pipe(map((statuses) => statuses.map((status) => ({ value: status }))));

    return this.http
      .get<SettlementStatus[]>("url short no break", { params })
      .pipe(map((statuses) => statuses.map((status) => ({ value: status }))));

    return this.http.get<SettlementStatus[]>("url short no break", { params });
  }
}

Expected output: from prettier 3.1.0

export class Test {
  public test() {
    return this.http
      .get<SettlementStatus[]>('url so very long that will break line on 120       (we use 120 so here also)', {
        params,
      })

      .pipe(map((statuses) => statuses.map((status) => ({ value: status }))));

    return this.http
      .get<SettlementStatus[]>('url so very long that will break line on 120       (we use 120 so here also)', {
        params,
      })
      .pipe(map((statuses) => statuses.map((status) => ({ value: status }))));

    return this.http.get<SettlementStatus[]>(
      'url so very long that will break line on 120       (we use 120 so here also)',
      { params },
    );
  }
}

export class Test {
  public test() {
    return this.http
      .get<SettlementStatus[]>('url short no break', { params })

      .pipe(map((statuses) => statuses.map((status) => ({ value: status }))));

    return this.http
      .get<SettlementStatus[]>('url short no break', { params })
      .pipe(map((statuses) => statuses.map((status) => ({ value: status }))));

    return this.http.get<SettlementStatus[]>('url short no break', { params });
  }
}

Why? seems more consistent especially where {params} ends up and how wierd

.get<
        SettlementStatus[]
      >(
``` looks like

Guida contributor