Is type checking worth using?

Hello!

So, recently, I learned type checking, but, I don’t really know if it’s worth using.
It seems like it takes a lot of time to implement, there are some weird behaviors, like not being able to access children with dot, ex. part.ParticleEmitter has to be part:FindFirstChild("ParticleEmitter"), and other behaviors, and I don’t see it used that often (at least on the devforum).

I just want to know if I should use type checking, or if it’s not worth using, and some other info about using it.

Here’s some questions I have:
Should I use type checking?
Should I use type checking in all of my scripts, or just important or specific ones?
Should I use type checking everywhere in my scripts, or just specific/certain parts?
Should I use always use --!strict?
And is there anything else important I should know?

If it helps, I’m a solo dev working on a ~decently sized game. I also usually use OOP in my systems.

Thank you in advance! And any help is appreciated!

2 Likes

Almost always, yes. The benefits are simply too great to ignore, it can eliminate an entire class of bugs in your code.

It really depends on what you can verify to be type-safe. Obviously you don’t need a type system to verify the soundness of a 5-line script that spins a part.

There is no way to enable it in “certain parts”, afaik.

--!strict is the core of the new type solver, so yes.

The Luau type system itself is still quite primitive and incomplete. It often fails to properly solve complex or even simple types in rare occasions. If you want more polished typing, and don’t fear the external editor, I would highly recommend roblox-ts.

2 Likes

this is basically how it built it can help with auto complete but it doesnt enforce it meaning u would have to do checks

-- part:FindFirstChild("ParticleEmitter")
local Base = {}
Base.__Index = Base

type Vaule = 'A' | 'B'

function Base:Find(a: Vaule)
    return a
end

return Base
1 Like

i have started asking these questions myself recently…
and my conclusion is: yes, especially when it comes to to Roblox API usage
it’s better to add obviously never possible nil check with warning and return than a crash in a live game
when it’s about user library which usage can be checked in run-time then it should be assertion, warning is good too if you used to read output

1 Like

I just turned that off in the setting a few days ago.. everything works fine. Think that is more for OOP and here that is simulated, so it’s really not faster or optimizing.

1 Like

Okay, so, I guess I’ll use type checking. Anyways, I think I’m getting a bit better at it, since it seems easier to do now. Thank you to everyone who helped!

2 Likes

I usually use type checking to avoid runtime errors and for autocomplete. In both cases it does a great job. Also having an orange line in a script during editing is eye catching and forces you to fix issues before they are caused in an unexpected way.

2 Likes

Type checking is useful for autocomplete on tables, everything else is a bit meh.

Typing doesn’t suit a language like Luau because it was never designed with that in mind, so its been grandfathered in without the greatest implementation.

4 Likes

in a general sense, type checking is definitely worth using especially in larger projects. it improves readability, error tracking and helps with maintaining larger code bases.

with that being said its not equally important everywhere.

as an example, lets say im passing data between client and server using a remote, the type checker can’t infer what the data will look like. there are some other non niche and niche situations like this that make defining and enforcing type’s extremely important because it forces you to agree on a structure for data.

another example, lets say you’re working on a large scale project with a decent size of developers all working on different systems, defining types helps you stay organized and to avoid common bugs and mistakes.

i personally wouldn’t want to work on a project where nothing is defined and im piling through 12 different scripts to figure out the structure being passed to me

Anyways if im mistaken on anything feel free to call me out and correct me.

2 Likes

Honestly, luau type checking is mostly up to preference. Personally, I use types and the--!strict directives everywhere in my games on roblox as I prefer to keep what’s left of my sanity. Plus, types are honestly goated and is proven for better maintainability in large projects.

The luau type checker, at least from my experience, isn’t a something to really appease as it could be wrong at times. I believe luau really doesn’t enforce types, especially since it’s still an interpreted language since it originated from lua… Which means you still have to check for the instance. Yes, the luau --!native directive (and @native attribute) does use the type annotations, but I’m not that sure to what extent.

3 Likes