yats.vim icon indicating copy to clipboard operation
yats.vim copied to clipboard

Arrow function with generic in TSX

Open alextes opened this issue 5 years ago • 4 comments

I understand this is getting quite ambiguous for the parser 🙈.

In TSX files, arrow functions with generics look a lot like JSX. In this issue the TypeScript side suggests there will be no fix and that extending or having multiple generics are two ways in which the parser can tell the arrow function from JSX. Sadly, this syntax also breaks all highlighting coming after it. Example below.

const updateSet = <T extends {}>(choice, set: Set<T>): Set<T> =>
  choice.isShown ? set.delete(choice.id) : set.add(choice.id);
};
// broken highlighting after this point

alextes avatar Feb 25 '19 10:02 alextes

Sadly this is not easy to fix. To tell generic arrow function from type cast requires complex regexp which usually makes Vim slow...

HerringtonDarkholme avatar Feb 25 '19 12:02 HerringtonDarkholme

FWIW, every other text editor fully supports this 🤷‍♂️

quinn avatar Mar 21 '19 18:03 quinn

@quinn FWIW, no other text editor plugin supports both highlight richness and performance at the same time. Maybe you could send a pull request for generic function here.

HerringtonDarkholme avatar Mar 22 '19 01:03 HerringtonDarkholme

@HerringtonDarkholme sorry about that, I didn’t understand the scope of the problem..

quinn avatar Mar 22 '19 01:03 quinn