-
-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove uses of static typing from the documentation #99925
Remove uses of static typing from the documentation #99925
Conversation
@onready var character_name: Label = $Label | ||
@onready var character_name = $Label |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Narrowing down the type of an @onready
variable is good practice but by hard-following the general rule this should be removed.
var texture = load("res://icon.svg") | ||
var image: Image = texture.get_image() | ||
var image = texture.get_image() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no guarantee that texture
is a Texture, and that it has the get_image()
method, so this is another example of type narrowing.
var heightmap_texture: Texture = ResourceLoader.load("res://heightmap_image.exr") | ||
var heightmap_image: Image = heightmap_texture.get_image() | ||
var heightmap_texture = ResourceLoader.load("res://heightmap_image.exr") | ||
var heightmap_image = heightmap_texture.get_image() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is type narrowing again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine by me; agree with the reasoning (if we were to do this, we need to decide about how/when), and the change looks good to me.
Thanks! |
Related to #99924
See #99325 (comment) and prior comments
TL:DR: We shouldn't use static typing in the documentation (unless it's relevant to the code example). At least not yet.
This is not the same PR as #99924.
The reason I decided to split the two is because the choice is not as clear-cut. Removing some of these static types may actually make the code examples worse, as I'll comment below.