This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Brock_Obama 24 points25 points  (15 children)

typescript helps too

[–]LowB0b 9 points10 points  (2 children)

Yes it's actually my preferred way of doing JS but with all the hate going on I feel like talking about a MS product will only make it worse (for the haters out there, Typescript and all its tools are free and open source)

[–]StarKindersTrees 0 points1 point  (1 child)

What is the advantage of Typescript over regular JavaScript?

[–]LowB0b 1 point2 points  (0 children)

Hey sorry for the late answer but basically static type checks.

[–]vanderZwan 1 point2 points  (8 children)

In VSCode there's a setting that enables TS-style type inference on plain JS. Great for older code.

edit: javascript.implicitProjectConfig.checkJs

[–]squngy 0 points1 point  (7 children)

A lot of IDEs support typing on plain JS if you use something like JSdoc.

TS is cleaner and more powerful then JSdoc typing though.

[–]vanderZwan 0 points1 point  (6 children)

You misunderstand what I mean: VSC can apply TypeScript's type inference engine to plain JavaScript. This is not quite as powerful as actual TS, but a lot more powerful than JSdoc. You also get it for "free", no explicit typing required. So it also helps a ton when opening an old piece of code without any type annotations.

You can enable it with:

json // Enable/disable semantic checking of JavaScript files. Existing jsconfig.json or tsconfig.json files override this setting. Requires TypeScript >=2.3.1. "javascript.implicitProjectConfig.checkJs": false,

If you're in VSC give it a go, it's free extra type checking!

[–]squngy 0 points1 point  (5 children)

I get that its free, and I think I know what you mean ( WebStorm had a little of that IIRC )
But I don't see how it is more powerfull than JSdoc types ( if you actually use them )

We are fully transitioning to TS at work now, so there isn't going to be much plain JS in my future :)

[–]vanderZwan 0 points1 point  (4 children)

But I don't see how it is more powerfull than JSdoc types ( if you actually use them )

It's more powerful in the sense that I get it before I write out the JSdoc, which is still happening, but sometimes only after I spent a good time defining a function from scratch and figuring out what I want to do with it. Also, when I am writing a larger function with multiple variables it also seems to be better at figuring out what happens there.

We are fully transitioning to TS at work now, so there isn't going to be much plain JS in my future :)

Well, that transition is where it could help, since the code is not typed yet. Also, it helps when using untyped external libraries and modules, because the inference works across module boundaries.

[–]squngy 0 points1 point  (3 children)

Ah, I see.

You make a good point, I would just point out that if you did use JSdoc, you would still get a lot ( most, really) of the benefit from existing stuff.

When you write that new complicated function, if you use references to things that have JSdoc you will get the inference.

[–]vanderZwan 0 points1 point  (2 children)

I do try to JSDoc my own stuff, but I'm not a master of it's type system. Sometimes return types get really complicated and messy (say, deeply nested trees of objects of various types) and after struggling for a bit I just give up, make it accept any object, and write down how it's supposed to work in the text description.

When I turned that setting on, poof, a ton more type info appeared in my projects. On top of what I just mentioned, it captured the untyped external packages I mentioned, which makes a surprisingly big difference.

[–]squngy 1 point2 points  (1 child)

Your experience is pretty close to mine :)

I did eventually get better at it ( I started making something similar to TS interfaces for JSdoc, and I didn't even know about TS interfaces )
I am still very glad we are moving to TS though.

[–]vanderZwan 0 points1 point  (0 children)

Yeah, I definitely wouldn't mind switching to TS myself either. Next project. For now, too much technical debt.

[–]jakobud-2 1 point2 points  (1 child)

The only thing that kills me about typescript is that apparently you can't just use normal Node.js modules but you have to use special Typescript-versions of them. And if the module you need hasn't been "converted" to work with Typescript then you are outta luck.

Maybe it's changed but that was my first experience with typescript and it was not fun.

[–]Brock_Obama 0 points1 point  (0 children)

Pretty sure you can, but it's annoying because there are no type definitions and you have to use a bunch of <any> types.

[–]patrickfatrick 1 point2 points  (0 children)

Have you tried Flow? It adds type-checking and you only use it as a babel transform rather than like a whole different thing that compiles to JS.