Issue 1:
Bug Report

Current Behavior

Mixin method declaration becomes undefined

Input Code

// Activatable Mixin
class Activatable {
isActive: boolean;
activate() {
this.isActive = true;
}
deactivate() {
this.isActive = false;
}
}

class SmartObject implements Activatable {
constructor() {

}

interact() {
this.activate();
}

// Activatable
isActive: boolean = false;
activate: () => void;
deactivate: () => void;
}
applyMixins(SmartObject, [Activatable]);

let smartObj = new SmartObject();
setTimeout(() => smartObj.interact(), 1000);

// Error: activate is not a method

////////////////////////////////////////
// In your runtime library somewhere
////////////////////////////////////////

function applyMixins(derivedCtor: any, baseCtors: any[]) {
baseCtors.forEach(baseCtor => {
Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name));
});
});
}

Expected behavior/code

A clear and concise description of what you expected to happen (or code).

Babel Configuration (.babelrc)

{
"presets": [
"@babel/preset-typescript",
[
"@babel/preset-env",
{
"modules": false,
"targets": {
"browsers": [
"> 1%",
"last 2 versions",
"ie >= 10"
]
}
}
],
"@babel/preset-react",
],
"plugins": [
"react-hot-loader/babel",
"react-require",
"@babel/plugin-proposal-object-rest-spread",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
[
"@babel/plugin-proposal-class-properties",
{
"loose": true
}
],
"react-html-attrs",
"jsx-control-statements",
[
"@babel/plugin-transform-runtime",
{
"corejs": 2
}
],
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-json-strings",
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions",
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-logical-assignment-operators",
"@babel/plugin-proposal-optional-chaining",
[
"@babel/plugin-proposal-pipeline-operator",
{
"proposal": "minimal"
}
],
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-do-expressions",
"@babel/plugin-proposal-function-bind"
]
}

Environment

Babel version(s):

"@babel/core": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-decorators": "^7.0.0",
"@babel/plugin-proposal-do-expressions": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-bind": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-proposal-pipeline-operator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.3.3",

Node/npm version: [Node 10.14.1/npm 6.4.1]

OS: OSX 10.12.5

Monorepo: no

How you are using Babel: loader

Possible Solution

remove all the declaration, not only the types

Additional context/Screenshots

compile typescript using babel-loader :

SmartObject

activate: undefind

deactivate: undefind

proto

activate()

deactivate()

compile typescript using ts-loader :

SmartObject

proto

activate()

deactivate()

Issue 2:
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.