1
votes
  this.setState({buildingName: building.name})

I am trying to pass value to the state but getting this error:

Argument of type '{ buildingName: string; }' is not assignable to parameter of type 'MoveInFormState | ((prevState: Readonly, props: Readonly) => MoveInFormState | Pick<MoveInFormState, "buildingName"> | null) | Pick<...> | null'. Type '{ buildingName: string; }' is not assignable to type 'Pick<MoveInFormState, "buildingName">'. Types of property 'buildingName' are incompatible. Type 'string' is not assignable to type '{ [key: string]: string; }'.

type MoveInForm = Pick<
  Types.Form.IFormData,
  "submitted" | "apartmentId" | "id" | "status" | "applicants"
>;

interface MoveInFormState {
  buildingName: {[key: string]: string}
}

this.state = {
      buildingName: {}
   };
1

1 Answers

1
votes

Read the last part of the error message.

Type 'string' is not assignable to type '{ [key: string]: string; }'.

It looks like building.name is a string value, and the component state is expecting a Record<string, string> mapping. It's likely the form should be using a string for the build name, but that depends on your app.