【发布时间】:2017-08-13 23:40:18
【问题描述】:
我的项目使用打字稿做出反应。我需要使用 react-breadcrumbs 来显示 react-router 的面包屑。
现在我将两个 @type 包添加到我的 package.json 中
"dependencies": {
"@types/react-breadcrumbs": "^1.3.7",
"@types/react-router": "^3.0.8"
}
react-breadcrumb 需要使用 route.props.name 来显示面包屑的名称,但是当我在 npm 中使用 @type 包时 Route.d.ts文件在RouteProps接口中没有名字Props。
interface RouteProps extends IndexRouteProps {
path?: RoutePattern;
}
interface IndexRouteProps {
component?: RouteComponent;
components?: RouteComponents;
getComponent?: (nextState: RouterState, callback: ComponentCallback) => void;
getComponents?: (nextState: RouterState, callback: ComponentsCallback) => void;
onEnter?: EnterHook;
onChange?: ChangeHook;
onLeave?: LeaveHook;
}
所以我需要直接编辑node_modules中的Route.d.ts文件到
export interface RouteProps extends IndexRouteProps {
path?: RoutePattern;
name?: String;
}
如果我不编辑它,我会编译错误并显示
错误 TS2339:类型上不存在属性“名称” 'IntrinsicAttributes & IntrinsicClassAttributes> & Readonly<...>
我认为直接编辑 node_modules 文件不是一个好习惯。
我可以用其他方法自定义类型文件吗?
谢谢。
【问题讨论】:
标签: javascript typescript react-router react-jsx typescript-typings