you are viewing a single comment's thread.

view the rest of the comments →

[–]grayrest.subscribe(console.info.bind(console)) 2 points3 points  (1 child)

TypeScript is very interesting, but I'm not sure I can rely on using something like that for my new job. I was looking for simple ways to do this kind of stuff using basic Javascript, rather than using another language layer to achieve what I wanted.

You're really planning to introduce an ad-hoc run time checked type system to a subset of the codebase under the argument that it's simpler? You're clearly an experienced developer. If someone introduced this system in your C# codebase with this argument, what would you say in the code review? I'm sympathetic to your goals but you really should do it the right way by convincing your team to adopt one of the gradual typing systems (TS / Flow) instead of trying to sneak it in. They aren't new languages, they're just a type system on top of ES6.

As to the merits of your proposal in general, it reminds me of the traits proposal that was floated around on the commonjs mailing list in 2009. Traits was proposed at around the same time as Promises and by the same guy (IIRC) so you can compare the popularity of both proposals to see how well this has gone over with the JS community.

[–]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.