Dealing with Strictness
Explore techniques to manage strict typing in TypeScript within Rails projects. Understand how to handle potential undefined values, fix common errors in controllers and debounce methods, and improve code reliability by preventing runtime issues through robust type validation.
We'll cover the following...
We'll cover the following...
Current errors
In compiling the file (venue-display), we receive several errors:
- The
venue-displayfile that kicks off the call to React does not handle a potentially undefined value. - The
SortControllerdoes aparseIntwith a potentiallynullvalue. - The
debouncemethod inSearchControlleris nonfunctional and we’ll need to restructure that. - The
CalendarControllerhas a few cases where we use thetarget.dataset. - The thunk dispatches in
Appare incompatible with any potentialnullvalues.
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 ...