Hey there, I've got a little dilemma. Imagine I have a type called A
:
type A = {
prop1: string,
prop2: {
prop3: string
}
}
Now, let's say I'm getting a JSON object from an outside service and I need to check if that JSON aligns with type A
:
function isA(obj:any): boolean {
// What's the best approach here?
}
If my obj
looks something like this:
{
prop1: "Hello",
prop2: {
prop3: "World"
}
}
or like this:
{
prop1: "Hello",
prop2: {
prop3: "World"
},
moreProps: "I don't care about"
}
The function should return true, but for something like this:
{
foo: "Hello",
bar: {
prop3: "World"
}
}
It should return false. Any ideas on how to make this happen easily?
Cheers!