1

We've started using TypeScript along with Emacs as thats our editor of choice.

One issue we have found is that the TypeScript error line format doesn't appear to be compatible with the Emacs compilation mode error handling.

e.g.

If we compile a C program and introduce a deliberate error we get

t1.c:6:5: error: use of undeclared identifier 'a'                                       

If we do the same for the TypeScript compiler we get (ignore the message, its the format thats important)

utilities.ts(13,18): error TS2384: Overload signatures must all be ambient or non-ambient.

Emacs can handle the first type of error message using the key command ESC-g n and will move the main editor window to the error.

Emacs cannot handle the second error line format.

We have hacked together a workaround by wrapping the TypeScript compiler in a Perl script and got the Perl script to reformat the lines appropriately. This works but is a bit of kludge and it would be nice if TypeScript had a little more flexibility.

We were wondering if there is a flag or some way to change the Typescript error output to a format that is compatible with Emacs.

3 Answers 3

1

The t1.c:6:5: ... format is actually the official format documented in the GNU Coding Standards, so I think you should contact the authors of the Typescript compiler and ask them to change the format of their error messages.

In the mean time, you'll want to tweak compilation-error-regexp-alist to explain to compile.el how to recognize Typescript's error messages.

Probably something like

(eval-after-load 'compile
  (add-to-list 'compilation-error-regexp-alist
               '("^\\([^(\n]+\\)(\\([0-9]+\\),\\([0-9]+\\)):" 1 2 3)))

might get you started. If some of the messages are not actual errors but more like warnings or side-information, you can refine the above. See C-h v compilation-error-regexp-alist RET for details of the format.

Sign up to request clarification or add additional context in comments.

Comments

1

You can also turn off the pretty mode by running something like tsc --pretty false app.ts and then emacs compile mode will start to recognize the error output.

Comments

0

To reiterate what Dimitri said above, you can wrap the tsc call in a Makefile in the normal way:

TSC = tsc
TSCFLAGS := --noEmitOnError --pretty false

.PHONY: clean

all: app.js

app.js: app.ts
    $(TSC) $(TSCFLAGS) $<

clean:
    rm -f *.js

Now you can M-x compile and then M-x next-error and Emacs will be able to interpret the tsc output properly (because of the --pretty option).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.