Hi, I don’t know how to explain it, so hopefully this code and the title is enough. Sorry!
type button = {
Name: string,
Cool: Boolean,
…--Allows for anything to be added?
}
Any help is appreciated, thanks!
Hi, I don’t know how to explain it, so hopefully this code and the title is enough. Sorry!
type button = {
Name: string,
Cool: Boolean,
…--Allows for anything to be added?
}
Any help is appreciated, thanks!
To allow anything in a type, you should use ‘any’
Ex.
type button = {
Name: string,
Cool: Boolean,
Property: any --Allows for anything to be added
}
Sorry, I meant so that it there could be anything added any time, for example,
local function addSomething(button: button)
-- these all add new stuff that wasn’t originally in the type
button.Hi = true
button.Hey = false
end
That defeats the purpose of the type - if you want to do something like this, you may as well just use a dictionary.
You can add a [string]: any
to be able to add anything to something assigned that type:
type foo = {
bar: number,
[string]: any,
}
Alternatively, Luau automatically assigns types to unsealed tables you declare them with values.
Yes! Exactly what I wanted! Thanks a lot!
(Again!)
Yeah, I was mainly doing this so that I can add functions to self, from all of the functions inside of the module
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.