typescript - 如何将 tsconfig.json 应用于 Emacs org-babel?

标签 typescript emacs org-mode org-babel

我正在使用带有 org-babel 模式的 Emacs 在我的 org-mode 文档中插入 TypeScript 代码示例。 我在.emacs.d/init.el中添加的elisp如下:

(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)

现在,我想将以下代码设置为错误:

#+BEGIN_SRC typescript :results output 
let data_1: string = undefined;
let data_2: string = null;
#+END_SRC

我想我可以通过将 tsconfig.json 指定为:

{
  "compilerOptions": {
    "strictNullChecks": true,
  },
}

但是我可以把tsconfig.json放在哪里?

我修改了 ~/.emacs.d/elpa/tide-20200327.1218/tsserver/tsconfig.json 并重新启动了 Emacs,但没有任何变化。

我从命令行运行了 tsc 并确认 tsconfig.json 按预期工作。

谢谢。

最佳答案

要使您提到的代码显示错误,您可以使用 :cmdline 参数。这允许您将命令行参数(例如 --strictNullChecks)直接传递给 tsc:

#+BEGIN_SRC typescript :cmdline --strictNullChecks :results output
let data_1: string = undefined;
let data_2: string = null;
#+END_SRC

我认为你不能使用 tsconfig.json 来配置它,因为为了评估代码块,emacs 首先将代码保存到临时文件中(例如 /tmp/babel -5NJb2Q/ob-input-Afjtyu),然后在其上运行 tsc (请参阅 ob-typescript.el )。该临时文件与您的 tsconfig.json 没有任何关系。

关于typescript - 如何将 tsconfig.json 应用于 Emacs org-babel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63842382/

相关文章:

javascript - 无法打印到控制台

emacs - 如何发送 M-。到 Emacs 中的终端(多项)

emacs - 交互式输入标题,使用捕获将标题放置在标题下方

node.js - Nodejs promise 捕获 "hell"然后使用 sequelize orm

javascript - Firestore 文档 typescript doc.data() 未定义?

emacs - 无法向 SLIME 发送有趣的字符

bash - `M-x term' 在 MS Windows 上使用 Emacs : error Spawning child process: invalid argument

emacs - 在源代码中存储组织模式TODO

emacs - 如何使用 org-annotate-file?

css - ngClass 不刷新 css 类