Skip to content

Remove special case for invariant #112

Open

Description

@petehunt

I'm finding it difficult to add type annotations to my function named invariant() because of this little guy:

let msg = "unsupported arguments in call to invariant()" in

It seems that many of these functions are special cased. I'm curious as to why, because I can't use any functions that share these names anymore.

Activity

  1. avikchaudhuri commented on Nov 24, 2014

    @avikchaudhuri
    Contributor

    Eventually the type system will be powerful enough to express the "signatures" of these functions, at which point their names will not need to be special-cased any more (since they can simply be declared to satisfy the necessary signatures).

    In the short-term, we'll try to scope these names somewhat, so that they don't interfere with other things with the same names.

  2. samwgoldman commented on Aug 1, 2015

    @samwgoldman
    Member

    The proposal for refinement carrying boolean types in #34 isn't powerful enough, AFAICT, to express the type of invariant. Since TypeScript has already implemented that, it's probably a good time to start thinking about how we'd express something like invariant in the type language.

  3. leebyron commented on Aug 13, 2015

    @leebyron
    Contributor

    Here's a rough working but not long-term stable proposal:

    invariant(predicate: any): $Asserts<predicate is true>

    This uses the Ident "is" Type grammar proposed in #34. It uses @mroch's recent addition of boolean literals as Types. And it uses Flow's "this is an uncommon and undocumented" pattern of $Thing for communicating specific typing behavior.

  4. samwgoldman commented on Aug 13, 2015

    @samwgoldman
    Member

    I like this syntax and I think the syntax does communicate all the necessary information. I feel like the implementation might get tricky around the $Assert type, which should result in an abnormal event. I haven't looked into this enough yet to say whether it's realistic or not (maybe @avikchaudhuri can weigh in), but I'll give this some more thought.

  5. changed the title [-]Special cases for static_upstream/core[/-] [+]Support predicate types[/+] on Jan 6, 2016
  6. mroch commented on Jan 6, 2016

    @mroch
    Contributor

    3e35bd4 should get the rest of the static_upstream/core special cases out of the way, except for invariant. Renamed this task to preserve the discussion of predicate types.

  7. changed the title [-]Support predicate types[/-] [+]Remove special case for `invariant`[/+] on Jan 7, 2016
  8. gajus commented on May 22, 2018

    @gajus
    invariant(predicate: any): $Asserts<predicate is true>
    

    Was this ever implemented?

  9. leebyron commented on May 23, 2018

    @leebyron
    Contributor

    No, %checks was built which is for predicate functions but not assertion functions. If this is a model the flow team is happy with then maybe something like this could be built such as %asserts?

  10. gajus commented on May 23, 2018

    @gajus

    For others reference, here is the documentation for %checks https://flow.org/en/docs/types/functions/#toc-predicate-functions.

  11. gajus commented on Jul 14, 2018

    @gajus

    This issue is duplicate of #34.

  12. mattconde commented on May 27, 2019

    @mattconde
    Contributor

    So I think I've caught up on this issue, am I right to think I still can't flowtype my own "invariant" module correctly because of this?

  13. goodmind commented on Aug 4, 2019

    @goodmind
    Contributor

    TypeScript now has this microsoft/TypeScript#32695

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions