Open vveisard opened 2 years ago
Maybe it would be better if AS supported interface
instead, and did with it similar to constructor-less classes, rather than investing time down this path.
Maybe it would be better if AS supported
interface
instead, and did with it similar to constructor-less classes, rather than investing time down this path.
This makes a lot more sense, as TypeScript interfaces are similar to constructorless classes in AssemblyScript (merely defines the shape of a plain object), and instances can easily be emit as those interfaces without changing their behavior.
Problem
Currently, plain objects (objects without constructors or functions) are emit to the deceleration file as generically named interface types, in the form of
__Record{classId}
.This is not expected behavior; I would expect AssemblyScript classes which merely define the shape of a plain object to be emit as
interface
ortype
with the same name as the class.Proposal
Plain object classes are emit as type/ interface if an annotation is present.
The name of this annotation, and what the new "default" behavior is, is an implementation detail.
Considerations
Plain objects returns/ arguments are "not really an instance"
In TypeScript, an
interface
ortype
with no functions merely defines the shape of plain object. On the AssemblyScript side, a class with no constructor or functions also merely defines the shape of a plain object. In both cases, that plain object really is that type in both TypeScript and AssmeblyScript.Naming Conflicts
As naming collisions are unavoidable, it is the responsibility of the application developer to resolve naming conflicts within their application through alias imports. eg,
import { Foo as MyFoo } from 'my-wasm-module';