Skip to content

error TS2612 Property will overwrite base property not raised if "strictNullCheck" is true #48667

Closed
@amodiopescefaro

Description

@amodiopescefaro

Bug Report

If you enable useDefineForClassFields then a new error is possible TS26126

If you have code that trigger TS2612 Property 'xxx' will overwrite the base propert in 'yyy'. It this is intentional, add an initializer. Othertwise, add a "declare" modifier or remove the redundant declaration.

The error do not appear if you enable strictNullCheck.

Without strictNullCheck you'll see this error.

If you put strict=true or strictNullCheck=true the error is not reported anymore

🔎 Search Terms

TS2612
strictNullCheck

🕗 Version & Regression Information

Noticed this on typescript 4.6.3
Tested on typescript@nightly 4.7.0-dev.20220408 and it behave the same (no error on strict mode)
Tested on 4.3.5 and it behave the same (no error on strict mode)

TS2612 was introduced in 4.3 so previous version do not make sense

⏯ Playground Link

This link contain a minimal code to show the problem but you need to enable/disable strictNullCheck and useDefineForClassFields to see it in action

Playground link with relevant code

💻 Code

type Base = {
    base: string;
};

type Derived = Base & {
    derived: string;
}

class A {
    prop: Base;

    constructor(prop?: Base) {
        this.prop = prop ?? { base: "base" };
    }
}

class B extends A {
    // This should trigger TS2612 but does not do it with strictNullCheck enabled
    prop: Derived;

    constructor(prop: Derived) {
        super();
        this.prop = prop;
    }
}

🙁 Actual behavior

When compiled with:

  • target - esnext
  • useDefineConfigForClass - true
  • strictNullCheck - true

the code does not raise any error

🙂 Expected behavior

It should raise the TS2612 error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions