TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Is TypeScript worth it?

365 pointsby roberttodover 2 years ago
I have been using TypeScript for a few years now, and I haven&#x27;t yet been convinced that I would choose to use it if I had the choice; not just for my own personal projects but for large scale applications where the codebase is shared with many developers.<p>I want to skip over the static typing benefits argument, because I think it is well understood that static typing is a good thing and if we could bless JavaScript with a built-in and robust typing system then I don&#x27;t think many people would be against that. My issue is with the amount of extra work it places on developers, much of it the &quot;dumb&quot; kind of work which can eat up hours and doesn&#x27;t deliver all that much value.<p>i) Like a framework, you are at the whim of TS devs as it gets updated (edited)<p>For example, a new package you install can require a new TypesScript version. Once installed, you then may need to update your source code. This can place quite a high tax on the developer, where perhaps a 10 minute change becomes hours long.<p>ii) Libraries are badly documented<p>Most libraries do not document their types, or have no examples using TypeScript. Some worst offenders: Apollo, Protobufjs. The type definitions exported by these libraries can be large and complex, and the error messages emitted by TypeScript are so long and cryptic the result is often a drawn out process of trial and error along with trawling through source files.<p>iii) Error messages are hard to follow<p>Errors are long and don&#x27;t provide enough detail. They will explain a type mismatch referencing many types you may not have ever seen, and are not documented anywhere. Except for simple errors, many of them are very hard to follow to a remedy.<p>iv) It requires yet more transpilation<p>Transpilation takes time, and always adds a burden to developers. I didn&#x27;t mind so much with ES6 etc because eventually many functions were included in a broad set of browsers. There doesn&#x27;t seem to be much progress including TypeScript in a browser, and feels like these complicated transpilation steps could be with us for a long time.<p>I could probably add more to this list, but my point is that I just can&#x27;t see that TypeScript is worth all this time investment and making progress so slow sometimes. Are there others that come to this conclusion? I mainly see positive posts about TypeScript.<p>edit: I referred to TypeScript as a framework which it isn&#x27;t. However it feels similar to me in that you are at the whim of TypeScript developers and how they decide to progress with the language.

146 comments

