You don't need the original source code, any code producing the object you want to check will do. If the object has a field "field" with value "value", then the code
function () { return {field: "value"}; }
produces a value of type Foo precisely when the original object was of type Foo, even if the code producing it was much more complex.I don't see why that wouldn't work. If you have a specific example where that approach fails, I'd like to know about it.