I'm currently working with the following TypeScript code:
type DormNodePredicate = DormEdge | (() => DormNode<DormNodePredicateRecord>);
interface DormNodePredicateRecord {
[key: string]: DormNodePredicate;
}
export class DormNode<DNPR extends DormNodePredicateRecord> {
constructor(public preds: DNPR) {}
}
enum PredicateType {
STRING = "string"
}
export class DormEdge<AsArray extends boolean = false> {
constructor(private predType: PredicateType, asArray: AsArray = false as AsArray) {}
}
const Audit = new DormNode({
user: () => User
})
const User = new DormNode({
name: new DormEdge(PredicateType.STRING),
audits: () => Audit
});
The issue I'm facing is that both Audit
and User
are being inferred as type any
. To reach a deep level of recursion like
Audit.preds.user().preds.audits()...
, I need to reference Audit from User. Although this example is simple, my actual use case involves much more complexity. How can I resolve this?
In relation to this part of the code:
export class DormEdge<AsArray extends boolean = false> {...}
Removing the = false
from the generics allows me to achieve my original intention. However, I'm unsure about the underlying mechanics at play here. Any assistance in identifying the problem would be greatly appreciated. For further context, I am utilizing
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3d49444d584e5e4f544d497d3c502b59584441">[email protected]</a>
. Thank you!