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

时间:2020-09-11 07:12:40

标签: typescript emacs org-mode org-babel

我在org-babel模式下使用Emacs在我的org-mode文档中插入TypeScript代码示例。 我在var uploadSession = await _graphServiceClient.Drives[driveId].Items[folderId].ItemWithPath(fileName).CreateUploadSession().Request().PostAsync(); int maxSlice = 320 * 1024; var largeFileUpload = new LargeFileUploadTask<DriveItem>(uploadSession, fileStream, maxSlice); IProgress<long> progress = new Progress<long>(x => { _logger.LogDebug($"Uploading large file: {x} bytes of {fileStream.Length} bytes already uploaded."); }); UploadResult<DriveItem> uploadResult = await largeFileUpload.UploadAsync(progress); resultDriveItem = uploadResult.ItemResponse; 中添加的elisp如下:

.emacs.d/init.el

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

(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失望,但没有任何改变。

我从命令行运行了~/.emacs.d/elpa/tide-20200327.1218/tsserver/tsconfig.json,并确认tsc可以正常工作。

谢谢。

1 个答案:

答案 0 :(得分:1)

要使您提到的代码显示错误,可以使用: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)中,然后运行{{ 1}}(请参阅ob-typescript.el)。该临时文件与您的tsc无关。