发送到外部库的参数已声明但从未使用过

时间:2017-12-18 11:23:10

标签: typescript react-native

我正在使用jsoendermann/rn-section-list-get-item-layout npm包来帮助我将getItemLayout属性定义为 SectionList 。我需要定义getItemLayout属性才能使scrollToLocation()起作用。

文档声明它应该像这样使用:

import sectionListGetItemLayout from 'react-native-section-list-get-item-layout'

// cut..

    this.getItemLayout = sectionListGetItemLayout({
      // The height of the row with rowData at the given sectionIndex and rowIndex
      getItemHeight: (rowData, sectionIndex, rowIndex) =>
                                                    sectionIndex === 0 ? 100 : 50,
  }

  render() {
    return (
      <SectionList
        {...otherStuff}
        getItemLayout={this.getItemLayout}
      />
    )
  }
}

TypeScript(2.5.3)编译器抱怨这一行:

getItemHeight :( rowData,sectionIndex,rowIndex)=&gt; sectionIndex === 0? 100:50,

error TS6133: 'rowData' is declared but never used. error TS6133: 'rowIndex' is declared but never used.

我想在{n}包内部使用rowDatarowIndex,但我该如何告诉TS编译器?

1 个答案:

答案 0 :(得分:1)

说服编译器在其他地方使用rowDatasectionIndex可能是徒劳的,因为错误是他们没有在这个特定的函数中使用。

根据https://www.triplet.fi/blog/typescript-getting-rid-of-error-x-is-declared-but-never-used/,解决方案是将rowDatasectionIndex替换为{},这将删除参数名称,从而消除未使用的参数。