-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Example try expression in Typescript #48
Comments
The details are basically that when it encounters the try keyword, it first tries to parse it as a statement, then as an expression, unless it's already in an expression context, in which case it parses it as an expression (curly braces become objects). I'm not sure I like that last part. I think curly braces should be an error unless they are surrounded by parentheses. But this sounds like all the other edge cases we're debating here, and a simple predictable language is better than one with random guarded edges. That's more what linters are for. But it could be a source of unending confusion in this case, so it might be a good idea. I haven't tested any unusual parts of Javascript yet, like using or for loops. |
For actual implementation in TypeScript, I think this should be converted to a self-executing function that returns the appropriate values. It's pretty standard for various syntax types to be converted into helper functions until they are implemented in Javascript. I'll probably do that sometime in this example. |
@arthurfiorette well, technically the parsing would still work. You'd have to edit the Result type. But I copied the code for the await and yield keywords, so it's valid for all expressions, not just the assignment expression. If I was going to do it again for the new proposal, I'd do it as a modifier of the assignment operator. |
I've updated the current Typescript to include this operator as a passthrough (as though it's implemented in Javascript) so we can play around with examples a bit.
https://github.com/Arlen22/TypeScript - main branch
I basically just implemented it as an expression operator, based off void and await.
To try it, clone the repo, run the following...
then npm install the output file in an example project. If you're using vscode you can change the tsserver location to get intellisense as well.
The text was updated successfully, but these errors were encountered: