Skip to content
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

Control flow analysis for implicit any and array initialization works only when --noImplicitAny is on #13779

Closed
zhuravlik opened this issue Jan 31, 2017 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@zhuravlik
Copy link

TypeScript Version: 2.1.1 / 2.2.0 nightly (current master)

As far as I understood from both #11263 and #11432, control flow analysis for implicit any and array initialization shouldn't be limited to the case when --noImplicitAny is enabled.

But currently it works only if --noImplicitAny is on.
If --noImplicitAny is off, variables are treated as 'any', and arrays are treated as 'any[]', after all the initializations.

function foo(flag: boolean) {
let a;
if (flag)
   a = 5;
else
  a = true;

a; // if --noImplicitAny is on, it is 'number | boolean', otherwise, it is 'any'
}

Is it an expected behavior, or should CFA for implicit any and array initialization work regardless of the state of --noImplicitAny flag?

@mhegazy
Copy link
Contributor

mhegazy commented Jan 31, 2017

Is it an expected behavior, or should CFA for implicit any and array initialization work regardless of the state of --noImplicitAny flag?

this is an intentional decision to limit the analysis to --noImplicitAny flag users. the rational is it is not a breaking change for --noImplicitAny users, who were getting errors on the original declaration, it is rather an enhancement to the the experience, i.e. less errors if the compiler can figure it out. Doing it for all users would have been a breaking change.

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jan 31, 2017
@zhuravlik
Copy link
Author

Thanks a lot for the explanation!

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants