question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Let's discuss TypeScript support.

See original GitHub issue

I am well aware that this is Babel world project and it was meant like that from the start. However, I would like to initiate the discussion here what it would take to have macros available in TypeScript world. Macros are such a great concept it would be almost a crime to leave it like this.

Problem

I am mostly coming from the situation I am trying to solve now. The LinguiJS is going to be using macros to transform i18n elements. While in a Webpack world it’s possible to run ts-loader and babel-loader in tandem, it already introduces challenges, eg. keep JSX untransformed so Babel can have enough information and do JSX transformation on its own later along with Macros.

Also, other toolings needs to solve the same. Be it extraction process of Lingui itself or Jest testing or any other bundler I suppose. None can use Webpack loaders and have its own way around. This is no good for a whole ecosystem in my opinion.

I am sure this situation is not unique and with rising adoption of TypeScript there will surely be more projects popping out trying to solve the same. I feel it would be rather unhealthy to keep ecosystem separated like this. Not only for library authors, but for users as well.

Solutions?

TypeScript has it’s own “plugin” system or rather it’s called custom transforms. There is some AST apparently, but I do have trouble finding a real documentation for that. Honestly, I’ve never been fiddling with AST in Babel, so I am probably the least capable person to deliver any valid information in here.

Would it be viable to basically have a Typescript transform that can understand babel macros out of the box? Most likely that due to AST difference the authors of macros would need to account for both variants, but on the user end it would mean complete transparency as you could use either language without hassle.

Goal

To prepare a TypeScript plugin/transform that would work in a similar fashion to babel-plugin-macros allowing user code driven transformation instead of relying on bunch of hard-to-configure plugins. Ultimately, if we can achieve some level of compatibility between these projects and bridge the gap, it make life easier for everyone.

Current stage

None 😃 We are seeking some smart people who have insight into TypeScript transforms and AST. We need to create a prototype that mimics the behavior of babel-plugin-macros at some basic level to verify the core idea.

Why not to use Babel-Typescript support?

One might argue that since there is TypeScript support in Babel now, it’s a clear path and no need to bother with this. I would agree in case that support would be building on a real TypeScript compiler. Since it’s completely separate implementation, it might introduce unexpected errors and incompatibilities. VSCode checking can tell A and then Babel will transform it into B. Current lack of some features is an example of that and more might come.

Personally, I think it’s a wrong path, but that’s not the point of this discussion. Perhaps I am mistaken on this and I would love to be proven otherwise.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:36
  • Comments:116 (29 by maintainers)

github_iconTop GitHub Comments

6reactions
xiaoxiangmoecommented, Dec 11, 2018

@FredyC https://github.com/xiaoxiangmoe/typescript-macros/

Babel-plugin-macros use mutable API, this does not seem to be compatible with TypeScript transformer, so I chose to use immutable API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The starting point for learning TypeScript
Find TypeScript starter projects: from Angular to React or Node.js and CLIs.
Read more >
Discuss TypeScript - Tutorialspoint
Discuss TypeScript, TypeScript lets you write JavaScript the way you really want to. ... Mastering TypeScript can help programmers to write object-oriented ...
Read more >
TypeScript: An Introduction - CODE Magazine
Let's talk about TypeScript as a solution to some of the ... In this case, you're creating a class, which isn't supported in...
Read more >
Stop Using “any” Type in TypeScript | by Chameera Dulanga
... and it can make your TypeScript project similar to a regular JavaScript project. So, let's discuss why we should not use any...
Read more >
4. Typescript Types. Lets learn the typescript types ... - YouTube
HI friendsIn this video, we will see the typescript types and the javascript types that both support like a number, string, and boolean....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found