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

strictNullChecks mode - Variable is used before being assigned. #10641

Closed
aliai opened this issue Aug 31, 2016 · 2 comments
Closed

strictNullChecks mode - Variable is used before being assigned. #10641

aliai opened this issue Aug 31, 2016 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@aliai
Copy link

aliai commented Aug 31, 2016

TypeScript Version: nightly (2.0.2)

In strictNullChecks mode only:

Code

const CONFIG = {
  foo: '',
  setFoo: function(foo: string) {
    // accessing (reading or writing) CONFIG.foo is not allowed!
    CONFIG.foo = foo;  // <-- Error: Variable 'CONFIG' is used before being assigned.
  }
};

Expected behavior:

I don't see why this is not a valid statement.

Actual behavior:

Trying to access any defined member of CONFIG in a method, defined within the object itself, raises an error: Variable 'CONFIG' is used before being assigned.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Aug 31, 2016
@mhegazy mhegazy added this to the TypeScript 2.0.3 milestone Aug 31, 2016
@yuit
Copy link
Contributor

yuit commented Sep 8, 2016

Slightly related the following will also issue similar error:

const helper = function<T>(t: T[]) {
        helper(t.slice(1));
}

@ahejlsberg
Copy link
Member

@yuit I have a fix for this, will be putting up a PR shortly.

@ahejlsberg ahejlsberg assigned ahejlsberg and unassigned yuit Sep 9, 2016
@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Sep 9, 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
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

5 participants