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

Example try expression in Typescript #48

Open
Arlen22 opened this issue Sep 19, 2024 · 2 comments
Open

Example try expression in Typescript #48

Arlen22 opened this issue Sep 19, 2024 · 2 comments

Comments

@Arlen22
Copy link

Arlen22 commented Sep 19, 2024

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...

npm install
npm run pack
npm pack

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.

@Arlen22
Copy link
Author

Arlen22 commented Sep 19, 2024

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.

@Arlen22
Copy link
Author

Arlen22 commented Sep 19, 2024

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.

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

No branches or pull requests

1 participant