Тёмный

JSDoc vs TypeScript  

Matt Pocock
Подписаться 99 тыс.
Просмотров 119 тыс.
50% 1

Free tutorials: www.totaltypescript.com/tutor...

Наука

Опубликовано:

 

8 янв 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 215   
@csoto91
@csoto91 4 месяца назад
JSDoc can be really handy when working in big codebases with old code, particularly when it’s not feasible to refactor the code into TS. It’s been very handy for me in the past.
@mattpocockuk
@mattpocockuk 4 месяца назад
Yeah I can definitely see that.
@efr89
@efr89 4 месяца назад
I believe the same thing can be achieved with a lenient tsconfig though. And you can then make it stricter over time.
@hansiboy5348
@hansiboy5348 4 месяца назад
The nicest thing about js doc is that I can right-click and go to the code to see for myself how the library implemented the function
@andycyz
@andycyz 4 месяца назад
Yeah, make it easier to debug when a library goes buggy
@migueljara9399
@migueljara9399 4 месяца назад
TS has a feature called "go to source definition", which allows you to do that
@baldcoder_
@baldcoder_ 4 месяца назад
That's a TS feature. It's only possible in JSDoc because the tsserver in your IDE/editor can use the JSDoc comments to infer types. Without tsserver, JSDoc is just a documentation tool.
@mattpocockuk
@mattpocockuk 4 месяца назад
Yes, this is very very important for libraries that want a good debugging experience for their users. This is why Svelte chose it.
@jeromesnail
@jeromesnail 4 месяца назад
​@@mattpocockukcan we do both? Is it possible to emit js "readable" files from transpiled ts?
@gobluebro
@gobluebro 4 месяца назад
My company refuses to upgrade to ts. Jsdoc has been one of the thing keeping me sane.
@GabrielPoussif
@GabrielPoussif 3 месяца назад
TS has been one of the things eating my sanity away
@azizsafudin
@azizsafudin 2 месяца назад
@@GabrielPoussifmust be a hobbyist programmer then.
@sacha9593
@sacha9593 2 месяца назад
@@azizsafudinI always find it funny when a TS dev say this kind of things. It would be quite pretentious from a low level language programmer but from someone coding in TypeScript it is really truly laughable. Do you think that you are a big guy because you know how to write types?
@82TheKnocKY
@82TheKnocKY 4 месяца назад
I think the key difference why people are switching is that jsdoc is opt-in typing. I can write a bunch of functions and only type the ones that actually interface with other code - say, only the ones that the library exports. Typescript is more like opt-out typing. You have to explicitly put any, or ts-ignore everywhere, otherwise the ts compiler starts infering static types on your code. JsDoc allows you to do the "trust me bro, this function will return a number" while not actually forcing you to type internals.
@harleyspeedthrust4013
@harleyspeedthrust4013 3 месяца назад
this is wrong though, typescript is and always has been "opt-in". you don't have to enable the strict compiler options and you can disable noImplicitAny to be able to write javascript with type annotations here and there. whether you should do this is another question entirely but typescript was designed with that use-case in mind.
@miguelfigueira1719
@miguelfigueira1719 3 месяца назад
Ts is a superset of js, almost all js code is valid ts code. So, typing is optional. You may have used ts with some strict linter rules and that's why you were getting errors without the types
@n8guy
@n8guy 3 месяца назад
💯
@juliohintze595
@juliohintze595 4 месяца назад
One thing that I love about JSDoc is that you can create your types in .ts files, and use them in a JS file with the import() function (like @type {import('./types').TheType}). So a lot of things that JSDoc lacks in typing can be circumvented by doing this.
@kbsanders
@kbsanders 4 месяца назад
I use JSDoc comments in my TS code to document the function and parameters with descriptions but not the types of the parameters themselves.
@magne6049
@magne6049 4 месяца назад
if you also add the types you get a cleaner reading JS too!
@MrWholphin
@MrWholphin 3 месяца назад
JSDoc does not require tsc for runtime, so it’s much faster to iterate on changes and simpler to deploy. Additionally, a well documented ts project will have JSDoc blocks everywhere, so the syntax ‘advantage’ isn’t that much
@PieterWigboldus
@PieterWigboldus 4 месяца назад
You dont need to build JS, only validate/lint, so no transformation is needed in the JS version. The browser en Node.js dont understand TS, that is always transformed to JS, also with ts-node. So JS with JSDoc is the best of both worlds. Also JSDoc makes more clear that it is just documentation, not for runtime. And you can use still import TS types and interfaces inside JSDoc. Which version looks better is a personal preference. And I think TS makes it less clear that the annotations are not validation, only helping with development.
@dealloc
@dealloc 4 месяца назад
No matter what you should bundle your code when shipping a production "executable". Both for optimization but also for bandwidth. There's also downsides to rely on manual file splitting rather than chunk in that you have to manually manage how and what is downloaded and which times. Just creating a file that is then imported but could be inlined would end up costing additional roundtrips for no good reason and hurt UX.
@PieterWigboldus
@PieterWigboldus 4 месяца назад
@@dealloc these frontend things had nothing to do with js vs ts. (And i dont write js only for frontend) Al optimization are hiding that your code of used framework isnt optimal. You dont need all that fancy auto split stuff, just learn how it works, it isnt that hard. Learn the base, not a framework of library.
@dealloc
@dealloc 4 месяца назад
@@PieterWigboldus Depends on what you're trying to build and ship. But I didn't mention frameworks once in my post. I said when it's time to ship to production, you have to think about the user experience for end-users long term.
@sinasalahshour
@sinasalahshour 4 месяца назад
but you don't need the build step for running the thing
@lengors7327
@lengors7327 4 месяца назад
Most of the time thats a bad thing (it means you will be running code that the build step could possibily identify preemptively as incorrect). Not to mention most of serious projects already have a build step
@vitalysuper3193
@vitalysuper3193 4 месяца назад
If you have node js project you can use tsx npm module (or bun btw) so you don’t need tsc or build step at all
@htondkar
@htondkar 3 месяца назад
So what? How big of an advantage is that?
@thegrumpydeveloper
@thegrumpydeveloper 4 месяца назад
Not sure the hate for the build some people have. You’re going to want to strip those comments and minify anyways just take a build step. Running from command line tsx, ts-node with swc and bun are all fast too. No reason to use jsdoc with worse syntax and worse type checking than normal ts
@PieterWigboldus
@PieterWigboldus 4 месяца назад
Why do you want to remove comments. Let users understand also the source code. 20 years ago, you learn developing JS by checking other browsers. Source code is open, and free to manipulate for your own usage. Be open to users, and let them understand and play with the source. Also in Node.js you dont have to build, no reason to downgrade the code to be compatible with old systems. You build for a specific Node version, so no removing of comments needed. Syntax worse is an opinion. JDSoc makes it more clear that Types in JS/TS are just documentation you can lint, it is not for runtime. And in JSDoc you can also use TS types and interfaces for complex and external types. Why should you build your code in TS if you can just build JS code with the same help from TS to check the code.
@thegrumpydeveloper
@thegrumpydeveloper 4 месяца назад
@@PieterWigboldus simple, my docs aren’t always correctly type checked, the syntax is more verbose, copilot chokes on it, and it’s far easier to write an incorrect js doc than a ts type. Syntax highlighting is better and I have 100% type feature availability and I don’t have to refer to two sets of docs to write my code. No one is shipping their comments to prod. That’s ridiculous if you want to ship comments you ship your source maps. If the difference is just putting comments around my ts types I’m all for it if my compiler does it. There’s just no point to remove the compiler from my workflow unless I’m writing in console and then types don’t matter. Syntax is worse is my opinion but some opinions are shared by a larger audience as we can see when we browse through the number of open source projects who chose ts vs jsdoc. So while it’s an opinion it’s the more widely held ( and in my opinion correct)
@PieterWigboldus
@PieterWigboldus 4 месяца назад
@@thegrumpydeveloper than you have configured sometime wrong, because it came be the same. Eslint with JSDoc check can do something, not as far as Typescript. But with Typescript modus you have the same.
@dealloc
@dealloc 4 месяца назад
@@PieterWigboldus Because of size, bandwidth, parsing time, compression and extranous round trips. Let the bundler be smart about how to bundle your files into chunks, rather than manually having to build your architecture around optimizing the UX. Creating a new file for your one function would end up with an additional round trip for no good reason. Users doesn't care about your source code and how you don't bundle your code-until it actually effects them negatively and take up all their cellular data with a slow connection. If you want to be open to your users then open your source up, and link to the repository. Easy.
@PieterWigboldus
@PieterWigboldus 4 месяца назад
@@dealloc if you need that, your build process isnt optimal, you use eg inefficiënt frameworks. Keep it simple, that makes it fast. Everybody has today a fast device and most people also a fast connection. Optimizing isnt needed if you keep it simple. Checking and manipulate code is not what most people do, only some developers. But most developers makes it also hard to do. Tech people that it is possible, give them freedom. Think about the time of css zen garden 😉
@jonkoops
@jonkoops 4 месяца назад
I think this is a bit naive, as JSDoc has the advantage that you don't need to compile it, that alone makes it much easier to debug and integrate in tooling that is not Typescript native.
@Trekiros
@Trekiros 4 месяца назад
Haven't used JSDoc much, so I'm curious Do projects that use it ship the JSDoc to the client? Or do these projects still do things like minify the code? If yes, why is there a problem with compilation specifically? Since those projects would already need to have a build process, I don't see much of a difference. And if no, doesn't that result in ultra-bloated files to send to the client?
@dealloc
@dealloc 4 месяца назад
@@Trekiros The point is that you consume the JSDoc and source through your source code. To provide a better UX, you bundle your source code. Some libraries may provide pre-optimized bundles (like React), in such cases you can tell your bundler to use those when bundling, instead of having to re-bundling the dependencies. On top of this you can build individual chunks of your source and the deps, but it has tradeoffs depending on the granularity you choose to chunk your deps when it comes to caching and cache invalidation.
@Trekiros
@Trekiros 4 месяца назад
@@dealloc I honestly can't make sense of what any of that means.
@dealloc
@dealloc 4 месяца назад
@@Trekiros Let me try to simplify. Access library source code for debugging and development, bundle when you ship to users. Is that clearer?
@lauraprates8764
@lauraprates8764 3 месяца назад
Yes and no, if you are doing a server side this is pretty much true, but as soon as your code hit the web client you'll need to convert to an older version of the standard and do minification, unless you're already coding in an old version of EcmaScript and don't care about minification
@irlshrek
@irlshrek 3 месяца назад
Static typing != Strong typing
@garretmh
@garretmh 3 месяца назад
I disagree with your takeaway on this which makes it sound like TS is just better. TS files require tooling and a build step. JSDoc is a progressive enhancement: it supports almost everything TS does but also always just works. Also the verbosity is nothing if you’re including JSDoc comments anyway. I usually prefer to use TS for programs and JSDoc for libraries.
@dvillegaspro
@dvillegaspro 3 месяца назад
JSDoc is more to write but also allows detailed explanations in your intellisense and it is opt-in unlike typescript. I try to use both because typescript provides type safety during running builds and JSdocs helps me document code better.
@sunofabeach9424
@sunofabeach9424 4 месяца назад
I wish amazing typesystem for Lua someday evolves in a sophisticated linter for Lua like Typescript of JS
@mattshnoop
@mattshnoop 4 месяца назад
The point about needing a lot of lines to add the types is totally moot to me because most of my TypeScript functions are going to have doc comments for the parameter descriptions anyways…
@skeleton_craftGaming
@skeleton_craftGaming 3 месяца назад
Yes, but I don't have to compile my JavaScript using jsdoc
@hkupty
@hkupty 3 месяца назад
JSDoc is like javadoc, KDoc (kotlin), luadoc and many others. As in those other cases, it can do one thing that types alone have a hard time doing: Communicating context and intent. It s is really not just to describe "what" - this is what types usually do, but "why". If you compare it with types, only from the "amount of code" dimension, you're narrowing the comparison and disregarding the other benefits of good documentation, which exist even in static typed languages.
@mahadevovnl
@mahadevovnl 3 месяца назад
I prefer JSDoc next to TS. They help one another so much. I use JSDoc where I find human-readable comments to be useful, and I use it when declaring code examples and resources. TypeScript will be done for things where you don't need those additions.
@kingjune6685
@kingjune6685 2 месяца назад
Typescript is good but giving me hard times
@KimberlyWilliamsch
@KimberlyWilliamsch 4 месяца назад
Is there a TypeScript native runtime, or does it solely transpile to JavaScript for execution?
@harleyspeedthrust4013
@harleyspeedthrust4013 3 месяца назад
i assume you're talking about a compiler from ts to native code which afaik does not exist. if you want to run ts without transpiling, you can use ts-node, but that's not native
@nodemodules
@nodemodules 4 месяца назад
What if you want to re use a complex object type in multiple files. Unions don't work properly. No utility types like Partial, Pick, Omit There's still a build step for production applications to remove the comments and minify the code. I personally don't see the utility in JSDoc, if you want Typescript like features just use it.
@dellavita3463
@dellavita3463 4 месяца назад
+1 And if you do not have build step sometime it will has runtime error instead 😂
@vitalysuper3193
@vitalysuper3193 4 месяца назад
I remember making contributions that change .js to .ts and other devs get confused like another build step to publish as npm module, saying that .ts files are too complicated and so on. Many projects on npm refuse to use .ts and use either weird workarounds / duplicating logic in .d.ts or not adding any types at all, oss sometimes can be wild
@11WicToR11
@11WicToR11 4 месяца назад
this ....people keep acting like these are equal and one has build step and another doesnt. I dont get this, typescript's value imho never was in its "this function accepts this argument" ...this is nothing ground breaking, even php has some sort of "i want this type mechanism". The reason i use typescript is that i can do logic on types and crafting this very specific type mixed from 10 other, with subtracting some other from it. Then I slap it on a function argument, ye jsdoc can do this last step
@PieterWigboldus
@PieterWigboldus 4 месяца назад
You can still import TS types and interfaces inside JSDoc. Or define a JSDoc with typedef, and import it in another file with JSDoc. I work a lot last 2 years with JSDoc in TS mode and JS files, and if you work longer with it. Also you still dont need always a build step, see e.g. Node.js code, where JSDoc is superior to TS. And in frontend code, it is also not always needed.
@vitalysuper3193
@vitalysuper3193 4 месяца назад
@@PieterWigboldus Are you afraid of having a build step? In node.js you can use tsx to run any ts file without building. And don't you lose 2x time as you need to always switch between .d.ts and .js (this was so annoying for me). TS syntax is so concise comparing to jsdoc. Another reason why good dev imo will never use types in js with jsdocs is because non-null assertions are also available only in .ts and there are other restrictions. TS is a small price for big advantages but many guys afraid of having it.
@Cropsii
@Cropsii 3 месяца назад
What are you using as whiteboard here, could you tell please
@mattpocockuk
@mattpocockuk 3 месяца назад
TLDraw
@anhdunghisinh
@anhdunghisinh 4 месяца назад
1 cons for JSDocs for me is the syntax is very cumbersome to write
@AllanSavolainen
@AllanSavolainen 3 месяца назад
Though jsdoc doesn't require typescript compiler though some implementations might do that
@mathiasgheno
@mathiasgheno 3 месяца назад
Doesn't depends the code editor? Webstorm does not need this tsfile, I guess.
@zwanz0r
@zwanz0r 4 месяца назад
JSdoc is a lot more convenient. Especially because you don't need to worry about sourcemaps and .gitignore. However, the biggest issue that _nobody seems to be talking about_, you cannot do everything that you can in TS. Especially non-null assertions are next to impossible in JS doc.
@mattpocockuk
@mattpocockuk 4 месяца назад
Yes, I want to touch on this one in a future short. You also can't pass type arguments directly to functions, i.e: useState();
@zwanz0r
@zwanz0r 4 месяца назад
@@mattpocockuk totally agree. People that are seriously talking about jsdoc being a valid alternative either haven't done so past 'hello world', or they like simple type definitions with an 'any' now and again.
@zwanz0r
@zwanz0r 4 месяца назад
Basically, we need the type annotations proposal :)
@dealloc
@dealloc 4 месяца назад
@@mattpocockuk You can... sort of. But it's bit of a hack. You can type the argument passed in: useState(/** @type {?string} */ (null)) This will correctly infer the return type, too. If the generic is only used for return type, you could also redefine the return type with @type. Though at this point you're in type assertion territory.
@zacisyahu
@zacisyahu 3 месяца назад
at least you document your code naturally with jsdoc
@Smbrine
@Smbrine 3 месяца назад
Js devs invented linter
@ClassicalByMetal
@ClassicalByMetal 4 месяца назад
I've had plenty of discussions around JSDocs in codebases, mostly where the consensus is to avoid them (comments like "code should be readable without explanation" get thrown around a lot), but I still think they are still really useful for contextualising more complex functionality. It's especially helpful for a11yship - they can be incredible for those with dyslexia, dyscalculia, ADHD etc., so I'll always advocate for them where appropriate.
@fiskegalendbpk
@fiskegalendbpk 3 месяца назад
Or use a strongly typed language so your code will run for more than 3 months before becoming buggy and deprecated
@BosonCollider
@BosonCollider 4 месяца назад
The reason to avoid transpilation is to avoid source maps when developing
@edgeeffect
@edgeeffect 4 месяца назад
This is also the answer to an argument I was having about PHPDoc Vs type hinting over in PHP-Land. If we're talking parseable code Vs comments, then parseable code always wins.
@magne6049
@magne6049 4 месяца назад
JSDoc TS is perfect for coding JS in Google Sheets!
@re.liable
@re.liable 4 месяца назад
Love JSDoc. I just find a lot of things are hard to do there, e.g. generics, type aliases, type functions. And as you say, needing tsconfig to actually check the types (in VSCode at least). It's really great when I can't use TS directly though. But I also just recently discovered Deno and `tsx` (the package/executable, not TypeScript JSX)
@RNDev666
@RNDev666 3 месяца назад
Why not just make js natively support ts? I remember it being the plan at some point, and it's so clearly superior imo
@sujezz
@sujezz 3 месяца назад
I was so happy when PHP got strong typing and attributes and we could finally get rid of this dogwater style of having stuff in comments.
@trapfethen
@trapfethen 3 месяца назад
JsDoc gives a better intellisense experience by default. If you want the same experience with TS, you literally have to write JsDocs in your typescript, thereby getting the worst of both worlds.
@mattpocockuk
@mattpocockuk 3 месяца назад
JSDoc comments in TypeScript is great! Using JSDoc as a typing system is bad.
@eatenpancreas
@eatenpancreas 4 месяца назад
Not entirely sure why Svelte decided to switch internally
@yaroslavpanych2067
@yaroslavpanych2067 2 месяца назад
Okay, I open code in Notepad. JSDoc, where is your results
@HumanoidTyphoon91
@HumanoidTyphoon91 3 месяца назад
AND no build step, let's not glance over that detail.
@matiasbpg
@matiasbpg 4 месяца назад
I had been using jsdoc in scripts lately mostly because its faster to itterate without the build step ( i feel that the transpiling takes an eternity when im editing short scripts and expect them to run instantly after a change)
@mattpocockuk
@mattpocockuk 4 месяца назад
You should use tsx to run them. It uses esbuild so feels instant.
@matiasbpg
@matiasbpg 4 месяца назад
@@mattpocockuk didn't know about tsx (only tsc and ts-node), I'll look into it for sure! Thanks
@nomadshiba
@nomadshiba 4 месяца назад
i was wonder that if your library only intended to run with ts, and you really on types for safety. is there reason why would i compile my code while releasing it? i mean why not just ship ts files?
@mattpocockuk
@mattpocockuk 4 месяца назад
Firstly, you HAVE to ship declaration files to make the experience of using your library pleasant. If you don't ship declaration files, TS has to do a lot of work to figure out the types in those files, and your IDE experience using TS slows down. In theory you could ship .ts files and .d.ts files, but if you have to transpile anyway it makes sense to ship .js files which are more portable.
@PieterWigboldus
@PieterWigboldus 4 месяца назад
NPM is a JS ecosystem, the browser and Node.js also only understand JS. So JS is the basic of everything, that is running in production. TS only helps on development.
@abdulazeezatanda2371
@abdulazeezatanda2371 3 месяца назад
Thank you! Louder please
@007arek
@007arek 4 месяца назад
Don't ppl in biger projects use doc also with ts?
@mattpocockuk
@mattpocockuk 4 месяца назад
Yes, JSDoc comments in general are great and should be used everywhere. I'm talking about using JSDoc as a typing system to replace TS annotations.
@SamyarBorder
@SamyarBorder 3 месяца назад
Jsdoc is cleaner tho
@derjansan9564
@derjansan9564 4 месяца назад
How do you comment your Typscript files?
@mattpocockuk
@mattpocockuk 4 месяца назад
You can use JSDoc in two different ways. To simply comment your code, or to rely on as a type system. JSDoc comments are great for describing things. But I don't think you should rely on them to type your code.
@savire.ergheiz
@savire.ergheiz 3 месяца назад
Goodluck comprehending dependencies hell on ts if the required lib are not up to date and backward compatibilities issue too
@gubatenkov
@gubatenkov 4 месяца назад
How to use generics in JSDocs ?
@ex-xg5hh
@ex-xg5hh 4 месяца назад
With the @template annotation
@hugodsa89
@hugodsa89 4 месяца назад
You still don’t need to build.
@rodrigoserafim8834
@rodrigoserafim8834 3 месяца назад
You still need to document your TS code. So you end up having to use Jsdoc on your TS files as well.
@MrLinuxFreak
@MrLinuxFreak 3 месяца назад
I really like jsdoc, ts making me waste more than time then needed instead of writing no types and use jsdocs and interfaces
@jamonh
@jamonh 3 месяца назад
For most apps, TS is better. However, there are a significant minority of projects where JSDoc is better. For example, my hockey team website where I have zero build tools on the CLI side and the only JSDoc typechecking tool is built into VS Code itself.
@MungeParty
@MungeParty 2 месяца назад
What the hell is this guy talking about. You don't need to transpile the code to run it, you just need TSC to lint it. Sure what's the difference between a linter that changes the syntax of your code making it useless in the target environment, and one that just tells you if types are correct? No difference I guess according to this genius.
@nubunto
@nubunto 3 месяца назад
I see this and think that I should just use Rust
@mladenorsolic370
@mladenorsolic370 3 месяца назад
You completely missed a point of jsdoc... i can include descriptions and examples in jsdoc that are then visible on mouse over to the user.
@alihammadshah
@alihammadshah 4 месяца назад
one is a valid JS
@z1adfps297
@z1adfps297 2 месяца назад
Typescript is not a programming language, it's a vs code extension
@redkay7969
@redkay7969 11 дней назад
tf ?
@user-vx1zm9fg6p
@user-vx1zm9fg6p 4 месяца назад
wrong! JSDoc need jsconfig.json file!
@magne6049
@magne6049 4 месяца назад
both
@yuryzhuravlev2312
@yuryzhuravlev2312 3 месяца назад
sorry, but it's a completely wrong point. To validate JSDoc, you need TS and build step, BUT you don't need such things to run it. TS, you can't run without the build step (in browser or nodejs)
@mattpocockuk
@mattpocockuk 3 месяца назад
Yes, that's my point...
@baka_baca
@baka_baca 3 месяца назад
Literally zero of the benefits you mention about typescript matter if you're working in a pre-existing code base that you aren't able to migrate over to typescript. It also doesn't matter if you can't move over to typescript for a variety of other reasons. JSDoc has been incredible in allowing me to get a ton of the benefits of types without any of the friction of adding full on typescript. So while it would be great if I could use typescript at work, the truth is I don't get to at this time but at least I get JSDoc and I get to skip the extra build step.
@mattpocockuk
@mattpocockuk 3 месяца назад
If these are your constraints, I would do the same!
@casad1as
@casad1as 4 месяца назад
JSDoc looks like anti-modular 🧐
@PieterWigboldus
@PieterWigboldus 4 месяца назад
No difference at all, you can import types from everywhere.
@dungeon4971
@dungeon4971 4 месяца назад
not typescript compiler but typescript language server
@mattpocockuk
@mattpocockuk 4 месяца назад
If you're only relying on the language server, you're not getting a full idea of whether your types are passing or not.
@yurkimus
@yurkimus 4 месяца назад
It's not worse. It's just a comment of a special format...
@jeffthekiller229
@jeffthekiller229 4 месяца назад
jesus stop arrow functions like that
@idk-_
@idk-_ 4 месяца назад
What's wrong with it?
@waynes84
@waynes84 4 месяца назад
oh snap
@AseasRoa
@AseasRoa 4 месяца назад
JSDoc is kinda ugly, but it stands out in the code. There is a good visual sepearation between types and code. I like it that way. TS to me looks like a soup of code and types, I don't know what is what.
@n8style
@n8style 3 месяца назад
JSDoc is a crappy way of imitating TypeScript
@RedStone576
@RedStone576 4 месяца назад
well fuck it typescript with jsdoc
@AlessioMichelini
@AlessioMichelini 4 месяца назад
If you use JSDoc just for type annotation, sure, it's worse than TypeScript, but I think you are missing the point a bit as JSDoc is for documenting the code, and you should also pass the meaning of what variable a or b are, something that you can't do in TS. Personally I used both JSDoc and TS, and you don't need to set the type in JSDoc in that case, but you should just add the meaning of a function or variable. Once you combine the two, you get all the power of intellisense. It's not TS OR JSDoc for me, it's TS AND JSDoc!
@mattpocockuk
@mattpocockuk 4 месяца назад
Yes, you're right - this is what makes the conversation hard. JSDoc is great. Using JSDoc for type annotations is, I think, bad for most people.
@AlessioMichelini
@AlessioMichelini 4 месяца назад
@@mattpocockuk if that’s all you want, then yes it’s not the best way to use it, but it’s like using a fork to cut the bread, it’s not the fork that is bad, it’s just the wrong tool for the job
@teamgartz-motorsports6881
@teamgartz-motorsports6881 3 месяца назад
TS is awful. It gets complex very quickly and you spend more time programming types than developing your software. JsDoc is a great middle ground, and you can test as you go even if the types ain’t there yet. A great commit hook can save you from unfinished work being merged without the loss of productivity. I just don’t like the syntax, it could be better, but it certainly better than TS.
@Saru-Dono
@Saru-Dono 4 месяца назад
It's 2024, is the build step even a legit argument against TS anyway.
@mattpocockuk
@mattpocockuk 4 месяца назад
Yes, for backend especially.
@JackBauerDev
@JackBauerDev 3 месяца назад
Hmm just don't use script languages when you should be using strongly typed langs
@mattpocockuk
@mattpocockuk 3 месяца назад
Gotta work with the web
@fcnealvillangca7943
@fcnealvillangca7943 4 месяца назад
This is nice Another good tool but F* JavaScript ecosystem new stuff every month
@zilahi8
@zilahi8 4 месяца назад
yeah, but jsdoc can actually generate _real_ documentation. that what is for really, do generate docs.
@mattpocockuk
@mattpocockuk 4 месяца назад
I'm not arguing against using JSDoc in libraries to generate docs. I'm arguing against relying on it as a way to add types to your application.
@zilahi8
@zilahi8 4 месяца назад
yes, fair enough :)
@daylen577
@daylen577 3 месяца назад
Wuh? What terrible IDE do you use where you need to run the typescript compiler and have a tsconfig.json to get type checking for JSDoc? That should be immediately functional in every modern IDE
@mattpocockuk
@mattpocockuk 3 месяца назад
Here's the thing - if you do that, you'll be using the default values in tsconfig.json. And the default values are just not suitable for most apps.
@jakehadley4044
@jakehadley4044 4 месяца назад
If you're only wanting linting errors, sure. If you actually want Javascript not to suck, then do static analysis with TS.
@ProtectedClassTest
@ProtectedClassTest 4 месяца назад
Wait till you jsdoc complex types 😅
@PieterWigboldus
@PieterWigboldus 4 месяца назад
No problem if you start learning JSDoc. And you can also import TS types and interfaces from a TS file. So no problem at all.
@PieterWigboldus
@PieterWigboldus 4 месяца назад
No problem if you start learning JSDoc. And you can also import TS types and interfaces from a TS file. So no problem at all.
@mattshnoop
@mattshnoop 4 месяца назад
You don't need a tsconfig or tsc. You can slap a //@ts-check comment at the top of your file and VS Code will check it automatically.
@mattpocockuk
@mattpocockuk 4 месяца назад
This is a bad idea for so many reasons
@Bon3air
@Bon3air 3 месяца назад
Typescript is just JS, but worse
@gro967
@gro967 4 месяца назад
It's 2024, no proper developer one should be writing plain JS anymore...
@george_davituri
@george_davituri 3 месяца назад
Js 🎷
@54peace
@54peace 4 месяца назад
Js doc clearly Not efficient.
@leocarvalho8051
@leocarvalho8051 2 месяца назад
Thats such a dumb take
@dasten123
@dasten123 4 месяца назад
aaaaaand it looks _really_ awful with import statements inside the comments when you are not just looking at an example with primitives. Just take a look inside the Svelte repo before you decide if you want this ugliness in your project
@ArashBizhanzadeh
@ArashBizhanzadeh 4 месяца назад
TS types are so freaking complicated for no runtime benefit. It just seems nuts
@P1oN4ik
@P1oN4ik 4 месяца назад
and JS code after TS translation has a much worse optimization in comparison to regular JS code.
@mattpocockuk
@mattpocockuk 4 месяца назад
This is a common misconception. Apart from enums, namespaces and parameter properties, TS only strips types.
@deestort
@deestort 3 месяца назад
typescript is worse
@teamadostamine9657
@teamadostamine9657 4 месяца назад
Yeah nahhh, this video aint it. While I do agree with your point, it is VERY oriented to enhance Typescript (which is fair due to it being your money maker). But plz, dont do this type of video without showing the trade off of each (only showing the good/bad side of one or the other)
@mattpocockuk
@mattpocockuk 4 месяца назад
What felt unfair to you?
@magne6049
@magne6049 4 месяца назад
enhance JS you mean
@ShinSpiegel
@ShinSpiegel 4 месяца назад
You got it wrong man.
@mattpocockuk
@mattpocockuk 4 месяца назад
What in particular?
@ShinSpiegel
@ShinSpiegel 4 месяца назад
@@mattpocockuk TS isn't just the "type" there is a whole bunch of wierdness from TS that we didn't account for, in special when we speak about Interfaces, this is a breaking point and usually bad at 50% of the time. Enuns that aren't enums and are just another breaking point. No compilation also means that the code you wrote will be the same, no mysterious TS magic to make the type system to work. The TS is just a "fancy" linter with extra steps. I can keep the list on and on. No type sucks, but between JSDocs and TS Wierdness, I'll take the docs all year long.
@PieterWigboldus
@PieterWigboldus 4 месяца назад
​@@ShinSpiegel In JSDoc you can also import TS types and interfaces. Also the Enum is just some type for an object, and you can also use Enum in JSDoc. If you talk about type and type checking, the same can be done, but JSDoc doesn't need to transform the code, and replacing all the types with ... nothing, like TS do. I don't understand why some people think TS is such a different world, after all the code inside the method is the same, and types are removed in the build. Just write JS, and if you like types, add JSDoc. Keep it simple!
@ShinSpiegel
@ShinSpiegel 4 месяца назад
⁠@@PieterWigboldusbecause it is. I'm limited by the constrains of the RU-vid comment. I'll write a blog post at some point in the future to better display the reason “why” TS and JSdoc aren't the same, and explain the whybecauae of it.
@PieterWigboldus
@PieterWigboldus 4 месяца назад
@@ShinSpiegel Let me know if you have the article 👍
Далее
Most TS devs don't understand 'satisfies'
4:10
Просмотров 52 тыс.
Await Async Tasks Are Getting Awesome in .NET 9!
9:24
Tutorial 😍 @elsarca #danilisboom #elsarca
00:16
Просмотров 1,9 млн
TypeScript: Should you use Types or Interfaces?
4:06
Просмотров 146 тыс.
Generics: The most intimidating TypeScript feature
18:19
My "as few deps as possible" monorepo setup
4:03
Просмотров 28 тыс.
Design patterns in React
14:37
Просмотров 140 тыс.
Rust's Alien Data Types 👽 Box, Rc, Arc
11:54
Просмотров 132 тыс.
All The JavaScript You Need To Know For React
28:00
Просмотров 547 тыс.
TypeScript in React - COMPLETE Tutorial (Crash Course)
53:21
How To Unlock Your iphone With Your Voice
0:34
Просмотров 17 млн