You can use wp_get_post_terms()
function, like this:
if ( wp_get_post_terms( $post->ID, 'topic', [ 'fields' => 'ids' ] ) ) {
// Your code
}
We passed the 'fields' => 'ids'
in args, just to prevent instantiation of the full WP_Term objects in the background, since you only need to check if there are any, and using a different function for the HTML generation.