Which Type Annotation mode do you like best?

The Problem:

Hey! I’ve been using roblox type annotaitons for a bit while now and I’ve been only exclusively using ‘strict’ mode for all my scripts. Though I always run into problems when utilizing popular resources, like Trove by Sleitnick or Replica by Loleris, where Roblox warns me that something is wrong even though I know that I’m using it correctly.


Examples:

Skip this, if you don’t like reading…

[Strict vs Nonstrict] when using Trove and Replica

Trove example:

In this example I’m creating a new Signal object and connecting it to a function using Trove. This also helps for later cleanup. Both the Signal and Trove modules is made by Sleitnick, so I should be safe to do this, however roblox still complains.


Replica example:

In this Replica example I just copy pasted the example code provided by Lolreis in this forum post. As you can see Roblox still makes complaints in strict mode.


As soon as I swap --!strict to --!nonstrict, everything is fine. Does this mean that nonstrict is better?

[Strict/Nonstrict vs 'NoCheck'] when lazy loading

Another problem I found with both strict and nonstrict modes is that they don’t like lazy loading modules and complain about cyclic module dependency. Even though during runtime this will not cause an infinite require loop.

Module A:

Module B:

The solution to silence this warning is to use --!nocheck. However using nocheck you don’t get any of the benefits from strict or nonstrict.


VVV

So the question is, what do you guys like to use? Strict, nonstrict, or nocheck? It seems that each has their own pros and cons. Do you consistently use one mode for everything, or whatever fits what your trying to do?

I would love any advice you can give, thank you so much for taking the time to read this. :slight_smile:

I use the new Luau Type Solver, and I prefer to use --!strict if possible.

You really don’t want to have cyclic module dependancies, even if it might not throw an error, it’s still bad practice. From ModuleScript documentation:

If a ModuleScript is attempting to require() another ModuleScript that in turn tries to require() it, the thread will hang and never halt (cyclic require() calls do not generate errors). Be mindful of your module dependencies in large projects!

And from sleitnick himself:

1 Like

what are cases that you don’t use strict mode?

The are cases where my script has no Type Errors on the improved type solver, but does on the old one.

1 Like