-
Notifications
You must be signed in to change notification settings - Fork 51
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
Support type-narrowing via discriminated unions #221
Comments
This is dependent the Equality Operators RFC actually landing. Until then we can't assume anything about what |
It's been more than a year since this feature request was opened and nearly 3(!) years since the equality operators RFC was first posted. Is there some way we can get this as an opt-in, i.e. assert to glint that the eq helper is defined as Not having the ability to discriminate unions in templates leaves the choice of either (a) adding a ton of boilerplate in the component backing class or controller to deal with all the various cases, or (b) just telling glint to ignore many templates and hoping for the best. |
And the RFC hasn't been implemented in that time, so my comment above still holds 🙂
Glint's maintainers have limited capacity, and we need to carefully prioritize when considering what additions and improvements we spent that capacity on. Since the RFC hasn't been implemented, other issues have taken higher priority for us, and will likely continue to for some time given our constraints. If the equality operators were to land in an Ember release, though, that would certainly change the calculus. In the meantime, I'd be happy to review a PR contributing the ability to opt in to native semantics for equality operators; it just isn't something we have the capacity to do ourselves at the expense of other work at present. |
@dfreeman glad to hear that you're open to having an opt-in to the new semantics I found it pretty easy to modify Do you have any guidance or opinions on this? Thanks! |
@bwbuchanan I'm currently overhauling how we handle special forms like |
Nice, I see you just merged #453 . I will have a go at rebasing my changes and making up a PR. |
@dfreeman What do you think is right for the option name? Or would it be better to have something like {
includeOptionalHelpers: ['equalityOperators', 'logicalOperators', 'numericComparisonOperators']
} |
I think what I'd suggest instead is directly accepting special forms config in a similar way to how the GlimmerX environment accepts an Then users could configure their environment to opt into the specific special forms they want to enable, e.g.: "glint": {
"environment": {
"ember-loose" {
"additionalSpecialForms": {
"globals" {
"eq": "===",
"not-eq": "!==",
"and": "&&",
"or": "||",
// ...
}
}
},
"ember-template-imports": {
"additionalSpecialForms": {
"imports": {
"ember-truth-helpers/helpers/eq": { "default": "===" },
"ember-truth-helpers/helpers/not-eq": { "default": "!==" },
// ...
}
}
}
}
} We can of course bikeshed on things like the appropriate names for these new special forms, and whether It's a bit more boilerplate than a simple flag would be, but I think that's ok for opting into an unstable feature of the platform, particularly given that things like import paths for strict mode haven't been established yet. |
Ah, I see you left a comment about import paths while I was writing that up—see above for how I think we might sidestep that particular issue within Glint 😄 |
Resolves typed-ember#221 As these helpers have not yet been merged into Ember, you can opt in by adding to your glint config: "glint": { "environment": { "ember-loose": { "additionalSpecialForms": { "globals": { "eq": "===", "not-eq": "!==" } } }, "ember-template-imports": { "additionalSpecialForms": { "imports": { "ember-truth-helpers/helpers/eq": { "default": "===" }, "ember-truth-helpers/helpers/not-eq": { "default": "!==" } } } } } }
PR filed! Once this is good enough to merge, I'll follow up with one to support logical and numeric comparison operators from RFCs 561 and 562. |
Great, thank you! I'll aim to give it a look this weekend, or Monday at the latest. |
I'm going to reopen this for the time being since there are still some additional operators to land. Thank you for driving this forward @bwbuchanan! |
Resolves typed-ember#221 As these helpers have not yet been merged into Ember, you can opt in by adding to your glint config: { "glint": { "environment": { "ember-loose": { "additionalSpecialForms": { "globals": { "and": "&&", "or": "||", "not": "!" } } }, "ember-template-imports": { "additionalSpecialForms": { "imports": { "ember-truth-helpers/helpers/and": { "default": "&&" }, "ember-truth-helpers/helpers/or": { "default": "||" }, "ember-truth-helpers/helpers/not": { "default": "!" } } } } } } }
I'm going to open a PR for logical operators (RFC 562). I believe that numeric comparison operators (RFC 561) do not require any glint special forms to implement and plain helper function typedefs should suffice. |
Resolves typed-ember#221 As these helpers have not yet been merged into Ember, you can opt in by adding to your glint config: { "glint": { "environment": { "ember-loose": { "additionalSpecialForms": { "globals": { "and": "&&", "or": "||", "not": "!" } } }, "ember-template-imports": { "additionalSpecialForms": { "imports": { "ember-truth-helpers/helpers/and": { "default": "&&" }, "ember-truth-helpers/helpers/or": { "default": "||" }, "ember-truth-helpers/helpers/not": { "default": "!" } } } } } } }
Resolves typed-ember#221 As these helpers have not yet been merged into Ember, you can opt in by adding to your glint config: { "glint": { "environment": { "ember-loose": { "additionalSpecialForms": { "globals": { "and": "&&", "or": "||", "not": "!" } } }, "ember-template-imports": { "additionalSpecialForms": { "imports": { "ember-truth-helpers/helpers/and": { "default": "&&" }, "ember-truth-helpers/helpers/or": { "default": "||" }, "ember-truth-helpers/helpers/not": { "default": "!" } } } } } } }
Type-narrowing via discriminated unions is a useful TypeScript feature. I believe it's not supported via Glint:
The
foo
getter compiles just fine as the TypeScript compiler does it's job, however thelog
in the HBS gives an error:It would be nice to be able to do this. Not sure it's possible though. At the very least a "built-in"
eq
helper must be defined and Glint should be hard-coded to know about it I guess.The text was updated successfully, but these errors were encountered: