Skip to content

How does Typescript parse customized syntax configured with babel? #9353

@tranvansang

Description

@tranvansang

It has been known long ago that babel supports typescript via the babel-preset-typescript.

The work flow is something like

  • .ts files are converted to .js file with type annotation removed by babel.

  • Concurrently, typescript type-checks the .ts files via tsc command.

How does typescript understands (parses) many custom syntax configured with babel? For example: @babel/plugin-proposal-optional-chaining

Is anyway to make babel just compile the code from Typescript into Typescript with custom syntax parsed. For example, I want babel to convert this code

const a: number = foo?.bar

into

const a: number = (_foo = foo) === undefined && _foo.bar

instead of

const a = (_foo = foo) === undefined && _foo.bar

If babel can do that, I can freely add any language features as I want without waiting for Typescript support.

Another way would be letting typescript ignore custom syntax configured with babel, and just do the type check.
However, IMO babel is too flexible for typescript to handle its supported syntax.


Metadata

Metadata

Assignees

No one assigned

    Labels

    i: needs triagei: questionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions