4 ms·
That's pretty neat. What I really want is this: function fn(query:string){ const stuff = // do some stuff with `query` variable return createType(stu
by bartq 6y ago
That's pretty neat. What I really want is this:
function fn(query:string){
const stuff = // do some stuff with `query` variable
return createType(stuff);
}
type MyType = FromJS<fn("SELECT id, name AS nom FROM things WHERE active = true")>;
This way we could compute types on the fly with JavaScript instead of creating monstrous types in TypeScript types system.
- Justsignedup 6y agowouldn't that be neat... However, there are Java frameworks that basically generate a type system from your database so whatever columns you query ends up being static types that can be determined at compile time. https://www.jooq.org/ https://www.jooq.org/ Java is really quite cool. I wonder if we'll ever get a typescript version of jOOQ
- NieDzejkob 6y agoSimilar libraries are also available for Rust, see diesel [1] or sqlx [2]. [1]: https://diesel.rs/ https://diesel.rs/ [2]: https://crates.io/crates/sqlx https://crates.io/crates/sqlx
- bartq 6y agoI think we eventually will be able to evaluate JS in context of types and return whatever we want even asynchronously. Now we have some combinators given by TS authors which allow us to compose some limited set of computations. I don't know how Java does it, but I hope TS will do it better :-)
- nsonha 6y agoif we are talking about code gen then it exists in every language, nothing extraordinary here. In nodejs, there is prisma for example. This typescript thing generates static type on the fly, not by generating code.
- nikki93 6y agoInterestingly this is something you can do in Zig with its `@Type`. Zig's compiler can eval (some) Zig code at compile time, this code can produce new types, and you can mention those types anywhere types are normally mentioned.