Register widget only page is a singular of custom post type

Instead of nuking the entire widget, you should put your conditional statements within the widget itself:

public function widget( $args, $instance ) {
     if ( is_singular( array( 'post_type_a', 'post_type_b' ) ) ) {
          // display your widget here
     }
}

Since you’re not printing $before_widget and $after_widget, there won’t be any output for this widget unless the conditions are met.