Dynamically update a node's socket type

I’m experimenting on a node-based addon. There are nodes that need to be able to handle different data types like integers, floats, vectors, bools and strings. These nodes have a dropdown menu that specifies which data type is currently in use. Is there a way to make the sockets update their type to reflect any changes made by this dropdown menu?

The problem i’m facing is that the sockets are created when initializing the nodes, while the data types could change after this initialization.

I found a workaround that’s almost perfect. i simply create all the nodes beforehand and enable/disable them whenever a certain property is changed. it’s a better solution than having to delete and create new ones.

There’s probably a right way to do it, but i can’t find that anywhere in the docs. the NodeSocket.type property is the closest i got.