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

typescript: misaligned indentation when using function shorthand with generic #132

Closed
zanona opened this issue Jun 21, 2020 · 4 comments
Closed

Comments

@zanona
Copy link

zanona commented Jun 21, 2020

Whenever having the following on typescript:

const foo = <T extends string>(key:T) => {};
useEffect(doAction, []);
...

The indented result becomes like:

const foo = <T extends string>(key:T) => {};
   useEffect(doAction, []);
   ....

This is due to foo accepting a generic <T extends string>, as if we take out the generic, the indentation works as expected.

The only workaround at the moment is declaring a long form function as:

const link = function<T extends string>(key:T) {};
useEffect(doAction, []);
...

I've noticed that this doesn't happen on yats.vim, but whenever having both yats.vim and vim-jsx-pretty, I believe that this plugin overrides the indentation rules set by yats.vim.

@yuezk yuezk added the bug label Jun 22, 2020
@yuezk
Copy link
Collaborator

yuezk commented Jun 22, 2020

It's similar to #86.

It's hard to differentiate the JSX syntax from generic syntax in typescript with plain regex syntax highlighting because the following is also a valid JSX syntax.

const T = 'div';

return <T extends string>text</T>;

Currently, we will treat all the <T as a generic and this problem can be resolved.

BTW, even though I comment out vim-jsx-pretty, this problem still exists on my machine.

@yuezk
Copy link
Collaborator

yuezk commented Jun 22, 2020

@zanona Update the plugin and try again.

@zanona
Copy link
Author

zanona commented Jun 22, 2020

@yuezk That works perfectly now. Thanks so much for adjusting this so quickly.

@zanona zanona closed this as completed Jun 22, 2020
@malectro
Copy link

sorry for the necromancy, but i'm curious if allowing generics with names other than T is an impossible problem to solve or if the TS/Flow highlighting should run after the jsx highlighting? currently vim-polyglot runs vim-javascript before jsx_pretty.

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

No branches or pull requests

3 participants