r/typescript • u/MeekHat • 2h ago
How do I circumvent referring to a block-scoped variable before declaration in this case?
I apologize that my title may be an XY problem. What I'm actually doing is I have basically a dialogue tree in a module. Each line is a separate variable and it should have inside itself a reference to the following line.
export type DialogLine = {
text: string;
responses: PlayerResponse[];
}
export type PlayerResponse = {
text: string;
nextLine: DialogLine;
}I guess the solution could be as simple as having the order reversed: later dialogue lines go at the top, earlier ones - at the bottom. But I can't guarantee that it'll always work and there won't be some branching or looping.
Maybe using string aliases rather than the actual variables is the solution. I've got no idea. Could just hide the issue from the compiler.