assemblyscript/tests/compiler/object-literal.ts
dcodeIO 9e508de69a Implement object literal parsing; Instantiate classes from object literals
Essentially, if the contextual type is a class with a constructor that takes zero arguments or doesn't have a constructor at all, an object literal can be used to initialize a new instance of that class with preset values.
2018-07-14 04:00:04 +02:00

27 lines
347 B
TypeScript

import "allocator/arena";
class Foo {
bar: i32;
baz: string;
}
function bar(foo: Foo): void {
assert(foo.bar == 1);
assert(foo.baz == "hello world");
}
bar({ bar: 1, baz: "hello world" });
class Foo2 {
bar: i32;
constructor() {
this.bar = 1;
}
}
function bar2(foo: Foo2): void {
assert(foo.bar == 2);
}
bar2({ bar: 2 });