Aiven-Open / Aiven-Open/klaw

refactor(coral): Remove type casting in useSearchParams

Open
#695 0 comments 0 reactions 0 assignees View on GitHub
Frontend
Dominant language
Java
Stars
195
Forks
77
Avg merge
8d 9h
Merged PRs (30d)
1

Description

# What is currently missing?

Currently, we do `as Type` type casting in some of our use of `searchParmas.get`: https://github.com/Aiven-Open/klaw/blob/main/coral/src/app/features/components/filters/useFiltersContext.tsx#L71-L89

This is actually a potential source of bugs for people entering search params directly in the URL: if they enter a value that is incorrect, we won't know about it, and will send wrong values as part of our API requests, which would result in an error:

![Screenshot 2023-02-24 at 09 45 20](https://user-images.githubusercontent.com/20607294/221134396-51978005-2183-41b3-ba9b-8fa344ef56f9.png)

# How could this be improved?

- remove type casting
- add typeguards to ascertain the type of the search params we get, for example:

```ts
const isRequestStatus = (param: string | null): param is RequestStatus => {
return param !== null && statusList.includes(param)
}

```

# Is this a feature you would work on yourself?

* [ ] I plan to open a pull request for this feature

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.