在ericgio对这个问题的回答中,我有同样的问题(但从未回答),React AsyncTypeahead using Typescript
labelKey的类型定义似乎有问题。
我从这段代码中得到以下错误:
<Typeahead
id="basic-typeahead-single"
labelKey="name"
onChange={this.changeEdgeName}
options={this.state.streetNames}
placeholder=""
/>重载2中的2,‘(道具: TypeaheadProps,上下文?:any):Typeahead',给出了以下错误。类型'string‘不能分配到键入'undefined’。TS2769
依赖关系:
"@types/react-bootstrap-typeahead": "^3.4.6",
"react-bootstrap-typeahead": "^5.1.1",发布于 2020-08-25 09:59:27
我找到解决办法了!
我将标记分离到它自己的组件,在该组件中,由于某种原因不需要labelKey。
我不知道这是为什么,但对我来说是这样的!
发布于 2021-10-19 23:25:46
我可以通过以下几个方面来解决这个问题:
import { Typeahead, TypeaheadLabelKey } from 'react-bootstrap-typeahead';
...
labelKey={'displayName' as TypeaheadLabelKey<string>}displayName是你的labelKey。
https://stackoverflow.com/questions/63575786
复制相似问题