Hacker News new | past | comments | ask | show | jobs | submit login
Stop giving code examples in TypeScript (steverydz.com)
5 points by steverydz on July 26, 2022 | hide | past | favorite | 12 comments



> About 10 years ago we had a similar problem with jQuery. Often you would go to Stack Overflow to find the answer to a JavaScript problem you were having only to find the answer was given in jQuery.

I don't understand this argument. TypeScript is just JS + type annotations — you should be able to boil away any fluff and be left with functioning JS. Whereas jQuery has actual runtime logic that would need to be reworked if you wanted a $-free solution.

The author goes on to say:

> This was even worse when the question was along the lines of “How do you do (jQuery thing) in JavaScript?”.

When would anyone ask "How do you do (TypeScript thing) in JavaScript"?


Type annotations can add a lot of noise to the code if you don't understand what they are. Bear in mind I'm talking about someone trying to learn something. If they don't know TS you're expectng them to boil code they don't understand down to its essence.

In regards to the jQuery comparison, I'm not suggesting that someone would ask such a question of TS. All I'm saying is that there was an expectation that everything should be done in jQuery at the time.


The author! Hello

> Bear in mind I'm talking about someone trying to learn something. If they don't know TS you're expectng them to boil code they don't understand down to its essence.

I agree with this, but only for people who are new to the JS language, and the content targeting them.

People using JS regularly should be able to separate out TS noise, and asking the world to avoid TS for _every_ piece of knowledge content sounds like hyperbole.

> In regards to the jQuery comparison, I'm not suggesting that someone would ask such a question of TS. All I'm saying is that there was an expectation that everything should be done in jQuery at the time.

Then why include it in your argument?


> People using JS regularly should be able to separate out TS noise, and asking the world to avoid TS for _every_ piece of knowledge content sounds like hyperbole.

I have worked with junior developers who struggle with this. I am not suggesting that all knowledge has to avoid TS, only that which isn't related to it. People who are new to the language want and need to learn _actual_ JS.

It's easy to not see this as a problem when you already know TS. Yes, it is clear what TS is once you know it. Imagine not knowing TS or the concept you are trying to learn about. What part of this is TS? What part of it is the information I am trying to find?

> Then why include it in your argument?

I was simply illustrating that there can be a tendency to assume knowledge which isn't relevant to the problem being solved.


The ecosystem is largely adopting Typescript as the canonical way to write javascript applications now, and having types makes the code more readable. I feel like it makes a lot more sense for tutorials to show things in Typescript, which is what most devs would actually use, rather than lose that type context with pure JS.


I wouldn't be so sure that MOST devs would use TS. It certainly is popular and dare I say trendy, but I know more people and projects that don't use it over those that do.


I'm going to drop a spicy hot take here... no one should be using typescript unless they actually understand javascript first. And I agree with the author. There's no good reason why JS code examples should all be in typescript, and more than when they were all written in JQuery. It speaks to a fundamental lack of knowledge within the JS community of anything beyond the surface level.

This pathological drive in the JS dev community to pretend the language they're working with doesn't exist is counterproductive - what happens when no one in the javascript development community actually knows javascript, and the standard tool for generating javascript moves on to something other than typescript?


I couldn't agree more. I see this with React too. You can go a long way without knowing much about JS as a language. You can also get a lot more out of tools and frameworks once you understand what problems they are solving.


> TypeScript has a steep learning curve

Does TS have a steep learning curve, or just a steep config curve? I personally feel that once a project has TS up & running, the actual use of it can be straightforward. Inference is so good these days, you shouldn't see many actual types at all in your code.

Have I just been using it too long, and I've forgotten the initial pain?


TypeScript is a great example of "low floor, high ceiling" (a phrase used by Seymour Papert to describe LOGO). It's easy for beginners to get started (low floor) since their JS code works as is. They can then learn and apply increasingly sophisticated features over time (high ceiling).


I'd say it depends on your JavaScript experience prior to learning TS. It will be easier for some than others. I don't think it's fair to assume that most people will find it straightforward.


Or do all your tutorials in TypeScript and let's move forward.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: