8
ostream
19d

Who the hell use any instead of a Boolean? Why on earth did I spend 10 months of my life learning a new language (Typescript) for a framework whose writer doesn't even respect their own good practices.

Comments
  • 3
    “Hmm... I don’t know which type this will be..., Eck, will do later”
  • 4
    Disabled isn't a Boolean attribute. It is present when the control is disabled, and absent when it's not:

    https://developer.mozilla.org/en-US...

    The developers chose to follow the same convention for expanded for consistency.
  • 1
    @SortOfTested Isn’t the type then ‘true | undefined’?

    Edit: afaik if disabled is present, it’s value is always true.
  • 2
    @010001111
    It never has a value. It's either present or it isn't. The disabled attribute does nothing with any value presented to it.

    If something is present, it will set the disabled attribute.

    If the field is null || undefined, it will unset it
  • 1
  • 0
    Why isn't that explained in the doc then? Am I supposed to guess it? -_-
  • 1
    @ostream
    That's just how html works. It has been like that for decades. So, yes?
  • 1
    @ostream @SortOfTested
    I agree with both of you. HTML is cause of it. There are more attributes like that (selected for example). When a framework takes over and generates the HTML it should elaborate on what it wants. Just a mention or reference to the html docs should be enough.

    Most CMS's also have a checkbox "checked" to specify the default value. That is a boolean too. The framework could do the same and implement it as boolean and translate it to present and not present.
  • 1
    @hjk101
    I can appreciate an attempt at mediation, but that is the rub: it's not a boolean. It's a stream, and is only looking for not null | undefined | false. It can be a boolean, number, string, Array, Object, evaluated expressions, et al. It is truly any. Typescript doesn't currently have a way to define a negative disjunction type.

    The documentation supplies exhaustive examples of both usage and composition, it's not just a jsdoc dump:

    https://material.angular.io/compone...

    Here's a stackblitz demonstrating the principle:

    https://stackblitz.com/edit/...
  • 0
    @SortOfTested I did not attempt to meditate. I see your point in what it is in html but it's not html but JS.
    They could have implemented it as disabled=false (default) results in absent. disabled=true results in disabled="disabled" html in other words present.

    I don't know what is wise as I'm not versed in angular at all. If the documentation states it follows html in its attributes the OP should have looked better.
Add Comment