@@ -988,7 +988,8 @@ let rec make_intermediate_error :
988988 ~frame: FrameAnonymous
989989 ~custom_error_message
990990 | Frame
991- ( OpaqueTypeCustomErrorCompatibility { lower; upper; lower_t; upper_t; custom_error_loc },
991+ ( OpaqueTypeCustomErrorCompatibility
992+ { lower; upper; lower_t; upper_t; name; custom_error_loc },
992993 use_op
993994 ) ->
994995 let lower_desc =
@@ -1012,7 +1013,7 @@ let rec make_intermediate_error :
10121013 }
10131014 )
10141015 in
1015- let frames = ([] , [ExplanationCustomError { custom_error_loc }]) in
1016+ let frames = ([] , [ExplanationCustomError { name; custom_error_loc }]) in
10161017 next_with_loc
10171018 ~loc: (loc_of_aloc (loc_of_reason lower))
10181019 ~frames
@@ -1912,7 +1913,7 @@ let to_printable_error :
19121913 text " using " ;
19131914 code example;
19141915 ]
1915- | ExplanationCustomError { custom_error_loc } ->
1916+ | ExplanationCustomError { name; custom_error_loc } ->
19161917 let loc = loc_of_aloc custom_error_loc in
19171918 let custom_docs =
19181919 Loc. source loc
@@ -1928,11 +1929,37 @@ let to_printable_error :
19281929 )
19291930 )
19301931 |> Base.Option. bind ~f: (fun jsdoc ->
1931- jsdoc |> Jsdoc. description |> Base.Option. map ~f: Base.String. strip
1932+ let description =
1933+ jsdoc |> Jsdoc. description |> Base.Option. map ~f: Base.String. strip
1934+ in
1935+ let example =
1936+ Base.List.Assoc. find
1937+ (Jsdoc. unrecognized_tags jsdoc)
1938+ ~equal: Base.String. equal
1939+ " example"
1940+ |> Base.Option. bind ~f: Base.Fn. id
1941+ |> Base.Option. map ~f: Base.String. strip
1942+ in
1943+ match (description, example) with
1944+ | (None, None) -> None
1945+ | (Some d , None) -> Some [text " Description of " ; code name; text " : " ; text d]
1946+ | (None, Some e ) -> Some [text " Example for " ; code name; text " : " ; code e]
1947+ | (Some d , Some e ) ->
1948+ Some
1949+ [
1950+ text " Description of " ;
1951+ code name;
1952+ text " : " ;
1953+ text d;
1954+ text " . Example for " ;
1955+ code name;
1956+ text " : " ;
1957+ code e;
1958+ ]
19321959 )
19331960 in
19341961 (match custom_docs with
1935- | Some d -> [text d]
1962+ | Some m -> m
19361963 | None -> [text " See " ; hardcoded_string_desc_ref " relevant docs" custom_error_loc])
19371964 | ExplanationReactComponentPropsDeepReadOnly props_loc ->
19381965 [
0 commit comments