ocsigen / ts2ocaml

Generate OCaml bindings from TypeScript definitions via the TypeScript compiler API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can generate use types without generating them

tmattio opened this issue · comments

For instance, in lib.es2015.symbol.d.ts:

interface SymbolConstructor {
    readonly prototype: Symbol;

    (description?: string | number): symbol;

    for(key: string): symbol;

    keyFor(sym: symbol): string | undefined;
}

declare var Symbol: SymbolConstructor;

will generate:

[@@@ocaml.warning "-7-11-32-33-39"]
[@@@js.implem 
  [@@@ocaml.warning "-7-11-32-33-39"]
]
open Ts2ocaml_baselib

module Internal : sig
  module AnonymousInterfaces : sig
    
  end
  module Types : sig
    open AnonymousInterfaces
    type _SymbolConstructor = [`SymbolConstructor] intf
    [@@js.custom { of_js=Obj.magic; to_js=Obj.magic }]
  end
end

open Internal
open AnonymousInterfaces
open Types
module[@js.scope "SymbolConstructor"] SymbolConstructor : sig
  type t = _SymbolConstructor
  val t_to_js: t -> Ojs.t
  val t_of_js: Ojs.t -> t
  type t_0 = t
  val t_0_to_js: t_0 -> Ojs.t
  val t_0_of_js: Ojs.t -> t_0
  val get_prototype: t -> _Symbol [@@js.get "prototype"]
  val apply: t -> ?description:string or_number -> unit -> symbol [@@js.apply]
  val for_: t -> key:string -> symbol [@@js.call "for"]
  val keyFor: t -> sym:symbol -> string or_undefined [@@js.call "keyFor"]
end
val symbol: _SymbolConstructor [@@js.global "Symbol"]

The type _Symbol is used, but never defined.

I suppose your input lacks the definition of Symbol in the first place?

It seems to be generated in my test output: https://github.com/ocsigen/ts2ocaml/blob/bootstrap/test/src/es2015.mli#L197

Turned out that ts2ocaml was failing to detect Symbol as a missing type because there is a value named Symbol in the context.