@@ -46,10 +46,12 @@ let safeTypeFromValue valueStr =
46
46
if valueStr = " " || (valueStr.[0 ] [@ doesNotRaise]) <> '_' then valueStr
47
47
else " T" ^ valueStr
48
48
49
+ let refTypeVar loc = Typ. var ~loc " ref"
50
+
49
51
let refType loc =
50
52
Typ. constr ~loc
51
- {loc; txt = Ldot (Ldot (Lident " ReactDOM " , " Ref " ), " currentDomRef " )}
52
- []
53
+ {loc; txt = Ldot (Ldot (Lident " Js " , " Nullable " ), " t " )}
54
+ [refTypeVar loc ]
53
55
54
56
type 'a children = ListLiteral of 'a | Exact of 'a
55
57
@@ -279,11 +281,11 @@ let makePropsTypeParams ?(stripExplicitOption = false)
279
281
(* TODO: Worth thinking how about "ref_" or "_ref" usages *)
280
282
else if label = " ref" then
281
283
(*
282
- If ref has a type annotation then use it, else `ReactDOM.Ref.currentDomRef .
284
+ If ref has a type annotation then use it, else 'ref .
283
285
For example, if JSX ppx is used for React Native, type would be different.
284
286
*)
285
287
match interiorType with
286
- | {ptyp_desc = Ptyp_any } -> Some (refType loc)
288
+ | {ptyp_desc = Ptyp_any } -> Some (refTypeVar loc)
287
289
| _ ->
288
290
(* Strip explicit Js.Nullable.t in case of forwardRef *)
289
291
if stripExplicitJsNullableOfRef then stripJsNullable interiorType
@@ -1077,7 +1079,14 @@ let mapBinding ~config ~emptyLoc ~pstr_loc ~fileName ~recFlag binding =
1077
1079
(* (ref) => expr *)
1078
1080
let expression =
1079
1081
List. fold_left
1080
- (fun expr (_ , pattern ) -> Exp. fun_ Nolabel None pattern expr)
1082
+ (fun expr (_ , pattern ) ->
1083
+ let pattern =
1084
+ match pattern.ppat_desc with
1085
+ | Ppat_var {txt} when txt = " ref" ->
1086
+ Pat. constraint_ pattern (refType Location. none)
1087
+ | _ -> pattern
1088
+ in
1089
+ Exp. fun_ Nolabel None pattern expr)
1081
1090
expression patternsWithNolabel
1082
1091
in
1083
1092
(* ({a, b, _}: props<'a, 'b>) *)
@@ -1293,7 +1302,7 @@ let transformSignatureItem ~config item =
1293
1302
psig_loc
1294
1303
((* If there is Nolabel arg, regard the type as ref in forwardRef *)
1295
1304
(if ! hasForwardRef then
1296
- [(true , " ref" , [] , Location. none, refType Location. none)]
1305
+ [(true , " ref" , [] , Location. none, refTypeVar Location. none)]
1297
1306
else [] )
1298
1307
@ namedTypeList)
1299
1308
in
0 commit comments