microsoft / TypeScript-TmLanguage

TextMate grammar files for TypeScript for VS Code, Sublime Text, and Atom.
MIT License
397 stars 125 forks source link

TS Syntax highlight broken for multiline generic arguments of function in object #1028

Open wolflu05 opened 2 months ago

wolflu05 commented 2 months ago

Type: Bug

When having a function with generic type params in an object and the generic type params wrap into multiple lines, the TS syntax highlighting is broken.

To reproduce, just paste the following code in a .ts file and see the broken output:

const myObj = {
  test<
    A extends Record<string, any>,
    C extends Record<string, any>,
    B extends Record<string, any>,
  >(a: A, b: B, c: C): Record<string, any>[] {
    if ('hello' in a) {
      console.log('Test');
    }
    return [a, b, c];
  },
};

For reference, I added the same function but outside of the object which shows the correct/broken highlight in comparison: image

VS Code version: Code 1.88.1 (e170252f762678dec6ca2cc69aba1570769a5d39, 2024-04-10T17:42:52.765Z) OS version: Darwin x64 22.6.0 Modes:

MCFX2 commented 2 weeks ago

Issues like this have been repeatedly opened and closed as wontfix/design limitation. See #767 and its siblings.

Unfortunately this issue has been known for 5 years and activity here has slowed significantly, down to just basically bare minimum maintenance. The best advice I can give you is "try to format your code a different way", or consider using a different editor.

wolflu05 commented 2 weeks ago

Issues like this have been repeatedly opened and closed as wontfix/design limitation. See #767 and its siblings.

This is very sad, as typescript is not just any language, it's a language created by Microsoft.

The best advice I can give you is "try to format your code a different way", or consider using a different editor.

So you suggest I should create an issue at prettier to not break generic arguments into multiple lines if the function is defined in an object? I don't think it's prettiers responsibility to handle this case, and such an issue would be closed as wontfix, as it's actually the wanted behavior.