2016-10-04 38 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