Skip to content

Object.assign not working with inheritance #6563

Closed
@tishinanton

Description

@tishinanton

Is this a bug report?

Yes

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

Environment

System:
OS: Windows 10
CPU: x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Binaries:
npm: 6.5.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 44.17763.1.0
Internet Explorer: 11.0.17763.1
npmPackages:
react: ^16.8.3 => 16.8.3
react-dom: ^16.8.3 => 16.8.3
react-scripts: 2.1.5 => 2.1.5
npmGlobalPackages:
create-react-app: Not Found

Steps to Reproduce

  1. create-react-app test --typescript
  2. add the following code to App.tsx
class A {
  constructor(...parts: Partial<A>[]) {
    Object.assign(this, ...parts);
  }
}

class B extends A {
  id: string;
  constructor(...parts: Partial<B>[]) {
    super(...parts);

  }
}

const a = new B({ id: '123' });
console.log(a);
  1. run and look into console

Expected Behavior

The output in the console should be: B {id: '123'}

Actual Behavior

Actual output is: B {id: undefined}

Reproducible Demo

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