wrong js code when using ts constructor assignment
See original GitHub issueBug Report
- I would like to work on a fix!
Current Behavior If a module imported from TypeScript has the same name as a constructor parameter, a bug occurs.
Input Code
- REPL or Repo link if applicable:
import { messaging } from 'firebase-admin'
export class Something {
constructor(
public messaging: messaging.Messaging
) {
}
}
Expected behavior/code
Expected,
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Something = void 0;
class Something {
constructor(messaging) {
this.messaging = messaging;
}
}
exports.Something = Something;
But actual,
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Something = void 0;
var _firebaseAdmin = require("firebase-admin");
class Something {
constructor(_firebaseAdmin.messaging) { // Whoops!
this.messaging = messaging;
}
}
exports.Something = Something;
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
- Filename:
.babelrc
{
"presets": [
["@babel/env", {
"targets": "maintained node versions",
"useBuiltIns": "usage",
"corejs": 3
}],
"@babel/typescript"
]
}
Environment
System:
OS: macOS 10.15.2
Binaries:
Node: 10.16.3 - ~/.nvm/versions/node/v10.16.3/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.9.0 - ~/.nvm/versions/node/v10.16.3/bin/npm
npmPackages:
@babel/cli: ^7.8.3 => 7.8.3
@babel/core: ^7.8.3 => 7.8.3
@babel/plugin-proposal-class-properties: ^7.8.3 => 7.8.3
@babel/plugin-proposal-decorators: ^7.8.3 => 7.8.3
@babel/plugin-proposal-object-rest-spread: ^7.8.3 => 7.8.3
@babel/plugin-proposal-optional-chaining: ^7.8.3 => 7.8.3
@babel/preset-env: ^7.8.3 => 7.8.3
@babel/preset-typescript: ^7.8.3 => 7.8.3
eslint: ^6.2.2 => 6.2.2
jest: ^24.9.0 => 24.9.0
- Babel version(s): 7.8.3
- Node/npm version: node 10.16.3 / npm 6.9.0
- OS: macOS 10.15.2
- Monorepo: no
- How you are using Babel: cli
Possible Solution
Additional context/Screenshots .
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Using TypeScript, and Object.assign gives me an error ...
javascript - Using TypeScript, and Object. assign gives me an error "property 'assign' does not exist on type 'ObjectConstructor'" - Stack ...
Read more >Incorrect transpiled constructor of derived classes #12123
Code. class C extends Error { constructor() { super('error'); } ... However, if TS users incorrectly use primitive values, the current code ......
Read more >TypeScript errors and how to fix them
A list of common TypeScript errors and how to fix them.
Read more >Custom errors, extending Error
Here's the code with MyError and other custom error classes, simplified: class MyError extends Error { constructor(message) { super(message) ...
Read more >TypeScript Done Wrong
Now that code won't work, because TS will not like you assigning "123" to your property. Problem solved! Private class attributes through the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sorry for delaying the work on this issue. Will start working on it from today onwards.
I experienced a very similar issue to this when importing a type with the same name as the constructor argument. However, in my case, the output was slightly different to the above, resulting in a module import.
Source
Expected output
Actual output
Versions