I am using Emacs with org-babel mode to insert the TypeScript code example in my org-mode document.
The elisp I have added in .emacs.d/init.el
is as follows:
(eval-after-load "org" '(org-babel-do-load-languages 'org-babel-load-languages '((typescript . t))))
(require 'typescript-mode)
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode))
(require 'tide)
Now, I want to make the following code as error:
#+BEGIN_SRC typescript :results output
let data_1: string = undefined;
let data_2: string = null;
#+END_SRC
I think I can make it by specifying tsconfig.json
as:
{
"compilerOptions": {
"strictNullChecks": true,
},
}
But where can I put tsconfig.json
?
I modified ~/.emacs.d/elpa/tide-20200327.1218/tsserver/tsconfig.json
and restarded Emacs but nothing changed.
I ran tsc
from the command line and confirmed tsconfig.json
works as expected.
Thank you.
To make the code you've mentioned display an error, you can use the :cmdline
parameter. That allows you to pass command line parameters (such as --strictNullChecks
) directly to tsc
:
#+BEGIN_SRC typescript :cmdline --strictNullChecks :results output
let data_1: string = undefined;
let data_2: string = null;
#+END_SRC
I don't think you can use tsconfig.json
to configure this, because to evaluate the code block, emacs first saves the code to a temp file (e.g. /tmp/babel-5NJb2Q/ob-input-Afjtyu
) and then runs the tsc
on it (see ob-typescript.el). That temp file bears no relation to your tsconfig.json
.