typed-ember / glint

TypeScript powered tooling for Glimmer templates
https://typed-ember.gitbook.io/glint
MIT License
110 stars 51 forks source link

Add support for logical operators (RFC 562) #510

Closed bwbuchanan closed 1 year ago

bwbuchanan commented 1 year ago

Resolves #221. With this PR merged, you should be able to fully make use of type narrowing for discriminated unions.

Note that the type effects of these operators do not strictly match the semantics specified by RFC 562, in that they express JavaScript truthiness instead of Handlebars truthiness. It's not clear to me that it is possible to express Handlebars truthiness in TypeScript in such a way that you can usefully narrow types with it in combination with logical operators.

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": "!" }
          }
        }
      }
    }
  }
}
boris-petrov commented 1 year ago

Do we get a new release really soon with that change, please, @dfreeman? :smile:

dfreeman commented 1 year ago

@boris-petrov I'm working my way through a big backlog of both OSS and work stuff, but aiming to do a release early next week