babel-preset-proposal-typescript
Yet another Babel preset for TypeScript, only transforms proposals which TypeScript does not support now.
So that you can use babel to transform proposals which are current in stage 0-2 and TypeScript team will not implement them temporarily.
TOC
Enabled proposal plugins
- class-properties
- do-expressions
- function-bind
- function-sent
- json-strings
- logical-assignment-operators
- nullish-coalescing-operator
- optional-chaining
- partial-application
- pipeline-operator
- private-methods
- throw-expressions
Install
yarn add -D babel-preset-proposal-typescript
npm i -D babel-preset-proposal-typescript
Usage
Via .babelrc
(Recommended)
.babelrc
{
"presets": ["proposal-typescript"]
}
Via CLI
babel input.ts --presets proposal-typescript > output.ts
Via Node API
require('@babel/core').transform('code', {
presets: ['proposal-typescript'],
})
Via webpack
Pipe codes through babel-loader
to ts-loader
or awesome-typescript-loader
.
loader = {
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
},
{
loader: 'babel-loader',
options: {
presets: ['proposal-typescript'],
},
},
],
}
Options
option | description | defaults |
---|
decoratorsLegacy | whether to use legacy decorators semantic | true |
isTSX | whether to enable jsx plugin with typescript | false , true for /\.[jt]sx$/ |
pipelineOperator | implementation of pipeline operator | "minimal" |