Bug Report
Current Behavior
When a class (B) extends another class (A) and includes a type definition to narrow the type of something specified in class A, it will set the narrowed property's value to undefined. This diverges from the TSC behavior.
The output from the below code under babel is a, undefined.
Input Code
class A {
value: any
constructor(value: any) {
this.value = value
}
}
class B extends A {
value: string
}
document.write(`${new A('a').value}, ${new B('b').value}`)
Expected behavior/code
The output from the code should be a, b.
Babel Configuration (.babelrc, package.json, cli command)
.babelrc:
{
"presets": [
"@babel/env",
"@babel/typescript"
],
"plugins": [
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"
]
}
Environment
- Babel version(s): 7.1.6
- Node/npm version: Node 10 / NPM 6
- OS: Any OS
- Monorepo: doesn't matter
- How you are using Babel: loader
Possible Solution
It seems like babel is setting value = undefined in the class property - it needs to check if that value is defined in the parent before overwriting it.
Bug Report
Current Behavior
When a class (B) extends another class (A) and includes a type definition to narrow the type of something specified in class A, it will set the narrowed property's value to undefined. This diverges from the TSC behavior.
The output from the below code under babel is
a, undefined.Input Code
Expected behavior/code
The output from the code should be
a, b.Babel Configuration (.babelrc, package.json, cli command)
.babelrc:
Environment
Possible Solution
It seems like babel is setting
value = undefinedin the class property - it needs to check if that value is defined in the parent before overwriting it.