2016-10-04 35 views
0

我想向RouteProps接口添加一个name属性。没有它,我得到:TypeScript 2.0和合并在Route.d.ts中声明的react-router接口

错误TS2339:房产 '名' 上不存在型 'IntrinsicAttributes &> IntrinsicClassAttributes> & RouteProp ......'

如果我添加name?: string;到外部路由。 d.ts文件错误消失。

我试图合并模块的一些建议的方式没有成功。

外部Route.d.ts声明开始了这样的:

declare const self: self.Route; 
type self = self.Route; 
export default self; 

declare namespace self { 

    interface RouteProps extends React.Props<Route> {... 

我使用打字稿2.

回答

0

我哈瓦同样的问题,我用“模块增强”:https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation

您可以添加新的文件自定义route.d.ts和编写代码

declare module "react-router/lib/Route" { 
    interface RouteProps { 
     name?: String; 
    } 
} 

你可以在 Typescript custom @types package for @types/react-router

+0

中看到我的问题请在你提供的链接中添加一些必要的部分/不支持链接回答。 :) – gofr1