-
Notifications
You must be signed in to change notification settings - Fork 16
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
Fix .AddObject
type definition
#34
Conversation
@@ -1,4 +1,4 @@ | |||
type Constructable<T, Args extends Array<unknown>> = new (...args: Args) => T; | |||
type Constructable<T> = new (...args: Parameters<T>) => T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅
janitor/index.d.ts
Outdated
O extends Constructable<T>, | ||
M extends undefined | ExtractKeys<InstanceType<O>, () => void> | true, | ||
I extends keyof U | undefined = undefined | ||
>(object: O, methodName?: M, index?: I, ...args: ConstructorParameters<O>): InstanceType<O>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth it to note that InstanceType<O>
is equivalent to T
.
janitor/index.d.ts
Outdated
>(object: Constructable<O, Args>, methodName?: M, index?: I, ...args: Args): O; | ||
T, | ||
O extends Constructable<T>, | ||
M extends undefined | ExtractKeys<InstanceType<O>, () => void> | true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be dropping ((this: O) => void) | ((_: O) => void)
from here?
Though we should be using T
, not O
here if we keep it.
Might be more clear if we use ExtractKeys<T, () => void>
rather than ExtractKeys<InstanceType<O>, () => void>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at Janitor's internals, we don't need ((this: T) => void) | ((_: T) => void>
:
we can see that Janitor warns if the method doesn't exist on the created instance, and it will later do nothing. We should explicitly ban this behavior from our consumers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like us to change these over to the explicit T
type for clarity. Other than that, looks good 🚀
Co-authored-by: OverHash <46231745+OverHash@users.noreply.github.com>
Co-authored-by: OverHash <46231745+OverHash@users.noreply.github.com>
There might be no difference between T and InstanceType, but some sources say its still needed in some cases.https://stackoverflow.com/questions/70364964/difference-in-typescript-between-types-instancetypetypeof-myclass-and-myc |
Sweet, my mistake. Let's use Also note that |
done |
What are your thoughts on this? It would remove the need for us to have a useless
|
Testing it |
I would add IO back so its less boilerplate. |
I'd prefer if we keep it out for now -- that way we have three types corresponding to the three parameters. Maybe in the future we add it. |
It's required in the luau side, so yeah we have to have it: local MyClass = {}
function MyClass.new(a, b, c)
print(`Created with {a}, {b}, {c}`)
return setmetatable({}, { __index = MyClass })
end
function MyClass:Destroy()
print("Being destroyed")
end
local a = Janitor.new()
a:AddObject(MyClass, "Destroy", nil, 1, 2, 3)
a:Destroy() |
the newest version should work, LGTM |
IO stands for InstanceType of O |
Can we make it just |
Thanks for your work ❤️ |
No description provided.