Generating modules representing anonymous interfaces
ulugbekna opened this issue · comments
When, say, a function type has an anonymous interface: fun(person: { name : string, age : int })
in a d.ts file, currently AnonymousInterfaceN
module is generated to represent the interface.
When there are many such interfaces, it gets tedious to rename them.
One of the possible automated naming schemes would be:
- If the anonymous object type is used as an argument, it could have the name of the argument (appended with a number or suffix “_arg” if there’re already similarly named modules or the argument is a union of several anonymous object types)
I guess it should look something like this:
interface Foo {
foo(person: { name: string; age: number }): void
}
module Foo: sig
module Person: sig
type t
...
end
val foo: person:Person.t -> unit
end
Argument names are likely to clash, so we need a numbering here like PersonN
or some namespacing FooArgPerson
(a bit too verbose?)
I think PersonN
is enough to prevent name clash.
Added an option --readable-names
to do this. Try it out in 1.4.0-beta.3
and please let me know your feedback.