Logo
Explore Help
Sign In
fluencelabs/assemblyscript
1
0
Fork 0
You've already forked assemblyscript
mirror of https://github.com/fluencelabs/assemblyscript synced 2025-05-09 22:02:15 +00:00
Code Issues Projects Releases Wiki Activity
assemblyscript/tests/compiler/std/object-literal.ts

30 lines
402 B
TypeScript
Raw Normal View History

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
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;
}
Legalize casting object literals to classes when linting
2018-07-14 15:00:07 +02:00
test(): void {
assert(this.bar == 3);
}
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
}
function bar2(foo: Foo2): void {
assert(foo.bar == 2);
}
Legalize casting object literals to classes when linting
2018-07-14 15:00:07 +02:00
bar2(<Foo2>{ bar: 2 });
(<Foo2>{ bar: 3 }).test();
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.23.7 Page: 90ms Template: 3ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API