5 ms·
Could someone ELI5? Actually, I wrote a lot of code in TypeScript and I know my SQL but I have absolutely no idea what is going on here.
by dandare 6y ago
Could someone ELI5?
Actually, I wrote a lot of code in TypeScript and I know my SQL but I have absolutely no idea what is going on here.
- alex_duf 6y agoI'm not entirely sure, but I suspect it's one of these programming "joke" where you take a concept and bring it far enough that it becomes ridiculous. So I'm guessing there's no real practical use case for this, and is a nice flex from the author. It would be nice if that were made dead clear in the Readme, something like "Why? Because it's fun"
- gfody 6y agostrong typing for arbitrary sql queries is actually really nice and this is much better than stuff like sequelize or typeorm which seem sadistic in comparison
- nsonha 6y agogenerating types from a swagger spec? Graphql? Or any kind of schema? Look up fsharp type providers.
- alex_duf 6y agoAs far as I understand (and I might be wrong so please correct me), this can't be used to generate anything. Of course all the technologies you've listed are useful and brilliant but this isn't what I'm seeing. It's more of an experiment of thoughts to generate types that are defined by the result of the SQL query, bending a compiler to a new strange behaviour that happens to be SQL like.
- nsonha 6y agoIt definitely can parse anything, the code that is required to make such a parser might be a bit unreadable but look up somewhere in this thread there is a twitter link to a github project of a generic json parser. Typescript 4.1 isn't event released yet, once it is there will be a dozen of projects like this. If you think this is useless because it doesn't generate any code then I'm assuming you're not familiar with typescript because type level libraries isn't supposed to do do that anyway. There are already libraries that generate open api client and graphql client but they generate type definition via an extra build step which libraries like this can eliminate. And this typescript feature was made to parse strings so no this is not "bending the compiler"
- tombh 6y agoI think this is an exploration of the somewhat surprising fact that type systems can be, and often are, Turing Complete[1]. A very naive view of type systems is that they're merely the next level up from code comments, except with the annoying burden of having the power to prevent compilation. As this project demonstrates type systems are far more than just glorified comments. Indeed, they are in fact a rigorous scaffolding that seemingly magically "intuit" the intention of code without having to run it. This project playfully explores the extent of Typescript's particular powers. 1. https://en.wikipedia.org/wiki/Turing_completeness https://en.wikipedia.org/wiki/Turing_completeness
- SCLeo 6y agoSince you already know TypeScript, I think it is important to note that this project uses a new TypeScript 4.1 feature called Template Literal Types to do pattern matching in order to parse the SQL string. https://devblogs.microsoft.com/typescript/announcing-typescript-4-1-beta/#template-literal-types https://devblogs.microsoft.com/typescript/announcing-typescr...
- dandare 6y agoThis is fascinating! On one hand, as an old guard JS developer that upscaled to TS, I often find new TS syntax incomprehensible. On the other hand I am still slowly learning new concepts. Am I correct to assume these new concepts are imported from more advanced languages? Or are these invented in TS for TS?
- nsonha 6y agoThis particular feature is invented in ts, other instances of ts inventing a completely new thing are conditional types and mapped types. F# has type provider which is similar in some of its usages but different enough i dont think they're related.