The problem here was that nested objects weren’t converted, so the returned Person
instance had an organization property with a value that was not an instance of
Organization. Rather that convert all these things by hand, I wanted to be
able to do this:

classPerson{@autocast(Organisation)organization:Organization;}

(Of course, you could use TypeScript’s emitDecoratorMetadata option and have
the decorator extract the required type, rather than passing it as a parameter,
but I’ll leave that as an exercise to the reader.)

So here’s my implementation of the @autocast decorator. Note that it makes
some assumption, such as that the type to cast to has a constructor that can be
called with no arguments, or that undefined should simply be passed through.
You may want to tune the implementation for your own use-cases, but the
framework can stay the same. I’ve also thrown in a decorator to apply to
properties that hold arrays of instances of some class: @autocastArray.