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 does not ensure class properties are initialized in constructor #10827

Swatinem opened this Issue Sep 9, 2016 · 2 comments


None yet
2 participants

Swatinem commented Sep 9, 2016

TypeScript Version: 2.1.0-dev.20160909


class A {
    prop: string;

const a = new A();
a.prop.length; // TypeError: Cannot read property 'length' of undefined

Expected behavior:

TS should throw a compile time error to ensure that non-nullable class members are initialized inside the constructor and can not lead to runtime errors.

Actual behavior:

No compile time error, rather an exception at runtime


This comment has been minimized.


RyanCavanaugh commented Sep 9, 2016

Duplicate #8476.



This comment has been minimized.

Swatinem commented Sep 9, 2016

Thanks for reminding me. Default search is set to is: open though -_-

@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.