fix --declaration typechecking (complex case)

This fixes generation of typescriptServices.d.ts,
although this is not a current requirement
( https://github.com/Microsoft/TypeScript/issues/465 ).

I don't have a unit test yet.  But I wanted to share this now.