首页 > 解决方案 > TypeScript 为 Semantic UI fullTextSearch 参数错误地抛出错误 TS2769

问题描述

当我将 TypeScript 与语义 UI 搜索功能一起使用时,即使存在参数“fullTextSearch”,我也会收到以下错误。为什么 TypeScript 就在那里时看不到它?

代码

   $('#'+this.uiSearch.id)
    .search({
      name: this.name+' Search',
      namespace: "search"+this.uiSearch.id,
      type: 'category',
      source: categoryContent,
      fullTextSearch: "exact",
      maxResults: 30,
      searchFields: ["category", "title", "description"],
      minCharacters: 0,
      onSelect: this.selectEntry,
    });

错误

js/browser/catalogueSelect.js:123:11 - error TS2769: No overload matches this call.
The last overload gave the following error.
 Argument of type '{
  name: string; namespace:
  string;
  type: string;
  source: { category: any; title: any; id: any; description: any; }[];
  fullTextSearch: string;
  maxResults: number;
  searchFields: string[];
  minCharacters: number;
  onSelect: (result: any, response: any) => void;
 }'
 is not assignable to parameter of type 'Param'.
  Object literal may only specify known properties, and 'fullTextSearch' does not exist in type 'Param'.

123           fullTextSearch: "exact",

node_modules/@types/semantic-ui-search/global.d.ts:100:9
100         (settings?: SearchSettings): JQuery;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The last overload is declared here.

文档

根据语义 UI 搜索文档

fullTextSearch 'exact' 指定为“true”将使用模糊全文搜索,设置为“exact”将强制精确搜索匹配字符串中的某处,设置为 false 将仅匹配字符串的开头。(此设置以前称为 searchFullText。)

细节

PS:我误解了错误消息,似乎“类型参数”描述了实际输入,而不是预期的输入,并且 global.d.ts 文件包含旧参数名称“searchFullText”而不是新参数名称“fullTextSearch ”。

标签: typescriptsemantic-ui

解决方案


@types/semantic-ui: "^2.2.7"已过时。

它仍然包含旧的“searchFullText”而不是新的“fullTextSearch”。我在以下网址报告了这一点:https ://github.com/Semantic-Org/Semantic-UI/issues/6961


推荐阅读