7 ms·
Ask HN: Does TypeScript live up to the hype?
I’ve only ever used vanilla JavaScript ever since I got into WebDev and while it can annoying to work with at times, it’s really well rounded overall in my opinion especially the current version of ECMAScript. Combined with svelte it’s absolutely delightful.
Then I started hearing more about Typescript on Twitter and such and I got really curious because everyone had at least one good thing to say about it - mainly the data types aspect of it. Which is the only benefit that I can really wrap my head around.
- phendrenad2 4y agoIt's a hard question to answer. TypeScript catches a certain class of bug, but requires a lot of extra work creating types and essentially over-specifying things. Personally I don't think it's worth it.
- orangecat 4y agobut requires a lot of extra work That's not my experience at all. I've found that you get most of the benefits via type inference with very little additional work. Although if you try to be super strict and forbid any use of "any" or casting, then that could get annoying and possibly counterproductive.
- matthewwolfe 4y agoUnless you are integrating typescript into an existing codebase, having the strictest feature set is great. I’ve never felt the need to use any/unknown, except for very occasionally when working with a library that has spotty typescript support.
- phendrenad2 4y agoYeah, almost everyone forbids "any". It's the default in most linter configs too.
- schwartzworld 4y ago> Although if you try to be super strict and forbid any use of "any" or casting, Why would you ever want to use any if you could avoid it? It completely undermines the benefits of TS. Most of the time you really want unknown or generics.
- speedgoose 4y agoAfter maintaining a slowly rotting JavaScript codebase developed by a few developers, I converted it to typescript and maintaining it was easier. I found some typing problems challenging and fun. I think it’s worth it if you enjoy types.
- phendrenad2 4y agoWell that's the thing, I don't want to choose tools based on my personal preferences, I want them to work and get the job done. No "enjoying" for me.
- matthewwolfe 4y agoAbsolutely worth the hype, doubly so if your backend is also written in typescript and you can share types. I would say except for very specific cases, you don’t need the complicated parts of typescript, and what you are left with is a lot of defining interfaces/records of what object are. This takes minimal effort to write but pays dividends when you can hover a variable and see the exact type, or the compiler complains about some unintentionally null or undefined value you didn’t consider.
- gardenhedge 4y agoYes, it lives to the hype. One good example, it is used by Prisma: https://www.prisma.io/typescript https://www.prisma.io/typescript I have seen types and type unions get pretty complicated though
- Leftium 4y agoI actually used to prefer CoffeeScript over JS because it allowed me to code more quickly and keep my code smaller. Then I saw a video of Rich Harris demonstrating the Svelte tools in VS code. The TS typing enabled autocomplete and even automatically importing files. That's what got me to try TypeScript. Perhaps TS could be faster than CoffeeScript, now. (By now, ECMAScript has borrowed most of the good ideas from CoffeeScript, and other devs are more likely to be familiar with JS/TS vs CoffeeScript.) Some times TS helps catch simple mistakes, but other times I feel like I am "fighting" with the TS type errors. Overall, I think it is worth using TS.
- marpstar 4y agoAfter using TypeScript professionally for almost 8 years now, using plain JS for anything but the most trivial of solutions feels downright dangerous.
- aprdm 4y agoWhere would people suggest to go to learn typescript ?
- ineedausername 4y agoDon't go anywhere, read a book, do it properly :). https://www.amazon.com/Programming-TypeScript-Making-JavaScript-Applications/dp/1492037656 https://www.amazon.com/Programming-TypeScript-Making-JavaScr...
- quickthrower2 4y agoThese days, I always start with the free official docs. They are usually pretty good.
- ineedausername 4y agoI hope so, most times I'm really not sure if it's worth it, or read intro and then just reference.
- quickthrower2 4y agoDepends on your MO but doing stuff trumps reading. And doing stuff interlaced with a bit of learning between is unbeatable.
- idontwantthis 4y agoTypescript docs are fantastic.
- bjourne 4y agoDynamic typing is too difficult for some developers. If you are one of them then TypeScript is for you.
- solumunus 4y agoIt's error prone and frankly silly when there is a superior option. It's more difficult because it's bad, not because it requires higher skill levels or is more complex and powerful. Why would you use something more difficult yet less effective? Using JS is foolish when you have TS.
- bjourne 4y agoDynamic typing is "difficult" in the same way that a microwave is "difficult" to someone only used to fireplaces. Some never get used to it, but that doesn't mean that microwaves are "bad".
- drakonka 4y agoI went from working mostly with Go and C# to JS last year and TypeScript has been amazing.
- tomjen3 4y agoYes. Typed languages such as C/C++ were annoying because the type system was too simple, but Typescript is much more powerful and it infers most things automatically. Plus you have structural types, so you can start converting one part of your project over at a time. In general I don't see any reason to use Javascript without Typescript anymore, except if you are in an environment where you can't compile it for some reason.
- solardev 4y agoYou can learn TypeScript really gradually, adding it to important things like parameters and props at first, for the simplest primitive types, then gradually expand complexity to include objects and inheritance and generics and such later. It's really useful for providing good code hints and autocomplete, and for avoiding runtime crash bugs due to uncoerced types. Give it a shot, a little at a time.
- mejutoco 4y agoIMO Typescript deserves all the hype. Some programmers take pride in having to remember everything and being careful while holding the whole program in memory. I am not one of them. I want the computer to help me as much as possible to remove basic errors, basic tests, and reduce cognitive load, so I can focus on the important bits. You can try this short guides with interactive exercises to learn about the type annotations. In 15 minutes you can get really familiar with it. https://type-level-typescript.com/types-and-values https://type-level-typescript.com/types-and-values After that, Typescript documentation should fill any other gaps. https://www.typescriptlang.org/docs/ https://www.typescriptlang.org/docs/