Typescript error when using component in React+Redux sample #196

Closed
opened 2025-08-09 17:15:22 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @AleksandrAlbert on 1/31/2018

When using the default Redux+React template, placing a component passed through the connect function into jsx causes TypeScript to throw an error:

Usage:

import Counter from './Counter'

export default class Home extends React.Component<RouteComponentProps<{}>, {}> {
    public render() {
        return <div>
            <Counter /> // <-- Throws error
             ...
        </div>;
    }
}

Error   TS2322  (TS) Type '{}' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Counter> & Readonly<{ children?: ReactNode; }> & R...'.
  Type '{}' is not assignable to type 'Readonly<CounterProps>'.
    Property 'count' is missing in type '{}'. 

I am able to stop this error by changing the type assertion of the connect function to any as follows:

export default connect(
     ...
)(Counter) as any

Is this expected behaviour?

*Originally created by @AleksandrAlbert on 1/31/2018* When using the default Redux+React template, placing a component passed through the `connect` function into jsx causes TypeScript to throw an error: Usage: ``` import Counter from './Counter' export default class Home extends React.Component<RouteComponentProps<{}>, {}> { public render() { return <div> <Counter /> // <-- Throws error ... </div>; } } ``` ``` Error TS2322 (TS) Type '{}' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Counter> & Readonly<{ children?: ReactNode; }> & R...'. Type '{}' is not assignable to type 'Readonly<CounterProps>'. Property 'count' is missing in type '{}'. ``` I am able to stop this error by changing the type assertion of the `connect` function to `any` as follows: ``` export default connect( ... )(Counter) as any ``` Is this expected behaviour?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#196
No description provided.