So I have this generator which simply gets subsets from a given array.
export class GenerateThings {
static *generateSubsets(elements: any[], offset: number = 0) {
while (offset < elements.length) {
const first = elements[offset];
for (const subset of this.generateSubsets(elements, offset + 1)) {
subset.push(first);
yield subset;
}
}
yield [];
}
}
This works in plain javascript (without types, of course) but when I build it on TypeScript like this, it says
'generateSubsets' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.
Is there a way to traverse the resulting subset of a set if we use this recursive approach in TypeScript? Thanks.