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

Property assignment in functions called from constructor #24446

Closed
Ionaru opened this issue May 28, 2018 · 3 comments
Closed

Property assignment in functions called from constructor #24446

Ionaru opened this issue May 28, 2018 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@Ionaru
Copy link

Ionaru commented May 28, 2018

TypeScript Version: 3.0.0-dev.20180526

Search Terms:
Initializer nested function

Code

class Initializer {
    public testValue: string;

    constructor() {
        this.setValue();
    }

    public setValue() {
        this.testValue = 'A value';
    }
}

(Compile with strictNullChecks and strictPropertyInitialization enabled)

Expected behavior:
Code compiles because the testvalue property is always defined in a class instance. Even though it's not directly in the constructor.

Actual behavior:
Compiler gives the error:

src/initializer.ts:2:12 - error TS2564: Property 'testValue' has no initializer and is not definitely assigned in the constructor.

2     public testValue: string;
             ~~~~~~~~~

Playground Link:
Link to the playground
Enable strictNullChecks and strictPropertyInitialization

Related Issues:
I did not find any related issues.

@s-ve
Copy link

s-ve commented May 28, 2018

Seems to be a duplicate of #21132

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label May 29, 2018
@Ionaru
Copy link
Author

Ionaru commented May 29, 2018

I'd like to know if this is still a "design limitation" in Typescript 3

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented May 29, 2018

Yes; we have no immediate plans to do aggressive function inlining analysis to prevent/catch more class property initialization issues.

@microsoft microsoft locked and limited conversation to collaborators Jul 31, 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

3 participants