Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types for typescript? #93

Closed
j-d-carmichael opened this issue Jun 25, 2020 · 12 comments · Fixed by #116
Closed

Types for typescript? #93

j-d-carmichael opened this issue Jun 25, 2020 · 12 comments · Fixed by #116
Labels
enhancement New feature or request released

Comments

@j-d-carmichael
Copy link

When using this tool programmatically within a typescript app, I could not see any type definitions anywhere.. are there any in the pipelines or an @types package i might have missed?

@j-d-carmichael j-d-carmichael added the enhancement New feature or request label Jun 25, 2020
@github-actions
Copy link

Welcome to AsyncAPI. Thanks a lot for reporting your first issue.

Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@derberg
Copy link
Member

derberg commented Jun 26, 2020

Hi @johndcarmichael. I don't have much experience with TypeScript. Parser is pure JS but the models have pretty good jsdoc, maybe these could be used to genereate types? there are some tools https://github.com/otris/jsdoc-tsd.

No one is working on it at the moment, and full focus is on 1.0 release and as high coverage of spec validation as possible.

@magicmatatjahu
Copy link
Member

magicmatatjahu commented Jul 9, 2020

Maybe ts-types repository would be great for this approach. Repo only with TS types with types helpers in guards form https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types.

In free time I tried to create types from JSON Schema spec by https://github.com/bcherny/json-schema-to-typescript lib, but it return trashed types in some places like:

export type Message =
  | Reference
  | (
      | {
          oneOf: Message[];
        }
      | {
          schemaFormat?: string;
          contentType?: string;
          headers?: Schema & {
            type?: {
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          payload?: unknown;
          correlationId?: Reference | CorrelationId;
          tags?: Tag[];
          /**
           * A brief summary of the message.
           */
          summary?: string;
          /**
           * Name of the message.
           */
          name?: string;
          /**
           * A human-friendly title for the message.
           */
          title?: string;
          /**
           * A longer description of the message. CommonMark is allowed.
           */
          description?: string;
          externalDocs?: ExternalDocs;
          deprecated?: boolean;
          examples?: {
            [k: string]: unknown;
          }[];
          bindings?: BindingsObject;
          traits?: (
            | Reference
            | MessageTrait
            | []
            | [Reference | MessageTrait]
            | [
                Reference | MessageTrait,
                {
                  [k: string]: unknown;
                }
              ]
          )[];
          [k: string]: SpecificationExtension;
        }
    );

Also https://app.quicktype.io/ has also a problem with generating types.

So I decided to write types from scratch and at the moment I have a full spec written in TS, without Bindings.

@derberg @fmvilas @jonaslagoni What do you think guys?

@jonaslagoni
Copy link
Member

jonaslagoni commented Jul 9, 2020

Isn't this issue regarding missing types package for the parser itself? (not the spec)

I added types for the generator, which was done with JSDoc to automatically generate the types, thinks that's the way to do here as well 😄 Think I used https://www.npmjs.com/package/tsd-jsdoc

@magicmatatjahu
Copy link
Member

@jonaslagoni Yes, this issue is related to parser, but I wonder if an idea with a separate package with only types would be a good one.

@jonaslagoni
Copy link
Member

@magicmatatjahu I am unsure of the use-case specifically in this context. Are you talking about making a repository containing types from the spec it self and use that to somehow solve this issue? 🤔

Cause with tsd-jsdoc we can have 0 maintaining from our side and generate it with github actions, which I think would be perfect fit which requires a minimal effort to solve from the maintainer point of view 😄

@j-d-carmichael
Copy link
Author

j-d-carmichael commented Jul 10, 2020

I think tsd-jsdoc is the better solution here as will be published and up to date with each release of this package. The @types namespace on npm i think was originally intended to give typescript more appeal when i was originally launched as no packages had types defined and waiting for the original authors to react would be too slow.

Is tsd-jsdoc something you will be publishing with this tool any time soon @jonaslagoni ?

@jonaslagoni
Copy link
Member

Is tsd-jsdoc something you will be publishing with this tool any time soon @jonaslagoni ?

@johndcarmichael unless @magicmatatjahu wants to take it for a spin. As long as there are no complications with the current jsdoc implementation it shouldn't take long 😄

@magicmatatjahu
Copy link
Member

@jonaslagoni I don't have any objections with using tsd-jsdoc.If it makes maintenance code easier, it's ok to me.

@jonaslagoni
Copy link
Member

jonaslagoni commented Jul 11, 2020

@johndcarmichael PR is up, are you up for reviewing it and ensure it works as you would expect 😄?

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 0.28.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@j-d-carmichael
Copy link
Author

Awesome! Thanks for the types guys, will work the new parser into boats and delete the ignore lints and custom unique opid checks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants