Open niloc132 opened 1 year ago
Hmm isDictionaryType
decision seems straightforward but looks like TypeReference abstraction doesn't resolve fields so we currently cannot tell if parent has any fields.
Does it matter if the parent has fields or not? Even if a record with no supertype has no fields, if the user must create an instance to use some api, it makes more sense to call MyRecord.create()
than to manually write out the Js.cast(JsPropertyMap.of())
call - or, if this doesn't make sense, it seems reasonable to remove all such create()
method, as the user can just as easily make this call in all places where a record is created?
Even if a record with no supertype has no fields, if the user must create an instance to use some api, it makes more sense to call MyRecord.create() than to manually write out the Js.cast(JsPropertyMap.of()) call
My recollection is; when we emit create methods unconditionally it had some unintended effect (though I don't remember what it was).
Steps to reproduce, create a record type with no members.
Expected, a Java interface with a static
create()
method. Actual output is a Java interface with no contents.--
While this might seem like a weird edge case, there are at least two ways that this comes up. First, when tsickle generates externs from typescript where a type is re-exported in another file, tsickle will generate a new type that extends the existing type. Second, a record type that extends from two other record types, but doesn't contribute new fields.
Expected Java output,
Actual Java output
An easy workaround is to just create an instance of a supertype, or just a plain
JsObject.create(null)
orJsPropertyMap.of()
, then wrap in a cast as the usual implementation does. But this isn't expected to be the correct way, since all other records get a generated factory method.