2017-04-27 24 views
1

我使用了React,material-ui,Flow,Jest在我的測試中做快照的設置。TypeScript material-ui允許未在@types中定義的道具

爲了創建一致的快照,我需要在我的material-ui組件中定義id,否則它們會自動生成並且每次都會有所不同。

,所以我這樣做: <Card style = { style } id = { id ? $ {ID} -card : null }>

這工作得很好。現在我切換到TypeScript,並有@ types/material-ui。打字稿抱怨的ID道具:

[ts] Property 'id' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Card> ...

我做錯什麼了嗎?有沒有辦法抑制這一點?我知道該組件支持傳遞一個id。

回答

0

我結束了創建typings/material-ui/index.d.ts

declare namespace __MaterialUI 
{ 
    interface SelectFieldProps 
    { 
     multiple?: boolean; 
     selectionRenderer?: (values: any[]) => string; 
    } 

    namespace Card 
    { 
     interface CardProps 
     { 
     id?: string; 
     } 

     interface CardHeaderProps 
     { 
     id?: string; 
     } 

     interface CardTitleProps 
     { 
     id?: string; 
     } 

     interface CardActionsProps 
     { 
     id?: string; 
     } 

     interface CardTextProps 
     { 
     id?: string; 
     } 
    } 
} 

和tsconfig:

"include": [ "./components/**/*", "./typings/**/*" ],

這個固定我的問題