News for hackers. Stuff that matters.
Re:Migrating 300k LOC from Flow to TypeScript by WorldMaker on Thursday June 20, 2019 @01:53PM (#20235381)
When you type json.Parse<T> you are taking on the responsibility that what is returned is actually T. If you want the type checker's help that you are sure it might not be T, then ask for it: json.Parse<unknown> or json.Parse<Partial<T>> is maybe more accurate, and would force you to write runtime checks. Partial<T> in particular is a great helper type that is often exactly what a lot of want in a json.Parse situation: gives you the field autocomplete you want, but reminds you that they may be undefined.

There are no comments on this comment yet.