Normally you would write a program that is a game of Doom when you run it (you create a program, then compile it and run). Dmitri created a program that does nothing and he don't even run it. But while it's compiling, it does a lot of tricky things to make typescript compiler to run Doom as a side effect.
It's extremely hacky because Typescript is not even a runtime, it's not meant to run any code at all. Typescript is a thing that takes .ts file and produces .js file (which you then run using different program - a javascript runtime).
TypeScript types are a kind of Prolog [1] (sort of, kind of, not entirely). Like any language they have primitives (`boolean`, `string`, `true`, 'Manchester'), functions (`type WaitWhat<T> = { yesReally: T }`), variables (`type X = number;`), and conditionals (`type Huh<T> = T extends Foo ? Bar : Baz`). You run the types program by asking `tsc` to check the types of some program - e. g. `type Foo<T extends number> = { x: T }; type Bar = Foo<string>;`. Getting output out of the type system other than via "hover over the type in VSCode" is probably a bit more involved, but it's definitely doable (I suspect some abuse of the Language Server Protocol here).
It might be helpful to look at something like Typescript Tic Tac Toe in the type system [1]. You can comment out individual lines in the GameLoop type, and then hover over `____________DISPLAY___________` to see the current game state. Illegal moves will result in type errors.
Running Doom in the type system effectively means a lot more types have been generated (effectively a C to typescript-type compiler was created if I understood this correctly), then the game was started with no inputs entered. Theoretically if the author had infinite time and compute resources, the history of control inputs up to a certain point in play could be put in a tuple, and the type system would generate the state of the game given the code and the moves which the user had input so far. This state would include what's on the screen, but also internal state variables controlling things like where the enemies were moving, whether projectiles are in air, their direction, collision detection, etc.
mahoro|1 year ago
It's extremely hacky because Typescript is not even a runtime, it's not meant to run any code at all. Typescript is a thing that takes .ts file and produces .js file (which you then run using different program - a javascript runtime).
svieira|1 year ago
[1]: https://en.wikipedia.org/wiki/Prolog
pcthrowaway|1 year ago
Running Doom in the type system effectively means a lot more types have been generated (effectively a C to typescript-type compiler was created if I understood this correctly), then the game was started with no inputs entered. Theoretically if the author had infinite time and compute resources, the history of control inputs up to a certain point in play could be put in a tuple, and the type system would generate the state of the game given the code and the moves which the user had input so far. This state would include what's on the screen, but also internal state variables controlling things like where the enemies were moving, whether projectiles are in air, their direction, collision detection, etc.
[1]: https://tsplay.dev/wE95vw