Closed ActualMasterOogway closed 2 months ago
it looks like a valid error to me, if getproto
returns the function (() -> any)
, it cannot be indexed?
it looks like a valid error to me, if
getproto
returns the function(() -> any)
, it cannot be indexed?
getproto
either returns a function (() -> any)
, a table containing functions { [number]: (() -> any) }
or a ProtoProxy (which is a custom class, wont go into detail since it has nothing to do with the issue)
so it CAN be indexed if it returns a table, it should return a table when Argument 3 is set to true
Yeah, the point is that it could return either of those 3 things, but Luau doesn't know which one gets returned. If it returned any of the other parts of the union type, then it would lead to a runtime error. So you get a type error here.
it should return a table when Argument 3 is set to true
Luau doesn't know that, you haven't encoded it in your type.
You could use a function overload that checks if the 3rd argument is true and then only return the table type:
type GetProto = ((f: Function | number | ProtoProxy, index: number?, activated: true) -> { [number]: (() -> any) })
& ((f: Function | number | ProtoProxy, index: number?, activated: boolean?) -> { [number]: (() -> any) } | (() -> any) | ProtoProxy)
In any case, this is not a Luau LSP issue. It is a valid type error. If you have incorrect type errors, I would recommend reporting them to Luau directly - this repository is only a language server implementation.
the type definition:
the type error: the type error prevention:
is this supposed to be that way?