Is it possible to add javascript to template parts

This is not supposed to work (and it does not work) in a way you wanted. I guess you are talking about new FSE template parts (.hmtl), and not legacy (.php) template parts. You can only add HTML and blocks to .html template parts and javascript is enqueued as a part of a block. Alternatively, you can check in a functions.php if certain page/post/template/block is loaded and then enqueue javascript you want.