Aiven-Open / Aiven-Open/klaw

refactor(coral): Remove type casting in useSearchParams

未关闭
#695 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Frontend
主要语言
Java
星标
195
派生
77
平均合并
8 天 9 小时
30 天内合并 PR
1

描述

# 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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。