Dealing with a messy API that returns inconsistent values is quite challenging. Instead of manually creating types for each entry, I am looking for a way to infer the types programmatically.
One approach could be by analyzing an array like this:
const array = [
{
title: "test",
name: "Katy Smith",
},
{
title: ["ACNM", "AAF3"],
name: "Mary Williams,
},
{
title: "test2",
name: { firstName: "John", lastName: "Doe" },
},
];
The goal is to automatically infer the type using TypeScript or similar tools, resulting in something like this:
{
title: string | string[],
name: string | {firstName: string, lastName: string}
}
My next step would be to save this inferred type and reuse it in my project, but unfortunately, TypeScript does not exist at runtime making this impossible.
Are there any alternate approaches to achieve this?