Is singleton type autofill for function parameter from table possible?

So I just know about the properties of how singleton type can autofill by setting types to and I just realize I can do this with my function parameter like how FindFirstChild or WaitForChild function were implemented. Although I don’t know if it the same but I felt a connection of how these work.

I was able to make it sort of working with this code

local function Singleton(Parameter:typeof(workspace)) end 
b({["SomethingInWorkspace"]}) -- Autofill in parameter

But I want it to be able to put the actual string in the Parameter and not in a table then define it with a dictionary children, also it gives error because the children isn’t redefine.

So I wonder if anyone who has figure out a way to know a way to get through this (A dictionary with it children, a variable that is some how type checked to give away the Table Children but somehow as a string)

I didn’t really understand what your current functionality is nor what your goal functionality is. Could you please describe it again, but possibly in a different way?

I want to be able to autofill my function Parameter but from the the workspace children. Take workspace:FindFirstChild as an example. In workspace:FindFirstChild() there a 2 parameters but we will only be caring about the first Parameter which is called name, now the name parameter will automatically autofill anything that is under the workspace children. I want to do that, I want to be able to autofill my function parameter that are from the workspace children as a string.

Oh, you mean how “BasePart” etc gets suggested when you type Instance.new()?

Sort of that I should change Instance.new() to something else because it already all define using type check some how and workspace FindFirstChild function is dynamic since it know when there a new Children there.

Oh okay I think I got you now. I don’t know how to solve this though, sorry.

1 Like

Unfortunately we don’t have the fancy utility types in Luau to do this. TypeScript definitely does, and it’s great. Maybe one day we will in Luau.

1 Like

Is this what you need?

local function set<T>(object: T)
    return function(properties: T)
        for i, v in pairs(properties) do
            object[i] = v
        end
    end
end
set(workspace) {
    -- Autocomplete for Workspace is here
}

Not really sure what you mean, but if it’s not this, you probably can’t.

2 Likes

Well not really, I’m trying to do like what the FindFirstChild function does: a string containing all of the children. Although your solution may work in some way that I haven’t tried, I guess I will have to mark Sleitnick’s reply as a solution, it may just not be possible right now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.