preset-typescript option "onlyRemoveTypeImports" is not working
See original GitHub issueBug Report
- I would like to work on a fix!
Current behavior
Input Code
I am trying transpile ts with babel using @babel/preset-typescript, but one of the challange I am facing is that, when injecting classes as parameter, import assigned type is removed by preset-typescript. I then came accross "onlyRemoveTypeImports": true
which promises to do exactly what I am trying to achieve. However, this does not seem to work 😦
Here is my ts file
some-service.ts
// THIS SHALL NOT BE REMOVED
import AWS from 'aws-sdk';
@Injectable()
export class SomeService {
constructor(
@Inject(AWS_TOKEN.DOCUMENT_CLIENT) private dc: AWS.DynamoDB.DocumentClient,
) {}
// ... do some stuff with this.dc
}
But in final output AWS import is removed as it wan’t used within a service. and running transpiled file gives me "ReferenceError: AWS is not defined"
error
Expected behavior when onlyRemoveTypeImports option is given, typescript preset should only ever remove type imports as stated in documentation.
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
- Filename:
.babelrc
{
"presets": [
[
"@babel/preset-env"
],
[
"@babel/preset-typescript",
{
"onlyRemoveTypeImports": true
}
]
],
"plugins": [
"babel-plugin-transform-typescript-metadata",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
["@babel/plugin-proposal-class-properties"]
]
}
Environment
System:
OS: Linux 4.15 elementary OS 5.1.3 Hera
Binaries:
Node: 12.5.0 - ~/.nvm/versions/node/v12.5.0/bin/node
npm: 6.13.7 - ~/.nvm/versions/node/v12.5.0/bin/npm
npmPackages:
@babel/plugin-proposal-class-properties: ^7.10.4 => 7.10.4
@babel/plugin-proposal-decorators: ^7.10.5 => 7.10.5
@babel/preset-env: ^7.11.5 => 7.11.5
@babel/preset-typescript: ^7.9.0 => 7.10.4
babel-plugin-transform-typescript-metadata: ^0.3.0 => 0.3.0
- Babel version(s): [ v6.26.0]
- How you are using Babel: [
cli
]
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
@whimzyLive can you create a repo that reproduces the problem? the import isn’t removed when I test this locally.
This indeed was a issue with babel-plugin-transform-typescript-metadata.
You can read more about it here