mohuk / ts-jsonapi

JSON API (De)Serializer in Typescript
MIT License
52 stars 10 forks source link

Export `SerializerOptions` #4

Open fastfedora opened 7 years ago

fastfedora commented 7 years ago

I'm new to learning TypeScript, but it seems like I can't use this library because it doesn't export SerializerOptions.

If I try to pass {} when creating a Serializer, I get Argument of type '{}' is not assignable to parameter of type 'SerializerOptions'. If I try to type {}, I get Cannot find name 'SerializerOptions'.

Am I missing something? It seems like SerializerOptions needs to be exported in index.ts (or in serializer.ts) so I can import it as a type and use it when I'm using the library.

fastfedora commented 7 years ago

Never mind. As I learn TypeScript, it seems like this isn't necessary.

I think I was getting the error because I was missing required properties on the options object. It looks like id is marked required for ts-jsonapi, but was optional for jsonapi-serializer.

The required attributes, which comes from jsonapi-serializer didn't make sense to me. I wound up developing my own function that derived the attributes from the passed in object instead (and derived relationships by looking for nested objects containing an id property).

I'll leave this open in case you want to track marking id as optional for SerializerOptions, but I have everything I need on my end, so feel free to close it if that's by design.

mohuk commented 7 years ago

I think id should be optional. Let me think about it and make another release.