Live data from Hacker News

Show HN: A SQL database implemented purely in TypeScript type annotations

github.com

61–70 of 196 posts

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#61
post #50

Earlier quoted context omitted.

This is why you need input validation. Eg, zod or io-ts.

Did not know about these. I wrote my own a while back because I couldn't find an example of this being done (fully type safe validation). https://github.com/cjdell/type-safe-validator

Not exactly the same thing, but protobuf.js also works really well for this: https://github.com/protobufjs/protobuf.js

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#62
post #59
post #33

Earlier quoted context omitted.

Can't speak for the GP but my single biggest complaint about TS is how it's basically a massive set of assumptions layered on top of JS. If the JS types at runtime don't align with your assumptions in TS, the whole house of cards can come crashing down.

At the end of the day, if you look at a low enough level in the stack, there are no types. In a very concrete way, types are a high-level idea, and if the high-level stops matching the low-level, then bugs crop up. See for example Tetris implemented in Pokémon Yellow via runtime code injection: https://www.youtube.com/watch?v=Vjm8P8utT5g Their compiler missed that! So I think there's good reason to switch from talkin…

I get what you're saying however even at the machine code level there is a difference between an i32 and an i64. Also the "sizeof" of a struct is important too when calculating how far to stride with regard to memory addresses.

Types can and do affect the way programs run at the lowest level. Perhaps someone with a better understanding of compiler theory can elaborate further on this...

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#63
post #56
post #23

TypeScript is becoming such a compelling language due to its insanely advanced type system (that allows for projects like this) that I now want to use it everywhere. I want it to become the next Python. I know Deno is supposed to be first class TypeScript but under the hood it's still a JavaScript runtime with all the baggage that comes with that. AssemblyScript is extremely interesting but last time I played with it…

If you're impressed with TypeScript, you should definitely check out ReScript (formerly BuckleScript). Its type system is clean and sound, and yet compiles to native JS without overhead. https://rescript-lang.org/docs/manual/latest/introduction

TS compiled to JS without any "overhead". This is not what the OP said.

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#64
post #32

Earlier quoted context omitted.

I'm glad you asked. :-) For a start, number types. I want i32, i64, u32 etc. JavaScript (and therefore TypeScript) only has "number". Yes we now finally have BigInt but it's not ideal for JIT optimisation. Object prototypes is a weird part of JS that we really could do without. If you really want that, use class syntax. The Date object. Need I say more... Little things like Object.keys() should return a (keyof T)[] r…

Object.keys() is always frustrating. Also, the array access not returning an optional type (I wish there was a strict option for that) often gets me. We need a middle ground: “TypeStrict“ that can clean up some of the edge cases. If you need strict integers, you can create your own fake type: type Int32 = number & {__type:'Int32'}; I do this with strings sometime when I want a string subtype that can’t be accidentall…

For anybody interested in this technique: the googleable term is "branding". It's bringing some nominal typing into TS's structural typing

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#65

Earlier quoted context omitted.

Object.keys() is always frustrating. Also, the array access not returning an optional type (I wish there was a strict option for that) often gets me. We need a middle ground: “TypeStrict“ that can clean up some of the edge cases. If you need strict integers, you can create your own fake type: type Int32 = number & {__type:'Int32'}; I do this with strings sometime when I want a string subtype that can’t be accidentall…

For anybody interested in this technique: the googleable term is "branding". It's bringing some nominal typing into TS's structural typing

I wrote an article about this a while ago: https://codemix.com/opaque-types-in-javascript

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#66

Earlier quoted context omitted.

Another potential benefit - runtime metaprogramming. All types are erased when converted to JS, but I can imagine a lot of utility for runtime types in Typescript.

Obligated mention of runtypes ( https://github.com/pelotom/runtypes ) that bridges the gap between type-land and runtime-land. It's not seamless at all but if you have a serious need for this sort of thing, it's great

I think there is some experimental decorator syntax which will allow for extracting type info. Does runtypes interop with that? Or is planning to?

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#67
post #66

Earlier quoted context omitted.

Obligated mention of runtypes ( https://github.com/pelotom/runtypes ) that bridges the gap between type-land and runtime-land. It's not seamless at all but if you have a serious need for this sort of thing, it's great

I think there is some experimental decorator syntax which will allow for extracting type info. Does runtypes interop with that? Or is planning to?

there's the reflect-metadata package but the type information it exposes is very limited, "object" instead of {a: "foo"} and so on.

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#68
post #23

TypeScript is becoming such a compelling language due to its insanely advanced type system (that allows for projects like this) that I now want to use it everywhere. I want it to become the next Python. I know Deno is supposed to be first class TypeScript but under the hood it's still a JavaScript runtime with all the baggage that comes with that. AssemblyScript is extremely interesting but last time I played with it…

Is this satire? What do you think is advanced about TS' type system and why?

Duck-typing that creates a minefield instead of providing correctness?

The unknown type that does the same?

TS is a step forward from JS, but JS's bar is so infamously low that making something better isn't a big achievement, especially compared to other languages with normal type systems.

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#69
post #32

Earlier quoted context omitted.

I'm glad you asked. :-) For a start, number types. I want i32, i64, u32 etc. JavaScript (and therefore TypeScript) only has "number". Yes we now finally have BigInt but it's not ideal for JIT optimisation. Object prototypes is a weird part of JS that we really could do without. If you really want that, use class syntax. The Date object. Need I say more... Little things like Object.keys() should return a (keyof T)[] r…

Object.keys() is always frustrating. Also, the array access not returning an optional type (I wish there was a strict option for that) often gets me. We need a middle ground: “TypeStrict“ that can clean up some of the edge cases. If you need strict integers, you can create your own fake type: type Int32 = number & {__type:'Int32'}; I do this with strings sometime when I want a string subtype that can’t be accidentall…

Good news, safe array access is coming in TS 4.1

https://devblogs.microsoft.com/typescript/announcing-typescr...

Re: Show HN: A SQL database implemented purely in TypeScript type annotations

#70
post #68
post #23

TypeScript is becoming such a compelling language due to its insanely advanced type system (that allows for projects like this) that I now want to use it everywhere. I want it to become the next Python. I know Deno is supposed to be first class TypeScript but under the hood it's still a JavaScript runtime with all the baggage that comes with that. AssemblyScript is extremely interesting but last time I played with it…

Is this satire? What do you think is advanced about TS' type system and why? Duck-typing that creates a minefield instead of providing correctness? The unknown type that does the same? TS is a step forward from JS, but JS's bar is so infamously low that making something better isn't a big achievement, especially compared to other languages with normal type systems.

I'm honestly curious. What other languages have a type system the would allow for this project? That is, (a subset of) SQL as a type. And assuming these languages exist, are they as ergonomic to the developer as TS while instrumenting the above?
Post reply on HN