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

Closed
Swatinem opened this issue Sep 9, 2016 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@Swatinem
Copy link
Contributor

Swatinem commented Sep 9, 2016

TypeScript Version: 2.1.0-dev.20160909

Code

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

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

Duplicate #8476.

image

@Swatinem
Copy link
Contributor Author

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

No branches or pull requests

2 participants