網站搜尋

tsc - Typescript 編譯器選項 alwaysStrict 無法使用?


在 TypeScript 網站上的編譯器選項頁面列出了 --alwaysStrict 選項,這個選項應該是告訴編譯器在輸出中生成 "use strict" 語句。

請注意,我正在使用 Visual Studio Code 工作。

我在我的 tsconfig.json 中添加了這個選項:

{
    "compilerOptions": {
        "alwaysStrict": true,
        //... blah blah ...

但是當我嘗試構建時,會出現 Unknown compiler option 'alwaysStrict'。

所以,我執行了 tsc 並發現該選項沒有列出,這是從命令提示字元複製的輸出:

Version 2.0.9
Syntax:   tsc [options] [file ...]

Examples: tsc hello.ts
          tsc --outFile file.js file.ts
          tsc @args.txt

Options:
 --allowJs                           Allow javascript files to be compiled.
 --allowSyntheticDefaultImports      Allow default imports from modules with no default export. This does not affect code emit, just typechecking.
 --allowUnreachableCode              Do not report errors on unreachable code.
 --allowUnusedLabels                 Do not report errors on unused labels.
 --baseUrl                           Base directory to resolve non-absolute module names.
 (blah blah, the rest of options alphabetically)

我是不是漏掉了什麼?

答案#1

如你在 TypeScript 的「新功能」中所見,這個 alwaysStrict 標誌是在版本 2.1 中新增的。

如果您想使用此標誌,請更新您的 TypeScript 版本。