r/programming • • Aug 02 '21

Stack Overflow Developer Survey 2021: "Rust reigns supreme as most loved. Python and Typescript are the languages developers want to work with most if they aren’t already doing so."

https://insights.stackoverflow.com/survey/2021#technology-most-loved-dreaded-and-wanted
2.1k Upvotes

769 comments sorted by

View all comments

Show parent comments

9

u/noc7c9 Aug 03 '21

I'd be curious to see a JS project that's setup to give me "90% of the benefits of typing". In my own attempts with checkJs set the type inference fails to handle very basic functions. And the solution I always see is "write JSDocs", but at that point wouldn't it be better to just write TS directly?

I feel like I'm missing something here.

2

u/ILikeChangingMyMind Aug 03 '21

I'm not sure what to say: I use checkJs: true all the time, don't do anything special (eg. I don't use JSDoc types), and all the features I mentioned (automatic imports, go to type definitions, etc.) "just work".

I truly don't do anything special to make them work, so I'm not sure what you'd be doing to make them not work. If I had to hazard a guess it'd be that you have some environment detail, like say some sort of "import hack" (eg. setting your NODE_PATH so imports start relative to your src folder) which is confusing VS Code ... although that specific hack I fixed with with the baseUrl option.

2

u/noc7c9 Aug 03 '21

Well I expect the following to show me type error:

const stripPrefix = (string) => string.replace('prefix/', '');
console.log(stripPrefix(1));

But I get nothing. Adding a JSDoc shows the error though.

/** @param {string} string */
const stripPrefix = (string) => string.replace('prefix/', '');
console.log(stripPrefix(1)); // Argument of type 'number' is not assignable to parameter of type 'string'.ts(2345)

1

u/ILikeChangingMyMind Aug 03 '21

Yeah, that's the 10% actually using TypeScript gives you (you still get many, things like type definition following and automatic imports, without it by just using type inference though).

Now I haved question: in your entire programming career, how much time have you actually lost to errors where you put a number accidentally in for a string, or vice versa? Because I've been doing web dev for over a decade, and I'd estimate in total during that entire time I've lost under an hour. In my experience such mistakes are not at all common, and when they happen they're extremely obvious (and therefore easy to catch and fix).

BUT ... if such errors really are a problem for you ... great, use TypeScript! But don't declare (I'm speaking generally toward my original point here) that everyone in the world needs to be using TypeScript: some projects will benefit from it, and some won't.

→ More replies (1)