2017-10-04 67 views
1

在我的打字稿/ reactjs應用程序我想在這樣的屬性稱爲測試通過,這是index.tsx的一部分:如何解決打字稿錯誤TS2339:屬性'XXX'不存在類型'IntrinsicAttributes&...?

ReactDOM.render(
    <Provider store={getStore()}> 
    <BrowserRouter> 
     <App test={1} /> 
    </BrowserRouter> 
    </Provider>, 
    document.getElementById('content') 
); 

在我app.tsx我:

export class App extends React.Component<any,{}>{ 
    constructor(props){ 
    super(props); 
    } 

    render(){ 
    .. 
    } 
} 

當我運行應用程序,我得到這個錯誤:

ERROR in ./src/index.tsx 
(24,12): error TS2339: Property 'test' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Component<{}, ComponentState>> & Readonly<{ childr...'. 

我怎樣才能確保這個錯誤得到解決或者我怎麼能在財產傳給我的應用程序組件?

回答

0

這似乎是ReactRedux連接的一個大問題,而Typescript,在找到可行解決方案時存在這樣的問題,因此我們的團隊正在認真考慮在我們的反應應用程序中放入Ty​​pescript。

0

您需要爲組件的Props定義一個interface並將其作爲類型參數傳遞給React.Component。這樣,App預計會收到prop,稱爲test。例如:

interface Props { 
    test: <whatever type test is> 
} 

class App extends React.Component<Props, {}> { 

    // your component code 
} 

周圍有connect一些臭名昭著的討論與TS。你可以看看這個SO帖子尋求幫助:Typescript + React/Redux: Property "XXX" does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes

相關問題