Answer the question
In order to leave comments, you need to log in
How to write recursion correctly?
I am writing mixins, I can’t write the correct recursion
type Constructor = new (...args: any[]) => {};
export function mixin<TBase extends Constructor>(Base: TBase[], count = 0): TBase {
const currentClass = Base[count];
if (count === Base.length - 1){
return class extends currentClass {};
} else {
count++;
return class extends mixin(Base, count++) {};
}
}
// должно получится типа так
// return class extends one
// return class extends two
// return class extends three
Answer the question
In order to leave comments, you need to log in
Use ready-made libs (or look at their code).
Now mixins in ts are crutches on top of bugs .
Following your example: you can't just take an array and get reasonable types out of it. You need ovrloads for each individual type in order to get a union as an output.
I could stick something, but I won't because it hurts.)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question