-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Ban old-style type assertions under erasableSyntaxOnly #61244
Ban old-style type assertions under erasableSyntaxOnly #61244
Conversation
you probably want to ban it in more places: // return and yield ASI
function *foo() {
yield <any>
1;
return <any>
1;
}
// at the start of an ExpressionStatement if followed by an object literal; though I'm not sure why one would use it there
<unknown>{foo() {}}.foo();
// at the start of an ExpressionStatement if followed by function keyword
<unknown>function() {}();
<unknown>function() {};
// at the start of an ExpressionStatement if followed by an anonymous class expression
// note that this exact syntax currently emits invalid JS (no parenthesis added like for function above)
<unknown>class {} there's probably more parsing ambiguity I cannot remember right now. |
Yeah, so that furthers my feeling that this syntax should be wholly banned in this mode. I tried to carve something out, but it sure doesn't seem like that's tractable if we want to ban something here. |
When I was first creating |
Updated the PR to just straight up ban the syntax. |
@typescript-bot cherry-pick this to release-5.8 |
Hey, @jakebailey! I've created #61320 for you. |
Code like
()=><any>{}
is not erasable, since()=> {}
is a different tree, and there's nowhere to add parens to the body without shifting its contents backwards one character. If there were extra spaces after the{}
, maybe it'd work, but that's atypical.This PR bans this specific case, though, I personally feel like banning the old-style assertions would be a good idea too.Updated the PR to just ban them. There are too may edge cases IMO.