find-a-mentor-api icon indicating copy to clipboard operation
find-a-mentor-api copied to clipboard

Stronger Type Safety for Auth0Id

Open brentmclark opened this issue 5 years ago • 0 comments

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.

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.

brentmclark avatar Feb 12 '21 16:02 brentmclark