-
What do you want to achieve? Be able to have a custom
type
whose definition is based on a conditional system. -
What is the issue? I don’t know how to do it (or if it’s even possible).
-
What solutions have you tried so far? Research on the topic and trying to implement it through different operations (assertions, functions), but no luck so far.
For example, let’s say I want to have a specific type
called FolderChild
for Model
s that are children of a specific Folder.
local model = game.Workspace.Model
local folder = game.Workspace.Folder
How may I insert this condition:
(model.Parent ~= folder)
implicitly into this type
definition?:
type FolderChild = Model
.
In other words, ‘embed’ this condition:
if model.Parent == folder then
-- type of model may be FolderChild
else
-- type of model may NOT be FolderChild (compiler throws warning)
end
Into a type, something like this (obviously this is conceptual, not actually correct)
type FolderChild = Model -> ([Parent] = folder) -- FolderChild = «a Model whose Parent property is set to Folder»
.
Yeah, I know this may be implemented easily through an external conditional system, yet I want to know if there’s a way to implicitly embed it into the type
’s root definition.
Let me know if I expressed myself clearly.
Thanks in advance!
Edit: typo.