With power of this open-source type function, the return type of QueryDescendants method will be inferred from the selector you passed in:
local QueryDescendants = require("mqdesc")
local result = QueryDescendants(game, "Workspace > BasePart:not(MeshPart), Part")
-- result is inferred as {(BasePart & ~MeshPart) | Part}
for _, v in result do
v.Position = Vector3.zero -- Just works!
end
Alternatively, you can use the Infer type manually:
local mqdesc = require("mqdesc")
local result = game:QueryDescendants("Workspace > BasePart:not(MeshPart), Part")
:: mqdesc.Infer<"Workspace > BasePart:not(MeshPart), Part">
for _, v in result do
v.Position = Vector3.zero -- Just works!
end
FYI: The type cast :: is necessary, because as far as I know, the only way to retrieve string contents in a type function is for the string to be a singleton.
EDIT: Thanks to @JoolCaat’s workaround, this is no longer necessary.
You can grab the module from releases page on GitHub. I am not going to publish the module as a package due to fear of being falsely moderated by Roblox. If you like this, consider upvoting my feature request so that there is a higher chance of it getting officially implemented for everyone.