'paginationRange.length' is possibly 'undefined'.ts(18048)
I don't know how to get rid of this
error
'paginationRange.length' is possibly 'undefined'.ts(18048)
export type IPaginate = {
totalCount: number
pageSize: number
siblingCount: number
currentPage: number
onPageChange?: () => void
}
paginateHook.ts
👇
export const usePagination = ({totalCount, pageSize, siblingCount = 1, currentPage}: IPaginate) => {
// do something here
}
UsePaginate.tsx
👇
const paginationRange = usePagination({
currentPage,
totalCount,
siblingCount,
pageSize
})
if ( currentPage === 0 || paginationRange?.length < 2){ // 'paginationRange.length' is possibly 'undefined'.ts(18048)
return null
}
3 Replies
when
paginationRange
is falsey, paginationRange.length
returns undefined as well. Then you are comparing undefined to a number, which doesn't make sense (JS will always return false, but TS does not allow that comparison).Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Resolved thanks