How to Configure LSP for TypeScript in Neovim

Second post in the series: How to configure LSP for your programming language in Neovim.


How to Configure LSP for TypeScript in Neovim


In previous post we showed how easy it is to configure LSP for the programming language Lua and in this article we will see how to configure LSP for one of the most used languages by web developers which is the famous one: TypeScript .

If you read the previous article you will see that there is no secret, however, having the Neovim settings as this other one series, it’s critical!


Install LSP for TypeScript

First you need to have typescript-language-server installed on your system. For this you can (and should) use NPM, if you are in systems that use the APT package manager, to install, simply:

sudo apt install nodejs npm

Use search from your system’s package manager to find the correct name, but usually they are referred to by these same names.

Now use npm to install typescript and typescript-language-server, with the following command:

sudo npm install -g typescript typescript-language-server

Configure Neovim

After installing the LSP for TypeScript, you now have to “call” it in your Neovim settings. In my case I use the settings I showed in the series mentioned above, which is the ~/.config/nvim/lua/plugins/lsp.lua file, but if you want to test it, you can try ~/.config/nvim/init.lua , however, the first case is ideal.

Enter the line below:

require'lspconfig'.tsserver.setup {}


Testing

After everything is installed and added as mentioned above, just test!

Remember that the LSP for TypeScript will only work if you have a package.json in the directory where you are writing the TypeScript code.

Create a project:

mkdir TEST
cd TEST
npm install typescript --save-dev
nvim index.ts

Write your code and if everything is ok, you will have: function details, error and warning information, autocomplete and among others. Examples:

TypeScript LSP 1 TypeScript LSP 2 TypeScript LSP 3 TypeScript LSP 4 TypeScript LSP 5


Useful links


neovim typescript javascript


Share


YouTube channel

Subscribe


Marcos Oliveira

Marcos Oliveira

Software developer
https://github.com/terroo

Related articles