Refactor and add purpose statements/contracts
Fix printing of tc-any-results in type errors.

In the long run, these error messages should get
simplified so that this printing is not necessary.

Closes PR 13577 and PR 13526