When you change a node type from the editor using
Change Type, what the editor node is actually deleting your node, creating a new one, and somehow assign some of the properties they have in common.
This operation is not a light one, and information may be lost when you do this, so I'd advise you to consider alternatives before doing this at runtime in your game.
I'm not aware of a function in GDScript doing this, but the whole thing can be done with a few lines of code:
# Replacing a Sprite with an AnimatedSprite.
# I assume you have the `parent` node in a variable.
# Get the old node
var old_node = parent.get_node("TheSprite")
# Remove it from the tree
# Destroy it (not immediately, some code might still use it)
# Create new node
var new_node = AnimatedSprite.new()
# Add the new node to the tree, under the same parent
# Move it to same order within children
# Set properties you want to be the same
new_node.name = old_node.name
new_node.position = old_node.position
new_node.rotation = old_node.rotation
new_node.scale = old_node.scale
There are variants of this, so you may want to change this code to suits your needs.