prettier / prettier/prettier

[typescript]: Missing line break with long generic parameter

Open
#12,920 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

lang:typescript status:needs discussion
Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
19h 2m
Merged PRs (30d)
117

Description

Prettier 2.6.2
Playground link

--parser typescript
--prose-wrap never

Input:


const hermesNotificationCancellationByUserTagSchema: ZodSchema<HermesNotificationCancellationByUserTag> =
  z.object({
    userTag: z.string(),
    notificationType: z.nativeEnum(NotificationType).optional(),
  })


const hermesNotificationCancellationByUserTagSchema: ZodSchema<
  HermesNotificationCancellationByUserTag
> =
  z.object({
    userTag: z.string(),
    notificationType: z.nativeEnum(NotificationType).optional(),
  })

Output:

const hermesNotificationCancellationByUserTagSchema: ZodSchema<HermesNotificationCancellationByUserTag> =
  z.object({
    userTag: z.string(),
    notificationType: z.nativeEnum(NotificationType).optional(),
  });

const hermesNotificationCancellationByUserTagSchema: ZodSchema<HermesNotificationCancellationByUserTag> =
  z.object({
    userTag: z.string(),
    notificationType: z.nativeEnum(NotificationType).optional(),
  });

Expected behavior:

Im not sure if this is intentional, but I would expect both calls to end up as the second input (or a variation of it), and not as the first, as the first one violates the maximum line length.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Playground reproduction using the TypeScript parser and compare the two generic-parameter inputs with their formatted output. Trace the formatter behavior for long TypeScript generic parameters; done means both equivalent inputs produce a wrapped result that respects the maximum line length, with a regression test covering the case.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.