Skip to content

Typescript constructor parameter properties is not working. #258

@soh335

Description

@soh335

Do you want to request a feature or report a bug?
bug

What is the current behavior?
Currently, don't work typescript constructor parameter properties correctly.

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.

repo here

class Employee extends Person {
   constructor(public name: string) {
     super();
   }
 }

yarn test change this typescript file to this.

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

var Employee = function (_Person) {
  _inherits(Employee, _Person);

  function Employee(name) {
    _classCallCheck(this, Employee);

    return _possibleConstructorReturn(this, _getPrototypeOf(Employee).call(this));
  }

  return Employee;
}(Person);

What is the expected behavior?

Employee like this

  function Employee(name) {
    var _this;

    _classCallCheck(this, Employee);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(Employee).call(this));
    _this.name = name;
    return _this;
  }

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.

metro: 0.45.4
node: v10.10.0
yarn: 1.9.4
macOS: 10.13.6

{
  "devDependencies": {
    "@babel/cli": "^7.1.0",
    "@babel/core": "^7.1.0",
    "@babel/plugin-transform-typescript": "^7.1.0",
    "metro-react-native-babel-preset": "^0.45.4"
  }
}

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