UP | HOME

Unconciously wasting CPU by forgetting tsconfig.json

Since the beginning of this week, I configured my Emacs to recognize JS files as TypeScript, and with the help of tide, I'm now able to have my Emacs nagging about returning string for a boolean function when I write my Backbone code.

But soon enough, I encountered a problem. Everytime I switch to another JS file, Emacs seems to get slower. Curiously, I run M-x tide-list-servers and holy cow, there are a lot of tsserver instance running, each of them has their own project, which is a folder that contains the file I'm openning.

The main reason for this is because I don't have tsconfig.json added in the root of my project, so tide can't determine where is the project root (which is stupid, why don't you pick the place where we have .git?), so it create a new tsserver instance, assuming I'm openning a new project everytime.

To fix this problem, just create a tsconfig.json file at the project root, I put something like this for the content, general enough to not depends on anything:

{
  "compilerOptions": {

    "target": "es5",
    "module": "commonjs",         
    "lib": [],                    
    "allowJs": true,              
    "checkJs": true,              
    "declaration": true,          
    "sourceMap": true,            
    "outFile": "./",              
    "outDir": "./",               
    "rootDir": "./",              
    "removeComments": true,       
    "noEmit": true,               
    "importHelpers": true,        
    "downlevelIteration": true,   
    "isolatedModules": true,      
  },
  "include": [
    "src/**/*"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

Date: 2019-05-03 Fri 00:00

Author: Huy Tran

Created: 2019-05-12 Sun 23:50