Hi! I am using react-bootstrap-typeahead 5.1.8 version. When I using typeahead it's show mistake in name. My code:
return (
<>
id="typeahead" onChange={actor => { console.log(actor); }} options={actors} labelKey={actor => actor.name} filterBy={['name']} placeholder="Write the name of the actor..." minLength={1} /> > ) Error: any Property 'name' does not exist on type 'Option'. View Problem No quick fixes available
Property 'name' does not exist on type 'string'.ts(2339)
Keith MollenkopfPosted Nov 29, 2022, 9:42 PM
I figured out a simple solution for this when I was doing this tutorial as well. The latest version of React and TypeAhead seems to break the original code.
I'm not a React expert so this may not be the best solution but a simple typecast worked for me.
id="typeahead"
onChange={actor => {
console.log(actor);
}}
options={actors}
labelKey={actor => (actor as actorMovieDTO).name}
filterBy={['name']}
placeholder="Type the name of the actor..."
minLength={1}
flip={true}
renderMenuItemChildren={actor => {
return (
<>
style={{
height: '64px',
marginRight: '10px',
width: '64px'
}} />
{(actor as actorMovieDTO).name}
>
);
}}
/>