Skip to content

No "Block-scoped variable '...' used before its declaration." error for earlier function call #17653

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

Closed
donaldpipowitch opened this issue Aug 7, 2017 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@donaldpipowitch
Copy link
Contributor

TypeScript Version: Playground (2.3.4?)

Code

class Bar {
    constructor() {
        console.log(foo); // BUG: no error
    }
}
const bar = new Bar();

function Bar2() {
    console.log(foo); // BUG: no error
}
const bar2 = new Bar2();

function bar3() {
    console.log(foo); // BUG: no error
}
bar3();

console.log(foo); // error is thrown

const foo = 2;

Expected behavior:

"Block-scoped variable 'foo' used before its declaration." error for the three cases mentioned in the code example.

I don't know if this is out of scope for TypeScript, but maybe flow analysis could catch very simple cases like this:

function bar() {
    console.log(foo);
}
bar();

const foo = 2;

Actual behavior:

No "Block-scoped variable 'foo' used before its declaration." error for the three cases mentioned in the code example.

@RyanCavanaugh
Copy link
Member

Duplicate of #13320

@RyanCavanaugh RyanCavanaugh marked this as a duplicate of #13320 Aug 7, 2017
@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 7, 2017
@donaldpipowitch
Copy link
Contributor Author

donaldpipowitch commented Aug 8, 2017

I see, thanks. Well #13320 was closed because

Correctly detecting this in all cases would require all function calls to trace out their call graphs, which would be pretty expensive relative to the number of bugs we'd actually detect.

I don't know how expensive it would be to detect some cases for some function calls? I actually stumbled over this when I re-ordered functions inside one file with no complex code.

Feel free to close this, if you think its too expensive anyway :)

@mhegazy
Copy link
Contributor

mhegazy commented Aug 22, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Aug 22, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants