Issue with intersection types

I am trying to create a custom type that i can index with a number or with a specific string key. With the way my code is currently structured i have to use an intersection for this:

type MyType = {[number]: any} & {["Hello"]: any}

When i index a table of this type with a number i get a strange warning message:

local myTable: MyType = {}

local value2 = myTable["Hello"] -- ok
local value1 = myTable[1] -- not ok: Expected type table, got '{[number]: any} & {["Hello"]: any}' instead

I dont really understand whats causing the issue, maybe im doing something wrong?
any help would be greatly appreciated! (:

1 Like