diff --git a/src/DataGrid.tsx b/src/DataGrid.tsx index be71e20960..40dc2d4590 100644 --- a/src/DataGrid.tsx +++ b/src/DataGrid.tsx @@ -22,8 +22,10 @@ import { createCellEvent, getCellStyle, getColSpan, + getColumnInColumns, getLeftRightKey, getNextActivePosition, + getRowInRows, isCellEditableUtil, isCtrlKeyHeldDown, isDefaultCellInput, @@ -365,33 +367,54 @@ export function DataGrid(props: DataGridPr enableVirtualization }); + /** + * computed values + */ + const isTreeGrid = role === 'treegrid'; const topSummaryRowsCount = topSummaryRows?.length ?? 0; const bottomSummaryRowsCount = bottomSummaryRows?.length ?? 0; const summaryRowsCount = topSummaryRowsCount + bottomSummaryRowsCount; const headerAndTopSummaryRowsCount = headerRowsCount + topSummaryRowsCount; const groupedColumnHeaderRowsCount = headerRowsCount - 1; const minRowIdx = -headerAndTopSummaryRowsCount; - const mainHeaderRowIdx = minRowIdx + groupedColumnHeaderRowsCount; const maxRowIdx = rows.length + bottomSummaryRowsCount - 1; + const mainHeaderRowIdx = minRowIdx + groupedColumnHeaderRowsCount; + const minColIdx = isTreeGrid ? -1 : 0; + const maxColIdx = columns.length - 1; + const headerRowsHeight = headerRowsCount * headerRowHeight; + const summaryRowsHeight = summaryRowsCount * summaryRowHeight; + const clientHeight = gridHeight - headerRowsHeight - summaryRowsHeight; + const isSelectable = selectedRows != null && onSelectedRowsChange != null; + const { leftKey, rightKey } = getLeftRightKey(direction); + const ariaRowCount = rawAriaRowCount ?? headerRowsCount + rows.length + summaryRowsCount; const frozenShadowStyles: React.CSSProperties = { gridColumnStart: lastFrozenColumnIndex + 2, insetInlineStart: totalFrozenColumnWidth }; - const [activePosition, setActivePosition] = useState>( - getInitialActivePosition + const initialActivePosition: ActiveCellState = { idx: -1, rowIdx: minRowIdx - 1, mode: 'ACTIVE' }; + let [activePosition, setActivePosition] = useState>( + initialActivePosition ); - /** - * computed values - */ - const isTreeGrid = role === 'treegrid'; - const headerRowsHeight = headerRowsCount * headerRowHeight; - const summaryRowsHeight = summaryRowsCount * summaryRowHeight; - const clientHeight = gridHeight - headerRowsHeight - summaryRowsHeight; - const isSelectable = selectedRows != null && onSelectedRowsChange != null; - const { leftKey, rightKey } = getLeftRightKey(direction); - const ariaRowCount = rawAriaRowCount ?? headerRowsCount + rows.length + summaryRowsCount; + // Reinitialize the active position and immediately use the new state + // if the current values are no longer valid. + // This can happen when a column or row is removed. + if ( + !( + activePosition.idx === initialActivePosition.idx && + activePosition.rowIdx === initialActivePosition.rowIdx && + activePosition.mode === initialActivePosition.mode + ) && + (activePosition.idx < minColIdx || + activePosition.idx > maxColIdx || + activePosition.rowIdx < minRowIdx || + activePosition.rowIdx > maxRowIdx) + ) { + activePosition = initialActivePosition; + setActivePosition(initialActivePosition); + setDraggedOverRowIdx(undefined); + } const defaultGridComponents = useMemo( () => ({ @@ -441,7 +464,6 @@ export function DataGrid(props: DataGridPr enableVirtualization }); - const maxColIdx = columns.length - 1; const { isPositionInActiveBounds: activePositionIsInActiveBounds, isPositionInViewport: activePositionIsInViewport, @@ -575,7 +597,7 @@ export function DataGrid(props: DataGridPr ) { const step = sign(rowIdx - previousRowIdx); for (let i = previousRowIdx + step; i < rowIdx; i += step) { - const row = rows[i]; + const row = getRow(i); if (isRowSelectionDisabled?.(row) === true) continue; if (checked) { newSelectedRows.add(rowKeyGetter(row)); @@ -646,7 +668,7 @@ export function DataGrid(props: DataGridPr function updateRow(column: CalculatedColumn, rowIdx: number, row: R) { if (typeof onRowsChange !== 'function') return; - if (row === rows[rowIdx]) return; + if (row === getRow(rowIdx)) return; const updatedRows = rows.with(rowIdx, row); onRowsChange(updatedRows, { indexes: [rowIdx], @@ -656,29 +678,34 @@ export function DataGrid(props: DataGridPr function commitEditorChanges() { if (activePosition.mode !== 'EDIT') return; - updateRow(columns[activePosition.idx], activePosition.rowIdx, activePosition.row); + updateRow(getColumn(activePosition.idx), activePosition.rowIdx, activePosition.row); } function handleCellCopy(event: CellClipboardEvent) { if (!activePositionIsCellInViewport) return; const { idx, rowIdx } = activePosition; - onCellCopy?.({ row: rows[rowIdx], column: columns[idx] }, event); + onCellCopy?.({ row: getRow(rowIdx), column: getColumn(idx) }, event); } function handleCellPaste(event: CellClipboardEvent) { - if (!onCellPaste || !onRowsChange || !isCellEditable(activePosition)) { + if ( + typeof onCellPaste !== 'function' || + typeof onRowsChange !== 'function' || + !isCellEditable(activePosition) + ) { return; } const { idx, rowIdx } = activePosition; - const column = columns[idx]; - const updatedRow = onCellPaste({ row: rows[rowIdx], column }, event); + const column = getColumn(idx); + const row = getRow(rowIdx); + const updatedRow = onCellPaste({ row, column }, event); updateRow(column, rowIdx, updatedRow); } function handleCellInput(event: KeyboardEvent) { if (!activePositionIsCellInViewport) return; - const row = rows[activePosition.rowIdx]; + const row = getRow(activePosition.rowIdx); const { key, shiftKey } = event; // Select the row on Shift + Space @@ -765,14 +792,15 @@ export function DataGrid(props: DataGridPr if (onRowsChange == null) return; const { rowIdx, idx } = activePosition; - const column = columns[idx]; - const sourceRow = rows[rowIdx]; + const column = getColumn(idx); + const sourceRow = getRow(rowIdx); const updatedRows = [...rows]; const indexes: number[] = []; for (let i = startRowIdx; i < endRowIdx; i++) { if (isCellEditable({ rowIdx: i, idx })) { - const updatedRow = onFill!({ columnKey: column.key, sourceRow, targetRow: rows[i] }); - if (updatedRow !== rows[i]) { + const targetRow = getRow(i); + const updatedRow = onFill!({ columnKey: column.key, sourceRow, targetRow }); + if (updatedRow !== targetRow) { updatedRows[i] = updatedRow; indexes.push(i); } @@ -787,8 +815,12 @@ export function DataGrid(props: DataGridPr /** * utils */ - function getInitialActivePosition(): ActiveCellState { - return { idx: -1, rowIdx: minRowIdx - 1, mode: 'ACTIVE' }; + function getColumn(index: number) { + return getColumnInColumns(columns, index); + } + + function getRow(index: number) { + return getRowInRows(rows, index); } /** @@ -831,7 +863,7 @@ export function DataGrid(props: DataGridPr function isCellEditable(position: Position): boolean { return ( validatePosition(position).isCellInViewport && - isCellEditableUtil(columns[position.idx], rows[position.rowIdx]) + isCellEditableUtil(getColumn(position.idx), getRow(position.rowIdx)) ); } @@ -843,7 +875,7 @@ export function DataGrid(props: DataGridPr const samePosition = isSamePosition(activePosition, position); if (options?.enableEditor && isCellEditable(position)) { - const row = rows[position.rowIdx]; + const row = getRow(position.rowIdx); setActivePosition({ ...position, mode: 'EDIT', row, originalRow: row }); } else if (samePosition) { // Avoid re-renders if the selected cell state is the same @@ -853,8 +885,8 @@ export function DataGrid(props: DataGridPr setActivePosition({ ...position, mode: 'ACTIVE' }); } - if (onActivePositionChange && !samePosition) { - onActivePositionChange({ + if (!samePosition) { + onActivePositionChange?.({ rowIdx: position.rowIdx, row: rows[position.rowIdx], column: columns[position.idx] @@ -982,14 +1014,14 @@ export function DataGrid(props: DataGridPr } const { idx, rowIdx } = activePosition; - const column = columns[idx]; + const column = getColumn(idx); if (column.renderEditCell == null || column.editable === false) { return; } const isLastRow = rowIdx === maxRowIdx; const columnWidth = getColumnWidth(column); - const colSpan = column.colSpan?.({ type: 'ROW', row: rows[rowIdx] }) ?? 1; + const colSpan = column.colSpan?.({ type: 'ROW', row: getRow(rowIdx) }) ?? 1; const { insetInlineStart, ...style } = getCellStyle(column, colSpan); const marginEnd = 'calc(var(--rdg-drag-handle-size) * -0.5 + 1px)'; const isLastColumn = column.idx + colSpan - 1 === maxColIdx; @@ -1029,16 +1061,16 @@ export function DataGrid(props: DataGridPr } const { idx, row } = activePosition; - const column = columns[idx]; + const column = getColumn(idx); const colSpan = getColSpan(column, lastFrozenColumnIndex, { type: 'ROW', row }); const closeOnExternalRowChange = column.editorOptions?.closeOnExternalRowChange ?? true; - const closeEditor = (shouldFocus: boolean) => { + function closeEditor(shouldFocus: boolean) { setShouldFocusPosition(shouldFocus); setActivePosition(({ idx, rowIdx }) => ({ idx, rowIdx, mode: 'ACTIVE' })); - }; + } - const onRowChange = (row: R, commitChanges: boolean, shouldFocus: boolean) => { + function onRowChange(row: R, commitChanges: boolean, shouldFocus: boolean) { if (commitChanges) { // Prevents two issues when editor is closed by clicking on a different cell // @@ -1051,9 +1083,9 @@ export function DataGrid(props: DataGridPr } else { setActivePosition((position) => ({ ...position, row })); } - }; + } - if (closeOnExternalRowChange && rows[activePosition.rowIdx] !== activePosition.originalRow) { + if (closeOnExternalRowChange && getRow(activePosition.rowIdx) !== activePosition.originalRow) { // Discard changes if rows are updated from outside closeEditor(false); } @@ -1100,7 +1132,7 @@ export function DataGrid(props: DataGridPr ? iterateOverViewportColumnsForRowOutsideOfViewport : iterateOverViewportColumnsForRow; - const row = rows[rowIdx]; + const row = getRow(rowIdx); const gridRowStart = headerAndTopSummaryRowsCount + rowIdx + 1; let key: K | number = rowIdx; let isRowSelected = false; @@ -1135,12 +1167,6 @@ export function DataGrid(props: DataGridPr .toArray(); } - // Reset the positions if the current values are no longer valid. This can happen if a column or row is removed - if (activePosition.idx > maxColIdx || activePosition.rowIdx > maxRowIdx) { - setActivePosition(getInitialActivePosition()); - setDraggedOverRowIdx(undefined); - } - // Keep the state and prop in sync if (isColumnWidthsControlled && columnWidthsInternal !== columnWidthsRaw) { setColumnWidthsInternal(columnWidthsRaw); diff --git a/src/TreeDataGrid.tsx b/src/TreeDataGrid.tsx index 37c366b4fa..ea366e9402 100644 --- a/src/TreeDataGrid.tsx +++ b/src/TreeDataGrid.tsx @@ -2,7 +2,7 @@ import { useCallback, useMemo } from 'react'; import type { Key } from 'react'; import { useLatestFunc } from './hooks'; -import { assertIsValidKeyGetter, getLeftRightKey } from './utils'; +import { assertIsValidKeyGetter, getLeftRightKey, getRowInRows } from './utils'; import type { CellClipboardEvent, CellCopyArgs, @@ -122,7 +122,7 @@ export function TreeDataGrid({ ): [Readonly>, number] => { let groupRowsCount = 0; const groups: GroupByDictionary = {}; - for (const [key, childRows] of Object.entries(rowGrouper(rows, groupByKey))) { + for (const [key, childRows] of Object.entries(rowGrouper(rows, groupByKey!))) { // Recursively group each parent group const [childGroups, childRowsCount] = remainingGroupByKeys.length === 0 @@ -159,7 +159,7 @@ export function TreeDataGrid({ Object.keys(rows).forEach((groupKey, posInSet, keys) => { const id = groupIdGetter(groupKey, parentId); const isExpanded = expandedGroupIds.has(id); - const { childRows, childGroups, startRowIndex } = rows[groupKey]; + const { childRows, childGroups, startRowIndex } = rows[groupKey]!; const groupRow: GroupRow = { id, @@ -189,6 +189,13 @@ export function TreeDataGrid({ } }, [expandedGroupIds, groupedRows, rawRows, groupIdGetter]); + const getRow = useCallback( + (index: number) => { + return getRowInRows(rows, index); + }, + [rows] + ); + const rowHeight = useMemo(() => { if (typeof rawRowHeight === 'function') { return (row: R | GroupRow): number => { @@ -206,7 +213,7 @@ export function TreeDataGrid({ (row: R | GroupRow) => { const rowIdx = rows.indexOf(row); for (let i = rowIdx - 1; i >= 0; i--) { - const parentRow = rows[i]; + const parentRow = getRow(i); if (isGroupRow(parentRow) && (!isGroupRow(row) || row.parentId === parentRow.id)) { return [parentRow, i] as const; } @@ -214,7 +221,7 @@ export function TreeDataGrid({ return undefined; }, - [isGroupRow, rows] + [isGroupRow, rows, getRow] ); const rowKeyGetter = useCallback( @@ -299,7 +306,7 @@ export function TreeDataGrid({ if (args.mode === 'EDIT') return; const { column, rowIdx, setActivePosition } = args; const idx = column?.idx ?? -1; - const row = rows[rowIdx]; + const row = getRow(rowIdx); if (!isGroupRow(row)) return; if ( @@ -347,8 +354,8 @@ export function TreeDataGrid({ const updatedRawRows = [...rawRows]; const rawIndexes: number[] = []; for (const index of indexes) { - const rawIndex = rawRows.indexOf(rows[index] as R); - updatedRawRows[rawIndex] = updatedRows[index]; + const rawIndex = rawRows.indexOf(getRow(index) as R); + updatedRawRows[rawIndex] = getRowInRows(updatedRows, index); rawIndexes.push(rawIndex); } onRowsChange(updatedRawRows, { diff --git a/src/hooks/useCalculatedColumns.ts b/src/hooks/useCalculatedColumns.ts index 9929d91a17..afa9ce4658 100644 --- a/src/hooks/useCalculatedColumns.ts +++ b/src/hooks/useCalculatedColumns.ts @@ -1,6 +1,6 @@ import { useMemo } from 'react'; -import { clampColumnWidth, max, min } from '../utils'; +import { clampColumnWidth, getColumnInColumns, max, min } from '../utils'; import type { CalculatedColumn, CalculatedColumnParent, ColumnOrColumnGroup, Omit } from '../types'; import { renderValue } from '../cellRenderers'; import { SELECT_COLUMN_KEY } from '../Columns'; @@ -189,14 +189,14 @@ export function useCalculatedColumns({ } if (lastFrozenColumnIndex !== -1) { - const columnMetric = columnMetrics.get(columns[lastFrozenColumnIndex])!; + const columnMetric = columnMetrics.get(getColumnInColumns(columns, lastFrozenColumnIndex))!; totalFrozenColumnWidth = columnMetric.left + columnMetric.width; } const layoutCssVars: Record = {}; for (let i = 0; i <= lastFrozenColumnIndex; i++) { - const column = columns[i]; + const column = getColumnInColumns(columns, i); layoutCssVars[`--rdg-frozen-left-${column.idx}`] = `${columnMetrics.get(column)!.left}px`; } @@ -222,7 +222,7 @@ export function useCalculatedColumns({ // get the first visible non-frozen column index let colVisibleStartIdx = firstUnfrozenColumnIdx; while (colVisibleStartIdx < lastColIdx) { - const { left, width } = columnMetrics.get(columns[colVisibleStartIdx])!; + const { left, width } = columnMetrics.get(getColumnInColumns(columns, colVisibleStartIdx))!; // if the right side of the columnn is beyond the left side of the available viewport, // then it is the first column that's at least partially visible if (left + width > viewportLeft) { @@ -234,7 +234,7 @@ export function useCalculatedColumns({ // get the last visible non-frozen column index let colVisibleEndIdx = colVisibleStartIdx; while (colVisibleEndIdx < lastColIdx) { - const { left, width } = columnMetrics.get(columns[colVisibleEndIdx])!; + const { left, width } = columnMetrics.get(getColumnInColumns(columns, colVisibleEndIdx))!; // if the right side of the column is beyond or equal to the right side of the available viewport, // then it the last column that's at least partially visible, as the previous column's right side is not beyond the viewport. if (left + width >= viewportRight) { diff --git a/src/hooks/useGridDimensions.ts b/src/hooks/useGridDimensions.ts index 907d6f02e3..bfeeb7441f 100644 --- a/src/hooks/useGridDimensions.ts +++ b/src/hooks/useGridDimensions.ts @@ -19,7 +19,7 @@ export function useGridDimensions() { setBlockSize(clientHeight); const resizeObserver = new ResizeObserver((entries) => { - const size = entries[0].contentBoxSize[0]; + const size = entries[0]!.contentBoxSize[0]!; // we use flushSync here to avoid flashing scrollbars flushSync(() => { diff --git a/src/hooks/useViewportColumns.ts b/src/hooks/useViewportColumns.ts index a36ceac8a8..ee13e59018 100644 --- a/src/hooks/useViewportColumns.ts +++ b/src/hooks/useViewportColumns.ts @@ -1,6 +1,6 @@ import { useCallback, useMemo } from 'react'; -import { getColSpan } from '../utils'; +import { getColSpan, getColumnInColumns, getRowInRows } from '../utils'; import type { CalculatedColumn, ColSpanArgs, @@ -52,7 +52,7 @@ export function useViewportColumns({ // check viewport rows for (let rowIdx = rowOverscanStartIdx; rowIdx <= rowOverscanEndIdx; rowIdx++) { - yield { type: 'ROW', row: rows[rowIdx] }; + yield { type: 'ROW', row: getRowInRows(rows, rowIdx) }; } // check bottom summary rows @@ -92,21 +92,21 @@ export function useViewportColumns({ const iterateOverViewportColumns = useCallback>( function* (activeColumnIdx): Generator> { for (let colIdx = 0; colIdx <= lastFrozenColumnIndex; colIdx++) { - yield columns[colIdx]; + yield getColumnInColumns(columns, colIdx); } if (columns.length === lastFrozenColumnIndex + 1) return; if (activeColumnIdx > lastFrozenColumnIndex && activeColumnIdx < startIdx) { - yield columns[activeColumnIdx]; + yield getColumnInColumns(columns, activeColumnIdx); } for (let colIdx = startIdx; colIdx <= colOverscanEndIdx; colIdx++) { - yield columns[colIdx]; + yield getColumnInColumns(columns, colIdx); } if (activeColumnIdx > colOverscanEndIdx && activeColumnIdx < columns.length) { - yield columns[activeColumnIdx]; + yield getColumnInColumns(columns, activeColumnIdx); } }, [startIdx, colOverscanEndIdx, columns, lastFrozenColumnIndex] @@ -136,7 +136,7 @@ export function useViewportColumns({ >( function* (activeColumnIdx = -1, args): Generator> { if (activeColumnIdx >= 0 && activeColumnIdx < columns.length) { - const column = columns[activeColumnIdx]; + const column = getColumnInColumns(columns, activeColumnIdx); yield [column, true, args && getColSpan(column, lastFrozenColumnIndex, args)]; } }, diff --git a/src/hooks/useViewportRows.ts b/src/hooks/useViewportRows.ts index 13b8502302..1eef73be7c 100644 --- a/src/hooks/useViewportRows.ts +++ b/src/hooks/useViewportRows.ts @@ -1,6 +1,6 @@ import { useMemo } from 'react'; -import { floor, max, min } from '../utils'; +import { floor, getRowInRows, max, min } from '../utils'; interface ViewportRowsArgs { rows: readonly R[]; @@ -80,14 +80,14 @@ export function useViewportRows({ return { totalRowHeight, gridTemplateRows, - getRowTop: (rowIdx: number) => rowPositions[validateRowIdx(rowIdx)].top, - getRowHeight: (rowIdx: number) => rowPositions[validateRowIdx(rowIdx)].height, + getRowTop: (rowIdx: number) => getRowInRows(rowPositions, validateRowIdx(rowIdx)).top, + getRowHeight: (rowIdx: number) => getRowInRows(rowPositions, validateRowIdx(rowIdx)).height, findRowIdx(offset: number) { let start = 0; let end = rowPositions.length - 1; while (start <= end) { const middle = start + floor((end - start) / 2); - const currentOffset = rowPositions[middle].top; + const currentOffset = getRowInRows(rowPositions, middle).top; if (currentOffset === offset) return middle; diff --git a/src/utils/activePositionUtils.ts b/src/utils/activePositionUtils.ts index 85f125e5d2..fbc03dd1c0 100644 --- a/src/utils/activePositionUtils.ts +++ b/src/utils/activePositionUtils.ts @@ -5,6 +5,7 @@ import type { Maybe, Position } from '../types'; +import { getColumnInColumns, getRowInRows } from '.'; import { getColSpan } from './colSpanUtils'; // https://github.com/vercel/next.js/issues/56480 @@ -60,19 +61,19 @@ function getCellColSpan({ ) { return getColSpan(column, lastFrozenColumnIndex, { type: 'SUMMARY', - row: topSummaryRows[rowIdx + topSummaryRowsCount] + row: getRowInRows(topSummaryRows, rowIdx + topSummaryRowsCount) }); } if (rowIdx >= 0 && rowIdx < rows.length) { - const row = rows[rowIdx]; + const row = getRowInRows(rows, rowIdx); return getColSpan(column, lastFrozenColumnIndex, { type: 'ROW', row }); } if (bottomSummaryRows) { return getColSpan(column, lastFrozenColumnIndex, { type: 'SUMMARY', - row: bottomSummaryRows[rowIdx - rows.length] + row: getRowInRows(bottomSummaryRows, rowIdx - rows.length) }); } @@ -129,7 +130,7 @@ export function getNextActivePosition({ const setHeaderGroupColAndRowSpan = () => { if (moveNext) { // find the parent at the same row level - const nextColumn = columns[nextIdx]; + const nextColumn = getColumnInColumns(columns, nextIdx); let { parent } = nextColumn; while (parent !== undefined) { const parentRowIdx = getParentRowIdx(parent); @@ -141,7 +142,7 @@ export function getNextActivePosition({ } } else if (moveUp) { // find the first reachable parent - const nextColumn = columns[nextIdx]; + const nextColumn = getColumnInColumns(columns, nextIdx); let { parent } = nextColumn; let found = false; while (parent !== undefined) { @@ -195,7 +196,7 @@ export function getNextActivePosition({ // Find the last reachable parent for the new rowIdx // This check is needed when navigating to a column // that does not have a parent matching the new rowIdx - const nextColumn = columns[nextIdx]; + const nextColumn = getColumnInColumns(columns, nextIdx); let { parent } = nextColumn; const nextParentRowIdx = nextRowIdx; nextRowIdx = mainHeaderRowIdx; diff --git a/src/utils/colSpanUtils.ts b/src/utils/colSpanUtils.ts index da83a5c6d3..a5958f5131 100644 --- a/src/utils/colSpanUtils.ts +++ b/src/utils/colSpanUtils.ts @@ -3,7 +3,7 @@ import type { CalculatedColumn, ColSpanArgs } from '../types'; export function getColSpan( column: CalculatedColumn, lastFrozenColumnIndex: number, - args: ColSpanArgs + args: ColSpanArgs, NoInfer> ): number | undefined { if (typeof column.colSpan !== 'function') return undefined; diff --git a/src/utils/index.ts b/src/utils/index.ts index ad576ba528..80d9736517 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -10,6 +10,23 @@ export * from './styleUtils'; export const { min, max, floor, sign, abs } = Math; +export function getColumnInColumns( + columns: readonly CalculatedColumn[], + index: number +) { + if (index < 0 || index >= columns.length) { + throw new Error(`columns[${index}] is out of bounds (length: ${columns.length})`); + } + return columns[index]!; +} + +export function getRowInRows(rows: readonly R[], index: number) { + if (index < 0 || index >= rows.length) { + throw new Error(`rows[${index}] is out of bounds (length: ${rows.length})`); + } + return rows[index]!; +} + export function assertIsValidKeyGetter( keyGetter: Maybe<(row: NoInfer) => K> ): asserts keyGetter is (row: R) => K { diff --git a/tsconfig.lib.json b/tsconfig.lib.json index e1cc3af350..6e3366feca 100644 --- a/tsconfig.lib.json +++ b/tsconfig.lib.json @@ -4,7 +4,8 @@ "composite": false, "declaration": true, "lib": ["ESNext", "DOM", "DOM.Iterable", "DOM.AsyncIterable"], - "noCheck": true + "noCheck": true, + "noUncheckedIndexedAccess": true }, "files": ["src/index.ts"], "include": ["src/globals.d.ts"] diff --git a/tsconfig.src.json b/tsconfig.src.json index b535e9f135..91fda87a05 100644 --- a/tsconfig.src.json +++ b/tsconfig.src.json @@ -1,7 +1,8 @@ { "extends": "./tsconfig.base.json", "compilerOptions": { - "lib": ["ESNext", "DOM", "DOM.Iterable", "DOM.AsyncIterable"] + "lib": ["ESNext", "DOM", "DOM.Iterable", "DOM.AsyncIterable"], + "noUncheckedIndexedAccess": true }, "include": ["src/**/*"] }