Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macro] How likely TypeScript will consider adding macro in the future #50815

Closed
5 tasks done
Bistard opened this issue Sep 17, 2022 · 10 comments
Closed
5 tasks done

[macro] How likely TypeScript will consider adding macro in the future #50815

Bistard opened this issue Sep 17, 2022 · 10 comments
Labels
Duplicate An existing issue was already created

Comments

@Bistard
Copy link

Bistard commented Sep 17, 2022

Suggestion

I believe the team of TypeScript definitely has considered related topics about macro in the past. Since we do not have macro right now in TypeScript, there must be some concerns or flaws about macro. I am actually kind of curious and want to know a few reasons why not having macro today.

I can guess a few points so far:

  1. It is against the design idea of TypeScript just like enum because it changes the actual behaviour.
  2. It is hard to do type-checking while using macro.
  3. macro used across different JavaScript files can resolve weird type-checking behaviours.

I personally wish to have macro to increase readability while writing TypeScript.

🔍 Search Terms

macro

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

📃 Motivating Example

TBD

💻 Use Cases

TBD

@jcalz
Copy link
Contributor

jcalz commented Sep 17, 2022

Polo?

@xiBread
Copy link

xiBread commented Sep 17, 2022

Assuming you mean macro, then #4892.

@fatcerberus
Copy link

fatcerberus commented Sep 17, 2022

I initially assumed this is about macros too, but the phrasing is... very odd.

related topics about Marco
concerns ... about Marco
having Marco
using Marco
I personally wish to have Marco

Given the commitment to this odd phrasing (and conspicuous capitalization of Marco) in an otherwise well-written issue, I'm left to ask either or both of these questions:

  1. Who is Marco?
  2. Is this a joke?

@Bistard Bistard changed the title [Marco] How likely TypeScript will consider adding Marco in the future [macro] How likely TypeScript will consider adding macro in the future Sep 17, 2022
@Bistard
Copy link
Author

Bistard commented Sep 17, 2022

I initially assumed this is about macros too, but the phrasing is... very odd.

related topics about Marco
concerns ... about Marco
having Marco
using Marco
I personally wish to have Marco

Given the commitment to this odd phrasing in an otherwise well-written issue, I'm left to ask either or both of these questions:

  1. Who is Marco?
  2. Is this a joke?

nah, I just typed everything wrong. Didn't mean't Macro Poll.

@fatcerberus
Copy link

Macro Poll

Okay, now you're just doing it on purpose. 😉

@fatcerberus
Copy link

This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)

I think macros probably fall under "non-ECMAScript syntax with JavaScript output", but I'm not positive. It does seem like a bit of a gray area w.r.t. the TS design goals.

@Bistard
Copy link
Author

Bistard commented Sep 17, 2022

Assuming you mean macro, then #4892.

Thanks for sharing (just realized the reason I didn't find related issues on macros is that I typed it as marcos). I read through the issue and found some related topics or comments on this one:

After reading through the above issue still haven't found any positive or negative responses from the team 😭 I guess this proposal is already been refused a long time ago.

@MartinJohns
Copy link
Contributor

MartinJohns commented Sep 17, 2022

I'm confused. You correctly identified

It is against the design idea of TypeScript

but then you check

[x] This feature would agree with the rest of TypeScript's Design Goals.

in the viability checklist.


Besides that, I find it highly unlikely to expect anything like this in the next 5 years, if ever.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Sep 19, 2022
@RyanCavanaugh
Copy link
Member

The most likely outcome, by a very large margin, is that macros are not happening. We've looked into this in the past and it doesn't seem like there's any tractable path that doesn't violate critical design constraints. If you macro with existing syntax (like how C's preprocessor works), there's a violation of the "all JS is TS" principle, plus it's super weird (what happens if you indirect a macro function?). If you macro with novel syntax, then there's a problem of how you even parse a file, especially in contexts like tooling where you expect to be able to open a TS file and get reasonable behavior without knowing the entire project context.

@alshdavid
Copy link

alshdavid commented Dec 1, 2024

#60645

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

7 participants