Skip to content

Wrong type on extend parent class object field #33899

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

Closed
zhongyuanjia opened this issue Oct 9, 2019 · 2 comments
Closed

Wrong type on extend parent class object field #33899

zhongyuanjia opened this issue Oct 9, 2019 · 2 comments
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@zhongyuanjia
Copy link

TypeScript Version: 3.6.3

Search Terms:

Code

class Par {
  obj = {
    a: 'par property'
  }

  tempObj = {
    a: 'temp par property'
  }
}

class Sub extends Par {
  // error type, obj is any
  obj = Object.assign({
    b: 'sub property'
  }, this.obj as Par["obj"])

  _tempObj: any = this.tempObj

  // correct type, tempObj is Par["tempObj"] & {b : string}
  tempObj = Object.assign({
    b: 'temp sub property'
  }, this._tempObj as Par["tempObj"])  
}

Expected behavior:

obj and tempObj type should be same

Actual behavior:

obj type is any

Playground Link:
http://www.typescriptlang.org/play/?ssl=17&ssc=31&pln=18&pc=1#code/MYGwhgzhAEAKYCdoG8CwAoa0D2AjAVtALwoZZZgBc0A5AA6LR0LZ0CmCALgJ41nQBfDP05sAtnQDyBYqUzkqtURKaNmrDjz7yh6XRlCQYAZQCuuaGwAeogHYATGPCRp5AejfQAlreDYECGzAnNA87Px4hCTS+EGcAHRGXgDmtgAUruTQuNQ0EOZMLOxcvPwCADShABZeEPGR0JBwiADaAESRbQC6AJTC8gD6ylIE1GC23LKcNXXDMf1YHtB+AXGh3OHyczLRBHGJUCnpmeQ5SuJ00PkW6sVaZZXTtfFDFzGNTq1t2-jdPVgYfToPy2CDYEBseIgbDJNK2NgAd2gZlwaR6-yAA

Related Issues:

@zhongyuanjia zhongyuanjia changed the title Wrong type on override object field Wrong type on override parent class object field Oct 9, 2019
@RyanCavanaugh RyanCavanaugh added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Oct 9, 2019
@RyanCavanaugh
Copy link
Member

Not mentioned in OP: this is flagged as an error.

Due to architectural constraints around how trees are marked as checked, this has to be treated as a circular reference despite the type assertion.

@zhongyuanjia zhongyuanjia changed the title Wrong type on override parent class object field Wrong type on extend parent class object field Oct 11, 2019
@zhongyuanjia
Copy link
Author

@RyanCavanaugh thanks for replying, it is possible extend parent class object field without temp variable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

2 participants