Coding-Coach / Coding-Coach/find-a-mentor-api
Stronger Type Safety for Auth0Id
- Dominant language
- TypeScript
- Stars
- 36
- Forks
- 33
- PR merge metrics
- No merged PRs in 30d
Description
While creating PR #184 a concern arose wherein the type applied to the `auth0Id` value in a few places was a `string` which also happens to accept `null` and `undefined` as valid values.
The suggestion at the time was to manually coalesce falsey values to `''` using something like this:
```
auth0Id || ''
```
Which this will certainly work, I don't believe it's not an ideal habit for us to establish. More specifically, I don't think it's a good use of time to manually enforce a level of type safety that the type checker itself is allowing.
What I propose instead is one or both of the following options:
1. Enable strict null checks so that none of the types in the system allow null/undefined unless told to do so explicitly. More can be read on this [here](Nullable Types: https://www.typescriptlang.org/docs/handbook/advanced-types.html#nullable-types).
2. Make a custom type just for the `auth0Id` that adds type-safe validation as well. Here's [an article covering one potential approach](https://medium.com/@dhruvrajvanshi/advanced-typescript-patterns-6cf8826c7944).
I'm not expecting any immediate progress on this topic. I think it's wise for us to consider whether or not we want to solve this problem at all, and, if so, how soon we want to solve this problem.
Contributor guide
Assessment
This issue has not been assessed yet.