Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update question about types #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

nicolo-ribaudo
Copy link
Member

The committee is actively exploring "parsing types to just throw them away", so saying that it will never happen is misleading.

@ljharb
Copy link
Member

ljharb commented Nov 15, 2023

That’s not a type system, though.

@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Nov 16, 2023

"Parsing type signatures, even just to throw them away when the console is closed" (which is currently included in this answer) is not a type system either

@ljharb
Copy link
Member

ljharb commented Nov 18, 2023

Totally agree. That's why the language won't ever have a type system - it just might have no-op type syntax space.

@littledan
Copy link
Member

littledan commented Nov 20, 2023

I support either merging this PR or deleting the question. It is important that this FAQ doesn’t take sides in an ongoing debate. I agree with the new answer and disagree with the old one. If Jordan disagrees with the new one, I suppose deletion might be the way to go. I really hope we can come up with a neutral, agreeable way to characterize situations like this, though, since it makes the FAQ more useful.

@ljharb
Copy link
Member

ljharb commented Nov 20, 2023

I don’t disagree with the PR, except that “no” remains the correct answer.

@nicolo-ribaudo
Copy link
Member Author

Would adding "No." at the beginning of the sentence satisfy both? i.e. JS is not getting a type system, but there is the types annotations proposal.

README.md Outdated Show resolved Hide resolved
@littledan
Copy link
Member

I think "No" leaves things confusing. Let's just leave this question out of the initial pass of the FAQ, and then we can work on adding text on this topic later.

@ljharb
Copy link
Member

ljharb commented Nov 27, 2023

That's also fine, but I'm not sure why a correct answer with elaboration after it would be confusing.

@bakkot
Copy link
Contributor

bakkot commented Nov 29, 2023

I like the wording @nicolo-ribaudo suggests above (with the leading "No"). I'm not sure how that leaves things confusing, but maybe it would help to make reference to the proposal in that first sentence?

No, although someday there may be syntax for writing out types which would be completely ignored by the runtime (but which could be checked by other tools).

Copy link
Member

@michaelficarra michaelficarra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like it as much as the original answer, but I have no problem with this.

@ctcpip
Copy link
Member

ctcpip commented Dec 5, 2023

may be pedantic, but JS does have a type system. should the question be something more along the lines of "will JS ever support static|strong typing"?

README.md Outdated Show resolved Hide resolved
@michaelficarra
Copy link
Member

@ctcpip Using that definition of a type system, there is no language (with more than one term) that doesn't "have a type system", making it meaningless. Let's not go down that rabbit hole. I support merging this PR as-is.

@ctcpip
Copy link
Member

ctcpip commented Dec 5, 2023

@michaelficarra either of the suggestions from Jordan or myself seem like improvements to me; I don't think there's any rabbit hole to go down

@sirisian
Copy link

sirisian commented Dec 9, 2023

No. Types that help the developer (such as those in TypeScript) are not the same types that would help the engine, so a built-in type-checking experience will always provide inferior guarantees compared to what the JavaScript ecosystem is used to.

That would make more sense for a question like:

Will JavaScript ever be identical to or evolve into TypeScript?

Which is actually a common question when people first learn about TypeScript as they read the phrase "TypeScript is a superset of JavaScript." I'd probably include wording like that. "While TypeScript is a superset of JavaScript, ..." and then explain the issues with that direction. (The Type Annotations FAQ has a few of them).

I'd then add the second question:

Will JavaScript ever get a run-time static type system?

This answer would then explain specifically why implementing "types that would help the engine" will not be included.

As someone that's followed this discussion for decades, it generally boils down to:

  • The parsing complexity currently is too demanding for low-end devices when parsing large web applications.
  • Implementation complexity is too high for engines. (I can't remember if this is related to mixing dynamic and static requiring a lot of run-time checks and potential code-paths).
  • Trying to add a full type system to JavaScript would be an enormous multi-year effort that would likely never reach consensus. (Taken from the Type Annotations FAQ). Additionally modifying any implemented syntax for all these systems can never break the web meaning the syntax must also be compatible with any future changes. A daunting task.
  • Even if it's optional, static typing could lead to conventions where developers type everything which is contentious.

This might be biased on my part as I maintain a long-term proposal on this topic, but I've been content with those kind of answers. There's probably more that can be included, but simply showing it's not viable for the present future is sufficient.

@ljharb
Copy link
Member

ljharb commented Dec 9, 2023

@sirisian that would be incorrect, as in no way is TS a superset of JS.

@bakkot
Copy link
Contributor

bakkot commented Dec 9, 2023

... TS is definitely a superset of JS? Every syntactically valid JS program is a syntactically valid TS program.

"TS programs with no type errors" is not a superset of JS programs, but that's a different claim.

@sirisian
Copy link

sirisian commented Dec 9, 2023

He might have meant my link was broken. The text was right, but I linked to subset by accident. Meant to link to: https://en.wikipedia.org/wiki/TypeScript which was where that quote is from.

@nicolo-ribaudo
Copy link
Member Author

TS is definitely a superset of JS? Every syntactically valid JS program is a syntactically valid TS program.

let a = b < c > (d)

Has completely different parsing and runtime semantics in JS and TS

@bakkot
Copy link
Contributor

bakkot commented Dec 9, 2023

Sorry, yes, modulo the edge case with generics. I didn't think that's what @ljharb meant, but maybe?

@ljharb
Copy link
Member

ljharb commented Dec 9, 2023

Yes, that’s what i meant - that edge case means it’s not a syntactic superset.

@bakkot
Copy link
Contributor

bakkot commented Dec 9, 2023

OK, well, I think describing it as "almost" a syntactic superset would convey the relevant information equally well, if we wanted to go down that route.

@ljharb
Copy link
Member

ljharb commented Dec 9, 2023

I don’t want to go down that route; i think the current state of the PR is ideal.

Copy link
Contributor

@bakkot bakkot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM. @nicolo-ribaudo @littledan does this work for you, or do you want the qualification I suggested above?

Copy link
Member

@ctcpip ctcpip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the additional text bakkot suggested, but good as is too.

@littledan
Copy link
Member

littledan commented Dec 11, 2023

I continue to think that starting the answer with "No" is confusing. I also disagree with the implication in the first sentence: the reason that a type system would be inferior is because we're not capable of making the sorts of evolving ad-hoc decisions that TS is, not because of engines, though it is true that the types wouldn't be useful for engines.

michaelficarra and others added 2 commits December 21, 2023 15:27
Co-authored-by: Nicolò Ribaudo <[email protected]>
Co-authored-by: Jordan Harband <[email protected]>
@michaelficarra
Copy link
Member

@littledan Do you have a concrete suggestion we could move forward with, then?

Copy link
Member

@jridgewell jridgewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I continue to think that starting the answer with "No" is confusing.

I agree.


[Disclaimer: FAQ answers are not endorsed by TC39][]

No. Types that help the developer (such as those in TypeScript) are not the same types that would help the engine, so a built-in type-checking experience will always provide inferior guarantees compared to what the JavaScript ecosystem is used to. The [type annotations](https://github.com/tc39/proposal-type-annotations) proposal is exploring parsing types with no runtime type-checking, which would be left to other tools.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
No. Types that help the developer (such as those in TypeScript) are not the same types that would help the engine, so a built-in type-checking experience will always provide inferior guarantees compared to what the JavaScript ecosystem is used to. The [type annotations](https://github.com/tc39/proposal-type-annotations) proposal is exploring parsing types with no runtime type-checking, which would be left to other tools.
Not a _full_ type system. Types that help the developer (such as those in TypeScript) are not the same types that would help the engine, so a built-in type-checking experience will always provide inferior guarantees compared to what the TypeScript ecosystem is used to. The [type annotations](https://github.com/tc39/proposal-type-annotations) proposal is exploring parsing types without enforcing them, leaving other tools to perform static and/or runtime checking.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WFM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to be consistent with the question, suggestion:

- _full_ type system
+ _full_ static type system

also can we generalize the language around statically typed supersets (Iinb4 'TS is not a superset') so we don't appear to be favoring any particular one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's "favoring any particular one" to use TypeScript as an example of what developers expect from a type system. Generalising the language would just make it less clear to the kind of reader we're targeting here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i completely agree with you on the first point, but it could give people the wrong impression. I think this is one reason why the annotations proposal uses language like "TypeScript, Flow, and other static typing supersets of JavaScript".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More importantly, @littledan what do you think about the suggested change here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not correct - it won't have any kind of static type system. That you can achieve one with external tools doesn't change that JavaScript will never have a static type system.

In other words, "No", full stop, is the only correct answer to this question.

Copy link
Member

@ctcpip ctcpip Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, yeah, you could argue Not a _full_ type system implies it could get some sort of static type system. and that's not what type annotations would be introducing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants