tannerntannern / ts-mixer

A small TypeScript library that provides tolerable Mixin functionality.
MIT License
379 stars 27 forks source link

Support extends up to 20 in Mixins function #50

Open ali-master opened 2 years ago

ali-master commented 2 years ago

Increase the Number of extends that the Mixins' type supports up to 20, The current is 10.

tannerntannern commented 2 years ago

Hi @ali-master, thanks for the contribution! I have a few concerns with the PR in it's current state, but I think we can figure those out and get this feature merged soon. My first concern is formatting: the higher arity overloads have the type parameters so spread out that the code is difficult to navigate and it feels prone to errors that are difficult to spot. However, the error prone nature can't be blamed entirely on the formatting -- with the shear number of overloads and type parameters, it's unavoidable, which leads me to my other concern: these overloads should really be generated automatically rather than hand typed (especially with the extra overloads). The framework for doing this code generation is already more or less in place. It would just require some edits to codegen.js at the root of the repository. It could leverage the replaceInFile function.

I don't want to "erase" your contribution by doing it myself, so I'll give you the option to make this change if you'd like. If you don't care about that and just want the feature, I'm also happy to make this change myself. Let me know what you think.

Scalahansolo commented 1 year ago

Would it not be possible to just the call signature on this to take an arbitrary number of mixins?

tannerntannern commented 1 year ago

Would it not be possible to just the call signature on this to take an arbitrary number of mixins?

I wish it was, but TypeScript's type system isn't powerful enough to handle this kind of type inference for an arbitrary number of inputs. This is a common problem in other languages as well.

There may be a possibility of some recursive type inference enabled by a recent TypeScript release, but I haven't had a chance to look into this yet.