Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

false type-error for a custom type definition #629

Closed
ActualMasterOogway opened this issue May 25, 2024 · 3 comments
Closed

false type-error for a custom type definition #629

ActualMasterOogway opened this issue May 25, 2024 · 3 comments

Comments

@ActualMasterOogway
Copy link

ActualMasterOogway commented May 25, 2024

the type definition:

getproto: (f: Function | number | ProtoProxy, index: number?, activated: boolean?) -> { [number]: (() -> any) } | (() -> any) | ProtoProxy,

the type error:
image
the type error prevention:
image

is this supposed to be that way?

@JohnnyMorganz
Copy link
Owner

it looks like a valid error to me, if getproto returns the function (() -> any), it cannot be indexed?

@ActualMasterOogway
Copy link
Author

ActualMasterOogway commented Jun 1, 2024

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

@JohnnyMorganz
Copy link
Owner

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.

@JohnnyMorganz JohnnyMorganz closed this as not planned Won't fix, can't repro, duplicate, stale Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants