-
Notifications
You must be signed in to change notification settings - Fork 23
Conversation
Follows the conclusion of the discussion at tc39/proposal-optional-chaining#34
Note the parallel change for optional chaining at tc39/proposal-optional-chaining#48 . |
Too many
PS. Compare to my syntax suggestion:
|
Using |
@ljharb As I said before, TS already use |
@hax existing meanings in JS, and other languages. That TS chose that meaning does not mean it's idiomatic for JS, nor that it would be consistent with non-JS non-TS languages. Separately, "assertion" usually means "throws if it fails" - which is the opposite of with optional chaining does. |
@ljharb If this is a widely used feature in TypeScript, it could be a real problem for adoption here, which we could avoid with the strategy in this PR. This isn't the only language community where grammar intersection with different languages comes up; for example, C++ has to worry about Objective-C grammar when considering its evolution. |
@littledan makes complete sense; i'm mostly trying to argue that |
@ljharb And if you not consider TS idioms, why consider Ruby/Rails or any other languages which more far from JS?
|
From the (hypothetical) perspective of someone who's learning JavaScript after coming from another language, I would think that
In the case of TypeScript, I would think most find themselves following the path: so there is a kind of difference, in my opinion. Further, (if perhaps more controversial)TypeScript is a superset of JavaScript so in the case of the two doubly-implementing the same feature (but with different syntax) I would think it's more logical for TypeScript to eventually deprecate said feature in a breaking update. |
I'm not sure if it's feasible for TypeScript to make breaking updates these days. cc @rbuckton @DanielRosenwasser |
@ScottRudiger
IMO, it begin at the wrong end to consider the new comers from Ruby/Rails prior to the core users from TS. NOTE: all TS users are actually JS heavy users! |
To start off, I'd like to clarify - TypeScript's postfix But apart from that, I have to agree that I don't feel the |
@DanielRosenwasser @littledan About repurpose To recap: change non-null assertion to Anyway, in this thread I just want to argue the problem of differentiating |
It's definitely a breaking change. 😄 For example, changing the semantics to null-propagation means that you could absolutely introduce a type error under in the expression Just to clarify, consider the following: declare let a: null | {
b: {
c: number
}
};
// Non-null assertion: has type `number`
a!.b.c;
// Rough equivalent of the null-propagation `a?.b.c`; is a type error
(a != null ? a.b : a).c; |
@DanielRosenwasser That's what I mean "not very breaking". (Forgive my poor english if I express the wrong meaning) And, it's very easy to migrate old |
I do not like these changes. Can someone summarise the problem with the current syntax? |
@0rvar This change is required if tc39/proposal-optional-chaining#48 is adopted, because otherwise |
Closing per #23 (comment) |
Follows the conclusion of the discussion at
tc39/proposal-optional-chaining#34