Skip to content

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

Open
rangoo94 wants to merge 1 commit intomicrosoft:mainfrom
rangoo94:add-information-about-breaking-change-usedefineforclassfields
Open

Inform about useDefineForClassFields breaking change in TS >=4.3#292
rangoo94 wants to merge 1 commit intomicrosoft:mainfrom
rangoo94:add-information-about-breaking-change-usedefineforclassfields

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.

1 participant