question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript constructor parameter properties is not working.

See original GitHub issue

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"
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
rafecacommented, Oct 5, 2018

Closing the issue, the PR got included in v0.48.0 🎉

1reaction
soh335commented, Sep 21, 2018

@rafeca submitted p-r. But I’m not familiar with babel and metro. So, I don’t have confidence in my p-r. Please review it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript parameter properties not working with Storybook + ...
However, for some reason, when using TypeScript with Storybook and Rollup, constructor properties are not transpiled to class properties.
Read more >
Documentation - Classes - TypeScript
The strictPropertyInitialization setting controls whether class fields need to be initialized in the constructor. name : string; Property 'name' has no ...
Read more >
TypeScript constructor parameter properties - My Memory
If we attempt to access the properties name and age from outside the class (using TypeScript) then we'll get the error “Property 'name'...
Read more >
no-parameter-properties - Rule
It can be cleaner to keep member variable declarations in one list directly above the class constructor (instead of mixed between direct class...
Read more >
parameter-properties | typescript-eslint
Require or disallow parameter properties in class constructors. TypeScript includes a "parameter properties" shorthand for declaring a class constructor ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found