mtth / avsc

Avro for JavaScript :zap:
MIT License
1.27k stars 148 forks source link

TypeScript Support #128

Open damonwildercarr opened 7 years ago

damonwildercarr commented 7 years ago

Thanks for the hard work on this - great project.

Any plans to include type definitions for TypeScript?

mtth commented 7 years ago

Typings would definitely be welcome. I doubt I'll have time to dig into TypeScript enough to add them anytime soon unfortunately; I'll keep this open in case someone else would like to take a stab at it. Thank you for the kind words and bringing this up!

andrew8er commented 6 years ago

I have an incomplete version here: https://github.com/andrew8er/avsc/tree/feature/typescript-definitions

I am pretty sure there are some errors, since I'm only really using a small part of the API so far.

mtth commented 6 years ago

Thanks @andrew8er! Can you submit a PR with what you have so far?

andrew8er commented 6 years ago

https://github.com/mtth/avsc/pull/134

mtth commented 6 years ago

Merged - thanks @andrew8er. Keeping this open since the typing file isn't complete yet.

TysonAndre commented 6 years ago

What's the intent for the package https://www.npmjs.com/package/@avro/types ?

Also, publishing declarations that are neither in "@types/avsc" nor packaged with "avsc" is non-standard and surprising. I proposed https://github.com/mtth/avsc/pull/146 ("bundling with your npm package") , but closed it since I'm not sure what the long term plan is.

According to https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/declaration%20files/Publishing.md

Now that you have authored a declaration file following the steps of this guide, it is time to publish it to npm. There are two main ways you can publish your declaration files to npm:

  1. bundling with your npm package, or
  2. publishing to the @types organization on npm.
mtth commented 6 years ago

Hey @TysonAndre, thank you for the publishing tips. I'd created the @avro/types package to hold the Avro type decoding/encoding logic from avsc: a long term effort to split avsc into modular components, unfortunately stalled for now. It isn't at all related to TypeScript so it sounds like the best option is to include the types/ folder in this package.

yonkeltron commented 6 years ago

Any status on this work? It's a really terrific initiative so I'm not nagging, just excited!

mtth commented 6 years ago

@yonkeltron - still a WIP but we already have reasonably complete typings thanks to @andrew8er and @TysonAndre.

yonkeltron commented 6 years ago

Roger! I'll pass it along to my teammates and we can try it out. Thanks for the hard work!

reuzel commented 6 years ago

Just added a pull request to improve the typings...

RandomFractals commented 5 years ago

shameless plug: you can see how I use it in TS here: https://github.com/RandomFractals/vscode-data-preview/blob/master/src/data.providers/avro.data.provider.ts

slifty commented 2 years ago

I apologize for commenting without being able to dedicate time to opening a PR, but wanted to point out this really handy set of features that live in AJV: https://ajv.js.org/guide/typescript.html

In particular, it would be amazing if:

  1. payloadAvroType.fromBuffer would be smart enough to be able to signal the type of object that is returned.
  2. avro.Type.forSchema would be able to take a type / validate that the schema aligns with that type.

I hope these ideas make sense