dphfox/Fusion

Don't allow varadics in Scope constructors

Closed this issue · 2 comments

In most cases the user would never need to do this and could be considered bad practice. It also is never defined that it could be done this way in the documentation. In technical cases - mainly due to Luau - it's a typing nightmare. Creating derivations supports varadic method tables to be merged together into one, which on paper just makes it feel like they should've already been together in the first place, and, the atrocity of the type coercion going on for DeriveScopeConstructor could be extremely simplified with this.

local scope = Fusion.scoped(Fusion, {
    -- ...
})

local newScope = Fusion.deriveScope(scope, {
    -- ...
})

This is perfectly normal formatting, and the second arguments table should be optional. Assuming a user would want to provide more arguments to do this could cause bad practice in writing scoped code and type complexity. Removing the varadic and treating it as <S, A>(Scope<S>, A & {}) -> Scope<S & A> is much more clean and allows A to be null. The user should be expected to already have merged them themselves - or - more correctly: never of gotten in a situation where they needed multiple method tables for one derived scope to all squash together.

Merging multiple tables is required because it allows for multiple libraries to be merged without users having to exhaustively list the contents of all of the libraries they're using. Moving away from variadic types would not solve for the fact that this would still need an exact transcription in types for useful autocomplete.

While I agree that Fusion does need to move away from variadics in other parts of the API surface, scopes are one of the places where this was an active design consideration, so I don't see what this would achieve.

I'll close this for now, but I'm happy to reopen if there's some other issue that turns out to be important.

I feel a better solution would be for Roblox Luau to better support varadic types so the Scope constructors were more clean. As of right now sadly, your method is the "cleanest" it can be. If Luau ever is to include this, I will open a new PR.