-
Notifications
You must be signed in to change notification settings - Fork 62
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
Potential syntax alternative (postfix exclamation mark) #300
Comments
The problem with postfix operators is that JavaScript's syntax is english-based and thus read left-to-right Being an array or a tuple is a fundamental difference and it affects the array/tuple contents, so when reading the code you would have to:
|
I'm not sure if this is really critical in practice. How long is the average/median record/tuple? Sure, there will be some cases of long records/tuples. const proposal = {
id: 1234,
title: "Record & Tuple proposal",
contents: `...`,
// tuples are primitive types so you can put them in records:
keywords: ["ecma", "tc39", "proposal", "record", "tuple"]!,
}!; If you set one of the properties to an object, your IDE would alert you immediately (yes yes, not always using an IDE, code review, etc.). It's not a perfect solution, but it may be worth considering. The only other idea I had was a subtle change to the current const proposal = |{
id: 1234,
title: "Record & Tuple proposal",
contents: `...`,
// tuples are primitive types so you can put them in records:
keywords: |["ecma", "tc39", "proposal", "record", "tuple"],
}; Essentially, using the pipe symbol instead of using class Example {
#field = #{id: 1234}; 😕
@dec field = @{id: 1234}; 😕
} |
Postfix exclamation, besides the issues raised earlier, is pretty much a non starter for anything that wouldn't be a runtime non-nullish assertion, because of Typescript's own static non-null assertion operator that is used in the wild. |
To be clear - not because of compat, because TS doesn’t run natively anywhere on the web - but likely because of documentation and tutorials and the user confusion it’d cause. |
I covered that in the OP. You don't non-null assert a literal. |
It's used in the same places syntactically. The confusion to both humans and parsers would be tremendous. |
I'm not sure how this would confuse parsers. It would mean the same thing in both JavaScript and TypeScript when appended to an array/object literal. Humans could be slightly confused by the distinction. I wouldn't go as far as tremendously confused. 😄 Anyway, how about the |
Technically yes because of bitwise OR |
Bitwise OR requires two operands though? |
let x = y|[1,2,3].at(index); Is already valid syntax, which means the tokeniser can't emit |
I see. I thought that it could tokenize it differently depending on its position. Clearly I don't now enough about tokenization. 😝 From the current options, my preference is |
Since #10 is limited to 3 alternatives, has a postfix exclamation mark (
!
) been considered? (it's not easy to search for, so I apologize if it has)The text was updated successfully, but these errors were encountered: