Skip to content

About

Yet another Babel preset for TypeScript, only transforms proposals which TypeScript does not support now.

Topics

Resources

Security policy

Stars

26 stars

Watchers

2 watching

Forks

Repository files navigation

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. discard-binding
  4. do-expressions
  5. duplicate-named-capturing-groups-regex
  6. export-default-from
  7. function-bind
  8. function-sent
  9. import-defer
  10. import-wasm-source
  11. optional-chaining-assign
  12. partial-application
  13. pipeline-operator
  14. regexp-modifiers
  15. throw-expressions
  16. v8intrinsic - Further Detail

Note

record-and-tuple syntax support has been removed in Babel 8, so it is no longer enabled.

Install

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

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

Options

option description defaults
decoratorsLegacy Whether to use legacy decorators semantic, version: 'legacy' or '2023-11' for Babel 8 true
importDefer Whether to enabled import-defer plugin, if true transform-modules-commonjs will be enabled automatically false
isTSX Whether to enable jsx plugin with typescript false, but true for /\.[jt]sx$/
optionalChainingAssignVersion Version for optional-chaining-assign plugin, only '2023-07' allowed for now '2023-07'
partialApplicationVersion Version for partial-application plugin, only '2018-07' allowed for now '2018-07'
pipelineOperator Implementation of pipeline operator, hack or fsharp fsharp
pipelineTopicToken Topic token for the pipeline operator, only used when pipelineOperator is hack '%'

Note

pipelineOperator: 'hack' cannot be combined with the always enabled v8intrinsic plugin since Babel 8, because both rely on the % token.

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

1stG RxTS UnTS
1stG Open Collective backers and sponsors RxTS Open Collective backers and sponsors UnTS Open Collective backers and sponsors

Backers

Backers

1stG RxTS UnTS
1stG Open Collective backers and sponsors RxTS Open Collective backers and sponsors UnTS Open Collective backers and sponsors

Changelog

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

License

MIT © JounQin@1stG.me

About

Yet another Babel preset for TypeScript, only transforms proposals which TypeScript does not support now.

Topics

Resources

Security policy

Stars

26 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages