代码之家  ›  专栏  ›  技术社区  ›  Konrad Höffner

TypeScript错误地为语义UI fullTextSearch参数抛出错误TS2769

  •  0
  • Konrad Höffner  · 技术社区  · 6 年前

    当我将TypeScript与Semantic UI search函数一起使用时,即使存在参数“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.
    

    文档

    根据 Semantic UI Search documentation :

    将搜索设置为“精确搜索” 匹配字符串中的某个位置,设置为false将只匹配到 字符串开头。(此设置以前称为searchFullText。)

    细节

    • TypeScript 3.7.5版
    • 带有JSDoc注释的JavaScript代码,通过 tsc --noEmit
    • 包.json包括 "@types/semantic-ui": "^2.2.7"

    P、 S:我误解了错误消息,似乎“parameter of type”描述的是实际输入,而不是预期的输入,global.d.ts文件包含旧的参数名“searchFullText”而不是新的“fullTextSearch”。

    0 回复  |  直到 6 年前
        1
  •  0
  •   Konrad Höffner    6 年前

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

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