-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Remove special case for invariant
#112
Comments
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. |
The proposal for refinement carrying boolean types in #34 isn't powerful enough, AFAICT, to express the type of |
Here's a rough working but not long-term stable proposal: invariant(predicate: any): $Asserts<predicate is true> This uses the |
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 |
Summary: flow has special-cased support for some deprecated Facebook-isms like `copyProperties` and `mergeInto` (both replaced by `Object.assign`). since these hacks were implemented in `type_inference_js`, they weren't sensitive to context (e.g. any function named `merge` was hijacked) and applied to all Flow projects, not just Facebook. This diff creates a `CustomFunT` type along with several magic type annotations (`$Facebookism$Merge`, for example), and uses those as sigils that are returned by the normal identifier lookup routine. So, if you write `const merge = require('merge'); merge(...)`, we'll treat it like a normal lookup to resolve `merge`, and then a normal `CallT`... except that the thing that gets returned is a `CustomFunT(..., Merge)`, which we handle specially. In other words, in order for any of these magic functions to do anything anymore, they need to be defined in your project's libs. See the `facebookisms` test for an example. Fixes #1206 Related to #112 (would fix it, except doesn't handle `invariant`) Reviewed By: jeffmo Differential Revision: D2782891 fb-gh-sync-id: b1d03eb9cf2cd44f9e5f99167a5e2d6725151917
3e35bd4 should get the rest of the static_upstream/core special cases out of the way, except for |
Was this ever implemented? |
No, |
For others reference, here is the documentation for |
This issue is duplicate of #34. |
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? |
TypeScript now has this microsoft/TypeScript#32695 |
I'm finding it difficult to add type annotations to my function named
invariant()
because of this little guy:flow/src/typing/type_inference_js.ml
Line 2058 in 0f56d17
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.
The text was updated successfully, but these errors were encountered: