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

Inform about useDefineForClassFields breaking change in TS >=4.3 #292

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rangoo94
Copy link

@rangoo94 rangoo94 commented Feb 9, 2022

While I've been upgrading the TypeScript, I encountered multiple strange issues, related to abstract classes. It took me a while to detect what was the problems reason, as I haven't found in any notes information about useDefineForClassFields option.

It's changing the default behaviour, which may easily break the existing code. I added simplest example as possible in this PR, as I felt that my specific example may be too specific, while this simplified example may help to identify issue anyway.

The exact problem I encountered:

abstract class Parent {
    public constructor() {
        this.run();
    }

    protected abstract run(): void;
}

class Child extends Parent {
    public value!: string;

    protected run() {
        this.value = "test value";
    }
}

console.log(new Child().value);
// for `useDefineForClassFields: false` -> "test value"
// for `useDefineForClassFields: true`  -> undefined

Took me a while to detect the culprit, so I think that it's worth to add information about that to documentation, so it will reduce problems with migration.

@ghost
Copy link

ghost commented Feb 9, 2022

CLA assistant check
All CLA requirements met.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant