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.
But I don't know where you'd get that source code from at runtime though? I'm sure there are languages that contain enough runtime information, but, as an pertinent example, there isn't a way to tell that you have an object with certain fields in OCaml at runtime. It's just a block at runtime. All of the names are gone, as they were only used at compile time.
I was assuming the TypeScript/JavaScript scenario, where TypeScript objects are implemented as JavaScript objects and their structure is available at runtime. Of course it does not work if you do not have that reflection capability.
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.