mathematic-inc / ts-japi

A highly-modular (typescript-friendly)-framework agnostic library for serializing data to the JSON:API specification
Apache License 2.0
202 stars 15 forks source link

[BUG] Polymorphic Serialiser - Not handling empty arrays #86

Closed janders4 closed 5 months ago

janders4 commented 5 months ago

Describe the bug*

When

To Reproduce*

Provide an empty array as the first argument for the PolymorphicSerializer.serialize function

Expected behavior*

When providing an empty array to the polymorphic serializer serialize function an unhandled type error is thrown: Reduce of empty array with no initial value

Platform*

Additional context

Stack:

TypeError: Reduce of empty array with no initial value
    at Array.reduce (<anonymous>)
    at PolymorphicSerializer.serialize (/ts-japi@1.11.0/node_modules/ts-japi/lib/classes/polymorphic-serialiser.js:20:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
message: 'Reduce of empty array with no initial value'