Support 'throw' expressions
brn opened this issue · 11 comments
Support 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!') })();
}
Just to note, @rbuckton is closely aligned to the TypeScript team. I highly suspect this proposal would be implemented when everyone is comfortable it is in a stable enough position.
So is this proposal premature?
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. 😄
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.
@DanielRosenwasser @rbuckton
I got it.
Thank you for the detailed explanation!
The proposal is now in stage 2 - would be cool if this gets implemented in TypeScript.
TypeScript's current stance is that we will not adopt a proposed JavaScript feature until it has reached Stage 3. Currently, Stage 3 for throw
expressions is blocked from advancement due to overlap with the do
expressions proposal.
This is now in stage 3 :)
No, this has not yet advanced to Stage 3.
Closing since there's nothing for us to do but wait for TC39