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

Unsupported syntax for async arrow functions with multiline generic parameters #18

Closed
wants to merge 1 commit into from

Conversation

seralexeev
Copy link

First of all, thank you for your work on ts-blank-space. I've migrated all my projects to use it, and everything works great. It has been a breath of fresh air in the complex world of building TypeScript projects in monorepos.

I wanted to share an edge case I encountered. I understand that this is an edge case that can be resolved by suppressing Prettier or changing a method expression to a method declaration. I don't think this case can be fixed by changing anything in ts-blank-space.

I studied the unsupported_syntax.md and didn't find this case documented. I believe it would be helpful to add it to the documentation.

Problem Description:

Consider the following async arrow function with generic parameters:

const fn = async <T>() => null;

After transformation with ts-blank-space, I get:

const fn = async () => null;

Which is syntactically correct.

However, if the function contains a large list of generic parameters, Prettier may move the parameters to new lines:

const fn = async <
    T,
    U,
    V
>() => null;

After transformation with ts-blank-space, I get:

const fn = async



 () => null;

This code is syntactically incorrect and leads to a runtime error:

Uncaught SyntaxError: Malformed arrow function parameter list

Since this is not an error in ts-blank-space but an example of code that is not supported by design, I think it would be helpful to add it to the documentation under unsupported syntax.

@seralexeev seralexeev marked this pull request as ready for review October 31, 2024 05:43
@acutmore
Copy link
Collaborator

Hi @seralexeev!

First of all, thank you for your work on ts-blank-space. I've migrated all my projects to use it, and everything works great. It has been a breath of fresh air in the complex world of building TypeScript projects in monorepos

I'm really pleased to hear this 😀

Thank you so much for finding this issue. I think this is a bug, and it can be supported. The output can be:

const fn = async (



  ) => null;

Moving the opening paren up to where the generic type began. This is similar to how a multi-line return type is fixed up.

@acutmore
Copy link
Collaborator

I've raised #19. should be an easy fix. I'll look into this today.

@seralexeev
Copy link
Author

Hey @acutmore. Thanks for the super quick response and your effort 🔥

@seralexeev seralexeev closed this Oct 31, 2024
@acutmore
Copy link
Collaborator

@seralexeev the fix is available in [email protected].

Thanks again for the report!

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

Successfully merging this pull request may close these issues.

2 participants