3 ms·
I cant believe how much more accessible typescript is than javascript. Type signatures are helpful. Refactoring is so much less stressful. Even things as simple
by saosebastiao 10y ago
I cant believe how much more accessible typescript is than javascript. Type signatures are helpful. Refactoring is so much less stressful. Even things as simple as catching misspelled imports have saved me tons of time.
At one point in time, a 'this' bug ate up half of my day. Ever since moving to typescript, I haven't had a single 'this' bug make it past the compiler. I still don't fucking understand 'this'...all I know is that Typescript knows what it is and can tell me to fix something before I send it off to the browser.
Typescript will never be my favorite language...not even close. But since we can't actually get rid of javascript, I'm pretty happy we have typescript around to make it not suck so much.
- ridiculous_fish 10y agoTypeScript catches a lot, but "this" bugs are still one of the most common things it misses. For example, when factoring a method into a free function, I'll often miss a this: function hypot(x:number, y:number) { return Math.sqrt(this.x * this.x + this.y * this.y) } TypeScript does not warn about this case.
- farnsworth 10y agoCheck out the option "noImplicitThis" in TS2, for this exact case. It will ban using `this` when it's implicitly `any`. I agree that it was much needed!
- ridiculous_fish 10y agoGreat addition! Thanks for pointing it out.
- hkjgkjy 10y agoA very happy way to live as a Javascript coder is to avoid the `this` keyword, in my experience. You really don't need it. Instead write this function as (x, y) => Math.sqrt(x*x + y*y) That can never have any state bugs, because it's a pure function (just like you can never have type errors with a sufficiently good type system). And you might be interested in the native JS function (since ES6) called Math.hypot. Happy hacking :-)
- BinaryIdiot 10y ago> I cant believe how much more accessible typescript is than javascript. Can you elaborate on your meaning? A language that requires transpiling by definition can't be more accessible than the language it transpiles into. > At one point in time, a 'this' bug ate up half of my day. Ever since moving to typescript, I haven't had a single 'this' bug make it past the compiler. I still don't fucking understand 'this'. 'this' can be a little complicated but it's really not that bad. I like the dry way the MDN explains 'this' [1] if you find it helpful. Even if you're using TypeScript I still think it's important to understand (TypeScript does compile into JavaScript after-all; debugging the transpiled output without chrome maps can be necessary at times). [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- regularfry 10y ago> A language that requires transpiling by definition can't be more accessible than the language it transpiles into. It's a funny definition of "accessible" that counts C as less accessible than assembler.
- spriggan3 10y agoC doesn't transpile to assembler.
- clappski 10y agoThat's a rather arbitrary statement; C _compiles_ to machine code that maps pretty directly to an assembly language, which is normally not far off of the abstraction level offered by C. Taking the definition of transpile being translating to a language with a similar abstraction level, you're just picking hairs.
- jensvdh 10y agohttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... This is the best guide to "This".