![]() Equality: x = "hello" will refine x to be a singleton type "hello".Īnd they can be composed with many of and/ or/ not.Type guards: if type(x) = "number" then will refine x to be number.Truthy test: if x then will refine x to be truthy.When we check the type of any lvalue (a global, a local, or a property), what we’re doing is we’re refining the type, hence “type refinement.” The support for this is arbitrarily complex, so go crazy! Which works out because value: T exists only when type is in actual fact "ok", and error: E exists only when type is in actual fact "err". type = "err" then - result is known to be Err - and attempting to index for value here will fail print ( result. type = "ok" then - result is known to be Ok - and attempting to index for error here will fail print ( result. Nocheck mode will simply not start the type inference engine whatsoever.Īs for the other two, they are largely similar but with one important difference: in nonstrict mode, we infer any for most of the types if we couldn’t figure it out early enough. They must be annotated on the top few lines among the comments. There are three modes currently available. Luau supports a gradual type system through the use of type annotations and type inference.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |