neoclide / coc-tsserver

Tsserver extension for coc.nvim that provide rich features like VSCode for javascript & typescript
MIT License
1.05k stars 68 forks source link

Syntax error with .tsx files - CoC does not recognise .tsx files to have .jsx syntax #299

Closed jininvt closed 3 years ago

jininvt commented 3 years ago

I am getting errors on all TSX / JSX code in my .tsx file. Attached is a screenshot of the App.tsx file you get when you run npx create-react-app --template typescript repo-name

One example of an error I'm seeing is: [tsserver 2304] [E] Cannot find name 'className'.

It seems that CoC does not recognise that .tsx files have .jsx syntax. Btw there is no issue with any .jsx files.

Screenshot 2021-06-24 at 9 04 06 PM

chemzqm commented 3 years ago

Fix your filetype option

jininvt commented 3 years ago

And how can I do that exactly? I've followed the instructions on the CoC Github page but the problem is still occurring.

Below is the updated coc-settings.json file. I've added in Lines 14 to 19.

Screenshot 2021-06-25 at 8 30 09 PM
chemzqm commented 3 years ago

Please read https://github.com/neoclide/coc-tsserver#coc-tsserver

jininvt commented 3 years ago

From what I understand I have to use g:coc_filetype_map to map tsx to typescriptreact. I have look at the example here but it still doesn't work. What am I missing?

Screenshot 2021-06-25 at 9 06 21 PM
saltedpotatos commented 3 years ago

For anyone else having this issue, this fixed it for me.

Quoting here in case link goes down:

Had a similar issue. Does :set ft output typescript?

If so, tsserver needs filetype to be ˋtypescriptreact` to parse your file as intended.

Add the following to your init.vim file:

augroup ReactFiletypes
autocmd!
autocmd BufRead,BufNewFile *.jsx set filetype=javascriptreact
autocmd BufRead,BufNewFile *.tsx set filetype=typescriptreact
augroup END
rafaVls commented 2 years ago

For anyone else having this issue, this fixed it for me.

Quoting here in case link goes down:

Had a similar issue. Does :set ft output typescript? If so, tsserver needs filetype to be ˋtypescriptreact` to parse your file as intended. Add the following to your init.vim file:

augroup ReactFiletypes
  autocmd!
  autocmd BufRead,BufNewFile *.jsx set filetype=javascriptreact
  autocmd BufRead,BufNewFile *.tsx set filetype=typescriptreact
augroup END

I had the same problem. and this solution fixed it for me.