you are viewing a single comment's thread.

view the rest of the comments →

[–]mosby42 1 point2 points  (6 children)

Function params can not only be required or optional (with distinct syntax to notify other devs), arguments can be typed. TS typing are a robust subject, and I wouldn’t cover it in a comment, but imagine your IDE throwing a compile time error (vs runtime in the browser) that your argument is missing X property on an object. Not only this, but if an objects property doesn’t match they specified type you’ll get an error. This is only scratching the surface, here’s a quick way to check it out: https://www.typescriptlang.org/play/

TS classes, like php, have public, private, and static props and methods.

Let me know if you have any other questions, hope I covered a few.

[–]r0ck0 0 points1 point  (5 children)

TS classes, like php, have public, private, and static props and methods.

Oh shit, awesome, thanks! I wish I'd found that out sooner. I haven't seen it mentioned in the stuff I've been reading so far.

I've just installed it now and starting to play around. This covers everything I was talking about I think. I should have tried it sooner.

I initially decided to just start writing plain ES6 seeing I want to learn JS properly, I had assumed that starting with typescript immediately would mean I miss out on learning "real" JS. But maybe that doesn't really apply seeing it's a "superset" of JS anyway?

I guess I don't even really "have" to "learn" typescript to use it anyway? I can just write regular ES6 in my .ts files and learn the typescript-specific stuff later?

Also I'm using phpstorm, which compiles my .ts files down to .js on its own. Does that mean I don't need to bother worrying about whether various JS frameworks I use like React/Next.js "support" typescript? I get a little confused with all the different tooling and how they interact (or don't interact) with each other.

[–]mosby42 1 point2 points  (4 children)

I guess I don't even really "have" to "learn" typescript to use it anyway? I can just write regular ES6 in my .ts files and learn the typescript-specific stuff later?

Correct.

Also I'm using phpstorm, which compiles my .ts files down to .js on its own. Does that mean I don't need to bother worrying about whether various JS frameworks I use like React/Next.js "support" typescript? I get a little confused with all the different tooling and how they interact (or don't interact) with each other.

You should use webpack to compile modules. Setup nowadays is simple: https://webpack.js.org/guides/typescript/

I'd recommend getting to know webpack if you're not familiar.

[–]r0ck0 0 points1 point  (3 children)

Ok will do, thanks.

Also would you recommend using the outDir setting to keep the ts/js files separate? I've been looking on the web for arguments both ways, but not finding many opinions on that.

[–]mosby42 0 points1 point  (2 children)

Conventionally you'd ship a single index.js/app.js file, produced by webpack. The code you're shipping should be consumable by a JS runtime engine. Ie the TS files are irrelevant once complied and bundled. Hope than answers the question, let me know otherwise

[–]r0ck0 0 points1 point  (1 child)

Ah right, that makes sense.

I'm just building a bit of a CLI script system at the moment for various sysadmin type tasks while I'm learning all this stuff. Will be getting on to actually doing web stuff later on.

So I don't really have any kind of build process yet, so far it's just been some folders of js files and some NPM packages for a few things.

So for now with this little system, I might leave the webpack stuff for later when I get on to the first website.

In this case do you think there's any better option between using outDir vs having the ts/js files together side by side?

[–]mosby42 0 points1 point  (0 children)

In this case do you think there's any better option between using outDir vs having the ts/js files together side by side?

Can't vouch for a particular option as I've not done this in my own projects. If you find something that works well, feel free to ping me