Skip to content

Missing error on class extending union of incompatible constructor types #42213

@ajafff

Description

@ajafff

TypeScript Version: 4.2.0-dev.20210105, worked in v3.6.3, regressed in v3.7

Search Terms: is not a constructor function type

Expected behavior:

Error: Type 'typeof Base | typeof Base2' is not a constructor function type.
Or super should not be inferred as any.

Actual behavior:

No error and super: any

Related Issues:

Code

class Base {
    prop = 1;
}

class Base2 {
    other = 1;
}

const base = Boolean() ? Base : Base2;

class Derived extends base { // ExpressionWithTypeArguments is inferred as 'any', expected error "Type 'typeof Base | typeof Base2' is not a constructor function type."
    static fn() {
        super.wargarbl.wat; // super is inferred as 'any'
    }
    fn() {
        super.wargarbl.wat; // super is inferred as 'any'
    }
}
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2017",
    "jsx": "React",
    "module": "ESNext"
  }
}

Playground Link: Provided

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: classesBehavior of various `class` constructs, e.g. mixins or base classes

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions