Skip to content

Type narrowing #548

Answered by chriskrycho
swastik asked this question in Q&A
Discussion options

You must be logged in to vote

You need an implementation of eq which "narrows" the same way that TypeScript's === does. At the moment, the types for eq from ember-truth-helpers or similar do not in general support that. I think we're missing some docs on that, but you can see how it works to give it those semantics in the implementing pull request. The reason this isn't "built in" is noted in the PR:

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…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by chriskrycho
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants