Closed lillallol closed 2 years ago
JSDoc syntax does work (with some missing pieces), and you agree that JSDoc annotations are more verbose than TypeScript/Flow annotations, but you say that "It is not that much of a big deal regarding verbosity."
What is and isn't a "big deal regarding verbosity" is a matter of values. Verbosity might not matter to one person, and it might matter a lot to another person. But, in fact, lots of people do think that JSDoc's verbosity is a big deal; it's such a big deal that the TypeScript, Flow, and Hegel teams all decided to fork JavaScript in order to build the language they want. As the proposal explains,
TypeScript was currently listed as the 4th most-used language in GitHub's State of the Octoverse, and on Stack Overflow's Annual Developer Survey it has been listed in both the top 4 most-loved languages since 2017 and the 10 most-used languages.
But that then brings us to the problem statement for this repository, which was presented at TC39:
The strong demand for ergonomic type annotation syntax has led to forks of JavaScript with custom syntax.
This has introduced developer friction and means widely-used JS forks have trouble coordinating with TC39 and must risk syntax conflicts.
Maybe you think all of those TypeScript and Flow developers are being unwise, and that they all should have written their types in JSDoc, in order to skip a compilation step. (Why don't they realize that the verbosity of JSDoc is actually no big deal?!)
But that doesn't solve the problem: there is demand in the ecosystem for ergonomic type annotation syntax (like TypeScript, and not like JSDoc). We can say "there shouldn't be demand in the ecosystem for TypeScript annotations, because JSDoc's verbosity is no big deal" but that won't make the demand go away, and it certainly won't make the forks go away.
Adopting ergonomic type annotation syntax in JavaScript is the only way to end the forks. Telling TypeScript developers that their preferences are incorrect didn't work in 2017, and it isn't gonna work today, when TypeScript is more popular than ever.
@dfabulich
JSDoc syntax does work (with some missing pieces)
I posed the following question:
Regarding importing .ts types via JSDoc comments in .js, which are these missing features (when compared to the features of this proposal)?
which remains unanswered. I do not understand why this proposal (and people) compare JSDoc to full TS, and not the proposal itself. And just to be crystal clear here, JSDoc is irrelevant. What I am actually talking about is importing types via comments. JSDoc happens to currently enable that.
Maybe you think all of those TypeScript and Flow developers are being unwise, and that they all should have written their types in JSDoc, in order to skip a compilation step.
Yes, they should have imported types in JS via comments. That is what should have been done from the beginning, because it is objectively better:
.ts
compile to .js
method/**@type {import("./some/path/without/ts/extension").IMyType}/
, can be universally used by TS, Flow, etcImporting types via comments has actually no intrinsic disadvantages when compared to compile .ts
to .js
method.
I hope that now it is clear that these people are unwise. They are the very reason the JavaScript ecosystem is a fragmented mess.
Are we going to take seriously these people? Of course not. Unless you want to fragment more the ecosystem.
And lets not forget that experienced people have talked about promotion driven development, i.e. some people create virtual problems to justify their existence and salary increase.
(Why don't they realize that the verbosity of JSDoc is actually no big deal?!)
Because they have never tried it, because resume/hype/promotion driven development, because: that is how things are done around here
, because they do not want to admit their mistakes.
It is clear from what I have said before that they are objectively wrong.
But, in fact, lots of people do think that JSDoc's verbosity is a big deal; it's such a big deal that the TypeScript, Flow, and Hegel teams all decided to fork JavaScript in order to build the language they want.
The strong demand for ergonomic type annotation syntax has led to forks of JavaScript with custom syntax.
there is demand in the ecosystem for ergonomic type annotation syntax
There is absolutely no evidence that there such a demand. And if there is, there is absolutely no evidence that it is unbiased. If we are really interested in a proper statistical result on what people prefer, then we should ask people that have been forced to write projects with both ways of static type checking and not just only one of them (like for example people like me). Anything different from that will give a biased answer.
Just to be crystal clear again. No I am not advocating for writing types in JSDoc. I am advocating for importing .ts
types in .js
files via comments. The majority of people do not actually understand that so they make wrong assumptions.
We can say "there shouldn't be demand in the ecosystem for TypeScript annotations, because JSDoc's verbosity is no big deal" but that won't make the demand go away, and it certainly won't make the forks go away.
Adopting ergonomic type annotation syntax in JavaScript is the only way to end the forks
No it is not the only way to end the forks. If the influencers (TS, and those who make forks of JS) admit their mistake and push/promote the objectively better solution which is importing types with comments, then the hype-driven people (i.e. the overwhelming majority) will start using this way of static type checking (not necessarily because they understand that is objectively better but because it is the next big thing).
Edit : We have to admit that is how the JS ecosystem works. It is hype driven. This is coming from the mouths of seniors, not by me.
Static type checking is not a problem anymore in JS. Ending hypes that promote objectively inferior ways of developing, is. And that is because it leads to fragmentation of JS ecosystem, and hence more time wasted for the JS developer (experienced or not). And that developer can be anyone (including me), because we might be asked to support legacy JS or be given a code base that we have not written.
Type imports with comments are objectively more ergonomic than what this proposal suggest and here is why:
We will make the JS parser slower for both client and server because hype driven people have been used to writing concretion in .ts
. This is absurd.
Telling TypeScript developers that their preferences are incorrect didn't work in 2017
What are you talking about?
Climb the ladder man, enjoy the bananas. There is nothing wrong with that. It is clear that no water drops anymore.
Abandon this proposal.
People who down vote me, prove me wrong with objective arguments and not with just what is in hype currently. Hypes come and go.
Typescript maintainers if you are reading this why did you enable writing concretions in .ts
files in the first place?
which remains unanswered. I do not understand why this proposal (and people) compare JSDoc to full TS, and not the proposal itself. And just to be crystal clear here, JSDoc is irrelevant. What I am actually talking about is importing types via comments. JSDoc happens to currently enable that.
This would not address the use case this proposal attempts to solve at all. Most people are not going to want to write:
//types.ts
export type Point = { x: number, y: number };
//index.js
/** @type {import("./types").Point} */
const x = getPointWithMaybeMoreProperties();
Over:
//index.js
const x: { x: number, y: number } = getPointWithMaybeMoreProperties();
// or
type Point = { x: number, y: number };
const x: Point = getPointWithMaybeMoreProperties();
@benjamingr
I am honestly not gonna repeat the arguments that I have already written (not even copy paste them).
Ok, thanks for your feedback on the proposal. It will be taken into consideration 🙏
Before attempting to counter argue with me, please try what I suggest.
This is already possible. You just have to write all your types in
.ts
files and then import them via JSDoc comments in the.js
files (do not forget to use"allowJs": true
,"checkJs": true
,include : ["./**/*.js"]
and maxNodeModuleJsDepth in your tsconfig).This section of the proposal did not mention importing types from
.ts
files via JSDoc comments. The section should be extended with this example:Regarding importing
.ts
types via JSDoc comments in.js
, which are these missing features (when compared to the features of this proposal)?You have to type
/*@type {}**/
and then the intellisense for importing types will work. It is not that much of a big deal regarding verbosity especially given the fact that like this you avoid the drawbacks of compiling.ts
to.js
, and also you do not need a new proposal that will make JavaScript parsing slower.There is no such need when importing types from
.ts
to.js
files via JSDoc comments.This is a biased opinion that is not true. With importing types from
.ts
to.js
files via JSDoc comments you can get all the benefits of this proposal without the need to introduce a new proposal and without the need to change existing JavaScript parsers (client or not) and make them slower. Finally forcing separation of abstractions and concretions is a good practice.Why did TypeScript support writing concretions in
.ts
files in the first place? That was a major mistake, that further fragmented the ecosystem and added an extra build step. The fact that we did/promoted a mistake in the past is not a valid argument in favor of continuing this mistake in present and future.