Skip to content

React-redux Continuing #21417, unable to pass props from parent without TS2322 complaining about missing properties #25103

@harshita-gupta

Description

@harshita-gupta

typescript@next does not fix the issue.

Going off issue #21417

Code
I define the component class and connect it as follows:

export class SkypeConversationArea extends React.Component<Props> {..}
const mapStateToProps = (state: State) => {
  return {
    loading: state.loading,
    hangUp: state.conversation.hangUp,
    selfParticipantStatus: state.conversation.selfParticipant.status
  }
}

const mapDispatchToProps = (dispatch: any) => {
  return {
    saveRef: (ref: HTMLElement) => {
      dispatch(saveConersationAreaRef(ref))
    },
    setFullscreen: (set: boolean) => {
      dispatch(setFullscreen(set))
    }
  }
}

type ReceivedProps = {
  lifecycleEndpointNotifyConfigured: (event: LIFECYCLE_EVENT) => any
};
type StateProps = ReturnType<typeof mapStateToProps>;
type DispatchProps = ReturnType<typeof mapDispatchToProps>;
type Props = StateProps & DispatchProps & ReceivedProps;

export default connect<StateProps, DispatchProps, ReceivedProps>(mapStateToProps, mapDispatchToProps)(SkypeConversationArea);

When I attempt to use the component in a parent component's render function, and pass in only "receivedProps", as such:

<SkypeConversationArea lifecycleEndpointNotifyConfigured={props.lifecycleEndpointNotifyConfigured} />

I get the error
TS2322: Type '{ lifecycleEndpointNotifyConfigured: (event: string) => any; }' is not assignable to type 'Readonly'. Property 'loading' is missing in type '{ lifecycleEndpointNotifyConfigured: (event: string) => any; }'.

My understanding is that I should be able to pass props from the parent and not have to worry about including the props in mapstatetoprops and mapdispatchtoprops. I believe that this is a bug, but I'm new to react-redux-typescript so not sure.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions