@@ -59,7 +59,7 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
5959 | false -> None
6060 (* one means don't know *)
6161 in
62- let import_string_opt, name_as, import_exact_opt , remote_export_name_opt =
62+ let import_string_opt, name_as, _import_exact_opt , remote_export_name_opt =
6363 type_attributes |> Annotation. get_attribute_import_renaming
6464 in
6565 let unboxed_annotation =
@@ -83,7 +83,7 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
8383 |> Translation. translate_dependencies ~config ~output_file_relative
8484 ~resolver
8585 in
86- {CodeItem. import_types; export_from_type_declaration; expected_type = None }
86+ {CodeItem. import_types; export_from_type_declaration}
8787 in
8888 let translate_label_declarations ?(inline = false ) label_declarations =
8989 let field_translations =
@@ -159,132 +159,21 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
159159 let base_import =
160160 {CodeItem. type_name; as_type_name = Some as_type_name; import_path}
161161 in
162- (* If the declaration has a manifest type, capture its full translation
163- so we can both build the Expected type and import its dependencies. *)
164- let expected_translation_opt =
165- match declaration_kind with
166- | GeneralDeclaration (Some core_type ) ->
167- Some
168- (core_type |> TranslateCoreType. translate_core_type ~config ~type_env )
169- | GeneralDeclarationFromTypes (Some type_expr ) ->
170- Some
171- (type_expr
172- |> TranslateTypeExprFromTypes. translate_type_expr_from_types ~config
173- ~type_env )
174- | RecordDeclarationFromTypes label_declarations ->
175- Some (label_declarations |> translate_label_declarations)
176- | VariantDeclarationFromTypes constructor_declarations ->
177- let variants =
178- constructor_declarations
179- |> List. map (fun constructor_declaration ->
180- let constructor_args = constructor_declaration.Types. cd_args in
181- let attributes = constructor_declaration.cd_attributes in
182- let name = constructor_declaration.cd_id |> Ident. name in
183- let args_translation =
184- match constructor_args with
185- | Cstr_tuple type_exprs ->
186- type_exprs
187- |> TranslateTypeExprFromTypes
188- .translate_type_exprs_from_types ~config ~type_env
189- | Cstr_record label_declarations ->
190- [
191- label_declarations
192- |> translate_label_declarations ~inline: true ;
193- ]
194- in
195- let arg_types =
196- args_translation
197- |> List. map (fun {TranslateTypeExprFromTypes. type_} -> type_)
198- in
199- (name, attributes, arg_types))
200- in
201- let variants_no_payload, variants_with_payload =
202- variants |> List. partition (fun (_ , _ , arg_types ) -> arg_types = [] )
203- in
204- let no_payloads =
205- variants_no_payload
206- |> List. map (fun (name , attributes , _argTypes ) ->
207- (name, attributes) |> create_case ~poly: false )
208- in
209- let payloads =
210- variants_with_payload
211- |> List. map (fun (name , attributes , arg_types ) ->
212- let type_ =
213- match arg_types with
214- | [type_] -> type_
215- | _ -> Tuple arg_types
216- in
217- {
218- case = (name, attributes) |> create_case ~poly: false ;
219- t = type_;
220- })
221- in
222- let variant_typ =
223- create_variant ~inherits: [] ~no_payloads ~payloads ~polymorphic: false
224- ~tag: tag_annotation ~unboxed: unboxed_annotation
225- in
226- Some {TranslateTypeExprFromTypes. dependencies = [] ; type_ = variant_typ}
227- | _ -> None
228- in
229-
230- (* Import any referenced non-builtin identifiers from the same module as
231- the base imported type. This ensures shims work (e.g. mapping ReactEvent
232- types to a local shim module), matching previous behavior. *)
233- let extra_type_imports =
234- match expected_translation_opt with
235- | Some tr ->
236- GentypeTypeFold. fold
237- (fun acc (t : GenTypeCommon.type_ ) ->
238- match t with
239- | Ident {builtin = false ; name; _} -> name :: acc
240- | _ -> acc)
241- [] tr.type_
242- |> List. sort_uniq String. compare
243- |> List. filter (fun n -> n <> type_name)
244- |> List. map (fun n ->
245- {CodeItem. type_name = n; as_type_name = None ; import_path})
246- | None -> []
247- in
248- let import_types = base_import :: extra_type_imports in
162+ (* Only import the aliased TypeScript type; no wrappers or extra aliases. *)
163+ let import_types = [base_import] in
249164 let export_from_type_declaration =
250165 (* Make the imported type usable from other modules by exporting it too. *)
251- let imported_ident =
166+ let export_type_body =
252167 as_type_name
253168 |> ident ~type_args: (type_vars |> List. map (fun s -> TypeVar s))
254169 in
255- let export_type_body =
256- match expected_translation_opt with
257- | Some tr -> (
258- let expected_for_wrapper =
259- if GentypeImportHelper. should_inline_expected tr.type_ then tr.type_
260- else
261- name_with_module_path ^ " $ReScript"
262- |> ident ~builtin: false
263- ~type_args: (type_vars |> List. map (fun s -> TypeVar s))
264- in
265- match import_exact_opt with
266- | Some true ->
267- ident GentypeImportHelper. strict_name
268- ~type_args: [imported_ident; expected_for_wrapper]
269- | _ ->
270- ident GentypeImportHelper. name
271- ~type_args: [expected_for_wrapper; imported_ident])
272- | None -> imported_ident
273- in
274170 typeName_
275171 |> create_export_type_from_type_declaration ~doc_string
276172 ~annotation: GenType ~loc ~name_as: None ~opaque: (Some false )
277173 ~type_: export_type_body ~type_env ~type_vars
278174 in
279175 [
280- {
281- CodeItem. import_types;
282- export_from_type_declaration;
283- expected_type =
284- (match expected_translation_opt with
285- | Some tr -> Some tr.type_
286- | None -> None );
287- };
176+ {CodeItem. import_types; export_from_type_declaration};
288177 ]
289178 | (GeneralDeclarationFromTypes None | GeneralDeclaration None ), None ->
290179 {
@@ -293,7 +182,6 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
293182 type_name
294183 |> create_export_type_from_type_declaration ~doc_string ~annotation ~loc
295184 ~name_as ~opaque: (Some true ) ~type_: unknown ~type_env ~type_vars ;
296- expected_type = None ;
297185 }
298186 |> return_type_declaration
299187 | GeneralDeclarationFromTypes (Some type_expr ), None ->
@@ -349,7 +237,6 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
349237 type_name
350238 |> create_export_type_from_type_declaration ~doc_string ~annotation ~loc
351239 ~name_as ~opaque ~type_ ~type_env ~type_vars ;
352- expected_type = None ;
353240 }
354241 |> return_type_declaration
355242 | VariantDeclarationFromTypes constructor_declarations , None ->
@@ -428,7 +315,7 @@ let traslate_declaration_kind ~config ~loc ~output_file_relative ~resolver
428315 |> List. map (fun (_ , _ , _ , import_types ) -> import_types)
429316 |> List. concat
430317 in
431- {CodeItem. export_from_type_declaration; import_types; expected_type = None }
318+ {CodeItem. export_from_type_declaration; import_types}
432319 |> return_type_declaration
433320 | NoDeclaration , None -> []
434321
0 commit comments