Skip to content

3.7.3 - Certain typescript code causes a file to alternate between 2 versions and never check ok #18379

@lukpsaxo

Description

@lukpsaxo

Prettier 3.7.3
Playground link

--parser babel-ts

Input:

export type AbcdProps = Readonly<
  {
    /**
     * comment
     */
    "data-test-id"?: string;
  } & (
    | {
        /**
         * comment
         */
        image: string | null;
      }
    | {
        image?: never;
      } // comment comment comment commment comment comment
  ) &
    (// comment comment comment commment comment.
    XyzProps | AbcProps)
>;

Output:

export type AbcdProps = Readonly<
  {
    /**
     * comment
     */
    "data-test-id"?: string;
  } & (
    | {
        /**
         * comment
         */
        image: string | null;
      }
    | {
        image?: never;
      } // comment comment comment commment comment comment
    // comment comment comment commment comment.
  ) &
    (XyzProps | AbcProps)
>;

Why?

If you copy the output to the input, you get the input - e.g. each time prettier writes you get a new version of the file.

This means just using prettier write and check, we can never have a passing file.

Of course I will change the comments on the original file to avoid this issue, but its still problematic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:idempotencyIssues with re-printing Prettier’s outputarea:intersection typeslang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions