Do I need to use static typing when using "as"

Godot Version

4.6

Question

Should I do

var x := get_x() as my_class

or

var x = get_x() as my_class

I know that as will set x as my_class if get_x() returns object of my_class or null if it wasn’t my_class. And I know that single : without any give type, sets variable type depending on what is on the other side.

Both lines of code, that I put above, work the same from my testing and both give hints.

I’m just curious if there is any real difference I didn’t notice or something I should know.

The var x := will be slightly more performant at runtime, because it’s implicitly typed, unlike the var x = which is untyped. It’s best to use var x: MyType = though if you can, as it’s explicitly typed and slightly more performant than implicitly typed. The difference is miniscule though, so you probably will never see the actual difference in practice.