-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Proposal: using ! prefix on JSX attributes to set them to false #47712
Comments
You should post your proposal at: https://github.com/facebook/jsx - TypeScript won't add non-type-only features that are not part of JSX. edit: Just saw that you did post it to the JSX repo already. But given the speed that JSX advances (almost zero) I wouldn't get my hopes up. Here's a comment regarding another issue request: #47589 (comment)
|
@MartinJohns, thanks for your quick response. What about ideas for extensions to the JSX type checking system and the JSX factory namespace (#3203) that do not require any JSX syntax changes - are you open for that?. I've some ideas for improving JSX typing/usability that can be used to perform stricter JSX validation and improve JSX intellisense. Some examples include:
Please let me know if applicable, i will open separate requests with use cases for each. |
I'm no member of the TypeScript team, just a noisy follower.
There's #21699 for this.
Not sure what you mean by that, but it sounds a lot related to the previous point.
This goes far beyond a type-only feature again, this would require additional runtime functionality. |
This issue has been marked as 'External' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Suggestion
π Search Terms
JSX, TSX, JSXElement, JSXAttribute, JSXAttributeName, markup, templates
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
According to current syntax, a JSX attribute without an initializer is set to boolean
true
.However, there is no such shortcut equivalent for initializing an attribute for
false
so in this case the full form must be used explicitly.My proposal is to allow an
!
prefix before the attribute name as shortcut forfalse
.This syntax extension is backward compatible with current grammar and can be added without impact on any existing JSX codebase.
I've opened corresponding feature request on facebook's draft JSX specification - see facebook/jsx#134, but i'm not sure whether TS follows that specification or not since it is not officially part of the EcmaScript specification.
π Motivating Example
<MyComp visible/>
is equivalent today to<MyComp visible={true} />
<MyComp !visible />
will become equivalent to<MyComp visible={false} />
π» Use Cases
This is quite a common case that is needed for any JSX attributes whose default value is defined as
true
. It helps reduce unnecessary clutter and simplify JSX expressions.The text was updated successfully, but these errors were encountered: