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

No error when using uninitialized value in noImplicitAny & strictNullChecks mode #12002

Closed
DanielRosenwasser opened this issue Nov 2, 2016 · 2 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Nov 2, 2016

From master as of right now (7b34b612beda66b0812462a3feeabc63852cd842)

var x;
var y = 100 + x;

Compile with strictNullChecks and noImplicitAny

Expected: Some sort of error for using x.
Actual: No error at all?

@DanielRosenwasser DanielRosenwasser added the Bug A bug in TypeScript label Nov 2, 2016
@ahejlsberg
Copy link
Member

This is actually by design. Your var x is an implicit any variable that is tracked by control flow analysis (#11263). Because it hasn't been initialized, its control flow type in the 100 + x expression is undefined, and the + operator permits undefined as an operand value. If anything, we should discuss whether the numeric operators should be stricter with respect to undefined and null, but that's a different discussion.

@DanielRosenwasser
Copy link
Member Author

Sure, that issue definitely sounds like something we should look into; is the type of x still going to be undefined under noImplicitAny?

@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label Nov 3, 2016
@mhegazy mhegazy removed the Bug A bug in TypeScript label Dec 7, 2016
@mhegazy mhegazy closed this as completed Dec 7, 2016
@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

3 participants