I feel like I am the only one in the world not liking typescript. It is not that I don't like types, it is what those types do to the readability of the codebase in terms of verbosity. My original programming language was Java but I switched to Node.js because I liked the simplicity of the code written in it. Nowadays every Javascript project seems worse than a Java project in terms of verbosity. My main gripe with p…
TypeScript is now officially 10 years old
101–110 of 207 posts
Re: TypeScript is now officially 10 years old
#102I was unsure of Typescript at first, but it has become an absolute joy and absolute pleasure to develop in. I was reluctant to introduce a build step (having got used to the simple refresh cycle of a browser plus vanilla javascript) but I am pleased to say that this is a bit of a non-issue now with modern tooling like esbuild et al. I still avoid NPM like the absolute plague, but the good news is that tooling like De…
Wait until you try a language that was supposed to have a decent type system from the beginning!
Some issues with TS are:
- There is no hard guarantee at runtime as everything is partially/optionally typed (including your deps).
- The types are not used to produce faster code at runtime (like in a compiled language).
It is almost like TS leaves half of the benefits of type checking on the table, obviously by design by being a JS superset.
Re: TypeScript is now officially 10 years old
#103Earlier quoted context omitted.
My project is small but TS takes 4-5 seconds to compile it from scratch on each run. The main speed impact is in developer productivity though. If something ain't working right, now I first gotta fix the types before I can see if I've fixed the actual logic. I imagine if my codebase was more "OOP-y" (i.e. if I replaced every layer of my domain model with 3 layers of dependency injection, turning the whole thing into…
For me the best experience during development is to build ts to js first with something fast like esbuild and check types in parallel without preventing the output in any way from running in the browser. A perfect scenario for me is having all errors in the project caught by vscode. At the moment vscode only checks files that are currently open. I think type checking should only be done when building to some sort of…
While TSC checks everything by default - even files that are not even part of the dependency graph. That's how great the "great tooling" is in reality.
>I think type checking should only be done when building to some sort of production or realtime in your editor.
Agreed, that's the lest awful option. The problem is that they had 10 years to think of it, and didn't.
>Templates like "create react app"
...are a big part of the problem. "But I don't want to spend a whole day just setting up a project!" You wouldn't have to, if you didn't drink the React kool-aid in the first place.
Re: TypeScript is now officially 10 years old
#104As a C++/C#/Java developer I just couldn't deal with Javascript. Since discovering TS its fast becoming my favorite language. I think I might even use in the back end going forward.
Re: TypeScript is now officially 10 years old
#105Earlier quoted context omitted.
I personally can’t agree with that. TS catches me writing numerous bugs a day, the structural typing plus static analysis is a superb combination. If your code base is in JS without types, you probably have many bugs, you just don’t know about them. Especially around undefined/null handling. TypeScript also allows me to refactor fearlessly, which substantially improves the quality of my code as I can do mini-rewrites…
> TS catches me writing numerous bugs a day I see this sentiment a lot but I honestly can't think of any non-trivial bugs that TS has caught for me. 99% of the bugs it catches I would see 1 second later when my page hot reloads and crashes.
Re: TypeScript is now officially 10 years old
#106Earlier quoted context omitted.
I personally can’t agree with that. TS catches me writing numerous bugs a day, the structural typing plus static analysis is a superb combination. If your code base is in JS without types, you probably have many bugs, you just don’t know about them. Especially around undefined/null handling. TypeScript also allows me to refactor fearlessly, which substantially improves the quality of my code as I can do mini-rewrites…
> TS catches me writing numerous bugs a day I see this sentiment a lot but I honestly can't think of any non-trivial bugs that TS has caught for me. 99% of the bugs it catches I would see 1 second later when my page hot reloads and crashes.
Re: TypeScript is now officially 10 years old
#107Earlier quoted context omitted.
For one, try redefining a property as a getter/setter pair in a subclass. Also, try implementing a function that takes keyword arguments, some of which are required, and some of which have default values. I'll wait. When you're back I might've remembered some more.
You’re right on the first (although classes are out of fashion, so this is low impact) On the second, doesn’t this work?: ‘function foo({ bar = 3 }: { bar?: number })’
Strictly speaking, it takes exactly one such behavior (that you cannot even disable) for TS to stop being a superset of JS.
>although classes are out of fashion, so this is low impact
Looking at the TSC codebase, so are keyword arguments. The "in" thing is just to write very very long lines of multiple verbosely named positional arguments instead.
That said, "clases are out of fashion" is a complete non-argument. I'm of the functional persuasion, yet I've found that classes are the ony way to write TypeScript that fits on your screen at all.
Especially now that classes are being introduced in JavaScript proper, and of course TypeScript does them only slightly differently (handling of default property values and "definedness" differs).
>On the second, doesn’t this work?: ‘function foo({ bar = 3 }: { bar?: number })’
You also need a `= {}` there, otherwise you'll need to call `foo({})` - it won't let you call `foo()`. This is also in JS though, so a bad example of TS breaking things (`function foo ({ bar })` still won't work though). There are probably better ones that people encounter, work around, and forget about, because nobody's listening anyway. "The code making sense is not important, what's important is helping the user" lol.
Now imagine how the above looks with 5-10 kwargs (because keeping context in the class instance is "out of fashion", so it's either a ton of args per function or a "context" record which is effectively reimplementing classes but with a worse experience), and an aggressive formatter insisting every individual thing has to be in its own line.
Here's another: failing to infer the type of `this.constructor`.
Sure, the constructor signature may change in a subclass (why not disallow incompatible constructor overrides, given incompatible property/method signatures are already disallowed?); then what about static methods accessed via `this.constructor`?
So you end up defining an interface type for the constructor and using `(this.constructor as MyConstructorType).staticMethod` or whatever. Which is just visual noise where the fucking intent of the code was previously clear as day, so clear that TSC should've been able to infer it (yeah the type inference also sucks).
Also, ever seen TS2322? It's my pet now. What it do
All in all, TS really puts the "Java" back in JavaScript, and then some.
EDIT: Also crap like not being able to have a question mark and a default value in positional arguments so you gotta add `|undefined` there. Even the stuff it adds on top of JS is poorly thought out.
Re: TypeScript is now officially 10 years old
#108Earlier quoted context omitted.
Opposite experience. Rust was my stepping stone into "hey, maybe JS will be better with some degree of static typing?" Yes it would. But not the way TypeScript does it though, and there aren't any other viable options, are there? TypeScript brands itself a "superset" of JavaScript. In practice, it arbitrarily invalidates completely sensible JavaScript idioms.
> In practice, it arbitrarily invalidates completely sensible JavaScript idioms. Such as?
I was not pleased when it told me I have have to do
this.blahBlah = value
in the constructor because it didn't quite catch, and maybe still doesn't, that
Object.defineProperties(this, { bla: { value: ... } blah: {get, set} })
is completely legit
That said, I do prefer ts to vanilla. It's less work than maintaining d.ts files
Re: TypeScript is now officially 10 years old
#109So what is the best book (under 250 pages!) to learn TS?
And then even if you don't I'd still say reading the docs and just browsing existing code assuming you already know JS would get you all the way there.
Re: TypeScript is now officially 10 years old
#110Earlier quoted context omitted.
Worse than useless.
It actually is. TS is like a force multiplier for shit devs. All the worst code I've ever seen has been in TS and within the last 5 years. The average code quality has fucking plummetted in that time too, it's not just the worst offenders.
You mention "within the last 5 years" without also taking into account the absolute explosion in the popularity of becoming a software dev in the last 10 years. So of course theres going to be a lot of bad (and some good) devs. With TS being one of the literal most popular languages in use right now, of course a lot of bad code will be concentrated there, but I wouldn't blame TS itself for it.
You can also blame hiring practices somewhat for it, since a lot of places I've worked for even myself recently hire anybody who can recite a couple ECMA features rather than focusing on good dev practices in general.