0
votes

I am getting error with type 'string'. TS2345

Argument of type 'Item' is not assignable to parameter of type 'string'. TS2345

 filter(resortList:ResortResult[], selectedFilters:SelectedFilters) {
    return resortList
      .filter(resort => {
        let roomTypes = resort.available.flat().map(room => room.roomType);
        let activities = resort.activities;
        let hasRoomType = selectedFilters["room"].some(
          (rt:Item)=> roomTypes.indexOf(rt) > -1
        );
        let hasActivity = selectedFilters["activity"].some(
          (act:Item) => ((activities.indexOf(act.value)) > -1)
        );
        return !(
          (selectedFilters["area"].length === 0 ||
            selectedFilters["area"].indexOf(resort.city) > -1) &&
          // (selectedFilters["views"].length === 0 ||
          //   selectedFilters["views"].indexOf(resort.city) > -1) &&
          (selectedFilters["activity"].length === 0 || hasActivity) &&
          (selectedFilters["room"].length === 0 || hasRoomType)
        );
      })
      .map(resort => {
        return resort.propertyCode;
      });
  }

How can I fix this error with react-typescript? Thanks alot!

1

1 Answers

0
votes

So it looks like you are using typescript. Typescript is a strongly-typed language, meaning that typically you have to define the datatype for a variable before you can use it. This also means that you can only set a variable to the type that it is assigned.

What this error is saying is that you are trying to assign a value that is not a string to a variable where the type is "string". More specifically, it looks like you are trying to assign a whole object (of type "Item") to a variable with the type "string".

You need to check your code and make sure that you are not trying to assign the wrong datatype somewhere. In the small code snippet that you gave, it's a bit difficult to see where the error is.