티스토리 뷰

react-table 라이브러리를 사용해서 recoil atom 데이터를 테이블로 만들려고 한다. useSortBy로 정렬기능과, useGlobalFilter로 검색기능을 구현하는데 에러가 생겼다.
타입스크립트를 사용해서 생기는 에러였다.

 

error1

getSortByToggleProps 에러메세지:
Property 'getSortByToggleProps' does not exist on type 'HeaderGroup

'.ts(2339)
'HeaderGroup' 형식에 'getSortByToggleProps' 속성이 없습니다.ts(2339)


error2

setGlobalFilter 에러메세지:
Property 'setGlobalFilter' does not exist on type 'TableInstance

'.ts(2339)
'TableInstance' 형식에 'setGlobalFilter' 속성이 없습니다.ts(2339)



해결방법

두 에러는 모두 react-table-config.d.ts파일을 생성함으로써 해결할 수 있다.


npm i --save-dev @types/react-table

react-table DefinitelyTyped 라이브러리를 설치했는데


These types depend upon declaration merging to work well. To get started, create a file react-table-config.d.ts using the example further down this readme, place it in your source tree (e.g. into a types folder). This expands the default types with all of the plugin extensions currently in the type definitions.

DefinitelyTyped/types/react-table Readme에
typescript로 react-table을 사용할 때 react-table-config.d.ts파일을 가지고 작업하라는 설명이 있다.


react-table-config.d.ts 파일을 생성하고 아래 코드를 저장하자.

//react-table-config.d.ts
import {
  UseColumnOrderInstanceProps,
  UseColumnOrderState,
  UseExpandedHooks,
  UseExpandedInstanceProps,
  UseExpandedOptions,
  UseExpandedRowProps,
  UseExpandedState,
  UseFiltersColumnOptions,
  UseFiltersColumnProps,
  UseFiltersInstanceProps,
  UseFiltersOptions,
  UseFiltersState,
  UseGlobalFiltersColumnOptions,
  UseGlobalFiltersInstanceProps,
  UseGlobalFiltersOptions,
  UseGlobalFiltersState,
  UseGroupByCellProps,
  UseGroupByColumnOptions,
  UseGroupByColumnProps,
  UseGroupByHooks,
  UseGroupByInstanceProps,
  UseGroupByOptions,
  UseGroupByRowProps,
  UseGroupByState,
  UsePaginationInstanceProps,
  UsePaginationOptions,
  UsePaginationState,
  UseResizeColumnsColumnOptions,
  UseResizeColumnsColumnProps,
  UseResizeColumnsOptions,
  UseResizeColumnsState,
  UseRowSelectHooks,
  UseRowSelectInstanceProps,
  UseRowSelectOptions,
  UseRowSelectRowProps,
  UseRowSelectState,
  UseRowStateCellProps,
  UseRowStateInstanceProps,
  UseRowStateOptions,
  UseRowStateRowProps,
  UseRowStateState,
  UseSortByColumnOptions,
  UseSortByColumnProps,
  UseSortByHooks,
  UseSortByInstanceProps,
  UseSortByOptions,
  UseSortByState,
} from "react-table";
declare module "react-table" {
  // take this file as-is, or comment out the sections that don't apply to your plugin configuration
  export interface TableOptions<
    D extends Record<string, unknown>
  > extends UseExpandedOptions<D>,
      UseFiltersOptions<D>,
      UseGlobalFiltersOptions<D>,
      UseGroupByOptions<D>,
      UsePaginationOptions<D>,
      UseResizeColumnsOptions<D>,
      UseRowSelectOptions<D>,
      UseRowStateOptions<D>,
      UseSortByOptions<D>,
      // note that having Record here allows you to add anything to the options, this matches the spirit of the
      // underlying js library, but might be cleaner if it's replaced by a more specific type that matches your
      // feature set, this is a safe default.
      Record<string, any> {}
  export interface Hooks<
    D extends Record<string, unknown> = Record<string, unknown>
  > extends UseExpandedHooks<D>,
      UseGroupByHooks<D>,
      UseRowSelectHooks<D>,
      UseSortByHooks<D> {}
  export interface TableInstance<
    D extends Record<string, unknown> = Record<string, unknown>
  > extends UseColumnOrderInstanceProps<D>,
      UseExpandedInstanceProps<D>,
      UseFiltersInstanceProps<D>,
      UseGlobalFiltersInstanceProps<D>,
      UseGroupByInstanceProps<D>,
      UsePaginationInstanceProps<D>,
      UseRowSelectInstanceProps<D>,
      UseRowStateInstanceProps<D>,
      UseSortByInstanceProps<D> {}
  export interface TableState<
    D extends Record<string, unknown> = Record<string, unknown>
  > extends UseColumnOrderState<D>,
      UseExpandedState<D>,
      UseFiltersState<D>,
      UseGlobalFiltersState<D>,
      UseGroupByState<D>,
      UsePaginationState<D>,
      UseResizeColumnsState<D>,
      UseRowSelectState<D>,
      UseRowStateState<D>,
      UseSortByState<D> {}
  export interface ColumnInterface<
    D extends Record<string, unknown> = Record<string, unknown>
  > extends UseFiltersColumnOptions<D>,
      UseGlobalFiltersColumnOptions<D>,
      UseGroupByColumnOptions<D>,
      UseResizeColumnsColumnOptions<D>,
      UseSortByColumnOptions<D> {}
  export interface ColumnInstance<
    D extends Record<string, unknown> = Record<string, unknown>
  > extends UseFiltersColumnProps<D>,
      UseGroupByColumnProps<D>,
      UseResizeColumnsColumnProps<D>,
      UseSortByColumnProps<D> {}
  export interface Cell<
    D extends Record<string, unknown> = Record<string, unknown>,
    V = any
  > extends UseGroupByCellProps<D>,
      UseRowStateCellProps<D> {}
  export interface Row<
    D extends Record<string, unknown> = Record<string, unknown>
  > extends UseExpandedRowProps<D>,
      UseGroupByRowProps<D>,
      UseRowSelectRowProps<D>,
      UseRowStateRowProps<D> {}
}




저장하면 ...

error_debug

에러표시 제거^_^ 잘 된다 !

이전 블로그(hahagarden.github.io)에서 이전해온 글입니다.

반응형

'개발 > TIL' 카테고리의 다른 글

Git과 Github  (0) 2023.03.09
Module not found Error 해결방법  (0) 2023.03.07
패키지와 패키지매니저 / Node.js  (0) 2023.03.07
JS 문법 Koans  (0) 2023.03.06
웹 개발 / HTML / VSCode  (2) 2023.03.03
댓글