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


Duplicate #8476.


Swatinem commented Sep 9, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment