-
Notifications
You must be signed in to change notification settings - Fork 12.8k
typeof operator fails on use-before-defined block scoped variable. #8775
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
Comments
Would this be a suitable bug for a first-timer? |
I imagine it will be pretty easy. There are lots of other places where we special-case use of an identifier inside a |
I don't think this is a special-casing of
I think the reason for the differences is the following lines in
Since the |
The runtime behavior is mostly irrelevant to how the type system can behave. There's not anything preventing us from figuring what's going on in a block like this let a: typeof b;
let b: string; |
My understanding of https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#3.8.10 is that the |
@RyanCavanaugh sorry if I'm misunderstanding the scope of this fix. But my interpretation of the spec leads me to conclude that this is the correct behavior (as I've explained above). And I wasn't sure a first-timer bug would involve changing the specification. |
@markwongsk just because the entity is being type-checked doesn't mean that TypeScript needs to consider it "used" before its definition in any manner that matters. Like Ryan mentioned, block scoping only matters when used in a value position, but when used as part of a type, there really isn't a reason to impose the restriction. At best, it seems like the spec leaves it unspecified from what I can see. |
TypeScript Version:
1.8.0
Code
Expected behavior:
The
let
definition should compile, since thetypeof
operator has no runtime effect.Actual behavior:
The
let
definition fails with a "used before declaration" error.The text was updated successfully, but these errors were encountered: