The type checker has access to the source code (and any type annotations). That information isn't available at runtime, so I'm not sure how you'd be able to run the type checker at runtime.
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.
Doing this in the general case, I assume, is probably not practical.