DanRosenwasserover 2 years ago
Hi there! I work on the TypeScript team and I respect your feedback. Of course I do think TypeScript is worth it, and I&#x27;ll try to address some of the points you&#x27;ve raised with my thoughts.<p>i. Dependency management is indeed frustrating. TypeScript doesn&#x27;t create a new major version for every more-advanced check. In cases where inference might improve or new analyses are added, we run the risk of affecting existing builds. My best advice on this front is to lock to a specific minor version of TS.<p>ii. My anecdotal experience is that library documentation could indeed be better; however, that&#x27;s been the case with JavaScript libraries regardless of types.<p>iii. Our error messages need to get better - I&#x27;m in full agreement with you. Often a concrete repro is a good way to get us thinking. Our error reporting system can often take shortcuts to provide a good error message when we recognize a pattern.<p>iv. Compilation can be a burden from tooling overhead. For the front-end, it is usually less of a pain since tools like esbuild and swc are making these so much faster and seamless (assuming you&#x27;re bundling anyway - which is likely if you use npm). For a platform like Node.js, it is admittedly still a bit annoying. You can still use those tools, or you can even use TypeScript for type-checking `.js` files with JSDoc. Long-term, we&#x27;ve been investigating ways to bring type annotations to JavaScript itself and checked by TypeScript - but that might be years away.<p>I know that these points might not give you back the time you spent working on these issues - but maybe they&#x27;ll help avoid the same frustrations in the future.<p>If you have any other thoughts or want to dig into specifics, feel free to reach out at Daniel &lt;dot&gt; MyLastName at Microsoft &lt;dot-com&gt;.
评论 #34364604 未加载
评论 #34365873 未加载
评论 #34364219 未加载
评论 #34365197 未加载
评论 #34361232 未加载
CSMastermindover 2 years ago
I&#x27;m old enough to have worked on two different large enterprise applications which predated TypeScript and it was a nightmare.<p>Personally I&#x27;ve found that JavaScript lends better to a functional style of coding but there are no protections in the language to enforce this and both codebases I saw had a weird mismatched set of object oriented and functional style principals. Defined classes, prototypical inheritance, modifying the prototype chain directly, a factory pattern here, a weird &quot;constructor&quot; there, just figuring out the shape of the data was difficult to do.<p>The lack of guardrails in JavaScript also empowered people writing &quot;clever&quot; code which technically works but was insanely hard to parse and understand, especially when you&#x27;re 20 function calls down a stack trying to understand what&#x27;s happening.<p>I agree the TypeScript compiler&#x27;s error messages are confusing but you should have see the types of stack traces JavaScript produces.
评论 #34363898 未加载
评论 #34366148 未加载
评论 #34366046 未加载
评论 #34377313 未加载
satvikpendemover 2 years ago
&gt; <i>I want to skip over the static typing benefits argument, because I think it is well understood that static typing is a good thing and if we could bless JavaScript with a built-in and robust typing system then I don&#x27;t think many people would be against that. My issue is with the amount of extra work it places on developers, much of it the &quot;dumb&quot; kind of work which can eat up hours and doesn&#x27;t deliver all that much value.</i><p>If I take your question <i>prima facie</i>, then yes it&#x27;s still worth it, since you seem to be dismissing the main reasons people use TypeScript, the static type benefits, and the bulk of your arguments seem to actually be about how TS can improve, not why one should throw out TS wholesale, which I personally would never do.<p>In other words, you&#x27;re focusing on the 20% BS out of the 80% benefits. Can the 20% be improved? Of course, but I&#x27;ll take 80% benefits over 0% with JS any day.
评论 #34360599 未加载
评论 #34363401 未加载
bestestover 2 years ago
I&#x27;ve been working with JavaScript for 20 years. And 5 years with TypeScript. And, well. I still am not convinced.<p>Too much overhead for me. I really dislike typing obvious things and boilerplate. Probably my fluency with JS is to blame. I don&#x27;t need to see types and autocompletion. If I really need to — I just go to the source and inspect the source code, that is how I familiarise myself with the interface. I also think this makes one a better developer.
评论 #34365610 未加载
评论 #34365646 未加载
评论 #34365664 未加载
评论 #34381471 未加载
评论 #34366846 未加载
评论 #34366269 未加载
评论 #34408272 未加载
评论 #34366112 未加载
评论 #34376288 未加载
评论 #34376270 未加载
评论 #34365483 未加载
评论 #34377558 未加载
评论 #34377329 未加载
chucklenorrisover 2 years ago
As i said before, a lot of people expect that writing typescript is as easy as writing js, which is not. I estimate the typescript tax to be around 40-100% more time, especially if you want to do typescript right and not use `any` all over the place. And besides, typescript is a poor fit for someone who is used to writing highly dynamic, lambda based code, which is one of the main niceities of js. My guess is that a lot of people with a background in java and c# found themselves writing server side js and were really unconfortable with this paradigm, so they tried again to turn js into what they knew best - an imperative object oriented programming language. Now, i&#x27;m not saying that types are a bad thing, i for one like typescript especially in projects with a lot of people, but, it&#x27;s funny to see new people struggling to finish a task that should take a few hours in days.
评论 #34361576 未加载
评论 #34369569 未加载
nforgeritover 2 years ago
I share your feelings. These times, whenever I&#x27;m setting up a new TS project, feel like:<p>1) Look up &quot;this months current way of doing things&quot;<p>2) have a couple of horrible hours wrestling with tooling and the module system<p>3) add a new feature, install 1 lib with 30 deps<p>4) figure out that one dep does not work with TS&#x2F;the chosen module system&#x2F;whatever versioning related thing<p>5) go for a walk. scream into the void. come back to the desk.<p>6) browse through dozens of Github issues to figure out what is going on<p>7) decide to fork the according dep knowing that I&#x27;ll hate myself in 3 months<p>8) ...<p>Yeah, so I&#x27;m kind of missing the good old YOLO JS times w&#x2F;o semi-colons and stuff. But I need to say that I&#x27;m usually not opting for NodeJS for deep &quot;OOP-alike&quot; Domains. I think NodeJS&#x27; sweet spot is infrastructural things, MQ Consumers, glue code or little http fetching&#x2F;posting orchestration scripts. I never had too many issues without static typing because I intentionally kept things simple, had tests and rolled out updates consciously watching the ongoings.
评论 #34373840 未加载
评论 #34368896 未加载
DiabloD3over 2 years ago
I think Typescript isn&#x27;t worth using, and I find this unfortunate. The Typescript team clearly has put years of work into this, and clearly has tried to shore up the deficiencies in Javascript.<p>Are you writing a brand-new codebase that needs to work on multiple platforms, and not exclusively in a browser? Don&#x27;t use Typescript, use a language with native WASM support. This includes avoiding solutions that involve Electron, Deno, and CEF, as they are browsers, too.<p>Are you writing a brand-new codebase that only works in the browser? Learn how to use HTML and CSS correctly, avoid as much Javascript and Typescript as possible: Less is more.<p>Are you maintaining an existing codebase with extensive Javascript, and you are not willing to rewrite entirely Typescript? Try using Typescript, but you&#x27;re better off jumping ship, nothing can save it now.<p>Any codebase that has untyped code in it, that cannot be compile-time analyzed for safety, that requires a significant client-side investment (ie, a giant blob sent to the browser), is kinda doomed to failure, and you will not realize the magnitude of your mistake until it is too late.<p>I realize my opinion is unpopular, as the programmers on HN seem to be a lot of front-end devs and a lot of &quot;fullstack&quot; devs, where the &quot;full&quot; is JS+TS in NodeJS, using some predefined popular NodeJS framework. I just want systems that are designed to minimize the BS, I&#x27;ve chased enough BS in my lifetime, TS can never deliver a no-BS system to me.
评论 #34362657 未加载
评论 #34362906 未加载
评论 #34363655 未加载
genezetaover 2 years ago
I won&#x27;t <i>defend</i> TypeScript. Mainly because I&#x27;m not interested in doing such a thing; I don&#x27;t like it that much, clearly not enough to care.<p>But even so, I will say a couple of things about your arguments.<p>Regarding <i>i)</i>, no, it&#x27;s not a framework. But then again, I don&#x27;t think that&#x27;s what your argument expresses anyway. You seem to be saying &quot;it&#x27;s yet another dependency you need to keep up with&quot;. This would be correct and a valid argument. But it&#x27;s unrelated with &quot;being a framework&quot; (which, again, it is not).<p>As for <i>ii)</i>... I&#x27;m afraid this argument could be valid for any large group you want to pick in software. Are you arguing JS libraries at large are <i>better</i> documented? Sounds highly dubious. From a different angle, is this a problem with the language itself or is it a problem with the libraries?<p>Finally, regarding <i>iv)</i>, there is <i>no</i> &quot;progress including TypeScript in a browser&quot; and you should never have expected it. Not saying it will never happen because some person somewhere might do it, but you shouldn&#x27;t expect it.
评论 #34360549 未加载
评论 #34360987 未加载
dunno7456over 2 years ago
I worked in two different team in two different companies where a full rewrite of the core system was done in typescript.<p>The technology itself had few issues like compilation time and inability to run the application locally because of reasons.<p>The new systems were so complicated that everything ended in neverending bike shedding.<p>The people pushing for &quot;everything to be written in typescript including other teams tooling (aka pulumi)&quot; were very unflexible crowd.<p>The previous system had few issues that could be solved with database indices.<p>It&#x27;s soul crushing to work on these type of places where technology is used for the sake of technology instead of bringing some business value.
评论 #34365971 未加载
评论 #34369430 未加载
larsrcover 2 years ago
Is it worth it compared to what? Plain JS? Transpilation from a different language? Rust? Growing apples?<p>I have used plain JS, GWT, and TypeScript. TS is an incredible improvement over the two others. The TS type system is excellent, very expressive and helpful. An important advantage you get from static typing is that your IDE has more information to work with and so becomes more powerful. If you code in a text editor, you won&#x27;t reap the full benefits, and you&#x27;ll have to do more of the grunt work yourself.
评论 #34365272 未加载
kitsunesobaover 2 years ago
My use case is a bit odd, but I&#x27;ve been using it for small personal web projects — so small that no dependencies are being pulled in and bare tsc is being used in place of a bundler — and as someone who doesn&#x27;t have all of the ins&#x2F;outs and do&#x27;s&#x2F;don&#x27;ts of JavaScript committed to memory (the vast majority of code I write is Swift or Kotlin) it&#x27;s wonderful to have something catching errors <i>before</i> I save and reload the browser window as well as preventing &quot;silent&quot; bugs JS is notorious for.
评论 #34360814 未加载
评论 #34360898 未加载
评论 #34365710 未加载
pontilandaover 2 years ago
Are tests useful? Because this is what TypeScript gives you: it helps you avoid regressions.<p>If I change a signature, tests fail. If I pass junk data, tests fail. It&#x27;s like invisible <i>live</i> tests and people forget this.<p>As in the other recent discussion, yeah, you can live without tests and you can live in JS-land. Whether it&#x27;s worth it it depends on you. TS and traditional testing lets me ship updates without even opening node or the browser.
评论 #34364771 未加载
评论 #34364595 未加载
评论 #34365119 未加载
eitlandover 2 years ago
Short answer:<p>It is worth it if you want me on the team. I refuse to work with anyone who throws out TS for JS in 2023.<p>Slightly longer answer:<p>I have said a number of times<p><pre><code> &quot;Javascript is a simple version of Java in the same way as a bike with one wheel is a simpler version of an ordinary bike.&quot; </code></pre> The same can be said about JS and TS. <i>If you want to do any serious work you go for the serious thing even if it means occasional adjustment of brakes and gears, or in Typescripts case, sometimes figuring out something.</i><p>If anybody suggest to use Javascript today I won&#x27;t take them seriously.<p>i) I have used Typeescript since 2017. For some reason I don&#x27;t have these problems and never had.<p>ii) Yes, some libraries are poorly documented, that is for me a reason to prove why I am a software engineer by either figuring it out, complain until they fix it or even better use my gut feeling and use some libraries that aren&#x27;t stuck 10 years ago.<p>iii) Error messages can be hard, but compared to debugging the mess that happens without typing it isn&#x27;t hard at all.<p>iv) Have someone look at your project setup.<p>And before someone says I don&#x27;t know Javascript: I wrote my first javascript application (OK ECMAScript since it was in Adobes SVG plugin), which was a working map, dynamically updated based on GPS position, back in the spring of 2005, that is half a year or so before Google Maps and years before most people took Javascript seriously so I should be qualified to have opinings. Yes, it wasn&#x27;t production quality, but I built the logic more or less alone in 5 months in between other school work.
评论 #34366623 未加载
评论 #34366814 未加载
评论 #34367212 未加载
评论 #34366726 未加载
评论 #34366344 未加载
faefoxover 2 years ago
In my experience yes, to the extent that I don&#x27;t intend to write vanilla JS ever again if I can possibly help it. If you&#x27;ve done webdev professionally in the past 5+ years you&#x27;ve almost certainly already been transpiling so to draw the line at introducing something as massively useful as static typing seems both arbitrary and bizarre.<p>FWIW I can&#x27;t recall the last time I reached for a 3rd-party library and found that it was lacking types. The DefinitelyTyped project has really done a remarkable job expanding type coverage. And even in that rare case where you might need to add type definitions yourself it&#x27;s simple enough to do so.<p>There&#x27;s a ton of room for improvement around error messages, no argument there. The TS team is very much aware of this and they&#x27;re working on it but it&#x27;ll take time.
andrewstuartover 2 years ago
I feel like TypeScript is definitely worth it BUT it seems to be getting ever more powerful but not in a good way, in complex way.<p>Too much time is spend fighting TypeScript as opposed to writing application code.<p>I have a question for the language experts out there .... why is TypeScript getting so complex? Are other strongly typed languages this complex? Or does the complexity arise from trying to overlay typing on JavaScript which is an incredibly dynamic language?<p>And if it is the case that TypeScript&#x27;s complexity keeps going up because essentially &quot;strongly typed JavaScript&quot; is a hack, then should we all be moving to a much simpler strongly typed language that compiles to WASM, and yet still richly interfaces with the DOM and browser APIs?<p>Does TypeScript just have to keep getting ever and ever more complex and detailed - is that the unavoidable future?
评论 #34364279 未加载
评论 #34364225 未加载
评论 #34364227 未加载
评论 #34364254 未加载
llanowarelvesover 2 years ago
I&#x27;d say for most people, beyond small scripts&#x2F;cli&#x2F;micro-microservices, the ceremony of setup&#x2F;environment overhead for it is worth it, and continually pays dividends. You can usually copy-paste a common config file around to bootstrap.<p>Most of your (pretty good actually) critique are points to make the least-bad way of doing JavaScript even better, and I&#x27;d agree could be improved.<p>Others have taken notice.<p>&quot;Native support&quot; of TypeScript is done by Deno. And tight TypeScript (and other adjacent tooling) integrations with VS Code and WebStorm.<p>And transpilation is being worked on by various builders. Stripping types and running through esbuild or swc is fast. For typechecking part, was a proposal to have TypeScript be rewritten in Rust for performance.<p>We can lament that JavaScript went from being a web document enhancer to being shoehorned into a full application compilation toolchain, but the old Jquery thru Expressjs era of doing things has significant drawbacks for full sized applications&#x2F;APIs&#x2F;etc.
评论 #34361264 未加载
8n4vidtmkvmkover 2 years ago
I like it. I wasn&#x27;t convinced it was worth it for the first year or two, especially when TS was young, but the devs have done a great job and have paved over a lot of the weak spots. Things I didn&#x27;t even expect would get fixed have been fixed.<p>I just try to type things 90% of the way, until it&#x27;s good enough, and slap an `as` in there if I get too annoyed or it takes too long to fix. Don&#x27;t even care. It doesn&#x27;t put me in a worse spot than JS would have.<p>Getting completions on all my giant objects is wonderful.
评论 #34365318 未加载
apatheticonionover 2 years ago
I am quite surprised at the turn out in the comments here against adding type checking to JavaScript.<p>In my opinion, TypeScript is not only essential in the context of any professional project, but it features one of the most ergonomic type systems I have ever worked with.<p>There are certainly pain points with certain TypeScript features (e.g. enums) but any project that takes me longer than 5 minutes to write, I need type checking. If I can&#x27;t be bothered with setting up tsc - and setup difficulty is a valid criticism - I just use jsdoc.<p>I have seen TypeScript take the heat when applied to JavaScript projects that implement multiple trendy programming paradigms. Often times the projects themselves are so complex that adding a type system requires type-kungfu. It&#x27;s not the type system at fault - but a needlessly complex architecture.<p>Love TypeScript. Wish there was anything like it that compiled down to static binaries.
评论 #34365994 未加载
tmpfileover 2 years ago
&gt; Is Typescript worth it? &gt; I want to skip over the static typing benefits argument…<p>Typescript, as the name implies, adds types to your script. If you don’t see the benefits of types then typescript may not be for you.<p>&gt; My issue is with the amount of extra work it places on developers… and doesn&#x27;t deliver all that much value.<p>If you think adding types doesn&#x27;t add much value then typescript may not be for you. In my experience, types are defined once then provide a lifetime of value.<p>&gt; you are at the whim of TypeScript developers and how they decide to progress with the language.<p>This is true of any library, programming language, operating system, hardware, etc. But adding types isn’t somewhere I’d worry about backward compatibility being broken. All the newer versions of typescript are backward compatible. If you have a library that requires a newer version of ts then upgrading ts won’t break anything dependent on earlier versions.
评论 #34364374 未加载
评论 #34364231 未加载
mejutocoover 2 years ago
&gt; static typing is a good thing [...] My issue is with the amount of extra work it places on developers<p>This is one of the eternal complains about type safety, somehow mitigated by type inference. I believe it is totally worth it in the case of Typescript.<p>&gt; i) Like a framework, you are at the whim of TS devs as it gets updated (edited)<p>As a language, it has proven quite stable. Even if development stopped tomorrow you could keep the current version forever.<p>&gt; ii) Libraries are badly documented<p>It is inconvenient but, since they are js libraries, they are compatible. You do not need specific ts examples, although it is extra nice.<p>&gt; iii) Error messages are hard to follow<p>Did not run into this issue myself but fair enough.<p>&gt; iv) It requires yet more transpilation<p>tsc compiles ts into js. Depending on what you use, you could get rid of webpack etc. and just use tsc.<p>In summary, for me Typescript is totally worth it. All this lost time you mention is different from the lost time adapting to x framework or y packer update, since it reduces errors down the line. It might feel like it is slowing you down, but you can always use any for certain modules and type things at the interface. It is still your decision what to type, the language gives you the tools to do so.
LASRover 2 years ago
The question of whether it&#x27;s &quot;worth it&quot; really boils down to you and your specific requirements.<p>Even within the same project, there are times when I don&#x27;t want typechecking - when I am prototyping something out and want to move fast.<p>And there are other times, when I want typechecking - when I am finalizing a feature implementation or doing integration with existing logic etc.<p>It&#x27;s not a framework. It definitely is a language in its own right.<p>But from personal experience, the group productivity goes way up with larger codebases with many ICs working on it. Unit tests become type checks. It opens up a lot of extra bandwidth for more sophisticated functionality or better tests.<p>Solo IC, working on a small project, with no intention of ever writing tests - you might see TS be an overhead.<p>To sum up, your requirements decide whether it&#x27;s worth it.
评论 #34360723 未加载
评论 #34362307 未加载
confidantlakeover 2 years ago
100% worth it to me. I love typescript. Working on large enterprise applications where one function calls other function and it goes 10+ layers deep I don&#x27;t know how I would work without typescript. Just being able to see this function takes argument of type FOO and returns type BAR[] is incredibly valuable.
评论 #34364228 未加载
评论 #34363955 未加载
fergieover 2 years ago
I have been using TypeScript at work since 2019. Personally I am not convinced that it is worth it, broadly for the reasons you note and also because TypeScript has in practice a soft dependency on Visual Studio, and in turn other MS services such as GitHub and Axure. Adopting TypeScript can often lead to de facto vendor lock-in.<p>There is a good argument for using types (and also a good argument for not doing so). If the argument for wins out, then types will be included in the native js spec and the need for TypeScript will disappear. If the argument against wins, then TypeScript will also disappear.<p>If TypeScript really floats your boat then by all means use it, but treat it for what it is- a hairy dependency that only a minority of developers love or need.
评论 #34399658 未加载
fedeb95over 2 years ago
I don&#x27;t like JavaScript, I don&#x27;t like TypeScript, I don&#x27;t like front end development at all. Is typescript worth it in my personal projects where I know all the code and they are pretty small? In my opinion, no. Is typescript worth it at work, where multiple people interact in a large codebase? Absolutely. Asking if a language is worth it is pointless unless you add &quot;to my use case&quot;
评论 #34365239 未加载
tobyhinloopenover 2 years ago
I&#x27;ve worked on multiple Typescript projects for years and I&#x27;m still not convinced it is actually an improvement over working with plain JS.<p>Lately I&#x27;ve been using Typescript&#x27;s JSDoc comments just so I don&#x27;t have to deal with transpiling code but still get most of the advantages like editor autocomplete and warnings.
oztenover 2 years ago
As humans it is easy to forget the time savings that we don&#x27;t see. For a project that uses a lot of Type annotations, it is like getting a bunch of unit tests for free or writing a bunch of boilerplate code to validate inputs.
评论 #34361095 未加载
评论 #34363888 未加载
brundolfover 2 years ago
I don&#x27;t have a lot to add except that my experience with it has been very positive; your complaints are mostly valid, but for me those pain points disappear in the shadow of all the things I no longer have to spend time stressing about or debugging
评论 #34360531 未加载
vlodover 2 years ago
I use TS as standard now (because every job requires it), but I dislike it immensely.<p>I&#x27;ve used static langs like Java and GoLang and prefer them over TS. Heck I even like ruby-rails more. Since I&#x27;m fullstack (TS on FE&#x2F;BE), it&#x27;s hard to move 100% away from TS (becz a use React) and it irks me how everything has changed the last 10 years of so.<p>I am a seasoned developer and can code (in JS) extremely fast, clean and performant. With sufficient test coverage you can go a long way. Of course if you use TS and change something important, the compiler will tell you all the places you have to refactor. This is super useful.<p>However in my experience with a fair amount of TS codebases, there has been a tendency for devs to use as many clever TS features of possible (e.g. utility classes and generating crazy generic types from multiple types). I detest this style of programming, becz when you have to can&#x27;t get something to work, it&#x27;s a pain to try and understand the errors. This also extends to TS enabled libraries which can be challenging when you try and do something non-standard.<p>I burn time trying to understand the errors and getting TS out of my way, so I can get on with the task at hand. I find cases that if you look at the logic I&#x27;ve written, there&#x27;s not a chance that something can be undefined and yet I have to wrap code in &quot;if&#x27;s&quot; just to satisfy the compiler.<p>Even though I have a ton of experience, I deliberately code for that junior devs can understand&#x2F;debug&#x2F;work-with or the support engineer who just got woke up and trying to fix prod, which in my experience, isn&#x27;t a common approach anymore. This is part of the problem IMHO.<p>Most devs I talk to are using TS as their first language and have mostly never experienced the joy (and lack of safety, I grant you) of dynamic&#x2F;non-typed languages (e.g. ruby&#x2F;lisp). Get a lisp-er to do TS and start hearing the flood of swear words. lol.<p>Of course, I understand the benefits of TS, but for me at least there&#x27;s no joy in it and that&#x27;s one of the reasons I got in this game in the first place.
d357r0y3rover 2 years ago
I&#x27;ve seen the codebases created and maintained by people who &quot;don&#x27;t need types because it just slows me down.&quot;<p>Hard pass.
评论 #34363861 未加载
评论 #34364092 未加载
azangruover 2 years ago
As for &quot;worth it&quot; — as someone replied in another comment, it&#x27;s a question for you. You better than us know your use case, your strengths and weaknesses.<p>Me, I love typescript. It&#x27;s an extra reassurance that my code will probably work correctly — and even though it isn&#x27;t as trustworthy as Elm, Haskell, or Purescript, it&#x27;s better than nothing. It is a good pair programmer who has many times saved me from stupid mistakes I made while writing code. And it holds my hand while I am refactoring — I would be scared to do that in a javascript codebase. Tests would help with refactoring, of course; but they aren&#x27;t as exhaustive as a static type checker is.
评论 #34360847 未加载
datasertover 2 years ago
We have been using typescript in large scale JS project with 15-20 library modules and 7-8 product modules. I cannot think of building such product without typescript. When we compile all libraries and products and see no TS errors, we know at least that we are referring to correct properties, and wiring the shape correctly.<p>Typescript has bunch of &quot;clever&quot; things but you don&#x27;t have to use it. We probably use 30-40% of TS features and that is more than sufficient for us. With that said, here is what I think about your questions.<p>1. Agree, and it is not any better without TS either. In case, a library is not compiling with your TS version, we ignore the error, put a FIXME there and remove the &quot;ignore&quot; sometime later<p>2. Yes but that is not TS problem. Without TS it is even worse.<p>3. Agree sometimes, we get so complicated errors. We search around and see if any smart people have figured what that means. If not, ignore and move on with a FIXME<p>4. Since many years, we are not writing any JS which doesn&#x27;t need transpiling. If not TS, you would be using babbel or some other tool most of the time anyways so we haven&#x27;t this to be an issue.
评论 #34364324 未加载
paxysover 2 years ago
#1 – You don&#x27;t have to upgrade TypeScript versions till you are ready, and newer versions never have breaking changes anyways. The syntax remains strictly compatible with ES6 and beyond. Packages you consume publish compiled JS and aren&#x27;t dependent on specific TypeScript versions at all.<p>#2 – If libraries haven&#x27;t published types, just use them as pure JavaScript (which is what you would have done anyways). Lack of documentation again applies to both JS and TS equally.<p>#3 – I assume you are talking about compiler errors? I have personally found them to be simple to understand, especially when the exact location is highlighted in your IDE. At runtime there will be no difference since it is all the same JS code under the hood.<p>#4 – Yes transpilation takes non-zero time. TypeScript has a lot of tooling around incremental compile&#x2F;watching for changes, so I don&#x27;t think it should really be that much of a burden during development. I have worked on massive TS projects and don&#x27;t even notice the compile task running in the background.<p>I find this post weird because TypeScript does have some real drawbacks – overly complex type system, makes the codebase more verbose, false sense of security (no runtime type mismatch errors), mix of typed and untyped code in codebase etc., but your reasons for disliking it all seem superficial and easy to overcome.<p>In my personal opinion everyone should be starting new JS projects in strict-mode TypeScript by default unless there is a reason not to.
评论 #34363680 未加载
评论 #34365225 未加载
评论 #34364758 未加载
评论 #34366301 未加载
评论 #34363658 未加载
评论 #34363980 未加载
logicalmonsterover 2 years ago
Of course, there&#x27;s more than one way to build a good product.<p>Personally speaking, I&#x27;d say that adding another layer of abstraction onto your stack shouldn&#x27;t be a dogmatic thing that you just reflexively do without considering the actual needs of a particular project. TypeScript offers some benefits for certain types of complex projects, but also some costs and problems that might not be worth dealing with for certain projects.<p>It&#x27;s a little bit like GraphQL in a sense. That&#x27;s a phenomenal idea...for a product like Facebook...but probably not actually needed for every single project.
评论 #34360600 未加载
hussainbilalover 2 years ago
The short answer is no. Typescript is not worth it. The reason is because:<p>- WebAssembley (which other, controversially better or at least more adopted languages also target)<p>- Javascript&#x27;s spec. is not time invariant (<a href="https:&#x2F;&#x2F;github.com&#x2F;tc39&#x2F;proposals#readme">https:&#x2F;&#x2F;github.com&#x2F;tc39&#x2F;proposals#readme</a>)<p>- Typescript isn&#x27;t the best solution (There are better less adopted solutions providing types, like Elm, Rescript, or Purescript)<p>For Javascript, the real solution is hygienic macros and contracts, but because `eval()` can&#x27;t get no love or safety on the browser side, everyone on the server-side has to suffer.<p>Ironically, introducing a fake compilation step where Javascript transpiles to Javascript (not like babel.js which targets older JS, but literally just the same lang spec) is the way to side step the `eval()` problem, lol! (expanding those `eval()` in a fake compile step)
bborudover 2 years ago
What is a bit sad is that JS and TS both get in the way of the development of something more sensible to replace it. I had hoped that WASM would make application development for the browser a bit more sane. I had hoped that someone would create an application framework for a sane, strongly typed, mainstream, compiled language that has decent tooling. With compiler and dynamic loading as part of the runtime.<p>JS is a garbage language. You need only look at identity or all the stupid asymmetries in the language to realize it isn&#x27;t a well designed language. TS tries to fix that, and good job for doing that, but you can&#x27;t escape the fact that it is desperately trying to fix a pig with lipstick, botox and hold-in pantyhose.
评论 #34367332 未加载
jacquesmover 2 years ago
I had some pretty strong pressure applied to use Typescript for pianojacq.com but resisted it for a very simple reason: no tooling other than an editor reduces the barrier for contribution so much that it makes it possible for outsiders that just know Javascript (a large multiple of the ones that know TS) to contribute to the project.<p>It also means there is no &#x27;development environment&#x27; as such, it&#x27;s just a repo on gitlab that anybody can read, fork and contribute to from within gitlab if they want.<p>I have also tried to keep the number of dependencies to an absolute minimum, which also helped to make something that doesn&#x27;t feel like a moving target.
vagrantJinover 2 years ago
To make an anology.<p>Js is a shovel. Simple. Does its thing. Digs dirt in our quest for gold.<p>TS is like adding a two stroke petrol engine so the shovel vibrates up and down. Loud, jerky, difficult to handle.<p>A sane person looking in would wonder why not just buy a jackhammer(java&#x2F;c#)? Or use an excavator(Rust&#x2F;C++)?<p>Why is it neccesary to attach an engine to a shovel?
jillesvangurpover 2 years ago
I think you are asking the wrong question. The right question is whether it is worth opting out of the benefits of typescript. The answer to that is probably no for lots of people. Another valid question to ask is if typescript is all there is when it comes to those benefits. And the question to that is also no. It&#x27;s a nice step up from Javascript. But why stop after that? There are so many other languages out there that offer so much more. And some of them even transpile to javascript.<p>Regarding your points:<p>I) this is indeed endemic in the javascript world. I would not blame typescript for this. I work with Java and Kotlin a lot. Things are more stable there. Five years is short for compatibility. In the js world, six months is long.<p>II) The typescript annotations are documentation too. They help your IDE figure out what is what and enable things like autocomplete. The original js code probably isn&#x27;t a whole lot better. Also, lots of libraries are developed in typescript these days.<p>III) That&#x27;s what happens in weakly typed and highly asynchronous environments. Pure javascript just moves that burden to runtime. Better to deal with it before you deploy your code.<p>IV) Most modern javascript is transpiled. It&#x27;s a compilation target at this point. So you might as well make full use of the fact that there is a compilation step. The packaging and minification is actually just as bad.
bborudover 2 years ago
To me the language is very secondary to me as it exists in an endless swamp of:<p>- chaotic and baroque layers of tooling that need to be figured out and made to keep working<p>- a software tradition where poorly thought out ideas are implemented with vigor resulting in design by accident<p>- ...which then results in frequent rewrites<p>- a universe of low quality libraries and frameworks resulting in frequent discovery of serious bugs<p>- every project having lots and lots of dependencies<p>And that&#x27;s before we even consider the language or the congenital defects inherited from JavaScript.
thadtover 2 years ago
Yep. I&#x27;ve had the foolish (mis?)fortune of scaling a couple of frontend projects from small to not-so-small starting in JavaScript and then converting to TypeScript. In each one, starting out with vanilla JavaScript was faster (no build!), but at some point our velocity would slow as changes required more testing infrastructure. After switching to TypeScript, we were faster than before.<p>Sure, dealing with TypeScript can be a hassle, but it is less hassle than dealing with broken software.
评论 #34360935 未加载
评论 #34360865 未加载
pipeline_peakover 2 years ago
I don’t see the need for TypeScript. A lot of people seem to see dynamic typing as this big bad thing that should just go away.<p>I haven’t used JS professionally so maybe I don’t know any better, but I think dynamic typing should be embraced. There are A LOT of applications where you really don’t need to worry about types. And from my experience working with app&#x2F;cloud code bases in C#, I’ve seen a lot of ugly classes that I can’t touch simply because they were written 10 years ago and I don’t trust them. My guess is the web world is plagued with all sorts of old code you don’t want to touch, I don’t think TypeScript solves that with static OOP.<p>I think the prototype based OOP approach in JS is better because you don’t have to concern yourself with all these hierarchies. You can have multiple car object definitions with dynamic typing, it doesn’t matter because it’s all about what’s being used in the moment. In static typing we expect a single concrete definition to be extended, composited, and reused in an intricate way. That way never works because what is defined today as “just the bare minimum” mutates into something larger and now everything inherited “needs” it too. But they don’t always truly need it, they just have to satisfy some argument. And of course that “single” definition gets duplicated across the code bases anyway. Initially we think of these approaches as elegant, but it almost always rots in its own hierarchal casket.<p>Dynamic typing allows cleaner OOP and its approach is more honest. “I need a representation of this abstract type right now”, not that type and a whole bunch of other crap that it’s fundamentally forced into bringing along for the ride.
bern4444over 2 years ago
i) TS isn&#x27;t a framework. And you don&#x27;t have to use it everywhere in your system. You can decide how heavily to leverage it, developing a &#x27;core&#x27; TS subset that powers a broader JS layer (or the opposite, or something different)<p>ii) Lots of libraries are extremely well documented and typed. This is the same in any language not just for types but also for docs, capability, perf etc. This argument applies to all software everywhere so it doesn&#x27;t make sense to single out TS<p>iii) Error messages can sometimes be hard to follow. But you get better at parsing them very quickly when they get gnarly.<p>iv) Transpilation is nearly always a required step anyway. Adding TS support is minimal. There are plenty of tools that do TS to JS on an order of magnitude of MS.<p>All decisions are tradeoffs.<p>What benefits does it bring (ignoring the biggest one of them all)?<p>TS makes it easier to maintain software across large teams by providing a mechanism to express relationships in a codebase.<p>They are self documenting and replace a lot of JSDoc needs (letting you focus docs on more useful info like intent, design choices, example usage, etc).<p>Types can also replace the majority of unit tests validating code is correct saving time on running fewer unit tests and letting devs focus on integration tests.<p>Lastly, I&#x27;ve never seen or experienced something breaking from upgrading the Typescript version in a project. Even when a TS upgrade has &#x27;breaking changes&#x27; they never actually break anything in practice that I&#x27;ve seen.
评论 #34360656 未加载
edwincoronadoover 2 years ago
I agree on the &quot;error messages are hard to follow&quot;. A lot of times when you have an error it doesn&#x27;t clearly communicate &quot;hey it should look like this&quot; (something Rust does soooo well) and instead says something like &quot;types or property A incompatible with property B that is incompatible with X and not Y and ....&quot;. It basically just explains the nesting but is so hard to actually make sense of or how to solve it.
typescriptfanover 2 years ago
&gt; It&#x27;s a framework, with all the usual framework downsides<p>&gt; For example, a new package you install can require a new TypesScript version. Once installed, you then may need to update your source code. This can place quite a high tax on the developer, where perhaps a 10 minute change becomes hours long.<p>No. It&#x27;s a language compiler. You can upgrade it safely without changing a single line in your codebase. If there is a breaking change (sometimes, regarding the strictness) there&#x27;s also a configuration option that lets you keep the previous behavior.<p>&gt; ii) Libraries are badly documented<p>And so you&#x27;re going to lose any and all typing as your solution? I don&#x27;t understand. Undocumented but typed &gt;&gt;&gt; undocumented and untyped.<p>&gt; iii) Error messages are hard to follow<p>I disagree completely, TypeScript has helped me many times to understand what&#x27;s happening and why - I mean errors that I wasn&#x27;t aware of in my previously untyped JS codebase.<p>&gt; iv) It requires yet more transpilation<p>&gt; Transpilation takes time, and always adds a burden to developers.<p>Doesn&#x27;t matter. Use SWC or esbuild for sub-100ms compilation times. Your CI is a long running job due to tests and lint anyways. Nobody is writing pure uncompiled JS these days - you can&#x27;t use NPM libraries that way, so there&#x27;s always some (Web)pack step. I haven&#x27;t seen a single developer who liked having to care about browser versions and wants to go back to that - but if you add a compilation step you get that for free and can write the latest and greatest.
评论 #34360447 未加载
评论 #34359979 未加载
danielEMover 2 years ago
Couple of years working with TS and I think I can add my 5 cents here:<p>1. It is worth it, but not as much for benefit of types safety straight forward as for ... &quot;intellisense&quot; that discharge you from remembering stuff and misspelling it<p>2. It is annoying - they (MS&#x2F;TS team) have very &quot;conservative&quot; approach which leads to:<p><pre><code> - no operators overloading, - no option to extend primitive types, - no option to get info about your types at transpile time, - no built in options to improve performance at transplantation time, - no built in options for transformation plugins - no other than JS transpilation targets - need of tons of other tools to make your actual target, - ... etc. </code></pre> At the end it does job well, but only because you put in it a lot of man hours (to learn, develop and maintain) - and everyone seem to be happy about that.<p>Sorry for being a bit grumpy, but sometimes it feels like wasting a life working with TS. ;-) (especially when I read again what I just wrote ;-) )<p>Seriously, let me know MS&#x2F;TS team if you need someone to drive to TS some real fresh new value ;-)
alixanderwangover 2 years ago
After years of Flow, Typescript, Webpack, React, JSX, etc, I went back to just vanilla HTML, CSS, JS for my most recent production project (<a href="https:&#x2F;&#x2F;play.d2lang.com" rel="nofollow">https:&#x2F;&#x2F;play.d2lang.com</a>, which is open source). The experience was great. I didn&#x27;t find myself missing any of those tools.
评论 #34360894 未加载
xigoiover 2 years ago
For me, TypeScript is like putting lipstick on a pig. It improves one thing about JavaScript while leaving all the numerous other flaws and introducing new ones.
jpgvmover 2 years ago
If you are doing JS then you should certainly be using Typescript.<p>The best choice however is to simply use a better ecosystem entirely.<p>IMO JVM+Kotlin is great general purpose combo, Rust is good if you don&#x27;t write the sort of code that needs GC&#x27;d structures, etc. Between those two I rarely need to consider anything else.
topherPedersenover 2 years ago
I find TypeScript very helpful! As a self taught developer I always used to just use JavaScript, but after joining a big company and working with TypeScript I prefer it now. I like how I always know &quot;what&#x27;s in the box&quot; now when working with different objects and whatnot.
评论 #34360622 未加载
rattrayover 2 years ago
One of the biggest mistakes that I see devs making is caring too much about making TypeScript happy when they know it doesn&#x27;t really matter.<p>There are a lot of cases where it&#x27;s totally reasonable&#x2F;rational and honestly fairly safe to just throw in a well-scoped &quot;any&quot; cast, a `&#x2F;&#x2F; @ts-expect-error` comment, etc.<p>If you know what you&#x27;re trying to do, and TS isn&#x27;t understanding, sometimes it&#x27;s just a lot more expedient to tell it to shut up and listen to you.<p>Of course, sometimes you&#x27;re wrong, and you don&#x27;t want unsafety to leak, so it does require a fair amount of experience and judgement to do responsibly.
评论 #34364322 未加载
评论 #34369218 未加载
sinenomineover 2 years ago
If you write a project for yourself, or develop a startup or an MVP it&#x27;s often not worth it.<p>Late-binding dynamically typed languages are underrated, if you can hold the mental picture of types in tour working memory, that is.
mauro_c8over 2 years ago
There&#x27;s elm, a statically-typed language with none of the pain points you described. So my short answer is: Compared to javascript, yes, it&#x27;s worth it. Compared to elm, no.
zekenieover 2 years ago
The answer to &quot;is {{tool}} worth it&quot; is almost always &quot;sometimes&quot;<p>Typescript is a wonderful tool for many situations. Typescript may not be needed for all situations. There&#x27;s upfront cost to configuration and tooling. But you get type safety and automatic documentation.<p>In all my new non-trivial projects, I default to typescript. It has caught so many issues and saved me a lot of time. Not having it feels like driving without a rear-view mirror. But, if I&#x27;m just writing a little script, I might omit it.
_gabe_over 2 years ago
For ii.) Typescript is a superset of javascript. If it annoys you to try to translate JS documentation into TS, then don&#x27;t. Just use the JS example and use ts-ignore or something similar. Why throw out TS when you can literally suppress those one-off instances?<p>iii) You should see C++ template errors if you think the TS errors are bad. The TS errors do suck sometimes, but when I see which line of code it&#x27;s complaining about, it&#x27;s usually enough to clue me in to what the problem is. And once again, ts-ignore exists for a reason ;)<p>iv) The majority of the frameworks I use allow you to skip transpilation while developing. So you can supply the TS files directly, and then transpile when you&#x27;re done.<p>TS has some problems sure, but these all seem like very surface level complaints that you have to deal with in any other language. Which language has dependency management solved? Or clear and concise error messages all the time? Or super fast compile times? I don&#x27;t see any alternatives that don&#x27;t host some or most of all of these warts.<p>Additionally, when I code using Javascript I feel like I&#x27;m blindly groping my way through the magical forest of dynamic code. Typescript gives me a clear and concise road map and helps me avoid <i>a lot</i> of traps laying around that are obscured by that dynamic magic.<p>Is typescript worth it? 100% yes.
评论 #34364268 未加载
syspecover 2 years ago
My problem with typescript is that at the hands of a typescript aficionado the code is nearly impossible to read.<p>It requires so much mental effort to understand what&#x27;s going on
brailsafeover 2 years ago
The way I think of this is, if I were running a small team as lean as possible and trying to grow as a business, getting as much out of expensive developer time as possible, my answer would be that I get productivity gains <i>sometimes</i> from the work put in to strictly type inputs and outputs to&#x2F;from functions, whether they be props on react components or whatever. Otherwise, largely a massive time sink that I&#x27;d be pissed I&#x27;m paying for.
fennecfoxyover 2 years ago
I&#x27;ve used TS since it came out and it&#x27;s always been great.<p>There are a few quibbles with TS devs over not implementing certain ideas because it breaks out of the JS superset paradigm, which really makes me wish we had a TS++ or TS# that broke this on purpose but hey.<p>It does have a lot of problems, but it usually comes down to pre-existing ones. i: yup but like, isn&#x27;t that true of every framework&#x2F;language&#x2F;library? But less so for TS given that it&#x27;s open source<p>ii: this is the JS ecosystem in a nutshell, but I think you&#x27;ll find with any similarly sized ecosystem, built from the thankless efforts of a bunch of amazing individuals in the community that this is true. If you want Oracle level support&#x2F;docu you gotta pay big $$$ for it<p>iii: this is very true and my advice to other devs I work with is usually to read more towards the bottom of the error. TS currently gives you a lot of context for the error, much of which may be but isn&#x27;t always useful.<p>iv: realistically we have been waiting for a very long time for node.js&#x2F;browsers to be able to run TS natively. I would be a huge fan of this. Transpilation on large projects can take a good amount of time, but I&#x27;d say the larger the project the _better_ the advantage you will have using TS; sure you&#x27;ll have to deal with trans times but TS can really save your butt when making a breaking change in a large project.<p>I&#x27;ve used Node.JS pretty much my whole career, whilst I&#x27;ve done a lot of stuff in C# and C&#x2F;embedded as well my mainstay has been Node &amp; JS and as soon as I could use it, TS.<p>I remember callback hell, I remember adding console logs every few lines to figure out what the fuck is going on, I remember sitting in the debugger trying to make sense of why various vaguely connected chunks of code weren&#x27;t working properly. I&#x27;ve seen things you people wouldn&#x27;t believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhäuser Gate. All those moments will be lost in time, like tears in rain.
steve_adams_86over 2 years ago
I love TypeScript in the right places, but I think it’s often used for things where other tools would be a much better fit.<p>On the backend it can be nice if you’ve got a monorepo including the front ends it supports. Maybe you’ve got graphql happening and you can share types. That seems great sometimes, and there are cases where it’s super handy and efficient.<p>I don’t know for sure, but it doesn’t seem worth it after a certain point. I’d much rather keep typescript to the front end where I find it really shines. I’ve worked on a lot of projects where it was full stack typescript and there were always these common, nagging, very typescript-and-JavaScript-specific problems.<p>Fundamentally the build and development tool chains in general tend to be awful. I can accept it on the front end out of necessity, but on the back end it gets egregious quickly unless you’re using micro services and builds stay quick by default.<p>Any time I work on something statically typed with nice tooling I realize how much better life can be. It feels like the minor gains I get from fullstack TS are quickly negated by the plethora of advantages to using something like Go or Rust where I can purpose-build applications with absolutely crazy performance, reliability, and portability.<p>So, TS in the browser is awesome. I think you’d be crazy not to. On the backend on the other hand — unless you’ve got like a perfect fit for using something like Next.js or a static site generator where the backend can be dead simple, I’m pretty tired of dealing with its deficiencies.<p>And even then it’s not the language so much as the cruft built up in tooling over the years. It’s slow and awkward. NPM is plain old awful. Basics like linting are painfully slow. Testing libraries feel like a house of cards. And so on.
评论 #34364103 未加载
nack_jickolsonover 2 years ago
Ok so I finally created an account just to respond to this post because I wanted to share my experience with typescript. I really don&#x27;t get the confusion and doubts about the usefulness of typescript. It&#x27;s my favorite language to use because of it&#x27;s expressiveness.<p>In my company we built a lot of web apps in very small teams (mostly just 2 people). We use mostly c# as a backend and typescript + mostly angular, sometimes react as a frontend. When typescript came out I built a conversion utility that allows me to generate typescript definitions and metadata from my c# type definitions. In angular I built my own type safe reactive forms, access control and API framework. Often we use ef core as a database layer on the backend, so we have a single source of truth (the c# types) for database and frontend types for the API. I use mapped types in typescript a lot to reuse the generated API types in my frontend code. If a field in a class is renamed ef core takes care of the database migration. On the frontend I get notified of every error because of the rename. Is there a table column for the field, I get an error. Is there a form that maps to the field I get an error. Do I check for write permissions of the field with the old name somewhere, I get an error. I use exhaustive matching to ensure that all cases of enums or union types in general are handled. Everything is type safe and the types come from a single source of truth.<p>It&#x27;s so insanely productive it feels like magic!<p>Edit: also wanted to add I mostly do not use libraries outside of framework libs for angular or react in my frontend. Generally most library code I need (with few exceptions) is built by myself rather fast and easily. I avoid libraries because of the npm ecosystem mess but it also has the upside that I don&#x27;t have problems with outdated type declarations or typescript incompatibilities.
评论 #34366510 未加载
adminuover 2 years ago
Hoenstly, for production code, TS makes me sleep better. No matter how many tests you write, that one undefined object will get you at some point. TS helps to eliminate a complete set at compile time (as you know) and that&#x27;s great!<p>Anecdotal evidence from my Haskell experience: If my Haskell programs compiled, they usually worked. Which is amazing. Powerful types for the win.
评论 #34365860 未加载
heresjohnnyover 2 years ago
I get your point, but it actually increases my productivity. Some examples:<p>I no longer have to worry about things unknowingly becoming undefined or falsey.<p>When chaining map, filter, and reduce, I know at every step of the way what kind of object I’m working with.<p>And when I use a dependency, I don’t have to trust possibly outdated documentation but can rely on types.<p>Just these three things make it 100% worth it for me.
评论 #34364592 未加载
jmullover 2 years ago
I don&#x27;t think (i) doesn&#x27;t make sense to me... I guess a package <i>could</i> foist a TS dependency on you but it certainly doesn&#x27;t have to. It&#x27;s pretty sloppy if it does, so maybe not the greatest package anyway. (ii) has nothing specifically to do with TS. (iii) agree. (iv) sure, though static type checking requires a static type-checking step and tool.<p>You started by skipping over the benefit of static type checking, but that&#x27;s the direct trade-off: is that benefit worth the extra complexity and time spent satisfying the compiler. For me it&#x27;s probably usually yes for smaller projects where I know the devs can handle it and definitely yes for larger projects where the communication burden is high (it just partially helps people stay on the rails, organized, and on the same page -- not sufficient by any means, but it eases the strain).
Seviiover 2 years ago
My biggest problems with TypeScript are that it regularly gives me null safety bugs even after I add guards. And I can&#x27;t really trust the types typescript offers.<p>I&#x27;ve been using typescript for a year now and I just want to go back to Java at this point. Biggest obstacle to that is management believe it or not.
throwaway0asdover 2 years ago
&gt; i) Like a framework, you are at the whim of TS devs as it gets updated (edited)<p>I have been using TypeScript for almost 6 years and not experienced this problem. Like everything else keep things simple, don’t chase trends, and so long as do right by your product everything will be smooth. I also don’t waste time with large SPA frameworks.<p>&gt; ii) Libraries are badly documented<p>I don’t use many dependencies. The DOM and Node type definitions are extremely well documented and inspired me to write better documentation.<p>&gt; iii) Error messages are hard to follow<p>For me this depends on the complexity of a given object or type definition. When things are primitive the error messages are more clear. My only suggestion is to keep your interfaces primitive.<p>&gt; iv) It requires yet more transpilation<p>I use SWC as a TypeScript stripper. My nearly 50kloc project takes about 2seconds to covert to JS, which pushes out my total build time to about 2.5seconds.
Tade0over 2 years ago
To me it&#x27;s worth it because as opposed to languages designed to be strictly statically typed, the type system is there to serve you, not the other way around. It&#x27;s pragmatic and tailor made for its use case.<p>People who&#x27;ve always programmed in traditional statically typed languages like Java scratch their heads on why would anyone not want to have static typing, but the reason for that is simple: in a dynamically typed language you can (and often do) produce code that&#x27;s hard or impossible to type in said statically typed languages.<p>TypeScript&#x27;s designers recognized this, so not only there are escape hatches here and there, but also the type system over time evolved to adapt to the real-life use cases instead of imposing some abstract, complex type system which might not even be very useful when used against all the creative ways JS programmers write their code.<p>And it works.
jokethrowawayover 2 years ago
Personally I moved over to Rust for as much as I can.<p>I still use TS on frontend (as frontend framework in rust are not quite there yet when compared to something like solid start - perseus is getting there though) but I definitely use any freely when I&#x27;m in a hurry.<p>That&#x27;s exactly what I don&#x27;t like about TS: it enables developer to bypass safety making the whole thing not very safe. You can&#x27;t trust your dependencies as you normally do with Rust (unless your dependencies specifically opt out with unsafe - there is still deps vetting needed, but it really hasn&#x27;t been a problem).<p>Is it worth it? Before swc I would say no, with swc (typescript compiler written in Rust) the perf hit and DX is not too bad and I&#x27;d say yes.
xiphias2over 2 years ago
I&#x27;m with others (it&#x27;s worth it when there are more people &#x2F; the code needs to be correct), but the example of Protobufjs is unfair: I expect it to be super complicated to work well with Typescript. TRPC is growing for a good reason.
nlover 2 years ago
I&#x27;ve come to TS from Python.<p>To me, install a new package and it requires &quot;target=ESNext&quot; and modules=&quot;ES2022&quot; and suddenly I feel like I&#x27;m back in the Python 2 to Python 3 transition debacle.<p>Except this happens every couple of weeks!
tluyben2over 2 years ago
We recently brought a large js project from js to ts and, while we had issues, almost all to do with transpiling and the obvious end result being javascript which is not typed. Coming from f#&#x2F;c#, and having used Purescript, typescript feels familiar, however, it takes too much from js imho. Especially the automatic coercing is pretty annoying to us and still causes pain we would not have in the other languages mentioned above, but it is miles better than js. We can refactor much faster than we could before.<p>We definitely are happy with the move. I will never be a fan, but the alternatives I cannot sell to the team.
cesarefover 2 years ago
I think what you&#x27;ve done here is document the pain introduced by using TypeScript, but you&#x27;ve not documented the (unknown) pain from not using it.<p>The question should really be, are the development pains you have more or less than the (most likely) production pains you&#x27;d see if you weren&#x27;t using it?<p>I personally believe that more problems in development for reduced production outages is the right answer for the vast majority of software development.<p>If would be interesting to know of cases where projects have stepped away from it. I&#x27;m sure there are some examples and it would be interesting to understand their reasoning.
MaxArt2501over 2 years ago
For me, the main problem is that TS doesn&#x27;t follow semantic versioning and this leads to a fragmentation of libraries support - unless they also provide multiple type definitions (some of them actually do) - and migrating to newer versions is usually harder, because breaking changes happen so often. So I guess point i) is correct.<p>Let&#x27;s see the others.<p>ii) It&#x27;s true that many libraries don&#x27;t have type definitions, but the most used ones have an externally-maintained corresponding @types&#x2F;### package that solves the problem. And even if they don&#x27;t, how is it the fault of TS? The alternative is no type documentation at all - is that better for you?<p>iii) Yes, error messages are something that can be improved, but then again, the alternative is no static error and eventually an even more laconic runtime error. Would that be better? At least, TS catches that there&#x27;s a problem <i>before</i> you run the code.<p>iv) Compilation adds a burden to the CPU, not the developer. But anyway, it&#x27;s a one-time process, and unless it takes 30 minutes it shouldn&#x27;t be a problem. There are new, much faster compilers nowadays, like esbuild and SWC, plus other tooling tricks like module caching, that makes your local development almost feel like there&#x27;s no compilation at all.<p>I won&#x27;t discuss the merits of the adoption of TypeScript. Since I started using it - except for very simple projects - I always felt like I&#x27;d be way less productive without it. And I actually had the confirm recently, when I had to work on a Loopback@3 BE that somehow is in JavaScript (even though Loopback 3 does support TS).<p>It&#x27;s been a mess. Trying to understand the models, the signature and the sense of all the entities has been a nightmare. The documentation for LB v3 is badly maintained and sometimes broken, and this adds even more difficulty. Some dev tried to add some JSDoc info here and there, but it&#x27;s not nearly sufficient to understand what&#x27;s going on without investing hours of study of the existing code.<p>This is part of the cause that prevented the team to upgrade to LB@4, so much that I even suggested to redo the BE altogether in Nest (save for the core business logic parts), rather than trying to make a sense of it.<p>So yeah, I&#x27;ll stick to TS for the foreseeable future, and strongly suggest all the teams I&#x27;m going to work with to do the same.
shagymoeover 2 years ago
I&#x27;ve seen &quot;we can&#x27;t get OpenAPI to automatically generate our types in a sane way&quot; derail a 3 month project to standardize an API&quot;. In 20 years of js, I never had that problem. YMMV
fortyover 2 years ago
In a word: YES.<p>Update TS regularly to avoid making updates hard and lagging behind to much. Unlike a runtime framework, updates are unlikely to break things at runtime, so there are no reason not to update very often. If some external types are wrong or annoying, don&#x27;t forget _any_ exists and simply brings you back to the crappy situation you&#x27;d have without TS (well admittedly it adds transpilation costs, but it&#x27;s still type checking everything else, which is well worth it).<p>I think TS is nearly the best language that could be done given the constraints of being fully compatible with JS.
sebastianconcptover 2 years ago
What I read is <i>static typing is a good thing</i> but the costs of using it in TS aren&#x27;t convincing really.<p>I feel that using it optionally where it&#x27;s easier to maintain and feel its value is the best of both worlds.
评论 #34366471 未加载
majestic5762over 2 years ago
I write types everywhere. Without types, I&#x27;m in the blind. So yeah, don&#x27;t look at motifs why some library maintainer has TS errors in their declaration files. I&#x27;m a full-stack TS developer, and I can count on my one hand fingers the times when some library had type problems. And if they had, I would fix them with my own declarations. But how do you code without types? It brings so much clarity to everything. Judging by your questions, you haven&#x27;t worked with TS a bit. Or you like sensational HN titles, drawing in all the kids lol
评论 #34385636 未加载
8noteover 2 years ago
For the most part, I only hear from typescript when there&#x27;s a type mismatch.<p>Understanding the type mismatch is ofter difficult, but it does solve a real problem.<p>I also like that it gives escape hatches, for when I know what the type should look like, or I don&#x27;t care what it looks like<p>I haven&#x27;t found the typescript updates to be difficult, nor situations where packages I&#x27;m depend on require incompatible typescript versions<p>My pains are on that it&#x27;s hard to get the setup right where you aren&#x27;t depending on a giant set of types packages, giving you size bloat for things you mostly don&#x27;t care about.
commitpizzaover 2 years ago
I would say, as a person who have been developing in JS&#x2F;TS daily for the last ~5-7 years that it depends on your team.<p>If you have a larger team, yes it is worth it. If it is your side project or if you are like 2 people working on a project then I would say it&#x27;s probably not worth it.<p>Typescripts biggest strength is that it&#x27;s easier to work several people on the same thing. When someone else makes a change, it&#x27;s easier to figure out what their code does.<p>The bigger the team and project, the bigger benefits you will get from typescript. At least, that is my opinion.
评论 #34365596 未加载
abalashovover 2 years ago
Oh, thank heavens! Finally someone says the quiet part out loud. I thought it was heresy and that the TS bubble would never pop. From my perspective, it&#x27;s not worth it at all. It&#x27;s just another hype train. It doesn&#x27;t prevent bad programmers from writing bad code, nor does it cause good programmers to write better code. It mostly just adds bureaucracy and hindrance, in the ways you allude to in your list. It doesn&#x27;t make hard things any easier, but it makes easy things harder.<p>It&#x27;s also way too complicated for what it is. To the extent static typing is beneficial, most developers and projects only need the bottom 30% or so, but the expansive - and expanding - feature set encourages byzantine solutions, especially for showy types for whom tight little chunks of terse syntactic cleverness are an aesthetic (I&#x27;ve been there, I get it). And as if JS build tooling wasn&#x27;t unnecessarily overcomplicated already, let&#x27;s pile on a bunch of transpilation infrastructure?<p>Now, I still use TS, having sensed that it&#x27;s where the centre of gravity was moving as far as JS developer fashions. Plus, of course it&#x27;s not bad to have types in the language in a rudimentary sense. Sure, why not? Moreover, I try to pick technologies that I could hire someone else to work on or collaborate with me on in the future, and TS is definitely &quot;in&quot;. There were subtle nudges from other areas; I&#x27;m a very heavy Vue user, and Vue 3.x certainly doesn&#x27;t mandate TypeScript, but let&#x27;s be real; they want you to use TypeScript.<p>I make a point of using as few &quot;clever features&quot; as possible; 90% of my uses are banally simple interfaces. I think I did foray once into `Map&lt;Partial&lt;keyof RTCSessionEventMap&gt;, RTCSessionEventMap[keyof RTCSessionEventMap]&gt;`, and it&#x27;s not at all clear that this got me anything. But it looks cool, doesn&#x27;t it? I guess that&#x27;s what leads TS-heavy developers to churn out impenetrable gobbledygook. I&#x27;m quite capable of not typoing my own key names. Why are we so fixated on abstruse manipulations of arbitrary contrivances that get transpiled away anyway? I suppose you could ask the same question about any high-level programming language insofar as it ends up machine code in the end, but TypeScript&#x27;s complexity doesn&#x27;t reflect an appropriate humility for its place high up the meta-hierarchy. You need to be an actual programming language to ride this ride; as a fancy templating system, it&#x27;s too entitled with its massive cognitive demands.<p>I&#x27;m not going to say there&#x27;s nothing good about TS. I do appreciate the ability to inspect type definitions to learn more about how a library works, especially if they have crappy documentation--which is often. Naturally, I also pocket the benefits that type definitions afford to IDE autocomplete. But on the whole, it&#x27;s a drag on my productivity, and I spend an awful lot of time either struggling to decipher someone else&#x27;s TypeScript or paying some sort of tribute to the exacting and mercurial TS compiler gods. I&#x27;m not writing better or error-free code because of it. Good end-to-end testing is a check on my code quality; the ever-so-occasional squiggle in the IDE is not.<p>Related thought: &quot;type safety&quot; has become some sort of metaphysical fixture, an unfalsifiable theory of quality and robustness. &quot;I&#x27;m so glad I have type safety!&quot; is a liturgical or ritualistic statement, the kind that nobody in their right mind would question, or attempt to unpack or otherwise anatomise. It&#x27;s a self-evident, ipso facto good. Types in JavaScript seem to have become a religious totem object. This oft-posited but seldom materialised correlation between &quot;types&quot; and &quot;quality&quot; remains to be illuminated for me. My background is entirely in statically typed languages (C above all else), so I understand the argument and need no convincing that types are good, and even elegant. However, I can assure you I wrote plenty of buggy code in C, C++, Go, Java...<p>It reminds me a bit of the apex of the TDD hypermania about &quot;refactoring with confidence&quot;, or specifically, the naive and childlike optimism of &quot;now that I have unit tests, I can refactor with confidence!&quot; Can you? That depends on many things, doesn&#x27;t it? Truly, how could it not? And either way, an overabundance of confidence owing to some platitudinal methodology is generally not a great vantage point to bring to engineering. Humbleness about breaking things keeps satellites in the sky, not euphoric, LSD-fuelled campfire paeans to TDD, and certainly not the mere presence of types. &lt;&#x2F;rant&gt;
评论 #34369122 未加载
Shish2kover 2 years ago
&gt; The type definitions exported by these libraries can be large and complex, and the error messages emitted by TypeScript are so long and cryptic<p>What’s the alternative? If you make a type error in TS you get a cryptic error[0], but if you make a type error in JS you get a bug which you learn about after it crashes prod…<p>[0] Personally I rarely get cryptic errors, because I go out of my way to design libraries in a way that the type definitions are kept simple, which also has the benefit of keeping the mental model of how the library works simple ;)
the42thdoctorover 2 years ago
My biggest fear with TS is people forgeting why TS exist in the first place and stop trying to solve the problem TS solves because it&#x27;s already solved. It&#x27;s not solved, TS is by far the best option, but its far from being ideal. Deno coming out of the box with TypeScript support and the JavaScript Type Annotations Proposal [1] gives me faith that we will grow past TS.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;tc39&#x2F;proposal-type-annotations">https:&#x2F;&#x2F;github.com&#x2F;tc39&#x2F;proposal-type-annotations</a>
ioulianover 2 years ago
You can&#x27;t believe from how much bugs TypScript has saved me. When it was &quot;first released&quot; (when it became more popular), I have ported our starter kit to TypScript and was amazed on how much stuff it was detecting as not safe.<p>Since then, I can&#x27;t image working without TS. As for Third Party libraries, I have a different experience from other devs here, it works very well for most (if not all) big libraries&#x2F;frameworks, and the autocomplete saves me so much time in digging in the docs.
sureglymopover 2 years ago
Typescript is great but be aware that sometimes it can annoyingly slow you down. Consider these scenarios:<p>- You want to use a third party library but it is completely untyped - You need an object but you&#x27;re just prototyping it. You don&#x27;t yet know which keys will be optional - You type a key of one of your objects. Now you load or fetch data from an API and want to assign that to it. But typescript complains because the promise can also return undefined. - and many more<p>Just be aware that it will annoy you at times.
评论 #34365740 未加载
评论 #34365447 未加载
difosforover 2 years ago
I like using Typescript in general, but sometimes it becomes painfully obvious that it&#x27;s Javascript with type checking added to it at a later time. So I actually kind of which there was a language I could use instead which is typed from the ground up and requires less boilerplate, no painful syntax and provides more extensive type checking. But of course the major downside would be that it becomes hard to mix that with plain Javascript.. Also due to its popularity I think this is the least of all evils.
franky47over 2 years ago
i) You could say the same thing for the underlying language: EcmaScript has evolved so much in recent years that new packages may use runtime language features that are not supported by an older interpreter runtime.<p>ii) You could argue that types themselves can be documentation, if named correctly. A JS library without types but great documentation is vulnerable to implementation changes that are not reflected in the documentation. TypeScript at least binds the internal assumptions on function arguments and object types to how they should be used, with a tool to check that there is a match at the call site. Throw in some runtime parsers (eg: Zod) to enforce correct input data at runtime, and from which types are inferred, and you are golden.<p>iii) Agreed, 100%. Some people are making tools around that, see Matt Pocock&#x27;s Total Typescript error explainer extension in VSCode: mattpocock.ts-error-translator<p>iv) Agreed again. Transpilation itself can be fast with modern tooling such as SWC or esbuild (or derivatives). Type checking is still the main bottleneck, though people like Donny (@kdy1dev) are working on a Rust-based alternative.<p><a href="https:&#x2F;&#x2F;www.totaltypescript.com&#x2F;rewriting-typescript-in-rust" rel="nofollow">https:&#x2F;&#x2F;www.totaltypescript.com&#x2F;rewriting-typescript-in-rust</a>
amalgamated_incover 2 years ago
No. It doesn&#x27;t fix any of the problems with JS and it introduces a lot of new ones, namely static types. Also just way more typing, but I suppose that&#x27;s literally in the name..
jetsnocover 2 years ago
The part you would like to skip over - the static typing benefits - is exactly where it provides the most value and that makes it worth it for &#x2F;me.&#x2F; Warts and all. I&#x27;m new to TypeScript so take it with a grain of salt. I agree with some of your thoughts but I see a lot of these same issues in a lot of languages and frameworks. I&#x27;m really enjoying typescript. I&#x27;ll probably be a little more jaded here in a few more thousand hours of working in it.
no_wizardover 2 years ago
I&#x27;d like to hear from anyone who has issues with typescript as a build tool, either via `tsc` or an integration via something like `rollup`, what issues are you having? How often?<p>I have not found, even in really large projects with thousands of files, that its been an impediment to anything.<p>My general disposition is the whole &quot;anti build tools&quot; moment is a bit overblown in practice, and I&#x27;m always searching for valid counter evidence of persistent issues that can&#x27;t be easily overcome.
asdajksah2123over 2 years ago
I don&#x27;t like Typescript. I just like it more than Javascript.
antifaover 2 years ago
Typescript was only not worth it when your core framework (e.g. react&#x2F;vue) wasn&#x27;t native ts and also didn&#x27;t have ts support.<p>In my experience, any npm library I try to use either already has community created types provided, is too simple to really need types&#x2F;extra docs, or the docs will still be pre-es6 (pre important, pre async&#x2F;await, etc.) so it&#x27;s not like it was going to be convenient to learn anyways.
nathiasover 2 years ago
v) It adds so much extra complexity.<p>vi) You trade a few type bugs that are easily debuggable and avoidable for type composition and hierarchy bugs which are hard to find.<p>I have seen good examples of TS that make sense and made to play with functional paradigm, but in practice it was always a bloated mess of OOP JS introducing heirarchy where none is required producing components that are too-tightly coupled and resistant to change and slowed down developing for at least x10.
rudnevrover 2 years ago
In my perception, TypeScript was initially designed to bring more people from Java world to web programming, and it sort of spoiled them, encouraging bad practices and avoiding to learn proper JS. I think TS has never really leaved that niche.<p>True JS programmers are still living without TS, and TS programmers haven&#x27;t evolved into some culture which could compete with them. That makes TS-based solutions inherently worse.
auggieroseover 2 years ago
TypeScript is great for what it is, and definitely worth it. It is like JavaScript, just better. Just don&#x27;t go overboard with types, because you don&#x27;t get proper guarantees anyway!<p>I am not using many third-party libraries at the moment, and mainly develop my own, so I am not really running into any of your pain points. For my own libraries, developing them in JavaScript rather than in TypeScript would be just plain stupid.
andrewfongover 2 years ago
Something that might help is creating typed &#x2F; untyped boundaries. Wrap a (possibly untyped) library with your own (maybe incomplete) typed wrapper. Then let Typescript check everything up to your particular boundary and ignore everything afterwards.<p>It&#x27;s on you to make sure you&#x27;re not misusing stuff at the boundary, but less hassle to get set up and always something you can clean up later.
phplovesongover 2 years ago
I find ReScript (<a href="https:&#x2F;&#x2F;rescript-lang.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;rescript-lang.org&#x2F;</a>) fundamentally <i>better</i> than TypeScript. It has easy FFI and a sound typesystem. With Rescript you wont have any runtime errors, like you can with typescript. But compared to vanilla javascript typescript is a big improvement.
yieldcrvover 2 years ago
I don’t mind it, but I do I think its a stretch to consider it a “skillset” that I need to pass memorized questions about when joining a company<p>its like, just there. I hate how its existence dilutes the javascript community’s example code for some libraries.<p>I find it cleaner than just JS but its pretty easy for me to keep up with value inferred type in just JS<p>I would write my new projects and tests in Typescript
zx14over 2 years ago
You&#x27;re at the whim of the crap dependencies that you choose to use in your projects. If they don&#x27;t document their code or if they force you to upgrade your tooling, it&#x27;s not the fault of the TS team.<p>I try avoid 3rd party libraries very aggressively and I don&#x27;t have half the issues people talk about in front end dev. My normal set up is angular and go.
ncover 2 years ago
One pitfall i&#x27;ve found with TypeScript is getting too clever with type definitions. Too much abstraction can end up eating up a lot of time (especially with a large team). This happens because as you say, the error messages are verbose and hard to follow.<p>Once we started keeping our type definitions small and simple we&#x27;ve found it&#x27;s hugely beneficial.
评论 #34367435 未加载
yakshaving_jgtover 2 years ago
I don’t think TS is worth it, because I don’t think gradual typing provides a good cost&#x2F;benefit ratio.<p>If I’m going to write a bit of JavaScript, I’ll write JavaScript with the minimal feature set possible. It’s not a good thing that the language has continued to accrete features.<p>If I’m going to write something non-trivial, I’ll go straight to Elm — an actual sane language.
thomasfromcdnjsover 2 years ago
I pretty much deplore using Typescript for fast paced UI development.<p>I will be using vanilla Javascript in my own projects for the foreseeable future.
k__over 2 years ago
TS is okay-ish.<p>The main thing that makes it shine is refactoring.<p>Besides that, the reast isn&#x27;t that mind blowing.<p>I still get crazy bugs just like I did in JS, TS just removed the countless small and easy to fix bugs. Which is good, because they can really slow you down. But when you get something ugly, tests and experience are the only thing that saves you.
motoxproover 2 years ago
I can&#x27;t imagine not having static typing. Maybe I am a bad coder but there is no way I would be able to catch some of the spelling mistakes, objects that are missing a property, etc. I am not sure how people catch these mistakes other than just getting value errors or doing unit tests for the smallest thing.
sarimartonover 2 years ago
&quot;ii) Libraries are badly documented&quot;<p>It goes both ways, a counter example which saved me from some frustration: plotly.js has a horribly bad online documentation, but their type def makes it super convenient to explore all the layout config stuff, when you&#x27;re buildling a custom visualization.
sircastorover 2 years ago
TS can be a pain. I know, I fight with it all the time. That’s probably my fault though. I’ve learned typescript by being exposed to it in our code base, rather than properly learning it through documentation.<p>For all the struggle, it makes me feel very confident about the code, and its reliability. That’s worth a lot.
评论 #34363607 未加载
florianherrengtover 2 years ago
Another point is that Typescript is most powerful when you use it everywhere and share types. E.g: Between frontend and backend API. It’s hard to keep track of where something is used when you change it. Typescript can do it for you.
brapover 2 years ago
I honestly can&#x27;t see how <i>anyone</i> can get <i>anything</i> done without static typing, for anything other than small scripts.<p>My only issue with TS is that there are no runtime type guarantees. That, and a few odd syntax choices that I mostly don&#x27;t have to deal with.
Aperockyover 2 years ago
What is the alternative? If it&#x27; javascript, then no it is not worth it.<p>If you&#x27;re talking about general backend languages, then there are a lot of options. Since you&#x27;re talking about large scale applications, that likely means you can use something like java or kotlin.
humaover 2 years ago
TypeScript feels like it&#x27;s trying hard to become Java Enterprise level of complexity :)
评论 #34367959 未加载
epolanskiover 2 years ago
I have been writing lots and lots of TypeScript in the last 5 years.<p>Going back to JavaScript just feels...wrong.<p>TypeScript isn&#x27;t a perfect language, but I also feel like most of its shortcomings are related to the aim of being a JS superset.
hsn915over 2 years ago
i) Never had a problem with this, although I use very very few libraries, so that might be why. (At this point basically only preact)<p>ii) Yes, but this can&#x27;t be used to favor JS instead. If a library is badly documented, you&#x27;re going to have a hard time whether using TS or JS.<p>iii) This is true, but it depends on what you are doing. One advice is to avoid defining complex types. Another good measure is to sometimes suppress type checking on a few lines that you know are correct but are near impossible for the compiler to verify.<p>iv) I use esbuild to compile, and have a tsc -watch window open all the time.
robotover 2 years ago
&quot;... is with the amount of extra work it places on developers, much of it the &quot;dumb&quot; kind of work which can eat up hours and doesn&#x27;t deliver all that much value.&quot;<p>that sounds terrible.
rltover 2 years ago
Absolutely worth it. The benefits far outweigh these downsides, and I’m surprised someone who’s been using it for two years doesn’t agree.<p>I would simply refuse to work on a JavaScript project at this point.
claytongulickover 2 years ago
I choose to avoid typescript for most of my projects and teams. There are some exceptions.<p>I have some fundamental guiding principles I apply to engineering, and I find that TypeScript violates these:<p>1) Reduce complexity<p>2) Don&#x27;t be clever<p>3) Achievement over activity<p>4) Longevity<p>---------------------<p>#1 Reduce complexity<p>---------------------<p>Cross compilation introduces additional complexity with debugging and production support. Sourcemaps work fairly well, but often fail on edge cases - normally where you want to be debugging. I&#x27;ve found that JSDoc with good tooling gets 70%+ of the benefit of TypeScript without the additional complexity of cross compilation.<p>In the browser Javascript ecosystem, I aim to have what executes in the browser be as close as possible to what I&#x27;ve authored. Typescript works against this goal. This is even more important to me on the server side, where introducing a build step diminishes a lot of the value of having a flexible, dynamic environment like Node. If types are desired on the server side due to needed formalism (several problem domains are like this - banking, etc...) there are other languages&#x2F;execution environments that may be a better choice.<p>------------------<p>#2 Don&#x27;t be clever<p>------------------<p>Clever code is frequently a maintenance nightmare. Code should be clear, readable, and approachable. It should tell a story that&#x27;s easy for anyone (even semi-technical folks) to read.<p>Typescript lends itself to &quot;clever&quot; and arcane types &amp; structures that increase cognitive load and decrease maintainability, especially as the rules change.<p>----------------------------<p>#3 Achievement over activity<p>----------------------------<p>I guide my teams to focus on delivering business results and shipping software. I&#x27;ve seen code bases where up to 40% or more of the total LOC are nothing but types and structures to satisfy the compiler, not to provide features. In some cases, that&#x27;s a good thing - where the business constraint is correctness over TTM, for example. If not though, it can be a company killer. You can end up shackled by your domain models, and small updates have massive cascading consequences.<p>I&#x27;ve seen developer&#x27;s entire sprints consumed by tasks that are abstraction related, and don&#x27;t provide business value. I&#x27;ve personally known several developers that have told me directly that they don&#x27;t like shipping software, they just prefer to play with frameworks and development theories. While those are extreme cases, I know many more developers that fall somewhere around there. I&#x27;m not sure why, but I think Typescript encourages this soft of thing. I get a sense that the whole ecosystem is more about the software process than delivering valuable features to the users. Though those things aren&#x27;t mutually exclusive, when taken to excess I&#x27;ve seen software process and tooling devolve into a weird sort of navel gazing that&#x27;s a barrier to delivery.<p>------------<p>#4 Longevity<p>------------<p>I prefer to stick to standards. I also tend to avoid frameworks, I use Web Components as a component solution, and keep everything as vanilla as possible. I don&#x27;t mind using stable libraries, like date-fns or lit-html, but I&#x27;ve been burned too many times by multimillion dollar boondoggles that result from framework churn.<p>I encourage my team to pick technologies and development methodologies that have a five year lifespan as a minimum goal. I have code I&#x27;ve developed in javascript that&#x27;s been running in production for 15 years without needing a major overhaul, and with stable dependencies.<p>On the other hand, I&#x27;ve had TypeScript codebases that completely broke based on rule changes that came from a TS update, and required significant revamping within <i>six months</i> of being authored.<p>While I do think that TS can be beneficial for some projects and teams - specifically ones that require a high degree of formalism - most of the time I don&#x27;t see it providing concrete business value. I see it consuming dev cycles for limited benefit.<p>I am looking forward to the optional typing that&#x27;s currently a stage 1 proposal. I miss AS3, which I thought struck the perfect balance between static and dynamic typing. Static by default, but it was easy to opt out when being dynamic made more sense.
评论 #34363050 未加载
Waterluvianover 2 years ago
I’m not getting into the pros and cons. All I know is that I dragged my feet for a few years and regret doing that. It’s been incredible. I now see javascript as a compile target.
ironmagmaover 2 years ago
I remember Flow being a little more strict. Typescript has much higher adoption now though so that has its own perks. Both are far and away superior to untyped JS.
incompletudeover 2 years ago
Type checking and strongly typed languages are rapidly taking market share and in the near feature, except for niche specific software, mostly everything will be typed. There are a few reasons for this: it makes software easier to change and to test, and in a scenario of fast-growing complexity like the world we live in today, it is better suited for software development.<p>I would recommend to every software developer to learn the type ecosystem inside their language to make sure they have a good&#x2F;high-paying job in the near future.<p>In 5 to 10 years, almost every serious engineering job will be working with an ecosystem that contains types.
mcphageover 2 years ago
It&#x27;s got its advantages, but they had an opportunity to solve one of JS&#x27;s biggest weaknesses—the terrible standard library. And they just... didn&#x27;t.
itover 2 years ago
Depending on your project, you may find that Dart+Flutter is a suitable alternative. The Dart syntax is simpler than Typescript, while meeting similar goals.
throwaway09432over 2 years ago
I can&#x27;t believe they chose an array for the Tuple type. Which has no sensible equality definition as arrays in JS are references.
bayesian_horseover 2 years ago
I generally think it is worth it. In React+Redux, Typescript enables a lot of help in the IDE and catches a few problems or bugs.
ly3xqhl8g9over 2 years ago
Learn <i>infer</i> and <i>extends</i> and you will accept all the downsides being zen from the height of your highly well typed codebase. If you don&#x27;t find the following compelling:<p><pre><code> type IsParameter&lt;Part&gt; = Part extends `[${infer ParamName}]` ? ParamName : never; type FilteredParts&lt;Path&gt; = Path extends `${infer PartA}&#x2F;${infer PartB}` ? IsParameter&lt;PartA&gt; | FilteredParts&lt;PartB&gt; : IsParameter&lt;Path&gt;; type ParamValue&lt;Key&gt; = Key extends `...${infer Anything}` ? string[] : number; type RemovePrefixDots&lt;Key&gt; = Key extends `...${infer Name}` ? Name : Key; type Params&lt;Path&gt; = { [Key in FilteredParts&lt;Path&gt; as RemovePrefixDots&lt;Key&gt;]: ParamValue&lt;Key&gt;; }; type CallbackFn&lt;Path&gt; = (req: { params: Params&lt;Path&gt; }) =&gt; void; function get&lt;Path extends string&gt;(path: Path, callback: CallbackFn&lt;Path&gt;) { &#x2F;&#x2F; TODO: implement } get( &#x27;&#x2F;purchase&#x2F;[shopid]&#x2F;[itemid]&#x2F;args&#x2F;[...args]&#x27;, ({ params }) =&gt; { params.shopid &#x2F;&#x2F; number params.itemid &#x2F;&#x2F; number params.args &#x2F;&#x2F; string[] }, ); </code></pre> (<a href="https:&#x2F;&#x2F;lihautan.com&#x2F;extract-parameters-type-from-string-literal-types-with-typescript" rel="nofollow">https:&#x2F;&#x2F;lihautan.com&#x2F;extract-parameters-type-from-string-lit...</a>)<p>then you probably don&#x27;t need TypeScript, or types in general. And that is fine.<p>As to the points:<p>(i) 99.99% of everything is being developed by someone else in our current stack, but here comes the benefits of open source: don&#x27;t like how a project is going? fork it and maintain it yourself;<p>(ii) If you don&#x27;t use a NPM package with the last release older than 2014 (and why would you given your (i)st fear), chances are pretty high (95%+) the library is written directly in TypeScript or there is a DefinitelyTyped package with the types;<p>(iii) Type errors, those that come directly from TypeScript, are pretty straightforward (was expecting X, you passed Y);<p>(iv) Yes, TypeScript should have never been written in an interpreted language, but what were the options in 2012: C? C++? Maybe some day in the unspecified future, we will have a Rust&#x2F;compiled language implementation with microsecond transpilation time.
评论 #34365540 未加载
评论 #34365162 未加载
quanticleover 2 years ago
<p><pre><code> I want to skip over the static typing benefits argument, because I think it is well understood that static typing is a good thing and if we could bless JavaScript with a built-in and robust typing system then I don&#x27;t think many people would be against that. </code></pre> Well, yes. That&#x27;s what Typescript is. If a built-in and robust typing system were added to Javascript, it would be the same thing as integrating Typescript into the ECMA spec. for Javascript.<p>EDIT (some more thoughts):<p><pre><code> For example, a new package you install can require a new TypesScript version. Once installed, you then may need to update your source code. This can place quite a high tax on the developer, where perhaps a 10 minute change becomes hours long. </code></pre> Yes, that&#x27;s not very different than upgrading to a new version of e.g. Python or Ruby on the back end. The problem is that you&#x27;re seeing Typescript as &quot;just a framework&quot;, rather than a compiler&#x2F;interpreter. If you view upgrading Typescript versions the same as e.g. upgrading Python or Ruby versions, and plan for it accordingly, then you&#x27;ll at least have the correct expectations regarding the scope of work, even if the actual work to do isn&#x27;t any less.<p><pre><code> Most libraries do not document their types, or have no examples using TypeScript. </code></pre> If a type system were integrated into Javascript itself, it would have to be optional, in order to maintain backwards compatibility with the vast untold billions of lines of Javascript that are out there. Thus, you&#x27;d have exactly the same problem. It&#x27;s very difficult to add a typesystem to a language after the fact.<p><pre><code> Errors are long and don&#x27;t provide enough detail. They will explain a type mismatch referencing many types you may not have ever seen, and are not documented anywhere. Except for simple errors, many of them are very hard to follow to a remedy. </code></pre> Poor error messages are an issue with any type system that allows generics. Typescript&#x27;s error messages are, at least in my experience, better than C++&#x27;s error messages. I find this remarkable, given that C++ was designed as a typed language from the beginning, and Typescript has, as one of its design constraints, strict backwards compatibility with Javascript.<p><pre><code> I referred to TypeScript as a framework which it isn&#x27;t. However it feels similar to me in that you are at the whim of TypeScript developers and how they decide to progress with the language. </code></pre> That&#x27;s true of any programming language, Javascript included. If you&#x27;re writing Java, you&#x27;re at the whim of Oracle. If you&#x27;re writing C#, you&#x27;re at the whim of Microsoft. If you&#x27;re writing C++, you&#x27;re at the whim of the C++ standards committee. If you&#x27;re writing Python, you&#x27;re at the whim of the Python Steering Council (and you used to be at the whim of Guido Van Rossum). Every programming language has some person or committee that&#x27;s in charge of it, and if you&#x27;re choosing to use that language, you&#x27;re implicitly accepting the decisions made by that person or committee.
nikanjover 2 years ago
v) It’s been well over a year, and IntelliJ Idea still requires me to go to the settings page to enable an experimental feature to be able to run a simple helloworld.ts.<p>Not sure whose domain this falls in, but the situation is a coal mine canary that tells me the whole ecosystem is not up to the level I want from my production tools
darepublicover 2 years ago
Since the front-end world was upended by webpack and react, my favourite change that I would abandon last is typescript
sngzover 2 years ago
i agree, I have to work with typescript for my current job and I hate every second of it. I was never a fan of any languages that require transpiling. the trade off and trouble it comes with is not worth it for the small benefits. Im not a fan of JS in the first place but typescript just makes it worse.
paulcarrotyover 2 years ago
TS can&#x27;t solve any real problem, so skip it. Dart &amp; Flutter worth it if you need cross-platform GUI.
评论 #34365060 未加载
mauro_c8over 2 years ago
Compared to javascript, yes. Compared to any other simpler statically-typed language, no.
cassepipeover 2 years ago
Well, I like Reason better. The type system is more robust and to infers more type.
dmakover 2 years ago
I love JS, but I want types. I don&#x27;t want TypeScript though, but I&#x27;ll do it if the job requires it.<p>Has anyone tried building in flow for a large project? This was facebook&#x27;s static type checking approach: <a href="https:&#x2F;&#x2F;flow.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;flow.org&#x2F;</a>
gardenhedgeover 2 years ago
TypeScript itself is good but typescript errors are bad and annoying
phazeedaeover 2 years ago
typescript as a language on it&#x27;s own, is worth it, however the nightmare of the landscape of all the poorly develop libraries and endless layers around it causes me to never pick it for a backend project.
AzzieElbabover 2 years ago
I prefer to avoid TS. I can’t stand its type system without pattern matching
jeroenhdover 2 years ago
Yes, in all cases except proof of concepts only demoed once. And even then probably still.<p>i) You can wait years to update TypeScript itself. I&#x27;ve never run into incompatibilities before.<p>ii) That&#x27;s the libraries&#x27; fault. Without types, you can pass in total garbage and it doesn&#x27;t work. With types you can only pass in some garbage and it doesn&#x27;t work. All the Javascript examples work in TypeScript except now you will be warned that your code won&#x27;t work before you try to find edge cases to test.<p>I&#x27;ve had the pleasure to use Frida a while back. It allows you to instrument running native applications using hooks written in various languages, though the live debugger usually uses Javascript. The documentation of many functions is scarce, to say it nicely. Without the TypeScript bindings, I would&#x27;ve never gotten most of these functions to work. You can find example code online but half the time that example code will be buggy and not do what it appears to do exactly because there is no type check on the plain JS API.<p>iii) I disagree, they&#x27;re verbose but not that difficult to read. &quot;You specified this but the type doesn&#x27;t exist&quot; or &quot;you didn&#x27;t specify this thing the type needs&quot; is almost always the problem, it&#x27;s just a little over eager to tell you where you&#x27;re missing something.<p>iv) Okay this is definitely a downside. If you&#x27;re not using Babel or another transpiler&#x2F;minifier&#x2F;obfuscator already, you&#x27;ll add an extra build step. A minor one, in my opinion, but a build step nonetheless.<p>In my experience, TypeScript isn&#x27;t making progress slow. It&#x27;s making you fix your bugs and broken promises before the customer calls that your code doesn&#x27;t work anymore. If you&#x27;re passing strings instead of numbers you&#x27;re going to break your code eventually, only now you&#x27;ll have to get your code to working order beforehand.<p>Working on a codebase that&#x27;s a few years old and added typescript retroactively, my experience is that renaming JS files to TS will instantly show you three to five bugs in every single JS file you come across. Import errors all throughout the code base, because it turns out components got reused wrong and what seemed like an optional label that didn&#x27;t have any contents was actually broken for five years.<p>TypeScript gets even better with a nice and strict set of linter rules. Not just the builtin ones, also extra stuff like &quot;don&#x27;t use any everywhere to avoid typing things&quot; and &quot;specify what you&#x27;re returning when you&#x27;re returning something&quot;. With the stricter guarantees the language can deliver because of types, the code quality analysis can be a lot better as well!
kyranjamieover 2 years ago
Why are we still talking about this.
johlitsover 2 years ago
Worth it if JS is worth it.
fithisuxover 2 years ago
Have you tried Deno?
lloydatkinsonover 2 years ago
Yes
garfieldnateover 2 years ago
The TS type system is incredibly powerful, and I wish I could apply to other languages out there. The biggest annoyances with it come from the fact that it isn&#x27;t its own language; you get runtime errors due to incorrect or out-of-date types (often maintained by people other than the library authors). Also, &quot;any&quot; and &quot;unknown&quot; types tend to sneak in via default generic arguments, vague external module typedefs, etc. These types can spread through your codebase, preventing the type checker from doing its job, and the &quot;strict&quot; mode doesn&#x27;t do much about it!<p>Generally speaking, I have to be extremely careful with working on a JS&#x2F;TS project. I use the strictest modes possible and enable as much linting as possible. I also use the type-coverage module and fail the build if the `any` type gets applied anywhere.<p>As another general complaint, NPM doesn&#x27;t do enough to incentivize its users to release quality software. JS&#x2F;TS has always been very trend-based and social, and even just running a few simple lints and prominently displaying a score on NPM would probably really help the community improve its standards.<p>Take pub.dev (Dart), for example. Here&#x27;s a module page: <a href="https:&#x2F;&#x2F;pub.dev&#x2F;packages&#x2F;firebase_core" rel="nofollow">https:&#x2F;&#x2F;pub.dev&#x2F;packages&#x2F;firebase_core</a>. The score is displayed prominently, and if you click on it you get a full breakdown of how it was calculated: static analysis, up-to-date dependencies, and documentation (although the coverage is not 100% for this module, so I think it&#x27;s wrong to assign full points). When you upload to pub.dev, you want a score of 100! It doesn&#x27;t guarantee that the module is fantastic software, but at least the basics have been taken care of.<p>In my opinion, the most important piece missing from the score on pub.dev is test coverage. Take for example a page from Metacpan (Perl packages). Here&#x27;s a module I&#x27;ve released: <a href="https:&#x2F;&#x2F;metacpan.org&#x2F;pod&#x2F;Algorithm::AM" rel="nofollow">https:&#x2F;&#x2F;metacpan.org&#x2F;pod&#x2F;Algorithm::AM</a>. On the left you see displayed the automated test results, including the test coverage, which has been submitted by volunteers who downloaded and tested the code on a variety of platforms and Perl versions. There&#x27;s also link to a &quot;kwalitee&quot; page, which is similar to the pub.dev score (though this could be much improved by having an actual score and displaying it prominently on the main module page).<p>Now an NPM module: <a href="https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;react" rel="nofollow">https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;react</a>. What info do we have about the quality of the package? Essentially just the activity from the community (open PR&#x27;s and issues, downloads). We have no idea how well it&#x27;s tested, what kind of static checks have been performed, whether your editor will be able to display documentation or typing when you mouse over a method from the library, etc. (TypeScript is mainstream enough now that it should be fine for NPM to provide a bit of special handling for it.) Most 3rd party libraries are from individual authors and probably have very little activity. When deciding whether or not to use them, right now you need to dive through the code to check if the basics are taken care of. Having some of this automated would save a lot of time.
eyelidlessnessover 2 years ago
Having spent the last two years back in JavaScript, and in the process of moving a &gt;10y project to TS as a part of a larger refactor, <i>emphatically yes</i> it’s been worth it. I have been hanging on to tsserver to bridge the gap for two years, and well… it’s night and day.<p>I can add ~95% of the same safeguards without it, but I’ll spend a lot more time doing so and it’s a lot harder to get buy in to make them stricter than my own editor.<p>&gt; For example, a new package you install can require a new TypesScript version. Once installed, you then may need to update your source code. This can place quite a high tax on the developer, where perhaps a 10 minute change becomes hours long.<p>If your project is already strict and if you generally have a good sense of the areas TS doesn’t cover, you probably wouldn’t need to update anything for the last couple years. If your project isn’t strict, you’re probably benefitting from updates more closely matching the semantics you wanted in the first place.<p>&gt; Most libraries do not document their types, or have no examples using TypeScript. Some worst offenders: Apollo, Protobufjs. The type definitions exported by these libraries can be large and complex, and the error messages emitted by TypeScript are so long and cryptic the result is often a drawn out process of trial and error along with trawling through source files.<p>It’s fairly trivial to add local type defs if you’re at all interested in the type safety it brings. They’re almost universally easy to transfer to PRs for DefinitelyTyped (which admittedly I should do more often, and I should open a few after I land this work in my project).<p>&gt; Errors are long and don&#x27;t provide enough detail. They will explain a type mismatch referencing many types you may not have ever seen, and are not documented anywhere. Except for simple errors, many of them are very hard to follow to a remedy.<p>This is true. You’re right. If you want a little helpful pointer:<p><pre><code> type Debug&lt;T&gt; = [AnyType&lt;T&gt;] extends [never] ? &#x27;My understanding of AnyType failing&#x27; : AnyType&lt;T&gt; </code></pre> Edit: this ^ was typed on my phone from recall and I’m tired and might not be quite right. I’m happy to revise it tomorrow if that’s the case.<p>It’s not great but it’s basically a very slow way to walk up the type resolution stack until you find what doesn’t behave the way you expect.<p>&gt; Transpilation takes time, and always adds a burden to developers. I didn&#x27;t mind so much with ES6 etc because eventually many functions were included in a broad set of browsers. There doesn&#x27;t seem to be much progress including TypeScript in a browser, and feels like these complicated transpilation steps could be with us for a long time.<p>ESBuild, Vite, SWC and such have basically made the build step instantaneous. They’re not without config woes, but they’re worlds better than what came before. So much so I will volunteer to help you set up a project’s build if you do the very easy legwork to find any number of ways to contact me.
armatavover 2 years ago
Yes
canacryptoover 2 years ago
Yes.
ajkjkover 2 years ago
I make it about 20 minutes into a JS project before I have to go install TS because I&#x27;m losing my mind. It&#x27;s such a no-brainer that the question barely parses. Javascript is medieval and typescript is... less so.<p>I know it&#x27;s not an interesting answer and a lot of other people say the same thing; guess I&#x27;m just casting my vote.
评论 #34363466 未加载
评论 #34363503 未加载
FractalHQover 2 years ago
You couldn’t pay me to work with Vanilla JS on any real life project. It feels like going back to horse and buggy.<p>The biggest things I wouldn’t be able to live without:<p>- the self-documenting nature of Typescript code (I instantly know what a function accepts and returns by hovering over it).<p>- the comprehensive auto complete my ide gets (saves hundreds of trips to the docs &#x2F; source code per day).<p>- the incredible productivity gains when refactoring (change one thing, instantly get notified of all 30 places in the codebase that change introduced errors and clean them up in minutes).
评论 #34363304 未加载
评论 #34363087 未加载
评论 #34363515 未加载
fckgnadover 2 years ago
Important distinction:<p>Are types worth it? Yes. Is typescript worth it? Maybe.
sphover 2 years ago
It&#x27;s lipstick on a pig, and yet another layer of complexity on top of the myriad of modern web development.<p>The solution to better web development is staying as far away from JavaScript as possible, not polishing what is frankly a turd.<p>I think it&#x27;s masochism to have a Javascript project that big that benefits from strict typing.
spaceheaterover 2 years ago
The whole shtick (and beauty) of Javascript is that it is a dynamic language. In some point in time corporate Java people started using JS, and now we have this : &quot;is well understood that static typing is a good thing&quot;. It&#x27;s not. But as always you have a vocal minority, influencers and evangelists shouting their BS, about how TypeScript has terraformed theirs lives and they can&#x27;t imagine life without it.<p>Use your head, if you don&#x27;t like TS, don&#x27;t use it.
评论 #34360743 未加载
评论 #34361128 未加载
typesornotlolover 2 years ago
This post is a joke right? The world has moved on. JS *is* the target, but it is *no longer* the source.<p>There is so much more to software development than the how quickly one can vomit code into their editor of choice. If typescript is slowing you down, your code is *bad*. End of story.<p>Continually pretending that types don’t matter is laughable. The thousands of dynamic language projects with littered with type-hints, type-assertions, and type-verifying unit tests proves otherwise.
评论 #34363995 未加载
评论 #34369314 未加载