Skip to content

Check base type for special property declarations #23671

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

Merged
merged 1 commit into from
Apr 26, 2018

Conversation

sandersn
Copy link
Member

If the base type has a property by that name, add it to the list constructor types to make it as authoritative as special assignments found in the constructor.

Before this fix, in JS files with strict null checks on, classes would not check their base types for special declarations -- they would just use the special declarations they found in methods, which incorrectly adds undefined to the type. In the example, below, Derived would say that it incorrectly extends Base because p: number | undefined, when it clearly relies on Base to initialise p.

class Base {
    constructor() {
        this.p = 1
    }
}
class Derived extends Base {
    m() {
        this.p = 1
    }
}

Fixes #23628

If the base type has a property by that name, add it to the list
constructor types to make it as authoritative as special assignments
found in the constructor.
@sandersn sandersn requested a review from mhegazy April 24, 2018 22:54
@sandersn sandersn merged commit 1541599 into master Apr 26, 2018
@mhegazy mhegazy deleted the js/fix-inherited-property-type branch April 26, 2018 16:22
@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In JS, property in derived class has wrong type with strict null checks on
2 participants