A fairly common case I'm trying to figure out how to handle, is type annotation in json objects returned by some API.
The spec says:
Apart from primitives, the most common sort of type you’ll encounter is an object type. This refers to any JavaScript value with properties, which is almost all of them! To define an object type, we simply list its properties and their types. For example, here’s a function that takes a point-like object:
// The parameter's type annotation is an object type
function printCoord(pt: { x: number; y: number }) {
console.log("The coordinate's x value is " + pt.x);
console.log("The coordinate's y value is " + pt.y);
}
printCoord({ x: 3, y: 7 });
So we should type every parameter and nested objects? What if I don't know in advance the response body? What if the body is very long and rich in nested objects and arrays of objects?
Which would be the best practice, or the sensible alternatives in the latter case?