Live data from Hacker News

Show HN: Instant API – Build type-safe web APIs with JavaScript

github.com

81–88 of 88 posts

Re: Show HN: Instant API – Build type-safe web APIs with JavaScript

#81
post #55

Earlier quoted context omitted.

…or just use Zod?

I don't like writing type definitions with zod's DSL. I want to write definitions in the "first party syntax" - which both JSDoc and Typescript types are - and have everything else generated out from that.

Everybody seems to want that, except for the people who work on Typescript, who argue it'd be the wrong tool.

Typescript's types simply aren't able to provide input validation, both because they don't exist at runtime and for lack of power ("number must be 0..10").

At least with Zod, you also get Typescript types, from the same schema.

Re: Show HN: Instant API – Build type-safe web APIs with JavaScript

#82
post #76
post #12

Type Safety != Runtime Type Validation. Something being Type Safe means that I, the programmer, am Safe from making type mistakes while developing and maintaining the software. For that to be possible, you need a type system that is embedded in the language and the editor and can continously analyze all of your code types to be correct. Type safe means that any breaking change to any interface will immediately error…

I find it mind boggling you don't understand that the solution provided here is about type-checks on data, i.e. data validation. And you can use TypeScript all day but not be protected from missing or wrong data validation. No compiler in the world can help you there.

That's what I'm pointing out though? That it is runtime type validation and not type safety. They are two different things, the only common is the word "type". Please read the comment again.

Re: Show HN: Instant API – Build type-safe web APIs with JavaScript

#85

Seems like you put a lot of work into this and as such I'm hesitant to criticize. But what in the world made you think this is superior to using an actual type-safe language like TypeScript? /** * Streams results for our lovable assistant * @param {string} query The question for our assistant * @stream {object} chunk * @stream {string} chunk.id * @stream {string} chunk.object * @stream {integer} chunk.created * @stre…

Side note: "Seems like you put a lot of work into this and as such I'm hesitant to criticize. But what in the world made you think [...]" It is absolutely possible to question the necessity of a or motivation behind a project, without attacking someone. It's not that OP did ruin a million dollar project. I find your comment quite harsh. Prefacing it with the very first sentence shows that you were quite aware of that…

You're not wrong and I tried to mellow my initial reaction when commenting. I don't feel like I attacked OP though. Getting some outside perspective is important.

Re: Show HN: Instant API – Build type-safe web APIs with JavaScript

#86

Earlier quoted context omitted.

I don't like writing type definitions with zod's DSL. I want to write definitions in the "first party syntax" - which both JSDoc and Typescript types are - and have everything else generated out from that.

Everybody seems to want that, except for the people who work on Typescript, who argue it'd be the wrong tool. Typescript's types simply aren't able to provide input validation, both because they don't exist at runtime and for lack of power ("number must be 0..10"). At least with Zod, you also get Typescript types, from the same schema.

[deleted]

Re: Show HN: Instant API – Build type-safe web APIs with JavaScript

#87
post #60

Earlier quoted context omitted.

> And no — type safety is applied at the HTTP interface. So it's basically validation middleware. The HTTP protocol does not define any such thing.

No, and neither does Typescript. One of the biggest weaknesses in Typescript is that it can't validate data across the wire. Which is a major use case for the language. There are various tools for it already, but the JS ecosystem has always been up for yet another framework.

> No, and neither does Typescript. One of the biggest weaknesses in Typescript is that it can't validate data across the wire. Which is a major use case for the language.

Not sure what particular use case you have in mind but which language has built-in functionality to validate chunks of bytes without some kind of type definition? To me this is an orthogonal problem to language design. Every web framework has to serialize and deserialize data.

What I was getting at is that TypeScript is perfectly suited to define type safe data structures wihtout reinventing the wheel. If you're going to parse type definitions for your validation middleware you might as well use something that can also applied to your business logic.

Re: Show HN: Instant API – Build type-safe web APIs with JavaScript

#88

Earlier quoted context omitted.

I don't like writing type definitions with zod's DSL. I want to write definitions in the "first party syntax" - which both JSDoc and Typescript types are - and have everything else generated out from that.

I like the sentiment, but you’ve gotta admit that being able to skip the “generation” step has its benefits

The only way to can skip that generation is if the zod type is your primary schema, which is only possible if your API is in javascript.
Post reply on HN