Skip to content

Instantly share code, notes, and snippets.

@benjaminjackman
Last active September 7, 2018 20:11
Show Gist options
  • Save benjaminjackman/0db88b6eb5880ff9e39d747a014ffad3 to your computer and use it in GitHub Desktop.
Save benjaminjackman/0db88b6eb5880ff9e39d747a014ffad3 to your computer and use it in GitHub Desktop.
Workaround for typescript#25023 (--watch mode hangs tsc)

This work around uses chokidar (which must be installed & on the path e.g. npm install -g chokidar)

I had to write a custom bash script tsc-noemit-tombstoned to give the problem matcher a way to detect when compilation starts and ends, that will need to be copied to a local file and be in your path as well

tldr

  1. Install chokidar npm install -g chokidar
  2. Download tsc-noemit-tombstoned, put it into your path and make it executable
  3. Copy tasks.json into your project's existing vscode tasks.json and modify the args to match where your source files are located (mine are typically all under a ./src folder in my projects)
//This can be used in VSCode to run the build, I have it set as the default build task
{
"label": "typescript:chokidar",
"type": "shell",
"command": "chokidar",
"isBackground": true,
//NOTE: You will want to chage the src/**/* portion to be appropriate for your project
"args": ["src/**/*", "--silent", "--initial", "-c", "tsc-noemit-tombstoned"],
"problemMatcher": {
"owner": "typescript",
"fileLocation": "relative",
"pattern": {
"regexp": "^([^\\s].*)\\((\\d+|\\d+,\\d+|\\d+,\\d+,\\d+,\\d+)\\):\\s+(error|warning|info)\\s+(TS\\d+)\\s*:\\s*(.*)$",
"file": 1,
"location": 2,
"severity": 3,
"code": 4,
"message": 5
},
"background": {
"beginsPattern": "^COMPILATION HAS BEGUN.*$",
"endsPattern": "^COMPILATION HAS CONCLUDED.*$"
}
},
"group": {
"kind": "build",
"isDefault": true
}
},
#!/bin/bash
echo COMPILATION HAS BEGUN
tsc --noEmit --pretty false
echo COMPILATION HAS CONCLUDED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment