This article demonstrates how to migrate an existing JavaScript function that performs GraphQL requests into type-safe TypeScript. It details the process of defining interfaces for API responses and handling object mutation safely using Omit and Object.assign.
Key points
Defining interface types for nested GraphQL response structures improves type safety.
Use Omit to derive types when adding temporary helper fields like fetchedAt to existing API data.
Object.assign provides a concise way to merge dynamic properties into an existing object while maintaining type compatibility.
Explicitly typing the JSON structure returned by the fetch API avoids 'any' type pitfalls.