NWACus / avy

Mobile-Native Viewing of NAC Avalanche Forecasts
MIT License
10 stars 6 forks source link

Add type safety to fieldRefs #716

Closed beaucollins closed 5 months ago

beaucollins commented 5 months ago

fieldRefs is more accurately represented as a const Record type. By as consting the strict key and value types are captured by the type system.

Before, it's an array of objects that get searched through

image

After, it's a Record of explicit keys and ref values:

image

We don't need getFieldRef anymore, the keys are statically known. And no more iterating just to look up the correct ref.

stevekuznetsov commented 5 months ago

Love it. I wish we could decorate the actual form context with the refs since we're not enforcing that the keys here match anything in the form, but /shrug. I know you saw some of the other TODOs around typing in here - we originally wrote this without strict tsconfig on, which let us be a little loosey-goosey, and adding types after the fact was tricky since I'm not an expert in TypeScript magic.