Dealing with Strictness

Learn to handle TypeScript strictness.

We'll cover the following

Current errors

In compiling the file (venue-display), we receive several errors:

  • The venue-display file that kicks off the call to React does not handle a potentially undefined value.
  • The SortController does a parseInt with a potentially null value.
  • The debounce method in SearchController is nonfunctional and we’ll need to restructure that.
  • The CalendarController has a few cases where we use the target.dataset.
  • The thunk dispatches in App are incompatible with any potential null values.

Fixing the Errors

Using other strict options would give us more errors. In particular, the “no explicit any” might be a problem, but this should be enough for us to deal with to get the idea.

Our venue_display file has essentially the same issue four times over. That is, we have code like element.dataset["rows"], which is now technically of type string | undefined, meaning the union type of a string or undefined, and we are passing it through to arguments that expect strings.

What we need to do is allow for the possibility that the values are undefined by creating default values. This is a quick solution for our purposes:

Get hands-on with 1200+ tech skills courses.