Sublime Forum

How Can I Get Intellisense for Typescript?

#1

What is the best way of getting intellisense for typescript files in Sublime Text3?

I am looking for (i) real-time error checking and (ii) code completion.

Here is some more detail:

In Atom, for instance, there is this: https://github.com/TypeStrong/atom-typescript.

I have downloaded Microsoft’s Typescript Plugin (https://github.com/Microsoft/TypeScript-Sublime-Plugin), but I haven’t been able to get it to work right, or at least not in the way I am hoping. It does make code suggestions when I am typing, but the suggestions are not actually specific to the code I am typing(!) It is the same very long list of suggestions no matter what code is there. I also tried CodeIntel, but that does not seem to cover typescript.

For real-time editing, I have tried SublimeLinter, but for the life of me I cannot get it to put error marks in the gutter (even after following installation and instructions–options I choose in the command palette don’t get saved). It also seems to not kick in sometimes.

Are there other options out there to get the intellisense experience that VSCode, IntelliJ, and Atom (with the Atom-Typescript plugin) provide?

0 Likes

#2

Typescript plugin intellisense works differently, it only respects suggestions from tsserver which might not be enough most of the times. It actually blocks sublime's default suggestions reason you intellisense doesn’t work as expected.

I opened an issue about this and closed recently with a solution to get suggestions from local file and tsserver which has been working great for me.

Here is the link https://github.com/Microsoft/TypeScript-Sublime-Plugin/issues/600

For realtime error checking you need sublimeLinter, tslintContrib and a valid tslint.json.

Another catch here is typescript plugin comes with its own compilation errors which is different from lint errors provided by sublimeLinter.

Hope this helps.

0 Likes

#3

Thank you for your reply. For code completion, I followed the instructions you gave in the github issue for typescript. They were very clear, and I believe code completion is working well now. (I had previously downloaded the “TypescriptCompletion” package, and I wonder if that was interfering with things. I have disabled it.)

For error checking, I am not able to get it to work. There seems to be something off or missing in my system. I have just downloaded a fresh Sublime Text 3 two days ago, so everything should be new. But I am also seeing issues with other plugins–several of them seem to not be working at all.

Like “NativeScript Snippets”–that one worked smoothly on Atom, but it is not doing anything at all on my Sublime. And I downloaded HTMLLint, and that seems to not be working at all (including after quitting and restarting). Similarly, when I go to “Choose Gutter Theme” for SublimeLinter and click on a gutter theme, it makes no difference. Nothing happens.

Maybe there is something else interfering with them. For trying to get SublimeLinter to work with typescript, I have tried to download tslint, but, weirdly, when I go to “PackageControl: Install Packages”, there is no tslint result, and no “SublimeLinter-Contrib-tslint” that shows up.

When I download these packages, I general go through package control: install, see that it is downloaded, and then restart sublime. Is there something else I need to do?

One update: for tslint, I looked in the sublime console, and I got this message: “SublimeLinter: tslint output:
No valid rules have been specified”. Googling that error has not come up with anything yet.

And I get this too: "SublimeLinter: WARNING: htmllint deactivated, cannot locate ‘’ "

0 Likes

#4

I had a lot of detail in my last message, so I thought I would boil it down:

I have downloaded several packages that don’t seem to be “kicking in.” Most importantly, I have downloaded SublimeLinter and Sublime-Linter-Contrib-tslint, but no errors show up in the gutter. The only error checking I am getting is a squigly line under error code. What could be going wrong?

Console shows this message: “SublimeLinter: tslint output: No valid rules have been specified”

0 Likes

#5

I am also getting these console messages:

SublimeLinter: tslint output:
Warning: The 'no-unused-variable' rule requires type information. 
SublimeLinter: No match for <_sre.SRE_Pattern object at 0x1069051e0> 

I have removed and reinstalled both SublimeLinter and the tslint accompaniment. No linting is happening. Any ideas?

0 Likes

#6

Like @Surya mentioned, to get SublimeLinter to work with typescript, I need to have a valid tslint.json file. Where do I locate that, and how do I need to configure it?

I do not see it within my packages folder. From what I can tell, this would be the case anytime someone wants to use SublimeLinter with typescript.

0 Likes

#7

FYI, the steps noted here have got this to work for me: https://github.com/SublimeLinter/SublimeLinter/issues/997#issuecomment-366172203

  1. follow installation steps at https://palantir.github.io/tslint/. ‘$ tslint --init’ creates the necessary tslint.json file.

  2. If not already done, install sublimelinter-contrib-tslint package

  3. in ‘SublimeLinter.sublime-settings --User’, point to the json file created in step 1, like the config_filename line below:

    “tslint”: {
    @disable”: false,
    “args”: [],
    “config_filename”: “/Users/[$YOURNAME]/desktop/tslint.json”,
    “excludes”: []
    }

  4. these steps enabled me to link SublimeLinter to tslint. The next step is to add in the relevant rules that you want in your tslint.json file.

I have not found a standard recommendation on rules for typescript, but (for typescript with angular2+) I have found success using the “rules” configuration from here: https://github.com/NativeScript/nativescript-angular/blob/master/nativescript-angular/tslint.json

(I have not used codelyzer for the rules directory, so did not insert that line from the repo)

0 Likes