I have recently been trying to get into the habit of annotating my code with types so that it is easier for me to write properties to classes and stuff. I have a Property in one of my classes that can either be a string or an array of strings but I cant figure out how I can express an array of string using Type Checking. If anyone knows please help.
1 Like
local t: {[number]: string} = {'a', 'b', 'c'}
--this is a shortcut; since arrays are known to have numerical keys, it can be omitted
local t: {string} = {'a', 'b', 'c'}
--singleton type
local t: {'hello'} = {'hello', 'hello', 'hello'}
If you have any other questions just consult the official Luau documentation website
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.