Pre-ES5 Getters/setters ?

Topics: General
Dec 3, 2012 at 3:34 PM

I really like getters/setters but since they rely on ES5 they are not that useful at the moment. It would be great if the compiler could be told to mimic ES5 code, essentially adding get/set functions and then for each usage, add calls to those functions directly.

---bjorn

 

Coordinator
Dec 4, 2012 at 12:13 AM

Unfortunately, this wouldn't be safe to do in the general case.  For it to work, we would have to know the type of every assignment.  When we're in the presence of the 'any' type, we don't have this knowledge, which means that the JavaScript we generate would not call your setter/getter. 

We're conservative because in general we don't want to have to know type information when we're doing codegen.

Dec 4, 2012 at 4:23 AM
Thanks, that makes sense. A bummer though, getters/setters makes the code so much easier to read and write.
---bjorn
From: [email removed]
Sent: Monday, December 03, 2012 4:13 PM
To: [email removed]
Subject: Re: Pre-ES5 Getters/setters ? [typescript:405395]

From: jonturner

Unfortunately, this wouldn't be safe to do in the general case. For it to work, we would have to know the type of every assignment. When we're in the presence of the 'any' type, we don't have this knowledge, which means that the JavaScript we generate would not call your setter/getter.

We're conservative because in general we don't want to have to know type information when we're doing codegen.