News for hackers. Stuff that matters.
Re:Show HN: A SQL database implemented purely in TypeScript ... by ricksharp on Monday September 28, 2020 @09:42AM (#24616499)
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 accidentally assigned by a normal string.

Re:Show HN: A SQL database implemented purely in TypeScript ... by svieira on Monday September 28, 2020 @10:59AM (#24617334)
In TS 4.1+ there _is_ an option for strict array access called `noUncheckedIndexedAccess` [1]

[1]: https://devblogs.microsoft.com/typescript/announcing-typescr...

Re:Show HN: A SQL database implemented purely in TypeScript ... by ricksharp on Monday September 28, 2020 @02:09PM (#24619568)
Awesome!

I was just searching for that and all I could find were old github issues saying it was working as intended.

Thank you!

Re:Show HN: A SQL database implemented purely in TypeScript ... by inbx0 on Monday September 28, 2020 @10:15AM (#24616814)
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 ... by williamdclt on Monday September 28, 2020 @10:06AM (#24616712)
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 ... by phpnode on Monday September 28, 2020 @10:08AM (#24616745)
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 ... by ricksharp on Monday September 28, 2020 @10:53AM (#24617257)
Cool, I never knew what that was called. Thanks!