【问题标题】:react-bootstrap-typeahead labelKey Typescriptreact-bootstrap-typeahead labelKey 打字稿
【发布时间】:2021-10-20 07:25:46
【问题描述】:

我有与 ericgio 对这个问题的回答 React AsyncTypeahead using Typescript 中讨论的相同的问题(但从未回答过)

labelKey

的类型定义似乎有问题

我从这段代码中得到以下错误:

<Typeahead
     id="basic-typeahead-single"
     labelKey="name"
     onChange={this.changeEdgeName}
     options={this.state.streetNames}
     placeholder=""
    />

Overload 2 of 2, '(props: TypeaheadProps, context?: any): Typeahead',给出了以下错误。 类型“字符串”不可分配给类型“未定义”。 TS2769

依赖:

"@types/react-bootstrap-typeahead": "^3.4.6",
    
"react-bootstrap-typeahead": "^5.1.1",

【问题讨论】:

    标签: reactjs typescript twitter-bootstrap react-bootstrap react-bootstrap-typeahead


    【解决方案1】:

    我找到了解决方法!

    我将标签分离到它自己的组件中,在该组件中,由于某种原因不需要 labelKey。

    我不知道为什么会这样,但它对我有用!

    【讨论】:

    • 你能举个例子吗?
    【解决方案2】:

    我可以通过以下方式解决这个问题:

    import { Typeahead, TypeaheadLabelKey } from 'react-bootstrap-typeahead';
    ...
    
    labelKey={'displayName' as TypeaheadLabelKey<string>}
    

    displayName 是您的 labelKey。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-15
      • 2013-12-29
      • 1970-01-01
      • 1970-01-01
      • 2021-02-19
      • 1970-01-01
      相关资源
      最近更新 更多