4.0.0 • Published 5 months ago

babel-preset-proposal-typescript v4.0.0

Weekly downloads
801
License
MIT
Repository
github
Last release
5 months ago

babel-preset-proposal-typescript

GitHub Actions Codecov npm GitHub Release

Conventional Commits Renovate enabled JavaScript Style Guide Code Style: Prettier changesets

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

  1. async-do-expressions
  2. destructuring-private
  3. do-expressions
  4. duplicate-named-capturing-groups-regex
  5. function-bind
  6. function-sent
  7. import-defer
  8. import-wasm-source
  9. optional-chaining-assign
  10. partial-application
  11. pipeline-operator
  12. record-and-tuple
  13. regexp-modifiers
  14. throw-expressions
  15. v8intrinsic - Further Detail

Install

# yarn
yarn add -D babel-preset-proposal-typescript

# npm
npm i -D babel-preset-proposal-typescript

Options

optiondescriptiondefaults
decoratorsBeforeExportSee Babel Documentundefined
decoratorsLegacyWhether to use legacy decorators semantictrue
importDeferWhether to enabled import-defer plugin, if true transform-modules-commonjs will be enabled automaticallyfalse
isTSXWhether to enable jsx plugin with typescriptfalse, but true for /\.[jt]sx$/
optionalChainingAssignVersionVersion for optional-chaining-assign plugin, only '2023-07' allowed for now'2023-07'
pipelineOperatorImplementation of pipeline operator, minimal, smart or fsharpminimal
recordTuplePolyfillWhether to enable import record-tuple plugin and polyfill, or specific the polyfill module nametrue for Node>=14.6, it represents @bloomberg/record-tuple-polyfill
recordTupleSyntaxTyperecord-tuple syntax, hash or barhash

Usage

Note that unlike plugins, the presets are applied in an order of last to first (https://babeljs.io/docs/en/presets/#preset-ordering), so please make sure proposal-typescript is used at the last.

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.

loader = {
  test: /\.[jt]sx?$/,
  loader: 'babel-loader',
  options: {
    presets: ['@babel/typescript', 'proposal-typescript'],
  },
}

// if you prefer `ts-loader` or `awesome-typescript-loader`
loader = {
  test: /\.tsx?$/,
  use: [
    {
      loader: 'ts-loader',
    },
    {
      loader: 'babel-loader',
      options: {
        presets: ['proposal-typescript'],
      },
    },
  ],
}

References

Sponsors

1stGRxTSUnTS
1stG Open Collective backers and sponsorsRxTS Open Collective backers and sponsorsUnTS Open Collective backers and sponsors

Backers

Backers

1stGRxTSUnTS
1stG Open Collective backers and sponsorsRxTS Open Collective backers and sponsorsUnTS Open Collective backers and sponsors

Changelog

Detailed changes for each release are documented in CHANGELOG.md.

License

MIT © JounQin@1stG.me

4.0.0

5 months ago

3.0.0

2 years ago

2.2.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.5.0

4 years ago

1.4.6

4 years ago

1.4.5

5 years ago

1.4.4

5 years ago

1.4.3

5 years ago

1.4.2

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

6 years ago

0.3.0

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago