Implements and closes benjamn/recast#22.

Didn't cover all the test cases, but this should obviously work for type inheritance of any level.