-
Notifications
You must be signed in to change notification settings - Fork 28
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
Suggestion: compact notation for an array of string literals #742
Comments
Neat idea! Some random thoughts:
|
Another fun thing we could do is transpile Another way to write this today would be |
True, and I guess you could type ssv so
would get the literal type Another random syntax possibility:
I'm not saying any of the suggested syntaxes are perfect, but some seem plausibly acceptable. This one is the most compact I've thought of that is currently a parse error and therefore potentially up for grabs. |
By the way, it's perhaps useful to reflect on other languages that have this feature:
Inspired by your last idea, I wonder about this syntax: []`skeleton ${key} x${key} ${...more}` → ["skeleton", key, `x${key}`, ...more] (though perhaps I'm getting carried away) |
I am actually pretty comfortable with
I think it's pretty suggestive of "make this literal into an array in the most obvious way". Covers my typical use case pretty nicely. I suppose to avoid the specialness of breaking on whitespace, making it just a default, it could be nice to allow e.g.,
Or maybe better
So that
really just becomes syntactic sugar for
with a new default of |
Nice, I like that generalization! I think the default should be []`
option1
option2
option3
` |
Well actually, I spoke too soon. I was going to contribute to this discussion some working correctly-typed code for ssv (that would split on
mostly because I would use it anyway and possibly it could provide a compilation target for
But then I ran into microsoft/TypeScript#33304. (And very gratifyingly/amusingly one of the comments on that issue is someone explicitly trying to produce a tagged template replicating ruby Oops, who knew? So I have given up on this micro-project for the time being. But in some sense it would make it even more useful/cool if Civet did implement this latest []-template literal notation as just above, which I get the sense the two of you like best from the options floated here, in a type-safe way today. |
P.S. About the meaning of interpolation in
I personally think that since the usual backticks just deal in strings so this feels "stringy" and feels mostly about literal arrays of literal strings, this syntax should just operate on the string level and so the above should precisely mean
with the caveat of when foo is absent there's the special-case behavior of splitting on Moreover, I would suggest it is fine to type as
|
@edemaine @gwhitney @STRd6 +1 vote for this! I use |
It's not that uncommon that I want a list of allowed keys or something like that. So not too infrequently I find myself writing
which looks a bit goofy, but it's significantly pleasanter to type than
because of all those pinky and ring-finger keystrokes.
LiveScript had a compact notation for this, I think it was
I don't love the
<[ ... ]>
as it looks sort of JSX-y, but I do think a compact notation for arrays of literal strings that don't contain whitespace would be pleasant/handy.Brainstorming some options:
Anyhow, just a thought.
The text was updated successfully, but these errors were encountered: