avsc icon indicating copy to clipboard operation
avsc copied to clipboard

TypeScript Support

Open damonwildercarr opened this issue 7 years ago • 13 comments

Thanks for the hard work on this - great project.

Any plans to include type definitions for TypeScript?

damonwildercarr avatar Sep 07 '17 18:09 damonwildercarr

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!

mtth avatar Sep 08 '17 04:09 mtth

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.

andrew8er avatar Nov 02 '17 16:11 andrew8er

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

mtth avatar Nov 04 '17 19:11 mtth

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

andrew8er avatar Nov 06 '17 12:11 andrew8er

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

mtth avatar Nov 18 '17 16:11 mtth

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

  • I don't see it mentioned in this repo's issues
  • Grepping the source code, I don't see @avro/types
  • @avro/types doesn't have a README on NPM

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.

TysonAndre avatar Jan 09 '18 22:01 TysonAndre

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.

mtth avatar Jan 11 '18 11:01 mtth

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

yonkeltron avatar Feb 20 '18 14:02 yonkeltron

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

mtth avatar Feb 21 '18 15:02 mtth

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

yonkeltron avatar Feb 21 '18 22:02 yonkeltron

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

reuzel avatar May 11 '18 14:05 reuzel

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

RandomFractals avatar Sep 12 '19 21:09 RandomFractals

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

slifty avatar Jun 21 '22 16:06 slifty