avsc
avsc copied to clipboard
TypeScript Support
Thanks for the hard work on this - great project.
Any plans to include type definitions for TypeScript?
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!
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.
Thanks @andrew8er! Can you submit a PR with what you have so far?
https://github.com/mtth/avsc/pull/134
Merged - thanks @andrew8er. Keeping this open since the typing file isn't complete yet.
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:
- bundling with your npm package, or
- publishing to the @types organization on npm.
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.
Any status on this work? It's a really terrific initiative so I'm not nagging, just excited!
@yonkeltron - still a WIP but we already have reasonably complete typings thanks to @andrew8er and @TysonAndre.
Roger! I'll pass it along to my teammates and we can try it out. Thanks for the hard work!
Just added a pull request to improve the typings...
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
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:
-
payloadAvroType.fromBuffer
would be smart enough to be able to signal the type of object that is returned. -
avro.Type.forSchema
would be able to take a type / validate that the schema aligns with that type.
I hope these ideas make sense