News for hackers. Stuff that matters.
Re:Typedefs by brabel on Thursday November 05, 2020 @03:05AM (#24996455)
I've been looking for something to create a data model that can be translated to many programming languages, and came across https://github.com/airtasker/spot.

It looks great: definitions are written in TypeScript, which as it turns out, can express really advanced data models quite well. Spot can translate TypeScript models (they must start with the API definition, but that can be just a single entry point to the model) to JSONSchema, OpenAPI, and from those, to basically any language supported by them (Java, Kotlin, Swift, C# and many others).

Spot also can create a mock server to provide testing, random data fitting the model, as well as a server to view the OpenAPI definition online.

It's really great.

The project posted here seems to not do any of the useful things I expect, which Spot does (though it's still very new and there's some bugs) so I thought others would like to know about it.

Re:Typedefs by pdimitar on Thursday November 05, 2020 @04:57AM (#24996926)
I actually did want to know, thank you.

I have been on the market for such a semi-generic interface/type definition for a while now and I'll try Spot.

Re:Typedefs by wires on Thursday November 05, 2020 @08:34AM (#24998074)
this is indeed quite nice, but the difference with Typedefs is that we have real ADT's whereas typescript doesn't.

in theory typedefs should be able to do what spot does, it is just very hard to write formalized code so it will take us a while before we get there

Re:Typedefs by brabel on Thursday November 05, 2020 @12:57PM (#25000349)
> real ADT's

I always thought these examples were real ADT's:

``` type Bool = true | false;

type Maybe<T> = T | null;

type SumTypeExample = Bool | Maybe<Bool>

interface ProductType1 { b: Bool c: Maybe<Bool> }

interface ProductType2 { s: "a" | "b" | "c" }

interface ProductTypeComposite extends ProductType1, ProductType2 {} ```

Can you explain what's the difference?

Re:Typedefs by breck on Thursday November 05, 2020 @10:58AM (#24999312)
> we have real ADT's whereas typescript doesn't.

This sounds interesting. Can you expound a bit more?

This is vague and anecdotal but I find about 80% of what I want to do in TS with types I find very easy to do, 10% I find annoying but possible, and then maybe 10% it just doesn't work.

I'm curious if there's a root cause here.