Skip to content

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

Description

@aliai

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.

Activity

  1. yuit commented on Sep 8, 2016

    @yuit
    Contributor

    Slightly related the following will also issue similar error:

    const helper = function<T>(t: T[]) {
            helper(t.slice(1));
    }
  2. ahejlsberg commented on Sep 9, 2016

    @ahejlsberg
    Member

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

  3. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions