vim-jsx-pretty icon indicating copy to clipboard operation
vim-jsx-pretty copied to clipboard

Broken .tsx highlighting for arrow functions using generics

Open noahbrenner opened this issue 4 years ago • 1 comments

I'm running into inconsistencies in highlighting between ft=typescript and ft=typescriptreact.

I'm using yats.vim, vim-javascript, and of course vim-jsx-pretty, all just updated using vim-plug.

Some example code:

const doFoo = <K extends keyof Foo>(key: K, value: Foo[K], foos: Foo[]) => {
  foos[0][key] = value;
};

const doBar = (bar: string) => {
  return bar;
};
  • When filetype is typescript: image

  • When filetype is typescriptreact: image

    • Highlighting is broken for the generic parameter, which looks like it's treated as a JSX element.
    • Highlighting is broken for the function parameters, function body, and for the next function (it's broken for all following functions, I just included 1 in the example).
  • Surprisingly (to me :smile:), the behavior is affected by the name of the generic variable. If I use T instead of K, I get this: image

    • Highlighting for the generic parameter is still broken, but in a different way than above. Now it's all the default text color.
    • Highlighting is correct for the function parameters, function body, and the following function(s).

For simple generics, I can get away with just using T for now, but that's not always the best type variable to use, doesn't cover functions that need more than one generic parameter, and is still missing highlighting for the type parameters themselves.

noahbrenner avatar Nov 03 '21 01:11 noahbrenner