guards: accept readonly arrays (and other array-likes) in isEmpty / hasElements / safeLength
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- frontend
Research direction
The guards live in src/utils/guards.ts; widen the isEmpty, safeLength and hasElements parameter types there and leave runtime behaviour alone. The two // guards-ok call sites to convert are src/bus/deriveEvents.ts line 82 and src/utils/abciQuery.ts line 70. Add readonly-array, Uint8Array, null and undefined cases to guards.test.ts, then confirm tsc -b passes.
Written by the indexing model from the issue text.
Description
Problem
isEmpty, hasElements and safeLength in src/utils/guards.ts only accept a mutable T[]:
export function isEmpty<T>(arr: T[] | null | undefined): boolean
export function hasElements<T>(arr: T[] | null | undefined): arr is T[]
export function safeLength<T>(arr: T[] | null | undefined): number
A readonly T[], which is what SDK DTO arrays and as const data usually are, isn't assignable to T[]. Typed arrays (Uint8Array) aren't either. Code holding one of those can't use the guard, so it keeps the raw check marked // guards-ok.
Two of the four // guards-ok lines left by the #937 migration are there only because of this:
src/bus/deriveEvents.ts:82:if (!actions || actions.length === 0) { // guards-ok.actionsis a readonlyActionDTO[](#940).src/utils/abciQuery.ts:70:if (bytes.length === 0) return ""; // guards-ok.bytesis aUint8Array(#941).
The other two (audio/actionSoundPlayer.ts, components/playPage/TableErrorPage.tsx) are legitimate: there, null and undefined mean different things.
Proposal
Widen the parameter types. Runtime behaviour doesn't change.
export function isEmpty(arr: ArrayLike<unknown> | null | undefined): boolean
export function safeLength(arr: ArrayLike<unknown> | null | undefined): number
export function hasElements<A extends readonly unknown[]>(arr: A | null | undefined): arr is A
hasElements keeps narrowing to the caller's own array type, readonly or not.
Then:
- Convert the two lines above and drop their
// guards-ok. - Add cases to
guards.test.tsfor a readonly array, aUint8Array,nullandundefined. - Check that
tsc -bstill passes at every existing call site. Any caller that relied onhasElementsnarrowing to a mutable array will show up there.
Related: #937 (guard migration), #940, #941.
🤖 Generated with Claude Code
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 5
- Avg merge
- 22h 35m
- Merged PRs (30d)
- 91
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from block52/ui
-
feat(ui): player notes and tags — click a seat to note a player; tag icons (fish, shark, tight, loose…) show by their pillPossibly taken @Dzeezbtc claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
chore(ui): move existing inline null/empty and typeof checks to the guardsPossibly taken @bitcoinbrisbane claimed this 1 day ago. Openrefactor tech debt UI
Maintainers usually reply within 1 day
-
architecture refactor tech debt
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
Maintainers usually reply within 1 day
-
feat(ui): display side pots separately when a player is all-inPossibly taken @TexasHODL claimed this today. OpenWeek 2
Difficulty 4/5 3-5 days Newbie friendliness 45/100
block52/ui#918 · 2 comments · 2 assignees ·
Maintainers usually reply within 1 day
Similar issues
-
Remove unused dependenciesPossibly taken @alastair-smith claimed this today. Openchore other
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
alastair-smith/card-games#384 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
code-yeongyu/senpi#5571 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nexu-io/open-design#9262 · 1 comment ·
Maintainers usually reply within 1 day
-
friction
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kentcdodds/kody#4753 ·
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 62/100
lingdojo/kana-dojo#33508 · 1 comment · 5 reactions ·
Maintainers usually reply within 1 day