Live data from Hacker News

TypeSpec: A new language for API-centric development

typespec.io

61–70 of 121 posts

Re: TypeSpec: A new language for API-centric development

#61

Would be nice if you could just import those typespec files in typescript (and other languages?) and get automatic typescript types from them. Codegen is annoying and error prone.

+1. It even looks very similar to TypeScript. Why not use TypeScript as a description of APIs in the first place? Get TypeScript types and even generate OpenAPI schema on the fly to serve it at `/openapi`?

Exactly - this is already a solved problem. https://docs.nestjs.com/openapi/introduction

Re: TypeSpec: A new language for API-centric development

#63

Spec api code, imo. Feels like it's going backwards - there's really no reason why it has to be a .tsp, instead of a .ts with actual api code. It's even using @annotations. In fact the annotations i see in the screenshot (@route, @query, @path) are practically the same in NestJS. I feel that we should be focusing on enhancing that paradigm instead. In fact I already have a working POC of NestJS -> OpenAPI -> Client l…

What if you need to generate two server implementations (possibly in different languages) that adhere to the same specification?

You don’t always go server -> spec -> client.

Re: TypeSpec: A new language for API-centric development

#64

I failed to find an answer to the main question: what output languages are supported. The only way is to emit OpenAPI and then using one of their terrible generators?

You can create your own emitters, there's info in the docs on how to do so. My team built a custom TypeSpec emitter to output a SDK and set of libraries

I wonder if they have plans to introduce any default emitters as part of the package? Nothing about that in the docs that I could find. [1]

[1] https://typespec.io/docs/extending-typespec/emitters

Re: TypeSpec: A new language for API-centric development

#65
post #7

Bespoke languages are a hard sell and incur significant extra effort on the team building this. 1. People don't want to learn bespoke languages. 2. You have to build all the ecosystem tools for a language (compiler, docs, language-server, IDE integrations, dependency management) Similar endeavors are WaspLang and DarkLang, which I have yet to see in the wild or (meaningfully) on HN. Better to use an existing language…

Thanks for hof! Thinking of using it for a project. In what state is the project? I noticed that commits slowed down lately and I was wondering if you consider it stable at the moment and can be used as is.

Re: TypeSpec: A new language for API-centric development

#66
post #59

Earlier quoted context omitted.

(I work on the team) I wouldn't say that TypeSpec is like GraphQL, so it would be hard for TypeSpec to become that on its own. GraphQL has a lot of opinions that are required in order to build a concrete application (protocols, error handling, query semantics, etc.), whereas TypeSpec at its core is just an unopinionated DSL for describing APIs. Bindings for particular protocols are added via libraries, and a GraphQL…

It’s probably more like smithy?

That’s what I thought when I saw this: smithy without the need to bring Gradle into your project

Re: TypeSpec: A new language for API-centric development

#67

Spec api code, imo. Feels like it's going backwards - there's really no reason why it has to be a .tsp, instead of a .ts with actual api code. It's even using @annotations. In fact the annotations i see in the screenshot (@route, @query, @path) are practically the same in NestJS. I feel that we should be focusing on enhancing that paradigm instead. In fact I already have a working POC of NestJS -> OpenAPI -> Client l…

What if you need to generate two server implementations (possibly in different languages) that adhere to the same specification? You don’t always go server -> spec -> client.

That seems like a rare use case. Surely we optimise for the general use case - you start working on a new server powered platform, and write it once in your stack of choice, and release libraries for clients (mobile apps, integrations, web apps).

Even so, a e2e test suite would surely serve far more utility over a spec that simply stubs out endpoints with no functionality.

Re: TypeSpec: A new language for API-centric development

#68

Spec api code, imo. Feels like it's going backwards - there's really no reason why it has to be a .tsp, instead of a .ts with actual api code. It's even using @annotations. In fact the annotations i see in the screenshot (@route, @query, @path) are practically the same in NestJS. I feel that we should be focusing on enhancing that paradigm instead. In fact I already have a working POC of NestJS -> OpenAPI -> Client l…

Spec-first approach works better when client and server teams work on their parts simultaneously and need some contract before the implementation starts.

Re: TypeSpec: A new language for API-centric development

#69
post #43

Feels like cheating, next to the yaml of openapi anything will look good. And that's all while I'm still considering openapi one of the best things that have happened. But I've also been kind of holding my breath for typescript making it's breakthrough as a schema language. More specifically its surprisingly big non-imperative, non-functional subset, obviously. And at first glance this seems to be exactly this, "what…

TypeScript type system is very advanced. It won't be possible to generate corresponding bindings for all popular languages, while keeping them idiomatic. I'd prefer API language to be very simple and straightforward.

OpenAPI's 'type system' is surprisingly advanced also, supporting explicitly discriminated unions and other things like that, which doesn't model well into all other languages.

Re: TypeSpec: A new language for API-centric development

#70
post #43

Feels like cheating, next to the yaml of openapi anything will look good. And that's all while I'm still considering openapi one of the best things that have happened. But I've also been kind of holding my breath for typescript making it's breakthrough as a schema language. More specifically its surprisingly big non-imperative, non-functional subset, obviously. And at first glance this seems to be exactly this, "what…

TypeScript type system is very advanced. It won't be possible to generate corresponding bindings for all popular languages, while keeping them idiomatic. I'd prefer API language to be very simple and straightforward.

Many things that can't be expressed in a given type system can still be expressed quite nicely in code generated for the domain data. You might experience some name elements getting forcibly moved from the types universe into accessor method names. This is state representation (hopefully!), not the CORBA-era's pipe dream of magically remoting arbitrary objects across space and languages.

If for some reason your problem does involve tapping the depth of typescript type expressivity (the elaborate rule systems expressed in maplibre style JSON come to mind?), you'd better have the closest approximation you can get on the other end of the line.

Post reply on HN