Skip to content

Private non-nullable fields can still be null after construction (strictnullchecks) #12273

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
shand-obs opened this issue Nov 15, 2016 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@shand-obs
Copy link

TypeScript Version: 2.1.1 & nightly (2.2.0-dev.20161115)

Code

class TestStrictNullChecks {
    public test() {
        var x = 0;
        var y = this.notNullable + x; // notNullable is undefined

        console.log(y);
    }

    private notNullable: number; // ERROR: with strictNullChecks, should be required initialized on construction (inline or in ctor)
}

const testObject = new TestStrictNullChecks();
testObject.test();

Expected behavior:
tsc should error, either on class definition or on object construction; _notNullable cannot be undefined or null.

Actual behavior:
tsc succeeds; NaN is output in console.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 15, 2016
@RyanCavanaugh
Copy link
Member

Duplicate of #8476 and many others. Please search before logging a new issue.

@shand-obs
Copy link
Author

shand-obs commented Nov 15, 2016

Honestly, I spent 20 minutes searching for a duplicate issue before posting. The trouble is that the default search criteria restricts to open bugs. It didn't occur to me to search for closed bugs, because to us it's not closed. I tested in both the 2.1 RC and the 2.2@next daily. Next time I will expand my search to include closed bugs.

@shand-obs
Copy link
Author

shand-obs commented Nov 15, 2016

I added my comment to #8476. Please re-open. This issue is definitely not resolved.

@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants