2016-11-18 46 views
0

我使用:如何指定布爾爲打字稿編譯器(真/假)選項

$ tsc --version 
Version 2.0.8 

,並試圖通過--experimentalDecoratorsoptiontsc這樣的:

$ tsc --experimentalDecorators true greeter.ts 
//error TS6053: File 'true.ts' not found. 

像這樣

$ tsc greeter.ts --experimentalDecorators true 
//error TS6053: File 'true.ts' not found. 

像這樣

$ tsc greeter.ts --experimentalDecorators=true 
// error TS5023: Unknown compiler option 'experimentaldecorators=true'. 

但沒有運氣。將選項傳遞給tsc的正確方法是什麼?

回答

3

默認情況下,布爾標誌爲false,因此您不需要隨標誌一起指定值。您只需要在包含該標誌時將其從false更改爲true即可。

刪除true

tsc --experimentalDecorators greeter.ts 

對於期待字符串編譯器選項,立即參數以下值指定參數的值。例如:

tsc --module system greeter.ts 

對於期望字符串數組編譯選項,單獨的字符串值應以逗號分隔:

tsc --lib es5,es6 greeter.ts 

編譯器假定在傳遞的值是如果該值的文件名不匹配參數名稱或不在預期的參數值位置。

+0

是的,它的工作,謝謝。但是如果'experimentalDecorators'默認是'true',那麼我該如何指定'false'呢? –

+0

@Maximus默認情況下它與所有其他標誌一樣是false,所以包括它會將值從false更改爲true。 –

+0

謝謝,字符串值的選項怎麼樣,比如'tsc --experimentalDecorators --module =「system」greeter'?這給出了一個錯誤:'未知的編譯器選項'module = system'.' –

1

當前,編譯器允許passing in explicit boolean values

當您針對tsconfig.json進行編譯並且想要爲當前編譯器運行的目的覆蓋特定值時,有一種強大的用例將明確的布爾值傳遞給編譯器。

在這種情況下,想象一下,如果你的tsconfig.jsonexperimentalDecorators假的,你要測試的編譯時,它是true在不改變項目本身:

tsc --experimentalDecorators true greeter.ts 
+0

感謝您的信息 –