Add static typing to all properties #57

Closed
opened 2024-04-25 00:29:33 +00:00 by HotNoggin · 9 comments
HotNoggin commented 2024-04-25 00:29:33 +00:00 (Migrated from github.com)

What happened?

I've just enabled enforcing static typing in my project, because I do like to see errors when I miss typing my variables. However, most of the variables in this plugin are completely untyped, so I was left with tens of errors to "fix".

Screenshot 2024-04-24 172442
Screenshot 2024-04-24 183232

It is a bit tricky to track down the root of these errors since they do come from an addon, so they appear with gdscript:// with a strange ID instead of a traceable res:// path.

I added static typing to every single variable and changed all of the paths to use this format: @onready var name: Type = $Path/To/Node as Type . It was a bit tedious, and since I do plan to use this addon and future versions in future projects, I would love if the addon could have strict static typing enforced already. plugin.gd seemed to be the biggest culprit with all of its paths and variables. The things that should be typed are:

  • Variable and constant declarations, as var name: Type (and as Type if necessary)
  • Function return values and parameters, as func name(parameter: Type) -> Type:

Aside from static typing, unsafe property access should also be fixed (Like setting the position of a Node which might be a Node2D but you don't know if it is).

If you do plan to do this, you can check if it's been done correctly by enabling these settings:
Screenshot 2024-04-24 135734

Thanks for reaching the bottom and please ease the suffering of us static typers. :)

Version

1.3.1

Godot Version

4.2.1

Exact steps to reproduce this error

Simply enable these settings and you'll get the same errors each time you reload the project:

Screenshot 2024-04-24 135734

GDScript

The whole repo

Godot output

PAIN

Additional information

cough cough

It's dusty down here.

Checks

### What happened? I've just enabled enforcing static typing in my project, because I do like to see errors when I miss typing my variables. However, most of the variables in this plugin are completely untyped, so I was left with tens of errors to "fix". ![Screenshot 2024-04-24 172442](https://github.com/vaporvee/discord-rpc-godot/assets/143744752/b9abca34-97b6-4d3f-8a68-011144e4a5ca) ![Screenshot 2024-04-24 183232](https://github.com/vaporvee/discord-rpc-godot/assets/143744752/a6dcab18-cc4e-4a4a-896d-7a1e4963aac7) It is a bit tricky to track down the root of these errors since they do come from an addon, so they appear with `gdscript://` with a strange ID instead of a traceable `res://` path. I added static typing to every single variable and changed all of the paths to use this format: `@onready var name: Type = $Path/To/Node as Type` . It was a bit tedious, and since I do plan to use this addon and future versions in future projects, I would love if the addon could have strict static typing enforced already. `plugin.gd` seemed to be the biggest culprit with all of its paths and variables. The things that should be typed are: - Variable and constant declarations, as `var name: Type` (and `as Type` if necessary) - Function return values and parameters, as `func name(parameter: Type) -> Type:` Aside from static typing, unsafe property access should also be fixed (Like setting the `position` of a `Node` which might be a `Node2D` but you don't know if it is). If you do plan to do this, you can check if it's been done correctly by enabling these settings: ![Screenshot 2024-04-24 135734](https://github.com/vaporvee/discord-rpc-godot/assets/143744752/42a365e8-fa1c-4450-950f-93c5ad4bcec2) Thanks for reaching the bottom and please ease the suffering of us static typers. :) ### Version 1.3.1 ### Godot Version 4.2.1 ### Exact steps to reproduce this error Simply enable these settings and you'll get the same errors each time you reload the project: ![Screenshot 2024-04-24 135734](https://github.com/vaporvee/discord-rpc-godot/assets/143744752/c6d823be-20b0-44e7-ac55-792d8de4a44e) ### GDScript ```gdscript The whole repo ``` ### Godot output ```shell PAIN ``` ### Additional information *cough cough* It's dusty down here. ### Checks - [x] I tried reinstalling the addon or tried to fix it myself with other methods. - [X] I tried restarting Discord and Godot completely. - [X] I did read the documentation https://vaporvee.com/docs/discord-rpc-godot/

Huh i thought i already did do that but will fix that soon! thanks for reporting :)

Huh i thought i already did do that but will fix that soon! thanks for reporting :)

"Soon" i said... Will make some time to fix all gh issues and some more next week. I promise

"Soon" i said... Will make some time to fix all gh issues and some more next week. I promise
HotNoggin commented 2024-08-03 16:47:48 +00:00 (Migrated from github.com)

No problemo!

No problemo!

okay i think i fixed it but i didn't get by far as many errors as you. I made everything static i may send you the update early to test it. Also thank you for showing me these settings these are very helpful! I like to type static too but forget it often..

okay i think i fixed it but i didn't get by far as many errors as you. I made everything static i may send you the update early to test it. Also thank you for showing me these settings these are very helpful! I like to type static too but forget it often..

ADDON-Discord-RPC-Godot.zip
try it whenever you have time for it

[ADDON-Discord-RPC-Godot.zip](https://github.com/user-attachments/files/16553077/ADDON-Discord-RPC-Godot.zip) try it whenever you have time for it
HotNoggin commented 2024-08-09 15:03:16 +00:00 (Migrated from github.com)

While the RPC is working 100%, the errors still seem to be there. It looks like there are only a few stray untyped variables left.
image

While the RPC is working 100%, the errors still seem to be there. It looks like there are only a few stray untyped variables left. ![image](https://github.com/user-attachments/assets/2734d13a-a9ee-4343-bfc0-616936eca5e6)
HotNoggin commented 2024-08-09 15:07:53 +00:00 (Migrated from github.com)

Checking the changes in github, and it looks to be a script in Debug.tscn:
image
The red is my version, which was static-typing-error-free.

Checking the changes in github, and it looks to be a script in Debug.tscn: ![image](https://github.com/user-attachments/assets/d9ee9f90-92fc-465b-8f60-bbd543ac0095) The red is my version, which was static-typing-error-free.

weird i dont get these errors somehow but will fix them

weird i dont get these errors somehow but will fix them

will be in future updates

will be in future updates
Sign in to join this conversation.
No description provided.