I have a result JSON object being passed onto a function which I would need to check the type of it against a Typescript interface definition model, in order to be perform specific rendering changes prior displaying it.
I am facing an issue, where the string matches all the interface types as it goes through the checks, using (jsonResult as TypeScriptInterfaceName) and simply doesnt deliver the correct value subsequently.
I tried the class transformer library as well with no luck. Whats the best way to explicitly check and fail the string against the typescript definition.
Thank you.
interface ParentOne {
id: string;
title: string;
child: Child
}
interface Child {
id: string;
title: string;
}
**JSON ONE**
{
id: value,
title: value,
child: [{}],
}
interface ParentTwo {
id: string;
title: string;
directory: Directory
}
interface Directory {
id: string;
title: string;
}
**JSON TWO**
{
id: value,
title: value,
directory: [{}],
}