-
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
Document advanced Utility Types #2464
Comments
PR submitted, feedbacks are very welcome! |
@gabro I think |
@anmonteiro yes, it's on my radar but I didn't include it there as I wasn't sure Long story short, are |
@anmonteiro about the documentation for |
@gabro IMO I agree it's a different concern so another issue is necessary. I should have clarified my initial intent, which was to bring up the fact that it wasn't documented, not to include in a PR for this one. |
Can anyone elaborate on usage of |
@STRML from what I was able to "reverse engineer", it looks like class MyAbstract<T> {
foo: $Abstract<T>
}
class MyConcrete extends MyAbstract<string> {} // error, foo is missing
class MyConcrete2 extends MyAbstract<string> {
foo = 'bar' // ok
}
class MyConcrete3 extends MyAbstract<string> {
foo = 42 // error, foo must be a string
}
class MyAbstract2<T> {
foo: T
}
class MyConcrete4 extends MyAbstract2<string> {} // no problemo From the examples above, the most notable difference between I would love if anyone from the Flow team could confirm my "hypothesis" (so that we can document this!) |
Interesting insight. It's odd, though, that you're not required to actually define |
@STRML I think you are required to, if you specify a type for it. Meaning class MyComponent extends React.Component { } // ok
class MyComponent extends React.Component<{ x: string }, any, any> { } // error
class MyComponent extends React.Component<{ x: string }, any, any> {
static defaultProps = { x: 'foo' };
} // ok Here's some example from the tests: https://github.com/facebook/flow/blob/master/tests/new_react/bad_default_props.js |
Gotcha. So if you just don't specify the type parameters at all, there isn't a difference? Strange. Still, I wonder why updating our |
I think as long as the type is unbound anything is accepted, including But again, I'm just guessing here. Either I'll learn some OCaml and start reading the source code, or someone from the Flow team can shed some light! 😄 |
Just to clarify my class MyAbstract<T> {
foo: $Abstract<T>
}
class MyConcrete extends MyAbstract<void> {} // ok! |
@anmonteiro I just opened a new issue for tracking the |
Adding |
Re:
|
Summary: Ref #2464 This PR adds documentation for writing enums in Flow, both using literal types as enum keys and using the `$Keys` operator to generate an enum from a literal object. I'm not sure whether the structure is appropriate (I just added a new chapter to the reference documentation), but I'd love some feedback! Closes #2465 Differential Revision: D3868308 Pulled By: thejameskyle fbshipit-source-id: 105ceed93d1810d33199f0f743527201f0606556
Summary: Ref #2464 This PR documents the `$Diff` utility type, explaining how it is used in React to define the type of the props accepted by a Component. Closes #2472 Reviewed By: samwgoldman Differential Revision: D4168072 Pulled By: gabelevi fbshipit-source-id: 62bde7da0940bf694f64f37bd5724c536627caff
@andreypopp Could you provide any information on $ObjMap, since it appears you've used it in validated? I've had no luck figuring it out so far. Edit: Got something going, it appears this doesn't throw an error if you rebind the var (so |
Another +1 for documentation for I think a nice motivating example would be Flow's type for static all<Elem, T:Iterable<Elem>>(promises: T): Promise<$TupleMap<T, typeof $await>>;
declare function $await<T>(p: Promise<T> | T): T; You could then use static props<Elem, T: { [prop: string]: Elem }>(promises: T): Promise<$ObjMap<T, typeof $await>>; |
Hoping the core team will place more importance on this. I understand some of these features are subject to change, but the community could help shape their development. |
That's appreciated, but largely incomplete, especially compared to the post from 2015. |
That particular one is actually in the OP. But yes, there is a lot of missing information. I have a PR open but it has not gotten any attention. |
The doc about utility types has just been updated => https://flow.org/en/docs/types/utilities/ |
@villesau blugh that was pretty careless of me to miss that. Thanks for catching it! @gabro it's much appreciated that you're keeping the ticket up to date though. I imagine any kind of bookkeeping we do immensely helps people when they can function as active maintainers. To the @villesau's point above, |
@LoganBarnett sure, done! |
It seems that |
Man this is disheartening coming from typescript |
@bitpit It's worse when you compare the issues lists of both TypeScript and of Flow. One of those two projects gets issues closed, the other one just collects them.... (not that the list of open issues is any shorter though) and we Flow users are mostly talking among ourselves here in the issues comments. I filed only one issue for TypeScript and had Anders Hejlsberg himself reply to it, and it was not an especially noteworthy issue at all. |
@lll000111 I had a lot of
|
Since I didn't see it anywhere, we should add |
Done 👍 |
should we document $Pred and $Refine as well? |
Nearly all of these are documented (or deprecated) now, mostly under Utility Types, but I've added links to the original list anyway for reference. $ObjMapi has a PR waiting, so it looks like all that's left is $Compose, $ComposeReverse and $CharSet. $Pred, $Refine and $Exports do sound like they're internal types not meant for public use -- maybe someone on the Flow team could confirm? cc @nmote @jbrown215 |
Honestly, I'm not even sure what these do, so my guess is yes. Maybe @panagosg7 could weigh in (looks like he authored the file that you linked) |
I learned about $Pred and $Refine from https://medium.com/netscape/secret-flow-types-86b2ebb30951 then by reading the documentation in the actual code which I believe was fairly detailed. However, not sure I ever used it anywhere in the end - this was ages ago now heh :-P Update: Not finding those comments in the codebase now :-D maybe i hallucinated them hah |
Indeed, $Pred and $Refine are purely experimental. They're mostly proof of concept for my internship project at the time. The API they expose has several holes that I haven't gotten to seal, since priorities have shifted since. |
Summary: I added documentation for the previously undocumented utility function (see #2464) To be honest, maybe we should consider deprecating `$Exports` because the `import typeof` feature is now supported and mentioned here: https://flow.org/en/docs/types/modules/ Pull Request resolved: #7945 Differential Revision: D16426558 fbshipit-source-id: 7bd3d2d4de6ad4acb229eebb75cf7faa984368fa
We don't plan on documenting the remaining 3 experimental types. |
In the process of learning Flow and adopting it at work, I've often needed "advanced" operators that are completely missing from the documentation.
So far I relied on this blog post (now slightly outdated) http://sitr.us/2015/05/31/advanced-features-in-flow.html and code found in the Flow and React codebases.
I think I'd be nice to have this features explained in the official documentation.
The features I'd like to see documented are:
$Supertype(deprecated)$Subtype(deprecated)$Abstract(removed)And maybe (they look like internal features though):
$Pred(experimental)$Refine(experimental)Am I missing something?
In order to get the ball rolling, I've sketched a documentation page for "dynamic" enums using
$Keys
(aka$Enum
). I have a PR almost ready that I will submit soon.Is this something that you guys are already working on?
I'd be glad to help (provided that I understand the features first 😅).
Let me know!
The text was updated successfully, but these errors were encountered: