Skip to content
This repository has been archived by the owner on Mar 20, 2022. It is now read-only.

fix(typescript): entities undefined if none found #435

Merged
merged 1 commit into from
Feb 22, 2020
Merged

fix(typescript): entities undefined if none found #435

merged 1 commit into from
Feb 22, 2020

Conversation

michael-martin
Copy link
Contributor

Problem

When there are no items found for a particular entity, normalizr returns nothing for that entity.

The problem is that the TypeScript definitions expect there to always be an object, so TypeScript fails to catch issues which later appear at runtime as undefined type errors.

Solution

Normalizr's behavior in this area has been discussed here before: https://github.com/paularmstrong/normalizr/issues/290

This PR doesn't change that, it just updates the TypeScript definition to match what Normalizr already returns.

Only issue is TypeScript will warn existing users about this error. It highlights a real potential bug in their system that it wasn't able to spot before, but likely to need users to fix their use of the result.entities object (or set {} as a default for undefined entities).

TODO

  • Add & update tests - NA, no TS definition tests.
  • Ensure CI is passing (lint, tests, flow)
  • Update relevant documentation - NA, no change to existing behavior.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling b445ddf on michael-martin:ts-undefined-entities into 09256f6 on paularmstrong:master.

Copy link
Owner

@paularmstrong paularmstrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@paularmstrong paularmstrong merged commit a8ac881 into paularmstrong:master Feb 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants