Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heuristic for line break after "=" on type definitions #674

Open
jasonkuhrt opened this issue Sep 23, 2024 · 0 comments
Open

Heuristic for line break after "=" on type definitions #674

jasonkuhrt opened this issue Sep 23, 2024 · 0 comments

Comments

@jasonkuhrt
Copy link

I find myself doing this often:

// dprint-ignore
type AddFnMerge<$FluentFn extends FnFluent<any>, $State extends State, $MergeFn extends FnMerge> =
  FnCallFluent<
    $FluentFn,
    State<$State['context'], $State['properties'], [...$State['merges'], $MergeFn]>
  >

Dprint would format that as:

type AddFnMerge<$FluentFn extends FnFluent<any>, $State extends State, $MergeFn extends FnMerge> = FnCallFluent<
  $FluentFn,
  State<$State['context'], $State['properties'], [...$State['merges'], $MergeFn]>
>

Note if I insert a newline after type addFnMerge< then this happens (which I approve of):

export type AddFnMerge<
  $FluentFn extends FnFluent<any>,
  $State extends State,
  $MergeFn extends FnMerge,
> = FnCallFluent<
  $FluentFn,
  State<$State['context'], $State['properties'], [...$State['merges'], $MergeFn]>
>

Keeping long type signatures on a single line apart from the type body helps me read the functions. I will resort to the multiline version eventually but there is a threshold before giving into that. For me, at least, vertical space is precious.

Even in a short[er] sig case I still think separating sig from body with a line break is more readable:

// What dprint does
type AddFnMerge<$FluentFn extends FnFluent<any>> = FnCallFluent<
  $FluentFn,
  State<$State['context'], $State['properties'], [...$State['merges'], $MergeFn]>
>
// What I prefer
type AddFnMerge<$FluentFn extends FnFluent<any>> =
  FnCallFluent<
    $FluentFn,
    State<$State['context'], $State['properties'], [...$State['merges'], $MergeFn]>
  >

I think the only time I would want no line break is when there are no type variables.

type ThisIsFine = string

What do you think? If my proposal is not strictly better, then could it at least be an option. E.g. newlineAfterTypeVariablesSignature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant