C++ can get around cyclic reference issues with it's forward declarations. Can't do that in gdscript for now, unfortunately that leaves us Waiting for Godot 4.0.
As a hacky workaround, if you want to make sure the node is of the correct type, but using that type would introduce a cyclic reference, you could try this:
#Type_A.gd
extends Node
class_name Type_A
var my_type_b: Type_B
func _ready():
my_type_b = $"path/to/node"
#Type_B.gd
extends Node
class_name Type_B
var my_type_a: Node # can't use static typing with Type_A, otherwise cyclic dependency
var type_a_script: Resource
func _ready():
my_type_a = $"path/to/node"
type_a_script = load("res://Type_A.gd") # using preload would also introduce a cyclic dependency
if my_type_a is type_a_script:
print("I have a Type_A prop")
else:
print("ERROR: I don't have a Type_A prop")
The Type_B
script won't have access to the autocomplete for its my_type_a
variable, but at least it allows you to validate the type of the node without causing a cyclic dependency.
However, since gdscript uses duck typing, you don't need to worry about the correct type. It's a different mindset from C++, I suggest you read this if you don't know what duck typing means: https://devopedia.org/duck-typing
edit: simplified code in Type_B.gd