Checking Types Against the Real World in TypeScript
This is an excerpt of a post that I wrote for Olio Apps.
The shape of data defines a program. There are important benefits to writing out types for your data.
Let’s consider a Hacker News client, which consumes stories and other items from the Hacker News API. This is a TypeScript type that describes the format for stories:
;
In Javascript and other dynamically-typed languages, it is common to write a program without any explicit description of a data structure like Story. The shape of the data is implied in the code that manipulates the data. But that means anyone reading the code has to mentally reconstruct that shape from context, or refer to documentation outside of the program itself.
» Read the rest on the Olio Apps blog.