2017-10-04 68 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

相关问题