2017-03-01 84 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" 
] 

而......就是这样!