Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Array index assignment followed by push only assigns #12

Open
michaelboyles opened this issue Nov 6, 2021 · 0 comments
Open

[BUG] Array index assignment followed by push only assigns #12

michaelboyles opened this issue Nov 6, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@michaelboyles
Copy link
Owner

Describe the bug

An array assignment to a specific index, followed by a call to a method such as Array.push will completely ignore the second method, and only the assignment will occur

Sample input

interface NumberArrayState {
    arr: number[]
}
const reducer = redcr((state: NumberArrayState) => {
    state.arr[1] = 123;
    state.arr.push(456);
});

Current output

Specify which ES version you're targeting: ES2020

const reducer = (state) => {
    state = {
        ...state,
        arr: Object.assign([...state.arr], { [1]: 123 })
    };
    return state;
};
@michaelboyles michaelboyles added the bug Something isn't working label Nov 6, 2021
@michaelboyles michaelboyles self-assigned this Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant