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

TSX support attribute object literal shorthand #31797

Closed
2 of 5 tasks
nojvek opened this issue Jun 6, 2019 · 10 comments
Closed
2 of 5 tasks

TSX support attribute object literal shorthand #31797

nojvek opened this issue Jun 6, 2019 · 10 comments
Labels
External Relates to another program, environment, or user action which we cannot control.

Comments

@nojvek
Copy link
Contributor

nojvek commented Jun 6, 2019

Search Terms

tsx attribute shorthand, object shorthand

Suggestion

ES6 has this great syntax of passing key value pairs in objects e.g.

function swahili() {
  const hello = 'jambo';
  const great = 'sawa';
  return {hello, great};
}

but in TSX land this doesn't transfer well e.g.

function render() {
  const hello = 'jambo';
  const great = 'sawa';
  return <Greetings {hello, great} />
}

typescript throws an error that it needs a TS1005: '...' expected.

It instead needs to be written as

function render() {
  const hello = 'jambo';
  const great = 'sawa';
  return <Greetings {...{hello, great}} />
}

which seems very boiler platey.

It would be awesome if we could make a small tweak to pass attributes like es6 shorthand.

so all of these would be equal

<Foo hello={hello} world={world} />
<Foo {hello} {world} />
<foo {hello, world} />

They would all be emitted as

h(Foo, {hello, world})

Use Cases

Examples

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.
@nojvek
Copy link
Contributor Author

nojvek commented Jun 6, 2019

@RyanCavanaugh ^

Since you're the TSX expert, I assume you may have thoughts on it.

@ajafff
Copy link
Contributor

ajafff commented Jun 6, 2019

This is better proposed to the JSX spec. If it's accepted there, it'll surely find its way into Typescript

@jwbay
Copy link
Contributor

jwbay commented Jun 7, 2019

Proposed for the JSX spec here: facebook/jsx#23

@nojvek
Copy link
Contributor Author

nojvek commented Jun 10, 2019

said JSX pr with BNF grammar change: facebook/jsx#118

@jhpratt
Copy link

jhpratt commented Jun 13, 2019

The problem I find with proposals to the JSX spec is that they go untouched for years. This issue was created in 2014, and has had no action. Another issue (facebook/jsx#66) was created in 2016 and is a relatively trivial change.

Even worse, there is no response from the maintainers even after being directly pinged. That's the case in both issues.

TypeScript is a superset of JavaScript, why not also make it a superset of JSX?

@RyanCavanaugh RyanCavanaugh added the External Relates to another program, environment, or user action which we cannot control. label Jun 13, 2019
@RyanCavanaugh
Copy link
Member

These proposals need to start with the JSX folks.

I'm vaguely surprised (but happy) it doesn't already parse as a sequence expression 😅

@nojvek
Copy link
Contributor Author

nojvek commented Jun 13, 2019

Just curious, What do you mean by sequence expression?

Yeah jsx folks have been non-active for years. I tried pinging some contributors so let’s see where this goes.

@RyanCavanaugh
Copy link
Member

The expression a, b (e.g. 1 + (2, 3) === 4) evaluates a, evaluates b, and produces the right operand's result.

@jhpratt
Copy link

jhpratt commented Jun 13, 2019

I've just created facebook/jsx#119. Let's see what happens; I absolutely intend on forking the spec and updating it if Facebook doesn't consider proposals that have been open for multiple years.

@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

6 participants