'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
.hatulapro
.hatulapro•2y ago
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
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Leke
Leke•2y ago
Resolved thanks
Want results from more Discord servers?
Add your server