Hacker News new | ask | show | jobs
by svieira 477 days ago
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).

[1]: https://en.wikipedia.org/wiki/Prolog