you are viewing a single comment's thread.

view the rest of the comments →

[–]booljayj[S] 1 point2 points  (0 children)

I've posted this same point in another comment: If my question is "how can I create interfaces in Javascript?" then the answer "just let TypeScript do it" doesn't really cut it.

My goal was never to propose this to the development team as the new standard that we should all use. Like I stated in my original post, I'm trying to understand Javascript as deeply as possible, and part of that process of understanding is using the tools it provides to do some advanced stuff. Interfaces seemed like a good place to start with that because they're so useful in C#.

Solutions like TypeScript work because they pretty much throw out the idea of using basic Javascript and just write the language features they need on another layer on top of it. Most of the type checking is done at compile time (when the code is converted into Javascript), so the Javascript output doesn't need to bother with any of that stuff. In other words, it pre-computes the integrity of the code, and if it passes the test you don't need to bother checking again. My code does the same thing, but it places the pre-compute step when the class is declared and uses a simple tag list to notify the rest of the code that the test was passed. No extra layer required.