5 ms·
We do this at my current company for all projects, it does not mean you don't use typescript, you will still validate all your files with TS, but there's no bui
by dobladov 3y ago
We do this at my current company for all projects, it does not mean you don't use typescript, you will still validate all your files with TS, but there's no build step, just a check.
Very rarely we find a case that we can't cover with JSDoc annotations, and most of the time it means the code could be refactored to be simpler.
I do this now for all my personal projects, in my opinion it's simpler, faster and closer to pure JS.
- makapuf 3y agoThis is great but -if I dare - wouldn't it be time to allow js to have type annotations [1] ? As in python, treat it as comments for now but with real syntax and let interesting dialects emerge from the consensus ? I like jsdoc but the syntax is urgh. [1] https://github.com/tc39/proposal-type-annotations https://github.com/tc39/proposal-type-annotations
- herpdyderp 3y agoIt will be impossibly exciting if that proposal happens. I hate build steps, one of the reasons I latched onto JS for my career, but TS is just so good that I had to go full blast with it after using it for the first time.
- Tade0 3y ago> Very rarely we find a case that we can't cover with JSDoc annotations I regret every `infer` statement I've put in application code. Grug phrased this elegantly: https://grugbrain.dev/#grug-on-type-systems https://grugbrain.dev/#grug-on-type-systems
- ripplefringe 3y agoI have never seen grug before. This is fantastic.
- Tade0 3y agoPast elder council with many wise tells: https://news.ycombinator.com/item?id=31840331 https://news.ycombinator.com/item?id=31840331
- paulddraper 3y agoTS compiler should have an CLI option to compile without type checks. TS features don't need types to produce output[1] and this is supported by the compiler; it just doesn't have a CLI option. Compiling without types is supported the compiler itself (this is what Babel does). [1] Except const enum and export *
- Rapzid 3y agoIt's really VERY easy to use something like esbuild or SWC though and just use TS for doing checks on the side. SWC would have ripped the TS annotations out of the top 100 TS projects on GitHub before I even finished typing this sentence.
- alerighi 3y ago> Very rarely we find a case that we can't cover with JSDoc annotations, and most of the time it means the code could be refactored to be simpler. Can with JSDoc define types? And can you define generic types? To me that is the real power of TypeScript, being able to type every object you use.
- mjjp 3y agoYes you can with @typedef and @template
- mdaniel 3y agofor those interested, https://jsdoc.app/tags-template.html https://jsdoc.app/tags-template.html is 404 but https://github.com/google/closure-compiler/wiki/Generic-Types https://github.com/google/closure-compiler/wiki/Generic-Type... appears to be the thing (reinforcing my rage at the JFC situation with JSDoc specification)
- mxkyb 3y agoand you can always define more complex types in interfaces and import into jsdoc.
- MrJohz 3y agoWhat your build/deployment steps without the Typescript syntax? Do you bundle or minify at all, or do you release your source files directly? Or is this mostly for NodeJS/server side stuff? I ask because for most of my projects there's at least some bundling going on, and in that case the added complexity of Typescript compilation is pretty minimal - with tools like Vite there is no added complexity, because JS and TS files are going down exactly the same pipeline, parsed by the same parser, etc. And I could get rid of the bundler, which would make some things simpler, but makes imports and deployment more complicated. For the scale of projects that I'm working on, bundling feels like necessary complexity. I guess I'm trying to figure out if this is a useful form of minimalism for the sorts of projects I work on, or if this is the sort of thing that works for some projects but not others.
- fenomas 3y agoI've been doing the same for years and I'm really happy with it. But the one big annoyance is events - I've never found a satisfying way of writing a JSdoc that says what events a class emits, or what parameters the events have. Do you have a way of handling this?
- brainzap 3y agoHow do you type class properties? https://github.com/microsoft/TypeScript/issues/26811 https://github.com/microsoft/TypeScript/issues/26811