问题
EDIT: I have rewritten this question to be much clearer.
I am trying to programmatically infer an interface which references itself.
I am writing some code which can encode a recursive structure in binary. For example:
const myTreeEncoder = Struct(Self => ({
name: Str,
children: List(Self)
});
This can encode structures like this from binary and back:
const someUint8Array = myTreeEncoder.encode({
name: 'parent',
children: [{
name: 'child',
children: []
}]
});
The problem is, how can the encode function be typed correctly so it expects an input of:
interface BinaryTree {
name: string;
children: BinaryTree[];
}
Here is a minimal reproducible example
来源:https://stackoverflow.com/questions/60305599/generate-a-typescript-interface-that-references-itself