2017-03-01 83 views
0

進口陣營+打字稿+的WebPack和UI路由器反應的

import {UIRouter, UIView, UISref, UISrefActive, pushStateLocationPlugin} from 'ui-router-react'; 

時到app.tsx是我一直在關注ui-router-react文檔我有很多用的WebPack問題編譯代碼庫我(https://ui-router.github.io/react/)當我得到這些錯誤:

ERROR in [at-loader] node_modules/ui-router-core/lib/common/common.d.ts:388:31 
    TS7006: Parameter 'a' implicitly has an 'any' type. 

ERROR in [at-loader] node_modules/ui-router-core/lib/common/common.d.ts:388:34 
    TS7006: Parameter 'b' implicitly has an 'any' type. 

ERROR in [at-loader] node_modules/ui-router-core/lib/resolve/resolveContext.d.ts:7:22 
    TS7005: Variable 'NATIVE_INJECTOR_TOKEN' implicitly has an 'any' type. 

ERROR in [at-loader] node_modules/ui-router-core/lib/transition/transitionHook.d.ts:13:37 
    TS7006: Parameter 'error' implicitly has an 'any' type. 

ERROR in [at-loader] src/components/loginComponent.tsx:23:33 
    TS2314: Generic type 'KeyboardEvent<T>' requires 1 type argument(s). 

ERROR in [at-loader] src/components/loginComponent.tsx:32:31 
    TS2314: Generic type 'KeyboardEvent<T>' requires 1 type argument(s). 

我想在我的webpack.config.js的WebPack並不想被看node_modules但很明顯,它是。

這裏是枝下reactRouting鏈接回購

https://github.com/JMStudiosJoe/ReactPractice/tree/reactRouting

+0

這裏有太多的問題需要具體回答。考慮將它們分解成單獨的問題,其中包括配置和中斷組件。 – Chris

回答

1

貌似這些錯誤是如何生成的ui-router-react的分型結果。

如果你看一下,說成node_modules\ui-router-core\lib\common\common.d.ts文件。\,行388,你會看到這個

export declare type sortfn = (a, b) => number; 

正如你所看到的,ab沒有類型信息協會。 w /他們。如果您手動編輯此行,使其看起來像

export declare type sortfn = (a: any, b: any) => number; 

前兩個編譯錯誤將消失。如果轉到您提供的錯誤列表中的每個文件/行,並執行相同的操作,則您的項目將進行編譯。

現在,這當然是一種臨時措施,真正的類型應該是any以外的其他類型。這個(即類型)應該由包裹的作者確定。但是,以這種方式編輯類型定義文件將暫時解除您的阻止。

+0

是的,我注意到,但任何時候我運行npm安裝將需要再次更改這些文件,所以不是一個很好的解決方法,但你的權利是一個。 –

1

有一個問題,但我正在尋找解決方案在tsconfig文件中的webpack配置。當我得到這些錯誤您可以設置"noImplicitAny": false選項擺脫任何錯誤

到app.tsx是:在錯誤[在裝載機] node_modules/UI路由器核心/ lib中/普通/ common.d.ts:388:31 TS7006:參數'a'隱式具有'any'類型。

ERROR in [at-loader] node_modules/ui-router-core/lib/common/common.d.ts:388:34 TS7006:參數'b'隱式具有'any'類型。 錯誤在[at-loader] node_modules/ui-router-core/lib/resolve/resolveContext.d.ts:7:22 TS7005:變量'NATIVE_INJECTOR_TOKEN'隱式具有'any'類型。錯誤'隱含地具有'任何'類型。在這種情況下,'error'參數'error'隱含地具有'any'類型。

爲了擺脫對方的錯誤就把操縱我的類型作出反應函數的參數

usernameValidator = (event: React.KeyboardEvent => { 

改爲

usernameValidator = (event: React.ChangeEvent<HTMLInputElement>) => { 

固定的最後2個問題。

1

我建議不要將"noImplicitAny"設置爲true,因爲它在您自己的代碼庫中非常有用,可以確保您充分利用Typescript(類型檢查)的強大功能之一。

您的問題在於您的打字稿譯員正在處理您的node_modules庫。而你並不是真的想要這樣,因爲你相信你的第三方庫。

,最簡單的方式來阻止那就是簡單地增加一個exclude字段中輸入您tsconfig.jsonhttps://www.typescriptlang.org/docs/handbook/tsconfig-json.html

如果您tsconfig.json是在根文件夾,同樣爲您node_modules文件夾,您可以添加:

"exclude": [ 
    "node_modules" 
] 

而......就是這樣!