The two words refer more or less to the same type of housing, the only difference between them is that the expression ’terraced building’ is used in the UK, whereas the word ’townhouse’ is used in the US.
Both types refer to a two or three-story house separated from the adjacent house by a common wall in a row of houses. They can also be called row houses or linked houses. In case of terrace houses, the first and the last houses in the row are called end terraces; the houses in the middle of the row are called mid terraces.
It is interesting to mention that in Australia, the expression ’terraced building’ is used for houses built during the Victorian era.