8000 getIn() throws TypeError if intermediary key doesn't exist · Issue #129 · immutable-js/immutable-js · GitHub
[go: up one dir, main page]

Skip to content
getIn() throws TypeError if intermediary key doesn't exist #129
Closed
@JannesMeyer

Description

@JannesMeyer

I'm not sure if this is an actual bug or if there is a decision behind this behavior.

Nonetheless, I would argue that it would be better for getIn() to return undefined in the case of an intermediary key not existing, because it would make for easier to read code. And it would also make sense since the value is "not defined" for all intents and purposes.

I have run into this issue with code like this:

var data = immutable.fromJS({
    items: [ { name: 'Test' }, null, { name: 'Another test' } ]
});
var selectedItems = immutable.Set();

// Select all items
selectedItems = data.get('items').keySeq().toSet();

// Somewhere else:
selectedItems.map(function(id) {
    var item = data.getIn(['items', id, 'name']); // Throws TypeError because of the null item
    // [...]
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0