2016-11-20 108 views
2

我的應用程序有很多TypeScript錯誤,但運行正常(我將一個JavaScript應用程序移動到了打字稿,並且無法修復所有類型問題...)。我建立了我的編輯器(webstorm)來忽略這些錯誤並編譯應用程序。在使用Angular 2 AoT進行編譯時,可以忽略typescript錯誤嗎?

運行應用程序(JiT)運行良好,但是當我嘗試使用AoT編譯應用程序(我遵循this tuto)時,我得到所有TypeScript錯誤,編譯失敗。我不能粘貼所有的錯誤(有太多),但這裏是一個示例:

Error at C:/app-path/services/app.service.ts:18:23: Property 'saveScroll' does not exist on type 'CanComponentDeactivate'. 
Error at C:/app-path/services/app.service.ts:45:20: Parameter 'object' implicitly has an 'any' type. 
Error at C:/app-path/services/app.service.ts:48:24: Parameter 'mObject' implicitly has an 'any' type. 
Error at C:/app-path/services/app.service.ts:75:30: Property 'value' does not exist on type 'FormBuilder'. 

知道我目前不能修復所有的錯誤(但要保留打字稿),我該怎麼辦能夠編譯?

回答

1

在你的情況下,最快的解決方案是禁用tsconfig.json中的noImplicitAny設置。這修正了2和3.

對於其他類型的錯誤,在編譯器抱怨丟失屬性的地方,您可以回退到將它們投射到any

+0

謝謝,它有助於消除一些錯誤,但我仍然有一噸!我可以繞過他們嗎? – ncohen

+1

不,編譯錯誤無法繞過,除noImplicitAny類型檢查 – marvinhagemeister