@@ -62,6 +62,30 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
6262 let import_string_opt, name_as, _import_exact_opt, remote_export_name_opt =
6363 type_attributes |> Annotation. get_attribute_import_renaming
6464 in
65+ let satisfies_opt = type_attributes |> Annotation. get_attribute_satisfies in
66+ let annotation_for_export =
67+ match satisfies_opt with
68+ | Some _ -> Annotation. GenType
69+ | None -> annotation
70+ in
71+ let apply_satisfies_wrapper type_ =
72+ match satisfies_opt with
73+ | None -> type_
74+ | Some (import_str , path ) ->
75+ (* Ensure we emit the helper once. *)
76+ config.emit_satisfies_helper < - true ;
77+ let import_path = ImportPath. from_string_unsafe import_str in
78+ let import_path_str = ImportPath. emit import_path in
79+ let inline_import =
80+ let base = " import(\" " ^ import_path_str ^ " \" )" in
81+ match path with
82+ | [] -> base
83+ | _ -> base ^ " ." ^ String. concat " ." path
84+ in
85+ let ts_type = ident ~builtin: true inline_import in
86+ ident ~builtin: true ~type_args: [type_; ts_type]
87+ " $RescriptTypeSatisfiesTypeScriptType"
88+ in
6589 let unboxed_annotation =
6690 type_attributes |> Annotation. has_attribute Annotation. tag_is_unboxed
6791 in
@@ -75,8 +99,11 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
7599 (translation : TranslateTypeExprFromTypes.translation ) =
76100 let export_from_type_declaration =
77101 type_name
78- |> create_export_type_from_type_declaration ~annotation ~loc ~name_as
79- ~opaque ~type_: translation.type_ ~type_env ~doc_string ~type_vars
102+ |> create_export_type_from_type_declaration ~annotation: annotation_for_export
103+ ~loc ~name_as
104+ ~opaque
105+ ~type_: (apply_satisfies_wrapper translation.type_)
106+ ~type_env ~doc_string ~type_vars
80107 in
81108 let import_types =
82109 translation.dependencies
@@ -220,7 +247,8 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
220247 ~polymorphic: true ~tag: None ~unboxed: false
221248 | _ -> translation.type_
222249 in
223- {translation with type_} |> handle_general_declaration
250+ {translation with type_ = apply_satisfies_wrapper type_}
251+ |> handle_general_declaration
224252 |> return_type_declaration
225253 | RecordDeclarationFromTypes label_declarations , None ->
226254 let {TranslateTypeExprFromTypes. dependencies; type_} =
@@ -235,8 +263,10 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
235263 CodeItem. import_types;
236264 export_from_type_declaration =
237265 type_name
238- |> create_export_type_from_type_declaration ~doc_string ~annotation ~loc
239- ~name_as ~opaque ~type_ ~type_env ~type_vars ;
266+ |> create_export_type_from_type_declaration ~doc_string
267+ ~annotation: annotation_for_export ~loc
268+ ~name_as ~opaque ~type_: (apply_satisfies_wrapper type_)
269+ ~type_env ~type_vars ;
240270 }
241271 |> return_type_declaration
242272 | VariantDeclarationFromTypes constructor_declarations , None ->
@@ -302,12 +332,12 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
302332 loc;
303333 name_as;
304334 opaque;
305- type_ = variant_typ;
335+ type_ = apply_satisfies_wrapper variant_typ;
306336 type_vars;
307337 resolved_type_name;
308338 doc_string;
309339 };
310- annotation;
340+ annotation = annotation_for_export ;
311341 }
312342 in
313343 let import_types =
0 commit comments