-
Notifications
You must be signed in to change notification settings - Fork 5
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
Flow port #13
Comments
@tycho01 I have found a way to iterate for unions
|
yeah |
@tycho01 I thought conditional types is basically |
@goodmind: you're not far off! it has two use-cases:
This is why I was kinda sad they gave us conditional types instead of |
@tycho01 hey! I implemented type RestFixed<T1, T2> = $Rest<T1, $Required<T2>>
type Pick<T1, T2> = RestFixed<
T1,
$ObjMap<RestFixed<T1, T2>, <V>(V) => any>
>;
declare var picked: Pick<{| a?: number, b?: string, c: string |}, {| a: any |}>;
picked.a; // void | number
picked.b; // error
picked.c; // error |
@tycho01 with latest generic function inference in TypeScript it seems like Flow now far off from typing Ramda :( |
that looks pretty cool! :D
Do you mean stuff like Like, how do you see the major differences in expressiveness in TS and Flow now? Is it mostly about some of the TS additions like edit: P.S. if you have a few types in a repo I can link it from the readme here, or alternatively I can give you push access over here if you want. |
@tycho01 Also, I don't have typelevel stuff repository, because I'm not a fun of too much complex typelevel stuff after I've seen what #27 also this lol I often write simple flow code, and if something can't be typed I fork library |
Yeah, type-level coding sucks, admittedly. I'm shocked about the |
@tycho01 I was playing around OCaml and wrote this 🔥 Any examples I can implement with this? |
hahaha, I'm quite confused about what happened in your example, but a type-level reduce is pretty cool! that's definitely among the remaining challenges in TS. I listed some potential use-cases for this based on Ramda here, though part may be solved already. |
@tycho01 I just hardcoded reducing into object | DefT (_, trust, ArrT arrtype), MapTypeT (reason_op, Reduce funt, tout) ->
let props = match arrtype with
| ArrayAT (_, opt) ->
(match opt with
| Some ts ->
Core_list.fold_left ts ~f:(fun acc value ->
match value with
| DefT (_, _, SingletonStrT str) ->
let t = EvalT (funt, TypeDestructorT (unknown_use, reason_op, CallType [value]), mk_id ()) in
SMap.add str (Field (None, t, Positive)) acc
| _ -> acc
) ~init:SMap.empty
| None -> SMap.empty)
| TupleAT (_, ts) ->
Core_list.fold_left ts ~f:(fun acc value ->
match value with
| DefT (_, _, SingletonStrT str) ->
let t = EvalT (funt, TypeDestructorT (unknown_use, reason_op, CallType [value]), mk_id ()) in
SMap.add str (Field (None, t, Positive)) acc
| _ -> acc
) ~init:SMap.empty
| ROArrayAT (_) -> SMap.empty in
let props_tmap = Context.make_property_map cx props in
let t =
let reason = replace_reason_const RObjectType reason_op in
let proto_t = ObjProtoT reason in
let call_t = None in
let dict_t = None in
let flags = {
exact = true;
sealed = Sealed;
frozen = false;
} in
DefT (reason, trust, ObjT {flags; dict_t; proto_t; props_tmap; call_t;})
(* Obj_type.mk_with_proto cx reason ~frozen:true ~sealed:true ~exact:true ~props proto *)
in
rec_flow_t cx trace (t, tout) , perhaps this is more limiting to implement something like Not sure how would initial value behave if we can't subtract and add types? // build object
var s: $Reduce<["a", "b"], <Acc, K>(Acc, K) => {
...Acc,
[K]: K // sorry no computed props in Flow
}, {||}> // failed example, should be special cased then
// build union without initial value
var s: $Reduce<["a", "b"], <Acc, K>(Acc, K) => Acc | K> // "a" | "b" And this quickly becomes more complicated to implement TypeScript in general allows more userland type magic, because all type utilities work well together but this isn't like this in Flow, |
hm. I thought you showed me a |
@tycho01, but Compose implementation doesn't work if you export function |
really? I'm probably missing some context but that sounds kinda lame. :/ |
Yeah, all exports should be annotated properly for performance reasons, and you can't do this with |
ah, I see, thanks! |
There is also discord server with Flow maintainers, usually they help with contributing. I managed to add BigInt parsing and |
whoa, that's pretty nice! |
Flow offers things like
$Call
which have been a bottleneck for me so far. I should finish up myflow
branch to get things up to parity. I'm not actually good at Flow so help welcome!edit: I should check
type-at-pos
to find the inferred types.The text was updated successfully, but these errors were encountered: