News for hackers. Stuff that matters.
Re:Go 1.18 by goodoldneon on Tuesday March 15, 2022 @02:52PM (#30689382)
A more robust type system can help you deal with coordination between various nooks of a codebase.

For example, let's say our platform supports multiple authentication methods. If we need to add a new auth method, how do we know all the spots we need to update? TypeScript can handle this using a sum type:

  type AuthMethods = "push" | "sms" | "fancy_new_thing"

  // No errors
  const authMethodHandlers: {[key in AuthMethods]: CallableFunction} = {
      push: () => {},
      sms: () => {},
      fancy_new_thing: () => {},
  }

  // Error: Property 'fancy_new_thing' is missing
  const authMethodTitles: {[key in AuthMethods]: string} = {
      push: "Push",
      sms: "SMS",
  }
With the above approach, static analysis tells us when we missed a spot. That adds a ton of safety and expedites feature work (since engineers don't need to manually find all the spots that need updating).

There are no comments on this comment yet.