Skip to content

"Class constructor [XXX] cannot be invoked without 'new'" when using extend in ES6+ env #2101

Closed
@RexSkz

Description

@RexSkz

Root Cause

The code https://github.com/immutable-js/immutable-js/blob/main/src/methods/merge.js#L27-L33 calls constructor without new. If the constructor is a class, it will throw this error.

Playground: https://immutable-js.com/play/#Y2xhc3MgTXlSZWNvcmQgZXh0ZW5kcyBSZWNvcmQoewogIC8vIGE6IDEKfSkge30KCnZhciBteVJlY29yZCA9IG5ldyBNeVJlY29yZCgpOwpteVJlY29yZC5tZXJnZSh7IGE6IDQgfSk7

Image

Workaround

Do not use the empty object as the parameter of Record.

- class MyRecord extends Record({}) {}
+ class MyRecord extends Record({ a: 1 }) {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions