Here's a simple example of what I'd like to do:
export class UserInfoPrivate {
constructor(
public repEmail: string,
public repPhone: string,
public agreedToTnC: boolean
) { }
}
export class UserInfo {
constructor(
public $uid: string,
public orgApproved: false,
public private: UserInfoPrivate, // <-- private is a reserved word
public open: UserInfoOpen,
) { }
}
Since the datebase is a NoSQL (Firebase) and returns simple JSON structured objects, and I have a node under users called "private" I'd like to just map my class directly to it without extra parsing. Is there a way to use a reserved word such as "private" in a class definition or do I have to go change the node?
My research thus far seems to point to no but I have a hard time accepting that this just isn't possible.
You can always put property names (in classes or object literals) in quotes - and for those that are not valid identifier names, you need to. You can access them using bracket notation then.
export class UserInfo {
public "private": UserInfoPrivate
constructor(
public $uid: string,
public orgApproved: false,
privateParam: UserInfoPrivate,
public open: UserInfoOpen,
) {
this.private = privateParam;
}
}
(I hope that looks like valid Typescript not only to my eye but also the compiler)
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