type GenericDatabase<T> = {
Items: {T},
}
type GenericItem = {
ItemID: string,
}
type CarUpgrade = {
Price: number,
}
type Car = {
Upgrades: {CarUpgrade}
} & GenericItem -- Comment out this type intersection to fix autocomplete.
local Database: GenericDatabase<Car> = {}
Database.Items = {
{
Upgrades = {
{
pri -- This will not auto complete "Price"
}
}
}
}
Upgrades is defined as an array of dictionaries. In your example, you are accidentally using it as just a dictionary itself, which is possibly the reason for you not getting auto-complete. The following should ideally get you autocomplete:
type Upgrade = {
Price: number,
}
type Item = {
Upgrades: {Upgrade}
}
type ThingDatabase = {
Items: {Item}
}
local Database: ThingDatabase = {}
Database.Items = {
{
Upgrades = {
{
Pr
} -- Each upgrade needs to be its own dictionary, even if we only have one
}
}
}
Alternatively, if you want to support Upgrades being a dictionary itself when you only have one upgrade. From a typechecking perspective, you could define the Item type as:
Yeah this was a mistake in my original post, this fixed my issue in my example code but I’m still getting the issue in a different script. The issue I’m experiencing is actually related to type intersections. I’m currently in the process of updating my original post to reflect the actual issue.
This snippet results in proper autocomplete for Upgrades:
This one does not: (only difference is the lack of & StoreItem)
Here are the types I’m intersecting with, removing the intersection between StoreItem and GenericItem doesn’t fix anything either.