Support 'throw' expressions
See original GitHub issueSupport proposal-throw-expressions.
That proposal is now stage-1, but worth to implements for convenience and this proposal not break backward-compatibilities.
Current
ts
const errorThrowExp = () => { throw new Error('Error!'); }
function errorThrowFn(maybeTrue) {
if (maybeTrue){
return ...;
} else {
throw new Error('Error!');
}
}
js
const errorThrowExp = function() {throw new Error('Error!')}
function errorThrowFn(maybeTrue) {
if (maybeTrue){
return ...;
} else {
throw new Error('Error!');
}
}
Proposal
ts
const errorThrower = () => throw new Error('Error!');
function errorThrowFn(maybeTrue: boolean) {
return maybeTrue? ...: throw new Error('Error!');
}
js
const errorThrower = function() { throw new Error('Error!'); }
function errorThrowFn(maybeTrue: boolean) {
return maybeTrue? ...: (function() { throw new Error('Error!') })();
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:10 (7 by maintainers)
Top Results From Across the Web
babel/plugin-syntax-throw-expressions
Syntax only. It's unlikely you want to use this plugin directly as it only enables Babel to parse this syntax.
Read more >C# 7.0 and 7.1 support in ReSharper – Throw expressions
Throw expressions allow us to throw exceptions from almost any expression, making our code more concise and readable. ReSharper adds inspections ...
Read more >@babel/plugin-syntax-throw-expressions - npm
Allow parsing of Throw Expressions. Latest version: 7.18.6, last published: 6 months ago. Start using @babel/plugin-syntax-throw-expressions ...
Read more >Using throw expressions - C# 7.0 - Gunnar Peipman
Throw expressions are here to help us write smaller code and use exceptions in expression-bodied members. It is just a language feature and...
Read more >throw expression - cppreference.com
throw expression ... Concurrency support library (C++11) ... 1) First, copy-initializes the exception object from expression ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://github.com/Microsoft/TypeScript/tree/throwOperator?files=1
Currently it does not yet support unreachability checks at the expression level. Also, I am waiting for the next TC39 meeting to see if the proposal moves to Stage 2.
Nope, it’s fine to track it here. Like @kitsonk said, @rbuckton is championing it and is part of our team, but we will need it to reach a later stage before adopting it in TypeScript.
For what it’s worth, I’d be willing to bet he has a branch with an implementation of
throw
-expressions. 😄