Is there a more beautiful way to express an anonymous class(?) with typed members in typeScript than this?
class Foo {
member = {
aNumber = <number>undefined;
aBoolean = <bool>undefined;
}
}
The only anonymous alternative would be:
class Foo {
member: { aNumber?: number; aBoolean?: bool; } = {
aNumber: undefined,
aBoolean: undefined
}
}
You're usually better off just writing an interface
so you can name the type.
Since members are undefined by default you could simply go with:
class Foo {
member:{aNumber:number;aBoolean:bool;} = <any>{};
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With