27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
import type { Dispatch, SetStateAction } from "react";
|
|
|
|
export type GridRow = Record<string, string | number>;
|
|
|
|
/**
|
|
* DataGrid가 제네릭이 아니라 rowData: Record<string, string|number>[] 를 그대로 요구함
|
|
* (실제 타입 에러로 확인됨: ts(2322), "missing properties from PopulationStatusItem").
|
|
*
|
|
* 훅/탭 내부에서는 명시적 도메인 타입(PopulationStatusItem 등)을 그대로 쓰고,
|
|
* DataGrid에 넘기는 이 경계에서만 캐스팅한다. 내부 로직의 타입 안정성은 유지하면서
|
|
* 외부 라이브러리(DataGrid)의 느슨한 타입과의 경계만 명시적으로 표시하는 용도.
|
|
*/
|
|
export function asGridRowData<T>(data: T[]): GridRow[] {
|
|
return data as unknown as GridRow[];
|
|
}
|
|
|
|
export function asGridRowSetter<T>(setter: Dispatch<SetStateAction<T[]>>): Dispatch<SetStateAction<GridRow[]>> {
|
|
return setter as unknown as Dispatch<SetStateAction<GridRow[]>>;
|
|
}
|
|
|
|
/**
|
|
* DataGrid의 onRowClick 등에서 넘어오는 GridRow(Record<string,string|number>)를
|
|
* 도메인 타입으로 되돌릴 때 사용. `as unknown as T`를 매번 직접 쓰지 않도록 모아둠.
|
|
*/
|
|
export function fromGridRow<T>(row: GridRow): T {
|
|
return row as unknown as T;
|
|
} |