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

Backtick string template literal in TSX without curly brackets #40662

Closed
5 tasks done
KSXGitHub opened this issue Sep 21, 2020 · 8 comments
Closed
5 tasks done

Backtick string template literal in TSX without curly brackets #40662

KSXGitHub opened this issue Sep 21, 2020 · 8 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@KSXGitHub
Copy link
Contributor

Search Terms

backtick string template literal react tsx

Suggestion

Curly brackets wrapping around quotes is visually noisy. It would be nice to have string interpolation without having to use curly brackets.

Use Cases

  • String interpolation in attribute names

Examples

<Link href=`https://www.example.com/{foo}/{bar}`>Link</Link>

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, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@MartinJohns
Copy link
Contributor

You should probably create a TC39 proposal for this, because this wouldn't be legal JSX.

@KSXGitHub
Copy link
Contributor Author

@MartinJohns JSX is not plain JavaScript. I don't think TC39 would care.

@MartinJohns
Copy link
Contributor

Good point, I wasn't aware of that. But there should still be special consideration for "jsx": "preserve", because I doubt any other tooling will support this.

@KSXGitHub
Copy link
Contributor Author

But there should still be special consideration for "jsx": "preserve"

"jsx": "preserve" does not prevent es5 transpilation right?

@MartinJohns
Copy link
Contributor

It does not prevent ES5 translation.

// Source:
<Link href={`https://www.example.com/${foo}/${bar}`}>My Link</Link>;

// ES5 result:
<Link href={"https://www.example.com/" + foo + "/" + bar}>My Link</Link>;

// ES2015 result:
<Link href={`https://www.example.com/${foo}/${bar}`}>My Link</Link>;

To be fair, I understand the curly braces can be annoying (and a distraction), but the difference is really negligible:

<Link href={`https://www.example.com/${foo}/${bar}`}>My Link</Link>;
<Link href=`https://www.example.com/${foo}/${bar}`>My Link</Link>;

@IllusionMH
Copy link
Contributor

I guess this depends on facebook/jsx#25

@RyanCavanaugh RyanCavanaugh added the External Relates to another program, environment, or user action which we cannot control. label Sep 22, 2020
@RyanCavanaugh
Copy link
Member

We don't want to create a variant of a variant - the linked issue above should be resolved first, at which point we can trivially take up a fix on our side.

@typescript-bot
Copy link
Collaborator

This issue has been marked as 'External' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
External Relates to another program, environment, or user action which we cannot control.
Projects
None yet
Development

No branches or pull requests

5 participants