0

I have the following code on a React proyect using typescript:

  interface ICountry {
    id: string;
    name: string;
  }
...

const [countries, setCountries] = useState<ICountry[] | undefined>();
...
       <Dropdown>
          <DropdownTrigger>
            <Button variant="bordered">Open Menu</Button>
          </DropdownTrigger>
          <DropdownMenu aria-label="Static Actions" items={countries}>
            {(country) => (
              <DropdownItem
                key={country.id}
                value={country.id}
                onPress={(e: any) => setCountry(e.currentTarget.value)}
              >
                {country.name}
              </DropdownItem>
            )}
          </DropdownMenu>
        </Dropdown>

The problem is that country is a generic object and I get this error :

Property 'id' does not exist on type 'object'.

enter image description here

How can I type country to be able to use the properties of the objects and stop getting this error?

MCSI
  • 2,818
  • 26
  • 35

0 Answers0