-
Notifications
You must be signed in to change notification settings - Fork 12.8k
disallow recursive references for block-scoped bindings #2309
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
Conversation
@@ -203,6 +203,33 @@ module ts { | |||
isCatchClauseVariableDeclaration(declaration); | |||
} | |||
|
|||
export function getEnclosingBlockScopeContainer(node: Node): Node { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did anything change here (can't tell cuz it moved)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, code was just moved from emitter to utilities
All TypeScript errors are effectively warnings since they never block emit |
@mihailik, your point is true of type errors as well, but we still report static errors for them. The idea is that we report an error on something if it will be an error when/if you get there. |
👍 |
disallow recursive references for block-scoped bindings
Let-recursivity is statically unknown in a general case, here's a very simple example: let x = someFunc() > 0.9 ? x : 10; For type errors the intention behind the code is very clear: type specification is a promise by the code writer. If it statically breaks, it's safe to point out a broken promise. For let-recursivity cases, it's not as clear what is intentional and what is not. And much worse, there is no syntax to silence the checker (for type checks you can always cast to < any >). |
Judging by the code and tests, the current behaviour is to report an error if That sounds a reasonable balance to limit false positives and false negatives to edge case minority. Being such a non-trivial error, it would be great to call out this validity check in the TS spec. |
Fixes #2188